From 9a1b163e1fdd99a838c082805c687205b766da25 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 22 Feb 2017 20:35:39 +0100 Subject: 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 --- src/plugins/sensors/generic/genericrotationsensor.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/plugins/sensors/generic/genericrotationsensor.cpp') diff --git a/src/plugins/sensors/generic/genericrotationsensor.cpp b/src/plugins/sensors/generic/genericrotationsensor.cpp index adf28e43..40768297 100644 --- a/src/plugins/sensors/generic/genericrotationsensor.cpp +++ b/src/plugins/sensors/generic/genericrotationsensor.cpp @@ -41,8 +41,6 @@ #include #include -#define RADIANS_TO_DEGREES 57.2957795 - char const * const genericrotationsensor::id("generic.rotation"); genericrotationsensor::genericrotationsensor(QSensor *sensor) @@ -88,8 +86,8 @@ bool genericrotationsensor::filter(QSensorReading *reading) // Note that the formula used come from this document: // http://www.freescale.com/files/sensors/doc/app_note/AN3461.pdf - pitch = qAtan(y / qSqrt(x*x + z*z)) * RADIANS_TO_DEGREES; - roll = qAtan(x / qSqrt(y*y + z*z)) * RADIANS_TO_DEGREES; + pitch = qRadiansToDegrees(qAtan(y / qSqrt(x * x + z * z))); + roll = qRadiansToDegrees(qAtan(x / qSqrt(y * y + z * z))); // Roll is a left-handed rotation but we need right-handed rotation roll = -roll; @@ -98,7 +96,7 @@ bool genericrotationsensor::filter(QSensorReading *reading) // Note that theta is defined as the angle of the Z axis relative // to gravity (see referenced document). It's negative when the // face of the device points downward. - qreal theta = qAtan(qSqrt(x*x + y*y) / z) * RADIANS_TO_DEGREES; + qreal theta = qRadiansToDegrees(qAtan(qSqrt(x * x + y * y) / z)); if (theta < 0) { if (roll > 0) roll = 180 - roll; -- cgit v1.2.3