diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2017-02-21 17:14:37 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2017-07-05 10:15:34 +0000 |
commit | 8095c33bcddefebd16b7cb08b07690caf877f600 (patch) | |
tree | 816731835b77eb798295c4324f95b23f9916ebef /src/plugins | |
parent | 827e53540c8de10f3a0b8548523ca80bf9e1c75b (diff) |
Use qRadiansToDegrees() and qDegreesToRadians() more widely
Especially in examples, where we should show off our convenience
functions, prefer calling these functions over doing arithmetic with
M_PI (or approximations thereto) and 180 (give or take simple
factors). This incidentally documents what's going on, just by the
name of the function used (and reveals at least one place where
variables were misnamed; the return from atan is in radians, *not*
degrees).
Task-number: QTBUG-58083
Change-Id: I6e5d66721cafab423378f970af525400423e971e
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/generic/tuiotouch/qtuiohandler.cpp | 2 | ||||
-rw-r--r-- | src/plugins/platforms/android/androidjniinput.cpp | 3 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowstabletsupport.cpp | 8 |
3 files changed, 7 insertions, 6 deletions
diff --git a/src/plugins/generic/tuiotouch/qtuiohandler.cpp b/src/plugins/generic/tuiotouch/qtuiohandler.cpp index ac410b7415..bb18ba5085 100644 --- a/src/plugins/generic/tuiotouch/qtuiohandler.cpp +++ b/src/plugins/generic/tuiotouch/qtuiohandler.cpp @@ -523,7 +523,7 @@ QWindowSystemInterface::TouchPoint QTuioHandler::tokenToTouchPoint(const QTuioTo QPointF delta = relPos - relPos.toPoint(); tp.area.moveCenter(win->mapToGlobal(relPos.toPoint()) + delta); tp.velocity = QVector2D(win->size().width() * tc.vx(), win->size().height() * tc.vy()); - tp.rotation = tc.angle() * 180.0 / M_PI; // convert radians to degrees + tp.rotation = qRadiansToDegrees(tc.angle()); return tp; } diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp index ef95b80dd4..75cffe3854 100644 --- a/src/plugins/platforms/android/androidjniinput.cpp +++ b/src/plugins/platforms/android/androidjniinput.cpp @@ -50,6 +50,7 @@ #include <QGuiApplication> #include <QDebug> +#include <QtMath> QT_BEGIN_NAMESPACE @@ -251,7 +252,7 @@ namespace QtAndroidInput QWindowSystemInterface::TouchPoint touchPoint; touchPoint.id = id; touchPoint.pressure = pressure; - touchPoint.rotation = rotation * 180 / M_PI; + touchPoint.rotation = qRadiansToDegrees(rotation); touchPoint.normalPosition = QPointF(double(x / dw), double(y / dh)); touchPoint.state = state; touchPoint.area = QRectF(x - double(minor), diff --git a/src/plugins/platforms/windows/qwindowstabletsupport.cpp b/src/plugins/platforms/windows/qwindowstabletsupport.cpp index 7e1017426f..299497a35b 100644 --- a/src/plugins/platforms/windows/qwindowstabletsupport.cpp +++ b/src/plugins/platforms/windows/qwindowstabletsupport.cpp @@ -463,13 +463,13 @@ bool QWindowsTabletSupport::translateTabletPacketEvent() // Z = sin(altitude) // X Tilt = arctan(X / Z) // Y Tilt = arctan(Y / Z) - const double radAzim = (packet.pkOrientation.orAzimuth / 10.0) * (M_PI / 180); - const double tanAlt = std::tan((std::abs(packet.pkOrientation.orAltitude / 10.0)) * (M_PI / 180)); + const double radAzim = qDegreesToRadians(packet.pkOrientation.orAzimuth / 10.0); + const double tanAlt = std::tan(qDegreesToRadians(std::abs(packet.pkOrientation.orAltitude / 10.0))); const double degX = std::atan(std::sin(radAzim) / tanAlt); const double degY = std::atan(std::cos(radAzim) / tanAlt); - tiltX = int(degX * (180 / M_PI)); - tiltY = int(-degY * (180 / M_PI)); + tiltX = int(qRadiansToDegrees(degX)); + tiltY = int(qRadiansToDegrees(-degY)); rotation = 360.0 - (packet.pkOrientation.orTwist / 10.0); if (rotation > 180.0) rotation -= 360.0; |