summaryrefslogtreecommitdiffstats
path: root/tests/auto/qquaternion
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-09-04 04:12:08 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-09-04 07:00:23 (GMT)
commit974aec137dfdbb1dd68c41113b22eb25131965b8 (patch)
treeadbf042502fd35d1bce5a2aea811d41633ecd495 /tests/auto/qquaternion
parent4c501d7fce503a610edabfba5d6efc3ef2778bef (diff)
downloadQt-974aec137dfdbb1dd68c41113b22eb25131965b8.zip
Qt-974aec137dfdbb1dd68c41113b22eb25131965b8.tar.gz
Qt-974aec137dfdbb1dd68c41113b22eb25131965b8.tar.bz2
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
Diffstat (limited to 'tests/auto/qquaternion')
-rw-r--r--tests/auto/qquaternion/tst_qquaternion.cpp29
1 files changed, 13 insertions, 16 deletions
diff --git a/tests/auto/qquaternion/tst_qquaternion.cpp b/tests/auto/qquaternion/tst_qquaternion.cpp
index 24427c3..e3c4cd6 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.