From 72338c12bc98ac1ad139436bedd422d61dd68291 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 8 Sep 2021 09:32:26 +0200 Subject: Use qmath.h's conversions between degrees and radians The make the semantics overt and avoid the joys of yet another approximation to pi/180 hard-coded in our source-code. Change-Id: I9dcbaada2e7de119e385fc7056bc601ecd59311a Reviewed-by: Shawn Rutledge --- src/gui/painting/qtransform.cpp | 5 ++--- src/plugins/platforms/ios/quiview.mm | 7 ++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index 7d057732c7..6e3adb6702 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtGui module of the Qt Toolkit. @@ -569,7 +569,6 @@ QTransform & QTransform::shear(qreal sh, qreal sv) return *this; } -const qreal deg2rad = qreal(0.017453292519943295769); // pi/180 const qreal inv_dist_to_plane = 1. / 1024.; /*! @@ -606,7 +605,7 @@ QTransform & QTransform::rotate(qreal a, Qt::Axis axis) else if (a == 180.) cosa = -1.; else{ - qreal b = deg2rad*a; // convert to radians + qreal b = qDegreesToRadians(a); sina = qSin(b); // fast and convenient cosa = qCos(b); } diff --git a/src/plugins/platforms/ios/quiview.mm b/src/plugins/platforms/ios/quiview.mm index c7f94cc707..ef6c9f49ad 100644 --- a/src/plugins/platforms/ios/quiview.mm +++ b/src/plugins/platforms/ios/quiview.mm @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. @@ -50,6 +50,7 @@ #include "qiosmenu.h" #endif +#include #include #include #include @@ -388,10 +389,10 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") // azimuth unit vector: +x to the right, +y going downwards CGVector azimuth = [cTouch azimuthUnitVectorInView: self]; // azimuthAngle given in radians, zero when the stylus points towards +x axis; converted to degrees with 0 pointing straight up - qreal azimuthAngle = [cTouch azimuthAngleInView: self] * 180 / M_PI + 90; + qreal azimuthAngle = qRadiansToDegrees([cTouch azimuthAngleInView: self]) + 90; // altitudeAngle given in radians, pi / 2 is with the stylus perpendicular to the iPad, smaller values mean more tilted, but never negative. // Convert to degrees with zero being perpendicular. - qreal altitudeAngle = 90 - cTouch.altitudeAngle * 180 / M_PI; + qreal altitudeAngle = 90 - qRadiansToDegrees(cTouch.altitudeAngle); qCDebug(lcQpaTablet) << i << ":" << timeStamp << localViewPosition << pressure << state << "azimuth" << azimuth.dx << azimuth.dy << "angle" << azimuthAngle << "altitude" << cTouch.altitudeAngle << "xTilt" << qBound(-60.0, altitudeAngle * azimuth.dx, 60.0) << "yTilt" << qBound(-60.0, altitudeAngle * azimuth.dy, 60.0); -- cgit v1.2.3