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 /examples/dbus | |
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 'examples/dbus')
-rw-r--r-- | examples/dbus/remotecontrolledcar/car/car.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/examples/dbus/remotecontrolledcar/car/car.cpp b/examples/dbus/remotecontrolledcar/car/car.cpp index 67daac79ba..2de4e6447a 100644 --- a/examples/dbus/remotecontrolledcar/car/car.cpp +++ b/examples/dbus/remotecontrolledcar/car/car.cpp @@ -50,9 +50,7 @@ #include "car.h" #include <QtWidgets/QtWidgets> -#include <math.h> - -static const double Pi = 3.14159265358979323846264338327950288419717; +#include <qmath.h> QRectF Car::boundingRect() const { @@ -135,10 +133,10 @@ void Car::timerEvent(QTimerEvent *event) Q_UNUSED(event); const qreal axelDistance = 54; - qreal wheelsAngleRads = (wheelsAngle * Pi) / 180; + qreal wheelsAngleRads = qDegreesToRadians(wheelsAngle); qreal turnDistance = ::cos(wheelsAngleRads) * axelDistance * 2; qreal turnRateRads = wheelsAngleRads / turnDistance; // rough estimate - qreal turnRate = (turnRateRads * 180) / Pi; + qreal turnRate = qRadiansToDegrees(turnRateRads); qreal rotation = speed * turnRate; setTransform(QTransform().rotate(rotation), true); |