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/gui | |
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/gui')
-rw-r--r-- | src/gui/math3d/qmatrix4x4.cpp | 6 | ||||
-rw-r--r-- | src/gui/math3d/qquaternion.cpp | 4 | ||||
-rw-r--r-- | src/gui/text/qdistancefield.cpp | 2 |
3 files changed, 6 insertions, 6 deletions
diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index 6b18e1ab03..d016f07522 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -1128,7 +1128,7 @@ void QMatrix4x4::rotate(float angle, float x, float y, float z) s = 0.0f; c = -1.0f; } else { - float a = angle * M_PI / 180.0f; + float a = qDegreesToRadians(angle); c = std::cos(a); s = std::sin(a); } @@ -1237,7 +1237,7 @@ void QMatrix4x4::projectedRotate(float angle, float x, float y, float z) s = 0.0f; c = -1.0f; } else { - float a = angle * M_PI / 180.0f; + float a = qDegreesToRadians(angle); c = std::cos(a); s = std::sin(a); } @@ -1496,7 +1496,7 @@ void QMatrix4x4::perspective(float verticalAngle, float aspectRatio, float nearP // Construct the projection. QMatrix4x4 m(1); - float radians = (verticalAngle / 2.0f) * M_PI / 180.0f; + float radians = qDegreesToRadians(verticalAngle / 2.0f); float sine = std::sin(radians); if (sine == 0.0f) return; diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp index e3262c8830..fe1b0425a8 100644 --- a/src/gui/math3d/qquaternion.cpp +++ b/src/gui/math3d/qquaternion.cpp @@ -408,7 +408,7 @@ QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, float angle) // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q56 // We normalize the result just in case the values are close // to zero, as suggested in the above FAQ. - float a = (angle / 2.0f) * M_PI / 180.0f; + float a = qDegreesToRadians(angle / 2.0f); float s = std::sin(a); float c = std::cos(a); QVector3D ax = axis.normalized(); @@ -467,7 +467,7 @@ QQuaternion QQuaternion::fromAxisAndAngle y /= length; z /= length; } - float a = (angle / 2.0f) * M_PI / 180.0f; + float a = qDegreesToRadians(angle / 2.0f); float s = std::sin(a); float c = std::cos(a); return QQuaternion(c, x * s, y * s, z * s).normalized(); diff --git a/src/gui/text/qdistancefield.cpp b/src/gui/text/qdistancefield.cpp index 746200fd9c..af13b96c32 100644 --- a/src/gui/text/qdistancefield.cpp +++ b/src/gui/text/qdistancefield.cpp @@ -516,7 +516,7 @@ static void makeDistanceField(QDistanceFieldData *data, const QPainterPath &path for (int i = 0; i < imgWidth * imgHeight; ++i) bits[i] = exteriorColor; - const qreal angleStep = qreal(15 * 3.141592653589793238 / 180); + const qreal angleStep = qDegreesToRadians(qreal(15)); const QPoint rotation(qRound(qCos(angleStep) * 0x4000), qRound(qSin(angleStep) * 0x4000)); // 2:14 signed |