diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2017-02-22 20:35:39 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2017-03-06 14:43:34 +0000 |
commit | 9a1b163e1fdd99a838c082805c687205b766da25 (patch) | |
tree | c9ce4b7fc05d93280628043c98c4e24b5c34e901 /src/plugins/sensors/generic/generictiltsensor.cpp | |
parent | bd1e063980355c82bb20af81a826a2860248ce6a (diff) | |
download | qtsensors-9a1b163e1fdd99a838c082805c687205b766da25.tar.gz |
Use qRadiansToDegrees() and qDegreesToRadians() more widely
They document intent more clearly than arithmetic with pi does.
Also eliminate some hand-rolled RADIANS_TO_DEGREES constants in
favor of calling qRadiansToDegrees().
Change-Id: I7ca5e876b3591433bf681b56ad51c4cb409ac59f
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src/plugins/sensors/generic/generictiltsensor.cpp')
-rw-r--r-- | src/plugins/sensors/generic/generictiltsensor.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp index 831b03e..a4ada7d 100644 --- a/src/plugins/sensors/generic/generictiltsensor.cpp +++ b/src/plugins/sensors/generic/generictiltsensor.cpp @@ -39,14 +39,13 @@ #include "generictiltsensor.h" #include <QDebug> -#define _USE_MATH_DEFINES #include <qmath.h> char const * const GenericTiltSensor::id("generic.tilt"); GenericTiltSensor::GenericTiltSensor(QSensor *sensor) : QSensorBackend(sensor) - , radAccuracy(M_PI / 180) + , radAccuracy(qDegreesToRadians(qreal(1))) , pitch(0) , roll(0) , calibratedPitch(0) @@ -106,11 +105,6 @@ void GenericTiltSensor::calibrate() calibratedRoll = roll; } -static qreal rad2deg(qreal rad) -{ - return rad / (2 * M_PI) * 360; -} - bool GenericTiltSensor::filter(QAccelerometerReading *reading) { /* @@ -159,18 +153,18 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading) qDebug() << "new yrot: " << yrot; qDebug() << "----------------------------------"; #endif - qreal dxrot = rad2deg(xrot) - xRotation; - qreal dyrot = rad2deg(yrot) - yRotation; + qreal dxrot = qRadiansToDegrees(xrot) - xRotation; + qreal dyrot = qRadiansToDegrees(yrot) - yRotation; if (dxrot < 0) dxrot = -dxrot; if (dyrot < 0) dyrot = -dyrot; bool setNewReading = false; - if (dxrot >= rad2deg(radAccuracy) || !sensor()->skipDuplicates()) { - xRotation = rad2deg(xrot); + if (dxrot >= qRadiansToDegrees(radAccuracy) || !sensor()->skipDuplicates()) { + xRotation = qRadiansToDegrees(xrot); setNewReading = true; } - if (dyrot >= rad2deg(radAccuracy) || !sensor()->skipDuplicates()) { - yRotation = rad2deg(yrot); + if (dyrot >= qRadiansToDegrees(radAccuracy) || !sensor()->skipDuplicates()) { + yRotation = qRadiansToDegrees(yrot); setNewReading = true; } |