From 974aec137dfdbb1dd68c41113b22eb25131965b8 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Fri, 4 Sep 2009 14:12:08 +1000 Subject: Modify QMatrix4x4 and QQuaternion to use qreal internally Some concerns were expressed about the float precision of QMatrix4x4, which this change addresses by using qreal instead. The QVector2D/3D/4D classes still use float internally, so that they can be used directly in large arrays of vertex values to be uploaded to an OpenGL server. QQuaternion is a client-side class, and it should produce rotations that are consistent with QMatrix4x4. So its precision was changed too. A consequence of this change is that the following no longer works in a portable fashion: QMatrix4x4 mat; ... glLoadMatrixf(mat.constData()); The caller must now repack the argument to convert from qreal to GLfloat. Reviewed-by: Michael Goddard Reviewed-by: Andreas --- tests/auto/qquaternion/tst_qquaternion.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'tests/auto/qquaternion') diff --git a/tests/auto/qquaternion/tst_qquaternion.cpp b/tests/auto/qquaternion/tst_qquaternion.cpp index 24427c3893..e3c4cd668d 100644 --- a/tests/auto/qquaternion/tst_qquaternion.cpp +++ b/tests/auto/qquaternion/tst_qquaternion.cpp @@ -98,14 +98,11 @@ private slots: void metaTypes(); }; -// qFuzzyCompare isn't always "fuzzy" enough to handle conversion -// between float, double, and qreal. So create "fuzzier" compares. -static bool fuzzyCompare(float x, float y) -{ - float diff = x - y; - if (diff < 0.0f) - diff = -diff; - return (diff < 0.001); +// QVector3D uses float internally, which can lead to some precision +// issues when using it with the qreal-based QQuaternion. +static bool fuzzyCompare(qreal x, qreal y) +{ + return qFuzzyIsNull(float(x - y)); } // Test the creation of QQuaternion objects in various ways: @@ -250,8 +247,8 @@ void tst_QQuaternion::length() QFETCH(qreal, len); QQuaternion v(w, x, y, z); - QCOMPARE((float)(v.length()), (float)len); - QCOMPARE((float)(v.lengthSquared()), (float)(x * x + y * y + z * z + w * w)); + QCOMPARE(v.length(), len); + QCOMPARE(v.lengthSquared(), x * x + y * y + z * z + w * w); } // Test the unit vector conversion for quaternions. @@ -273,11 +270,11 @@ void tst_QQuaternion::normalized() if (v.isNull()) QVERIFY(u.isNull()); else - QCOMPARE((float)(u.length()), (float)1.0f); - QCOMPARE((float)(u.x() * len), (float)(v.x())); - QCOMPARE((float)(u.y() * len), (float)(v.y())); - QCOMPARE((float)(u.z() * len), (float)(v.z())); - QCOMPARE((float)(u.scalar() * len), (float)(v.scalar())); + QCOMPARE(u.length(), qreal(1.0f)); + QCOMPARE(u.x() * len, v.x()); + QCOMPARE(u.y() * len, v.y()); + QCOMPARE(u.z() * len, v.z()); + QCOMPARE(u.scalar() * len, v.scalar()); } // Test the unit vector conversion for quaternions. @@ -299,7 +296,7 @@ void tst_QQuaternion::normalize() if (isNull) QVERIFY(v.isNull()); else - QCOMPARE((float)(v.length()), (float)1.0f); + QCOMPARE(v.length(), qreal(1.0f)); } // Test the comparison operators for quaternions. -- cgit v1.2.3