diff options
Diffstat (limited to 'tests/auto/math3d')
-rw-r--r-- | tests/auto/math3d/math3d.pro | 3 | ||||
-rw-r--r-- | tests/auto/math3d/qfixedpt/qfixedpt.pro | 2 | ||||
-rw-r--r-- | tests/auto/math3d/qfixedpt/tst_qfixedpt.cpp | 643 | ||||
-rw-r--r-- | tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp | 83 | ||||
-rw-r--r-- | tests/auto/math3d/qmatrixnxn_fixed/qmatrixnxn_fixed.pro | 8 | ||||
-rw-r--r-- | tests/auto/math3d/qquaternion/tst_qquaternion.cpp | 75 | ||||
-rw-r--r-- | tests/auto/math3d/qquaternion_fixed/qquaternion_fixed.pro | 8 | ||||
-rw-r--r-- | tests/auto/math3d/qvectornd/tst_qvectornd.cpp | 18 | ||||
-rw-r--r-- | tests/auto/math3d/qvectornd_fixed/qvectornd_fixed.pro | 8 | ||||
-rw-r--r-- | tests/auto/math3d/shared/math3dincludes.cpp | 54 | ||||
-rw-r--r-- | tests/auto/math3d/shared/math3dincludes.h | 35 |
11 files changed, 68 insertions, 869 deletions
diff --git a/tests/auto/math3d/math3d.pro b/tests/auto/math3d/math3d.pro index 3977e92..d6189ef 100644 --- a/tests/auto/math3d/math3d.pro +++ b/tests/auto/math3d/math3d.pro @@ -1,3 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = qfixedpt qmatrixnxn qquaternion qvectornd -SUBDIRS += qmatrixnxn_fixed qquaternion_fixed qvectornd_fixed +SUBDIRS = qmatrixnxn qquaternion qvectornd diff --git a/tests/auto/math3d/qfixedpt/qfixedpt.pro b/tests/auto/math3d/qfixedpt/qfixedpt.pro deleted file mode 100644 index 94598b5..0000000 --- a/tests/auto/math3d/qfixedpt/qfixedpt.pro +++ /dev/null @@ -1,2 +0,0 @@ -load(qttest_p4) -SOURCES += tst_qfixedpt.cpp diff --git a/tests/auto/math3d/qfixedpt/tst_qfixedpt.cpp b/tests/auto/math3d/qfixedpt/tst_qfixedpt.cpp deleted file mode 100644 index ef333a6..0000000 --- a/tests/auto/math3d/qfixedpt/tst_qfixedpt.cpp +++ /dev/null @@ -1,643 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <QtCore/qmath.h> -#include <QtGui/qfixedpt.h> - -class tst_QFixedPt : public QObject -{ - Q_OBJECT -public: - tst_QFixedPt() {} - ~tst_QFixedPt() {} - -private slots: - void create_data(); - void create(); - void add_data(); - void add(); - void sub_data(); - void sub(); - void mul_data(); - void mul(); - void div_data(); - void div(); - void neg_data(); - void neg(); - void shift_data(); - void shift(); - void sqrt_data(); - void sqrt(); - void round_data(); - void round(); - void compare_data(); - void compare(); -}; - -// qFuzzyCompare isn't quite "fuzzy" enough to handle conversion -// to fixed-point and back again. So create a "fuzzier" compare. -static bool fuzzyCompare(double x, double y) -{ - double diff = x - y; - if (diff < 0.0f) - diff = -diff; - return (diff < 0.0001); -} - -// Test the creation of QFixedPt values in various ways. -void tst_QFixedPt::create_data() -{ - QTest::addColumn<int>("value"); - QTest::addColumn<int>("intValue"); - QTest::addColumn<float>("realValue"); - - QTest::newRow("zero") << 0x00000000 << 0 << 0.0f; - QTest::newRow("one") << 0x00010000 << 1 << 1.0f; - QTest::newRow("1.5") << 0x00018000 << 2 << 1.5f; // int rounds up - QTest::newRow("-1.5") << (int)0xFFFE8000 << -1 << -1.5f; // int rounds up - QTest::newRow("-7") << (int)0xFFF90000 << -7 << -7.0f; -} -void tst_QFixedPt::create() -{ - QFETCH(int, value); - QFETCH(int, intValue); - QFETCH(float, realValue); - - if (qFloor(realValue) == realValue) { - QFixedPt<16> ivalue(intValue); - QCOMPARE(ivalue.bits(), value); - QCOMPARE(ivalue.toInt(), intValue); - QCOMPARE(ivalue.toReal(), (qreal)realValue); - } - - QFixedPt<16> fvalue(realValue); - QCOMPARE(fvalue.bits(), value); - QCOMPARE(fvalue.toInt(), intValue); - QCOMPARE(fvalue.toReal(), (qreal)realValue); - - QFixedPt<16> fpvalue; - fpvalue.setBits(value); - QCOMPARE(fpvalue.bits(), value); - QCOMPARE(fpvalue.toInt(), intValue); - QCOMPARE(fpvalue.toReal(), (qreal)realValue); - - QFixedPt<16> fpvalue2(fpvalue); - QCOMPARE(fpvalue2.bits(), value); - QCOMPARE(fpvalue2.toInt(), intValue); - QCOMPARE(fpvalue2.toReal(), (qreal)realValue); - - if (qFloor(realValue) == realValue) { - QFixedPt<16> ivalue2(63); // Initialize the something else. - ivalue2 = intValue; // Then change the value. - QCOMPARE(ivalue2.bits(), value); - QCOMPARE(ivalue2.toInt(), intValue); - QCOMPARE(ivalue2.toReal(), (qreal)realValue); - } - - QFixedPt<16> fvalue2(36); - fvalue2 = realValue; - QCOMPARE(fvalue2.bits(), value); - QCOMPARE(fvalue2.toInt(), intValue); - QCOMPARE(fvalue2.toReal(), (qreal)realValue); - - QFixedPt<16> fpvalue3; - fpvalue3 = fpvalue; - QCOMPARE(fpvalue3.bits(), value); - QCOMPARE(fpvalue3.toInt(), intValue); - QCOMPARE(fpvalue3.toReal(), (qreal)realValue); - - // Now do some of the tests again with a different precision value. - - if (qFloor(realValue) == realValue) { - QFixedPt<4> ivalue3(intValue); - QCOMPARE(ivalue3.bits(), value >> 12); - QCOMPARE(ivalue3.toInt(), intValue); - QCOMPARE(ivalue3.toReal(), (qreal)realValue); - } - - QFixedPt<4> fvalue3(realValue); - QCOMPARE(fvalue3.bits(), value >> 12); - QCOMPARE(fvalue3.toInt(), intValue); - QCOMPARE(fvalue3.toReal(), (qreal)realValue); - - QFixedPt<4> fpvalue4; - fpvalue4.setBits(value >> 12); - QCOMPARE(fpvalue4.bits(), value >> 12); - QCOMPARE(fpvalue4.toInt(), intValue); - QCOMPARE(fpvalue4.toReal(), (qreal)realValue); - - // Test conversion between the precision values. - -#if !defined(QT_NO_MEMBER_TEMPLATES) - if (qFloor(realValue) == realValue) { - QFixedPt<16> ivalue(intValue); - QFixedPt<4> ivalue3(intValue); - QVERIFY(ivalue.toPrecision<4>() == ivalue3); - QVERIFY(ivalue3.toPrecision<16>() == ivalue); - } - QVERIFY(fvalue.toPrecision<4>() == fvalue3); - QVERIFY(fvalue3.toPrecision<16>() == fvalue); -#endif - - if (qFloor(realValue) == realValue) { - QFixedPt<16> ivalue(intValue); - QFixedPt<4> ivalue3(intValue); - QVERIFY(qFixedPtToPrecision<4>(ivalue) == ivalue3); - QVERIFY(qFixedPtToPrecision<16>(ivalue3) == ivalue); - } - QVERIFY(qFixedPtToPrecision<4>(fvalue) == fvalue3); - QVERIFY(qFixedPtToPrecision<16>(fvalue3) == fvalue); -} - -// Test fixed point addition. -void tst_QFixedPt::add_data() -{ - QTest::addColumn<float>("a"); - QTest::addColumn<float>("b"); - - QTest::newRow("zero") << 0.0f << 0.0f; - QTest::newRow("test1") << 1.0f << 0.0f; - QTest::newRow("test2") << 0.0f << 1.0f; - QTest::newRow("test3") << 10.0f << -3.0f; - QTest::newRow("test4") << 10.5f << 3.25f; -} -void tst_QFixedPt::add() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - QFixedPt<16> cvalue = avalue + bvalue; - QFixedPt<16> dvalue = a + bvalue; - QFixedPt<16> evalue = avalue + b; - - QCOMPARE(cvalue.toReal(), (qreal)(a + b)); - QCOMPARE(dvalue.toReal(), (qreal)(a + b)); - QCOMPARE(evalue.toReal(), (qreal)(a + b)); - - QFixedPt<16> fvalue(avalue); - fvalue += bvalue; - QCOMPARE(fvalue.toReal(), (qreal)(a + b)); - - QFixedPt<16> gvalue(avalue); - gvalue += b; - QCOMPARE(gvalue.toReal(), (qreal)(a + b)); - - if (qFloor(a) == a && qFloor(b) == b) { - QFixedPt<16> hvalue = int(a) + bvalue; - QFixedPt<16> ivalue = avalue + int(b); - - QCOMPARE(hvalue.toInt(), int(a) + int(b)); - QCOMPARE(ivalue.toInt(), int(a) + int(b)); - QCOMPARE(hvalue.toReal(), (qreal)(a + b)); - QCOMPARE(ivalue.toReal(), (qreal)(a + b)); - - QFixedPt<16> jvalue(avalue); - jvalue += int(b); - QCOMPARE(jvalue.toReal(), (qreal)(a + b)); - } -} - -// Test fixed point subtraction. -void tst_QFixedPt::sub_data() -{ - // Use the same test data as the add() test. - add_data(); -} -void tst_QFixedPt::sub() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - QFixedPt<16> cvalue = avalue - bvalue; - QFixedPt<16> dvalue = a - bvalue; - QFixedPt<16> evalue = avalue - b; - - QCOMPARE(cvalue.toReal(), (qreal)(a - b)); - QCOMPARE(dvalue.toReal(), (qreal)(a - b)); - QCOMPARE(evalue.toReal(), (qreal)(a - b)); - - QFixedPt<16> fvalue(avalue); - fvalue -= bvalue; - QCOMPARE(fvalue.toReal(), (qreal)(a - b)); - - QFixedPt<16> gvalue(avalue); - gvalue -= b; - QCOMPARE(gvalue.toReal(), (qreal)(a - b)); - - if (qFloor(a) == a && qFloor(b) == b) { - QFixedPt<16> hvalue = int(a) - bvalue; - QFixedPt<16> ivalue = avalue - int(b); - - QCOMPARE(hvalue.toInt(), int(a) - int(b)); - QCOMPARE(ivalue.toInt(), int(a) - int(b)); - QCOMPARE(hvalue.toReal(), (qreal)(a - b)); - QCOMPARE(ivalue.toReal(), (qreal)(a - b)); - - QFixedPt<16> jvalue(avalue); - jvalue -= int(b); - QCOMPARE(jvalue.toReal(), (qreal)(a - b)); - } -} - -// Test fixed point multiplication. -void tst_QFixedPt::mul_data() -{ - // Use the same test data as the add() test. - add_data(); -} -void tst_QFixedPt::mul() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - QFixedPt<16> cvalue = avalue * bvalue; - QFixedPt<16> dvalue = a * bvalue; - QFixedPt<16> evalue = avalue * b; - - QCOMPARE(cvalue.toReal(), (qreal)(a * b)); - QCOMPARE(dvalue.toReal(), (qreal)(a * b)); - QCOMPARE(evalue.toReal(), (qreal)(a * b)); - - QFixedPt<16> fvalue(avalue); - fvalue *= bvalue; - QCOMPARE(fvalue.toReal(), (qreal)(a * b)); - - QFixedPt<16> gvalue(avalue); - gvalue *= b; - QCOMPARE(gvalue.toReal(), (qreal)(a * b)); - - if (qFloor(a) == a && qFloor(b) == b) { - QFixedPt<16> hvalue = int(a) * bvalue; - QFixedPt<16> ivalue = avalue * int(b); - - QCOMPARE(hvalue.toInt(), int(a) * int(b)); - QCOMPARE(ivalue.toInt(), int(a) * int(b)); - QCOMPARE(hvalue.toReal(), (qreal)(a * b)); - QCOMPARE(ivalue.toReal(), (qreal)(a * b)); - - QFixedPt<16> jvalue(avalue); - jvalue *= int(b); - QCOMPARE(jvalue.toReal(), (qreal)(a * b)); - } -} - -// Test fixed point division. -void tst_QFixedPt::div_data() -{ - // Use the same test data as the add() test. - add_data(); -} -void tst_QFixedPt::div() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - qreal result; - if (b == 0.0f) - result = 0.0f; // Divide by zero results in zero. - else - result = a / b; - - QFixedPt<16> cvalue = avalue / bvalue; - QFixedPt<16> dvalue = a / bvalue; - QFixedPt<16> evalue = avalue / b; - - QVERIFY(fuzzyCompare(cvalue.toReal(), result)); - QVERIFY(fuzzyCompare(dvalue.toReal(), result)); - QVERIFY(fuzzyCompare(evalue.toReal(), result)); - - QFixedPt<16> fvalue(avalue); - fvalue /= bvalue; - QVERIFY(fuzzyCompare(fvalue.toReal(), result)); - - QFixedPt<16> gvalue(avalue); - gvalue /= b; - QVERIFY(fuzzyCompare(gvalue.toReal(), result)); - - if (qFloor(a) == a && qFloor(b) == b) { - QFixedPt<16> hvalue = int(a) / bvalue; - QFixedPt<16> ivalue = avalue / int(b); - - QCOMPARE(hvalue.toInt(), int(result)); - QCOMPARE(ivalue.toInt(), int(result)); - QVERIFY(fuzzyCompare(hvalue.toReal(), result)); - QVERIFY(fuzzyCompare(ivalue.toReal(), result)); - - QFixedPt<16> jvalue(avalue); - jvalue /= int(b); - QVERIFY(fuzzyCompare(jvalue.toReal(), result)); - } -} - -// Test fixed point negation. -void tst_QFixedPt::neg_data() -{ - // Use the same test data as the add() test. - add_data(); -} -void tst_QFixedPt::neg() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - QFixedPt<16> cvalue = -avalue; - QCOMPARE(cvalue.bits(), -avalue.bits()); - QCOMPARE(cvalue.toInt(), int(-a)); - QCOMPARE(cvalue.toReal(), (qreal)-a); - - QFixedPt<16> dvalue = -bvalue; - QCOMPARE(dvalue.bits(), -bvalue.bits()); - QCOMPARE(dvalue.toInt(), int(-b)); - QCOMPARE(dvalue.toReal(), (qreal)-b); -} - -// Test left and right shift operators on fixed point values. -void tst_QFixedPt::shift_data() -{ - QTest::addColumn<float>("a"); - QTest::addColumn<int>("amount"); - - QTest::newRow("zero") << 0.0f << 5; - QTest::newRow("one") << 1.0f << 4; - QTest::newRow("-1.75") << -1.75f << 4; -} -void tst_QFixedPt::shift() -{ - QFETCH(float, a); - QFETCH(int, amount); - - int lresult = int((a * 65536.0) * (1 << amount)); - int rresult = int((a * 65536.0) / (1 << amount)); - - QFixedPt<16> avalue(a); - avalue <<= amount; - QCOMPARE(avalue.bits(), lresult); - - QFixedPt<16> bvalue(a); - bvalue >>= amount; - QCOMPARE(bvalue.bits(), rresult); - - QFixedPt<16> cvalue(a); - - QFixedPt<16> dvalue; - dvalue = cvalue << amount; - QCOMPARE(dvalue.bits(), lresult); - - QFixedPt<16> evalue; - evalue = cvalue >> amount; - QCOMPARE(evalue.bits(), rresult); -} - -// Test fixed point square root. -void tst_QFixedPt::sqrt_data() -{ - QTest::addColumn<float>("a"); - - QTest::newRow("zero") << 0.0f; - QTest::newRow("one") << 1.0f; - QTest::newRow("two") << 2.0f; - QTest::newRow("sixteen") << 16.0f; - QTest::newRow("1.5") << 1.5f; -} -void tst_QFixedPt::sqrt() -{ - QFETCH(float, a); - - QFixedPt<16> avalue(a); - QVERIFY(fuzzyCompare(avalue.sqrt().toReal(), qSqrt(a))); - QVERIFY(fuzzyCompare(avalue.sqrtF(), qSqrt(a))); -} - -// Test fixed point rounding. -void tst_QFixedPt::round_data() -{ - QTest::addColumn<float>("a"); - QTest::addColumn<int>("rounded"); - QTest::addColumn<int>("ceiling"); - QTest::addColumn<int>("flooring"); - QTest::addColumn<int>("truncated"); - - QTest::newRow("zero") << 0.0f << 0 << 0 << 0 << 0; - QTest::newRow("test1") << 1.0f << 1 << 1 << 1 << 1; - QTest::newRow("test2") << 2.5f << 3 << 3 << 2 << 2; - QTest::newRow("test3") << 2.3f << 2 << 3 << 2 << 2; - QTest::newRow("test4") << -2.5f << -2 << -2 << -3 << -3; - QTest::newRow("test5") << -2.3f << -2 << -2 << -3 << -3; - QTest::newRow("test6") << -2.7f << -3 << -2 << -3 << -3; -} -void tst_QFixedPt::round() -{ - QFETCH(float, a); - QFETCH(int, rounded); - QFETCH(int, ceiling); - QFETCH(int, flooring); - QFETCH(int, truncated); - - QFixedPt<16> avalue(a); - QVERIFY(avalue.round() == rounded); - QVERIFY(avalue.ceil() == ceiling); - QVERIFY(avalue.floor() == flooring); - QVERIFY(avalue.truncate() == truncated); - - QCOMPARE(qRound(avalue), rounded); - QCOMPARE(qCeil(avalue), ceiling); - QCOMPARE(qFloor(avalue), flooring); -} - -// Test comparison operators. -void tst_QFixedPt::compare_data() -{ - QTest::addColumn<float>("a"); - QTest::addColumn<float>("b"); - - QTest::newRow("test1") << 0.0f << 0.0f; - QTest::newRow("test2") << 1.0f << 0.0f; - QTest::newRow("test3") << 2.5f << 2.5f; - QTest::newRow("test4") << 2.5f << -2.5f; - QTest::newRow("test5") << -2.5f << 2.5f; -} -void tst_QFixedPt::compare() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - if (a == b) { - QVERIFY(avalue == bvalue); - QVERIFY(avalue == b); - QVERIFY(a == bvalue); - QVERIFY(!(avalue != bvalue)); - QVERIFY(!(avalue != b)); - QVERIFY(!(a != bvalue)); - QVERIFY(!(avalue < bvalue)); - QVERIFY(!(avalue < b)); - QVERIFY(!(a < bvalue)); - QVERIFY(!(avalue > bvalue)); - QVERIFY(!(avalue > b)); - QVERIFY(!(a > bvalue)); - QVERIFY(avalue <= bvalue); - QVERIFY(avalue <= b); - QVERIFY(a <= bvalue); - QVERIFY(avalue >= bvalue); - QVERIFY(avalue >= b); - QVERIFY(a >= bvalue); - if (qFloor(a) == a) { - QVERIFY(int(a) == bvalue); - QVERIFY(!(int(a) != bvalue)); - QVERIFY(!(int(a) < bvalue)); - QVERIFY(!(int(a) > bvalue)); - QVERIFY(int(a) <= bvalue); - QVERIFY(int(a) >= bvalue); - } - if (qFloor(b) == b) { - QVERIFY(avalue == int(b)); - QVERIFY(!(avalue != int(b))); - QVERIFY(!(avalue < int(b))); - QVERIFY(!(avalue > int(b))); - QVERIFY(avalue <= int(b)); - QVERIFY(avalue >= int(b)); - } - } - - if (a != b) { - QVERIFY(avalue != bvalue); - QVERIFY(avalue != b); - QVERIFY(a != bvalue); - QVERIFY(!(avalue == bvalue)); - QVERIFY(!(avalue == b)); - QVERIFY(!(a == bvalue)); - if (qFloor(a) == a) { - QVERIFY(int(a) != bvalue); - QVERIFY(!(int(a) == bvalue)); - } - if (qFloor(b) == b) { - QVERIFY(avalue != int(b)); - QVERIFY(!(avalue == int(b))); - } - } - - if (a < b) { - QVERIFY(avalue < bvalue); - QVERIFY(avalue < b); - QVERIFY(a < bvalue); - QVERIFY(!(avalue >= bvalue)); - QVERIFY(!(avalue >= b)); - QVERIFY(!(a >= bvalue)); - QVERIFY(!(avalue > bvalue)); - QVERIFY(!(avalue > b)); - QVERIFY(!(a > bvalue)); - QVERIFY(avalue <= bvalue); - QVERIFY(avalue <= b); - QVERIFY(a <= bvalue); - QVERIFY(!(avalue >= bvalue)); - QVERIFY(!(avalue >= b)); - QVERIFY(!(a >= bvalue)); - if (qFloor(a) == a) { - QVERIFY(int(a) < bvalue); - QVERIFY(!(int(a) >= bvalue)); - QVERIFY(!(int(a) > bvalue)); - QVERIFY(int(a) <= bvalue); - } - if (qFloor(b) == b) { - QVERIFY(avalue < int(b)); - QVERIFY(!(avalue >= int(b))); - QVERIFY(!(avalue > int(b))); - QVERIFY(avalue <= int(b)); - } - } - - if (a > b) { - QVERIFY(avalue > bvalue); - QVERIFY(avalue > b); - QVERIFY(a > bvalue); - QVERIFY(!(avalue <= bvalue)); - QVERIFY(!(avalue <= b)); - QVERIFY(!(a <= bvalue)); - QVERIFY(!(avalue < bvalue)); - QVERIFY(!(avalue < b)); - QVERIFY(!(a < bvalue)); - QVERIFY(avalue >= bvalue); - QVERIFY(avalue >= b); - QVERIFY(a >= bvalue); - QVERIFY(!(avalue <= bvalue)); - QVERIFY(!(avalue <= b)); - QVERIFY(!(a <= bvalue)); - if (qFloor(a) == a) { - QVERIFY(int(a) > bvalue); - QVERIFY(!(int(a) <= bvalue)); - QVERIFY(!(int(a) < bvalue)); - QVERIFY(int(a) >= bvalue); - } - if (qFloor(b) == b) { - QVERIFY(avalue > int(b)); - QVERIFY(!(avalue <= int(b))); - QVERIFY(!(avalue < int(b))); - QVERIFY(avalue >= int(b)); - } - } - - if (qFuzzyCompare(a, b)) - QVERIFY(qFuzzyCompare(avalue, bvalue)); - else - QVERIFY(!qFuzzyCompare(avalue, bvalue)); -} - -QTEST_APPLESS_MAIN(tst_QFixedPt) - -#include "tst_qfixedpt.moc" diff --git a/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp b/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp index 8a7dd49..bb510fc 100644 --- a/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp +++ b/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp @@ -321,7 +321,7 @@ void tst_QMatrix::setMatrix(QMatrix4x3& m, const qreal *values) // to be in row-major order. This sets the values using fixed-point. void tst_QMatrix::setMatrixFixed(QMatrix2x2& m, const qreal *values) { - qrealinner *data = m.data(); + float *data = m.data(); for (int row = 0; row < 2; ++row) { for (int col = 0; col < 2; ++col) { data[row + col * 2] = values[row * 2 + col]; @@ -330,7 +330,7 @@ void tst_QMatrix::setMatrixFixed(QMatrix2x2& m, const qreal *values) } void tst_QMatrix::setMatrixFixed(QMatrix3x3& m, const qreal *values) { - qrealinner *data = m.data(); + float *data = m.data(); for (int row = 0; row < 3; ++row) { for (int col = 0; col < 3; ++col) { data[row + col * 3] = values[row * 3 + col]; @@ -339,7 +339,7 @@ void tst_QMatrix::setMatrixFixed(QMatrix3x3& m, const qreal *values) } void tst_QMatrix::setMatrixFixed(QMatrix4x4& m, const qreal *values) { - qrealinner *data = m.data(); + float *data = m.data(); for (int row = 0; row < 4; ++row) { for (int col = 0; col < 4; ++col) { data[row + col * 4] = values[row * 4 + col]; @@ -348,7 +348,7 @@ void tst_QMatrix::setMatrixFixed(QMatrix4x4& m, const qreal *values) } void tst_QMatrix::setMatrixFixed(QMatrix4x3& m, const qreal *values) { - qrealinner *data = m.data(); + float *data = m.data(); for (int row = 0; row < 3; ++row) { for (int col = 0; col < 4; ++col) { data[row + col * 3] = values[row * 4 + col]; @@ -365,15 +365,6 @@ static bool fuzzyCompare(float x, float y, qreal epsilon = 0.001) diff = -diff; return (diff < epsilon); } -#ifdef QT_GL_FIXED_PREFERRED -static bool fuzzyCompareFixed(qrealinner x, int y) -{ - int diff = x.bits() - y; - if (diff < 0) - diff = -diff; - return (diff < 50); -} -#endif static bool fuzzyCompare(const QVector3D &v1, const QVector3D &v2, qreal epsilon = 0.001) { @@ -402,7 +393,7 @@ static bool matrixFuzzyCompare(const QMatrix4x4 &m1, const QMatrix4x4 &m2) // The values are assumed to be specified in row-major order. bool tst_QMatrix::isSame(const QMatrix2x2& m, const qreal *values) { - const qrealinner *mv = m.constData(); + const float *mv = m.constData(); for (int row = 0; row < 2; ++row) { for (int col = 0; col < 2; ++col) { // Check the values using the operator() function. @@ -413,24 +404,17 @@ bool tst_QMatrix::isSame(const QMatrix2x2& m, const qreal *values) // Check the values using direct access, which verifies that the values // are stored internally in column-major order. -#ifdef QT_GL_FIXED_PREFERRED - if (!fuzzyCompareFixed(mv[col * 2 + row], (int)(values[row * 2 + col] * 65536.0))) { - qDebug() << "column fixed-point failure at" << row << col << "actual =" << mv[col * 2 + row] << "expected =" << (int)(values[row * 2 + col] * 65536.0); - return false; - } -#else if (!fuzzyCompare((float)(mv[col * 2 + row]), (float)(values[row * 2 + col]))) { qDebug() << "column floating-point failure at" << row << col << "actual =" << mv[col * 2 + row] << "expected =" << values[row * 2 + col]; return false; } -#endif } } return true; } bool tst_QMatrix::isSame(const QMatrix3x3& m, const qreal *values) { - const qrealinner *mv = m.constData(); + const float *mv = m.constData(); for (int row = 0; row < 3; ++row) { for (int col = 0; col < 3; ++col) { // Check the values using the operator() access function. @@ -441,24 +425,17 @@ bool tst_QMatrix::isSame(const QMatrix3x3& m, const qreal *values) // Check the values using direct access, which verifies that the values // are stored internally in column-major order. -#ifdef QT_GL_FIXED_PREFERRED - if (!fuzzyCompareFixed(mv[col * 3 + row], (int)(values[row * 3 + col] * 65536.0))) { - qDebug() << "column fixed-point failure at" << row << col << "actual =" << mv[col * 3 + row] << "expected =" << (int)(values[row * 3 + col] * 65536.0); - return false; - } -#else if (!fuzzyCompare((float)(mv[col * 3 + row]), (float)(values[row * 3 + col]))) { qDebug() << "column floating-point failure at" << row << col << "actual =" << mv[col * 3 + row] << "expected =" << values[row * 3 + col]; return false; } -#endif } } return true; } bool tst_QMatrix::isSame(const QMatrix4x4& m, const qreal *values) { - const qrealinner *mv = m.constData(); + const float *mv = m.constData(); for (int row = 0; row < 4; ++row) { for (int col = 0; col < 4; ++col) { // Check the values using the operator() access function. @@ -469,24 +446,17 @@ bool tst_QMatrix::isSame(const QMatrix4x4& m, const qreal *values) // Check the values using direct access, which verifies that the values // are stored internally in column-major order. -#ifdef QT_GL_FIXED_PREFERRED - if (!fuzzyCompareFixed(mv[col * 4 + row], (int)(values[row * 4 + col] * 65536.0))) { - qDebug() << "column fixed-point failure at" << row << col << "actual =" << mv[col * 4 + row] << "expected =" << (int)(values[row * 4 + col] * 65536.0); - return false; - } -#else if (!fuzzyCompare((float)(mv[col * 4 + row]), (float)(values[row * 4 + col]))) { qDebug() << "column floating-point failure at" << row << col << "actual =" << mv[col * 4 + row] << "expected =" << values[row * 4 + col]; return false; } -#endif } } return true; } bool tst_QMatrix::isSame(const QMatrix4x3& m, const qreal *values) { - const qrealinner *mv = m.constData(); + const float *mv = m.constData(); for (int row = 0; row < 3; ++row) { for (int col = 0; col < 4; ++col) { // Check the values using the operator() access function. @@ -497,17 +467,10 @@ bool tst_QMatrix::isSame(const QMatrix4x3& m, const qreal *values) // Check the values using direct access, which verifies that the values // are stored internally in column-major order. -#ifdef QT_GL_FIXED_PREFERRED - if (!fuzzyCompareFixed(mv[col * 3 + row], (int)(values[row * 4 + col] * 65536.0))) { - qDebug() << "column fixed-point failure at" << row << col << "actual =" << mv[col * 3 + row] << "expected =" << (int)(values[row * 4 + col] * 65536.0); - return false; - } -#else if (!fuzzyCompare((float)(mv[col * 3 + row]), (float)(values[row * 4 + col]))) { qDebug() << "column floating-point failure at" << row << col << "actual =" << mv[col * 3 + row] << "expected =" << values[row * 4 + col]; return false; } -#endif } } return true; @@ -1333,7 +1296,7 @@ void tst_QMatrix::multiply4x3() QMatrix4x3 m1((const qreal *)m1Values); QMatrix3x4 m2((const qreal *)m2Values); - QGenericMatrix<3, 3, qreal, qrealinner> m4; + QGenericMatrix<3, 3, qreal, float> m4; m4 = m1 * m2; qreal values[9]; m4.toValueArray(values); @@ -2901,11 +2864,7 @@ void tst_QMatrix::extractAxisRotation() m.extractAxisRotation(extractedAngle, extractedAxis); -#ifdef QT_GL_FIXED_PREFERRED - qreal epsilon = 0.003; -#else qreal epsilon = 0.001; -#endif if (angle > 180) { QVERIFY(fuzzyCompare(360.0f - angle, extractedAngle, epsilon)); @@ -2953,11 +2912,7 @@ void tst_QMatrix::extractTranslation() QVector3D vec = rotation.extractTranslation(); -#ifdef QT_GL_FIXED_PREFERRED - qreal epsilon = 0.01; -#else qreal epsilon = 0.001; -#endif QVERIFY(fuzzyCompare(vec.x(), x, epsilon)); QVERIFY(fuzzyCompare(vec.y(), y, epsilon)); @@ -2992,7 +2947,7 @@ enum { // Structure that allows direct access to "flagBits" for testing. struct Matrix4x4 { - qrealinner m[4][4]; + float m[4][4]; int flagBits; }; @@ -3225,24 +3180,6 @@ void tst_QMatrix::fill() QVERIFY(isSame(m2, fillValues4x3)); } -// Force the fixed-point version of the test case to put a -// different test name on the front of failure reports. -class tst_QMatrixFixed : public tst_QMatrix -{ - Q_OBJECT -public: - tst_QMatrixFixed() {} - ~tst_QMatrixFixed() {} -}; - -#ifdef QT_GL_FIXED_PREFERRED - -QTEST_APPLESS_MAIN(tst_QMatrixFixed) - -#else - QTEST_APPLESS_MAIN(tst_QMatrix) -#endif - #include "tst_qmatrixnxn.moc" diff --git a/tests/auto/math3d/qmatrixnxn_fixed/qmatrixnxn_fixed.pro b/tests/auto/math3d/qmatrixnxn_fixed/qmatrixnxn_fixed.pro deleted file mode 100644 index cd1c8fa..0000000 --- a/tests/auto/math3d/qmatrixnxn_fixed/qmatrixnxn_fixed.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4) -VPATH += ../shared -VPATH += ../qmatrixnxn -INCLUDEPATH += ../shared -INCLUDEPATH += ../../../../src/gui/math3d -DEFINES += FIXED_POINT_TESTS -HEADERS += math3dincludes.h -SOURCES += tst_qmatrixnxn.cpp math3dincludes.cpp diff --git a/tests/auto/math3d/qquaternion/tst_qquaternion.cpp b/tests/auto/math3d/qquaternion/tst_qquaternion.cpp index 325cb40..f25f858 100644 --- a/tests/auto/math3d/qquaternion/tst_qquaternion.cpp +++ b/tests/auto/math3d/qquaternion/tst_qquaternion.cpp @@ -88,8 +88,11 @@ private slots: void fromAxisAndAngle_data(); void fromAxisAndAngle(); - void interpolate_data(); - void interpolate(); + void slerp_data(); + void slerp(); + + void nlerp_data(); + void nlerp(); }; // qFuzzyCompare isn't quite "fuzzy" enough to handle conversion @@ -693,7 +696,7 @@ void tst_QQuaternion::fromAxisAndAngle() } // Test spherical interpolation of quaternions. -void tst_QQuaternion::interpolate_data() +void tst_QQuaternion::slerp_data() { QTest::addColumn<qreal>("x1"); QTest::addColumn<qreal>("y1"); @@ -740,7 +743,7 @@ void tst_QQuaternion::interpolate_data() << (qreal)0.5f << (qreal)1.0f << (qreal)2.0f << (qreal)-3.0f << (qreal)-45.0f; } -void tst_QQuaternion::interpolate() +void tst_QQuaternion::slerp() { QFETCH(qreal, x1); QFETCH(qreal, y1); @@ -760,7 +763,7 @@ void tst_QQuaternion::interpolate() QQuaternion q2 = QQuaternion::fromAxisAndAngle(x2, y2, z2, angle2); QQuaternion q3 = QQuaternion::fromAxisAndAngle(x3, y3, z3, angle3); - QQuaternion result = QQuaternion::interpolate(q1, q2, t); + QQuaternion result = QQuaternion::slerp(q1, q2, t); QVERIFY(fuzzyCompare(result.x(), q3.x())); QVERIFY(fuzzyCompare(result.y(), q3.y())); @@ -768,24 +771,60 @@ void tst_QQuaternion::interpolate() QVERIFY(fuzzyCompare(result.scalar(), q3.scalar())); } -// Force the fixed-point version of the test case to put a -// different test name on the front of failure reports. -class tst_QQuaternionFixed : public tst_QQuaternion +// Test normalized linear interpolation of quaternions. +void tst_QQuaternion::nlerp_data() { - Q_OBJECT -public: - tst_QQuaternionFixed() {} - ~tst_QQuaternionFixed() {} -}; + slerp_data(); +} +void tst_QQuaternion::nlerp() +{ + QFETCH(qreal, x1); + QFETCH(qreal, y1); + QFETCH(qreal, z1); + QFETCH(qreal, angle1); + QFETCH(qreal, x2); + QFETCH(qreal, y2); + QFETCH(qreal, z2); + QFETCH(qreal, angle2); + QFETCH(qreal, t); -#ifdef QT_GL_FIXED_PREFERRED + QQuaternion q1 = QQuaternion::fromAxisAndAngle(x1, y1, z1, angle1); + QQuaternion q2 = QQuaternion::fromAxisAndAngle(x2, y2, z2, angle2); -QTEST_APPLESS_MAIN(tst_QQuaternionFixed) + QQuaternion result = QQuaternion::nlerp(q1, q2, t); + + qreal resultx, resulty, resultz, resultscalar; + if (t <= 0.0f) { + resultx = q1.x(); + resulty = q1.y(); + resultz = q1.z(); + resultscalar = q1.scalar(); + } else if (t >= 1.0f) { + resultx = q2.x(); + resulty = q2.y(); + resultz = q2.z(); + resultscalar = q2.scalar(); + } else if (qAbs(angle1 - angle2) <= 180.f) { + resultx = q1.x() * (1 - t) + q2.x() * t; + resulty = q1.y() * (1 - t) + q2.y() * t; + resultz = q1.z() * (1 - t) + q2.z() * t; + resultscalar = q1.scalar() * (1 - t) + q2.scalar() * t; + } else { + // Angle greater than 180 degrees: negate q2. + resultx = q1.x() * (1 - t) - q2.x() * t; + resulty = q1.y() * (1 - t) - q2.y() * t; + resultz = q1.z() * (1 - t) - q2.z() * t; + resultscalar = q1.scalar() * (1 - t) - q2.scalar() * t; + } + + QQuaternion q3 = QQuaternion(resultscalar, resultx, resulty, resultz).normalized(); -#else + QVERIFY(fuzzyCompare(result.x(), q3.x())); + QVERIFY(fuzzyCompare(result.y(), q3.y())); + QVERIFY(fuzzyCompare(result.z(), q3.z())); + QVERIFY(fuzzyCompare(result.scalar(), q3.scalar())); +} QTEST_APPLESS_MAIN(tst_QQuaternion) -#endif - #include "tst_qquaternion.moc" diff --git a/tests/auto/math3d/qquaternion_fixed/qquaternion_fixed.pro b/tests/auto/math3d/qquaternion_fixed/qquaternion_fixed.pro deleted file mode 100644 index a0d5401..0000000 --- a/tests/auto/math3d/qquaternion_fixed/qquaternion_fixed.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4) -VPATH += ../shared -VPATH += ../qquaternion -INCLUDEPATH += ../shared -INCLUDEPATH += ../../../../src/gui/math3d -DEFINES += FIXED_POINT_TESTS -HEADERS += math3dincludes.h -SOURCES += tst_qquaternion.cpp math3dincludes.cpp diff --git a/tests/auto/math3d/qvectornd/tst_qvectornd.cpp b/tests/auto/math3d/qvectornd/tst_qvectornd.cpp index 83bacdf..a092fb0 100644 --- a/tests/auto/math3d/qvectornd/tst_qvectornd.cpp +++ b/tests/auto/math3d/qvectornd/tst_qvectornd.cpp @@ -2040,24 +2040,6 @@ void tst_QVector::dotProduct4() QCOMPARE(QVector4D::dotProduct(v1, v2), d); } -// Force the fixed-point version of the test case to put a -// different test name on the front of failure reports. -class tst_QVectorFixed : public tst_QVector -{ - Q_OBJECT -public: - tst_QVectorFixed() {} - ~tst_QVectorFixed() {} -}; - -#ifdef QT_GL_FIXED_PREFERRED - -QTEST_APPLESS_MAIN(tst_QVectorFixed) - -#else - QTEST_APPLESS_MAIN(tst_QVector) -#endif - #include "tst_qvectornd.moc" diff --git a/tests/auto/math3d/qvectornd_fixed/qvectornd_fixed.pro b/tests/auto/math3d/qvectornd_fixed/qvectornd_fixed.pro deleted file mode 100644 index a667fcc..0000000 --- a/tests/auto/math3d/qvectornd_fixed/qvectornd_fixed.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4) -VPATH += ../shared -VPATH += ../qvectornd -INCLUDEPATH += ../shared -INCLUDEPATH += ../../../../src/gui/math3d -DEFINES += FIXED_POINT_TESTS -HEADERS += math3dincludes.h -SOURCES += tst_qvectornd.cpp math3dincludes.cpp diff --git a/tests/auto/math3d/shared/math3dincludes.cpp b/tests/auto/math3d/shared/math3dincludes.cpp deleted file mode 100644 index 725079d..0000000 --- a/tests/auto/math3d/shared/math3dincludes.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "math3dincludes.h" - -#if defined(FIXED_POINT_TESTS) - -#include "qmatrix4x4.cpp" -#include "qgenericmatrix.cpp" -#include "qvector2d.cpp" -#include "qvector3d.cpp" -#include "qvector4d.cpp" -#include "qquaternion.cpp" -#include "qmath3dutil.cpp" - -#endif diff --git a/tests/auto/math3d/shared/math3dincludes.h b/tests/auto/math3d/shared/math3dincludes.h index 23b0f16..1ac0c08 100644 --- a/tests/auto/math3d/shared/math3dincludes.h +++ b/tests/auto/math3d/shared/math3dincludes.h @@ -42,41 +42,6 @@ #ifndef MATH3DINCLUDES_H #define MATH3DINCLUDES_H -#if defined(FIXED_POINT_TESTS) - -// Rename the classes we want to test in fixed-point mode so that -// they don't conflict with the ones that are built into Qt. -#define QT_NO_GL_FLOAT 1 -#define QVector2D tst_QVector2D -#define QVector3D tst_QVector3D -#define QVector4D tst_QVector4D -#define QQuaternion tst_QQuaternionX -#define QMatrix2x2 tst_QMatrix2x2 -#define QMatrix3x3 tst_QMatrix3x3 -#define QMatrix4x4 tst_QMatrix4x4 -#define QMatrix2x3 tst_QMatrix2x3 -#define QMatrix2x4 tst_QMatrix2x4 -#define QMatrix3x2 tst_QMatrix3x2 -#define QMatrix3x4 tst_QMatrix3x4 -#define QMatrix4x2 tst_QMatrix4x2 -#define QMatrix4x3 tst_QMatrix4x3 -#define QGenericMatrix tst_QGenericMatrix -#define qt_math3d_sincos tst_qt_math3d_sincos -#define qt_math3d_convert tst_qt_math3d_convert -#define qrealinner tst_qrealinner - -// We need to re-include the headers with the changed class names. -#undef QGENERICMATRIX_H -#undef QMATH3DGLOBAL_H -#undef QMATH3DUTIL_P_H -#undef QMATRIX4X4_H -#undef QQUATERNION_H -#undef QVECTOR2D_H -#undef QVECTOR3D_H -#undef QVECTOR4D_H - -#endif - #include <QtGui/qmatrix4x4.h> #include <QtGui/qgenericmatrix.h> #include <QtGui/qvector2d.h> |