diff options
author | Mitch Curtis <mitch.curtis@nokia.com> | 2012-08-01 16:02:10 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-22 04:04:57 +0200 |
commit | 09dd19df5c4b708960e5aade568eb15d996ef200 (patch) | |
tree | 3a997704b1324dfb45f69d892128399affcac242 /tests/auto/gui/math3d | |
parent | 7f469ef4cc614925d7a4fdb3380ff5470e25b03b (diff) |
Do not consider sign in qIsNull.
The current implementation of qIsNull only returns true if the value is
positive zero. This behaviour is not useful for use cases like
QPointF::isNull, where QPointF(-0, -0).isNull() will return false.
There doesn't seem to be a reason why the function exhibits this
behaviour (-0.0 is not accounted for in the unit tests), and for the
case of QSizeF::scale it causes a bug: qIsNull is used to check for
division by 0.0 before it proceeds, which fails in the case of -0.0.
Task-number: QTBUG-7303
Change-Id: I767e5280bd26614e8e78ae62b274eb9bc4ade385
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'tests/auto/gui/math3d')
-rw-r--r-- | tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp | 7 | ||||
-rw-r--r-- | tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp | 18 |
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp b/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp index a4e1f940fc..f42cc30fb1 100644 --- a/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp +++ b/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp @@ -116,6 +116,13 @@ void tst_QQuaternion::create() QCOMPARE(identity.scalar(), (qreal)1.0f); QVERIFY(identity.isIdentity()); + QQuaternion negativeZeroIdentity(qreal(1.0), qreal(-0.0), qreal(-0.0), qreal(-0.0)); + QCOMPARE(negativeZeroIdentity.x(), qreal(-0.0)); + QCOMPARE(negativeZeroIdentity.y(), qreal(-0.0)); + QCOMPARE(negativeZeroIdentity.z(), qreal(-0.0)); + QCOMPARE(negativeZeroIdentity.scalar(), qreal(1.0)); + QVERIFY(negativeZeroIdentity.isIdentity()); + QQuaternion v1(34.0f, 1.0f, 2.5f, -89.25f); QCOMPARE(v1.x(), (qreal)1.0f); QCOMPARE(v1.y(), (qreal)2.5f); diff --git a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp index 72a4ecef97..4b6d9839a2 100644 --- a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp +++ b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp @@ -162,6 +162,11 @@ void tst_QVectorND::create2() QCOMPARE(null.y(), (qreal)0.0f); QVERIFY(null.isNull()); + QVector2D nullNegativeZero(qreal(-0.0), qreal(-0.0)); + QCOMPARE(nullNegativeZero.x(), (qreal)-0.0f); + QCOMPARE(nullNegativeZero.y(), (qreal)-0.0f); + QVERIFY(nullNegativeZero.isNull()); + QVector2D v1(1.0f, 2.5f); QCOMPARE(v1.x(), (qreal)1.0f); QCOMPARE(v1.y(), (qreal)2.5f); @@ -252,6 +257,12 @@ void tst_QVectorND::create3() QCOMPARE(null.z(), (qreal)0.0f); QVERIFY(null.isNull()); + QVector3D nullNegativeZero(qreal(-0.0), qreal(-0.0), qreal(-0.0)); + QCOMPARE(nullNegativeZero.x(), (qreal)-0.0f); + QCOMPARE(nullNegativeZero.y(), (qreal)-0.0f); + QCOMPARE(nullNegativeZero.z(), (qreal)-0.0f); + QVERIFY(nullNegativeZero.isNull()); + QVector3D v1(1.0f, 2.5f, -89.25f); QCOMPARE(v1.x(), (qreal)1.0f); QCOMPARE(v1.y(), (qreal)2.5f); @@ -379,6 +390,13 @@ void tst_QVectorND::create4() QCOMPARE(null.w(), (qreal)0.0f); QVERIFY(null.isNull()); + QVector4D nullNegativeZero(qreal(-0.0), qreal(-0.0), qreal(-0.0), qreal(-0.0)); + QCOMPARE(nullNegativeZero.x(), (qreal)-0.0f); + QCOMPARE(nullNegativeZero.y(), (qreal)-0.0f); + QCOMPARE(nullNegativeZero.z(), (qreal)-0.0f); + QCOMPARE(nullNegativeZero.w(), (qreal)-0.0f); + QVERIFY(nullNegativeZero.isNull()); + QVector4D v1(1.0f, 2.5f, -89.25f, 34.0f); QCOMPARE(v1.x(), (qreal)1.0f); QCOMPARE(v1.y(), (qreal)2.5f); |