diff options
Diffstat (limited to 'tests/auto/gui/math3d')
-rw-r--r-- | tests/auto/gui/math3d/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt | 13 | ||||
-rw-r--r-- | tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp | 204 | ||||
-rw-r--r-- | tests/auto/gui/math3d/qquaternion/CMakeLists.txt | 11 | ||||
-rw-r--r-- | tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp | 94 | ||||
-rw-r--r-- | tests/auto/gui/math3d/qvectornd/CMakeLists.txt | 11 | ||||
-rw-r--r-- | tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp | 62 |
7 files changed, 230 insertions, 168 deletions
diff --git a/tests/auto/gui/math3d/CMakeLists.txt b/tests/auto/gui/math3d/CMakeLists.txt index 11c50163ad..a7f2a55aa1 100644 --- a/tests/auto/gui/math3d/CMakeLists.txt +++ b/tests/auto/gui/math3d/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from math3d.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(qquaternion) add_subdirectory(qvectornd) diff --git a/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt b/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt index 5c54bd6b95..22f581e9c8 100644 --- a/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt +++ b/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt @@ -1,14 +1,19 @@ -# Generated from qmatrixnxn.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qmatrixnxn Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qmatrixnxn LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qmatrixnxn SOURCES tst_qmatrixnxn.cpp - DEFINES - QT_DISABLE_DEPRECATED_BEFORE=0 - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp b/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp index 972bbe2f1c..38ecaa7e44 100644 --- a/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp +++ b/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtCore/qmath.h> @@ -125,6 +100,7 @@ private slots: void rotate4x4_data(); void rotate4x4(); + void projectedRotate(); void normalMatrix_data(); void normalMatrix(); @@ -157,6 +133,11 @@ private slots: void properties(); void metaTypes(); + // Tests for deprecated APIs +#if QT_DEPRECATED_SINCE(6, 1) + void deprecatedMultiplications(); +#endif + private: static void setMatrix(QMatrix2x2& m, const float *values); static void setMatrixDirect(QMatrix2x2& m, const float *values); @@ -1994,12 +1975,7 @@ void tst_QMatrixNxN::scale4x4() } QVector3D v1(2.0f, 3.0f, -4.0f); - QVector3D v2 = m1 * v1; - QCOMPARE(v2.x(), (float)(2.0f * x)); - QCOMPARE(v2.y(), (float)(3.0f * y)); - QCOMPARE(v2.z(), (float)(-4.0f * z)); - - v2 = v1 * m1; + QVector3D v2 = m1.map(v1); QCOMPARE(v2.x(), (float)(2.0f * x)); QCOMPARE(v2.y(), (float)(3.0f * y)); QCOMPARE(v2.z(), (float)(-4.0f * z)); @@ -2018,7 +1994,7 @@ void tst_QMatrixNxN::scale4x4() QCOMPARE(v4.w(), (float)34.0f); QPoint p1(2, 3); - QPoint p2 = m1 * p1; + QPoint p2 = m1.map(p1); QCOMPARE(p2.x(), (int)(2.0f * x)); QCOMPARE(p2.y(), (int)(3.0f * y)); @@ -2027,7 +2003,7 @@ void tst_QMatrixNxN::scale4x4() QCOMPARE(p2.y(), (int)(3.0f * y)); QPointF p3(2.0f, 3.0f); - QPointF p4 = m1 * p3; + QPointF p4 = m1.map(p3); QCOMPARE(p4.x(), (float)(2.0f * x)); QCOMPARE(p4.y(), (float)(3.0f * y)); @@ -2140,7 +2116,7 @@ void tst_QMatrixNxN::translate4x4() } QVector3D v1(2.0f, 3.0f, -4.0f); - QVector3D v2 = m1 * v1; + QVector3D v2 = m1.map(v1); QCOMPARE(v2.x(), (float)(2.0f + x)); QCOMPARE(v2.y(), (float)(3.0f + y)); QCOMPARE(v2.z(), (float)(-4.0f + z)); @@ -2160,12 +2136,12 @@ void tst_QMatrixNxN::translate4x4() QCOMPARE(v6.w(), (float)34.0f); QPoint p1(2, 3); - QPoint p2 = m1 * p1; + QPoint p2 = m1.map(p1); QCOMPARE(p2.x(), (int)(2.0f + x)); QCOMPARE(p2.y(), (int)(3.0f + y)); QPointF p3(2.0f, 3.0f); - QPointF p4 = m1 * p3; + QPointF p4 = m1.map(p3); QCOMPARE(p4.x(), (float)(2.0f + x)); QCOMPARE(p4.y(), (float)(3.0f + y)); @@ -2370,7 +2346,7 @@ void tst_QMatrixNxN::rotate4x4() p1z /= p1w; QVector3D v1(2.0f, 3.0f, -4.0f); - QVector3D v2 = m1 * v1; + QVector3D v2 = m1.map(v1); QVERIFY(qFuzzyCompare(v2.x(), v1x)); QVERIFY(qFuzzyCompare(v2.y(), v1y)); QVERIFY(qFuzzyCompare(v2.z(), v1z)); @@ -2390,12 +2366,12 @@ void tst_QMatrixNxN::rotate4x4() QVERIFY(qFuzzyCompare(v6.w(), v5w)); QPoint p1(2, 3); - QPoint p2 = m1 * p1; + QPoint p2 = m1.map(p1); QCOMPARE(p2.x(), qRound(p1x)); QCOMPARE(p2.y(), qRound(p1y)); QPointF p3(2.0f, 3.0f); - QPointF p4 = m1 * p3; + QPointF p4 = m1.map(p3); QVERIFY(qFuzzyCompare(float(p4.x()), p1x)); QVERIFY(qFuzzyCompare(float(p4.y()), p1y)); @@ -2408,6 +2384,22 @@ void tst_QMatrixNxN::rotate4x4() } } +void tst_QMatrixNxN::projectedRotate() +{ + QMatrix4x4 m1, m2; + const QPointF origin(1000, 1000); + + m1.translate(origin.x(), origin.y()); + m1.projectedRotate(60, 0, 1, 0, 0); + m1.translate(-origin.x(), -origin.y()); + + m2.translate(origin.x(), origin.y()); + m2.rotate(60, 0, 1, 0); + m2.translate(-origin.x(), -origin.y()); + + QCOMPARE(m1.toTransform(), m2.toTransform()); +} + static bool isSame(const QMatrix3x3& m1, const Matrix3& m2) { for (int row = 0; row < 3; ++row) { @@ -2629,11 +2621,11 @@ void tst_QMatrixNxN::ortho() { QMatrix4x4 m1; m1.ortho(QRect(0, 0, 300, 150)); - QPointF p1 = m1 * QPointF(0, 0); - QPointF p2 = m1 * QPointF(300, 0); - QPointF p3 = m1 * QPointF(0, 150); - QPointF p4 = m1 * QPointF(300, 150); - QVector3D p5 = m1 * QVector3D(300, 150, 1); + QPointF p1 = m1.map(QPointF(0, 0)); + QPointF p2 = m1.map(QPointF(300, 0)); + QPointF p3 = m1.map(QPointF(0, 150)); + QPointF p4 = m1.map(QPointF(300, 150)); + QVector3D p5 = m1.map(QVector3D(300, 150, 1)); QVERIFY(qFuzzyCompare(float(p1.x()), -1.0f)); QVERIFY(qFuzzyCompare(float(p1.y()), 1.0f)); QVERIFY(qFuzzyCompare(float(p2.x()), 1.0f)); @@ -2648,11 +2640,11 @@ void tst_QMatrixNxN::ortho() QMatrix4x4 m2; m2.ortho(QRectF(0, 0, 300, 150)); - p1 = m2 * QPointF(0, 0); - p2 = m2 * QPointF(300, 0); - p3 = m2 * QPointF(0, 150); - p4 = m2 * QPointF(300, 150); - p5 = m2 * QVector3D(300, 150, 1); + p1 = m2.map(QPointF(0, 0)); + p2 = m2.map(QPointF(300, 0)); + p3 = m2.map(QPointF(0, 150)); + p4 = m2.map(QPointF(300, 150)); + p5 = m2.map(QVector3D(300, 150, 1)); QVERIFY(qFuzzyCompare(float(p1.x()), -1.0f)); QVERIFY(qFuzzyCompare(float(p1.y()), 1.0f)); QVERIFY(qFuzzyCompare(float(p2.x()), 1.0f)); @@ -2667,11 +2659,11 @@ void tst_QMatrixNxN::ortho() QMatrix4x4 m3; m3.ortho(0, 300, 150, 0, -1, 1); - p1 = m3 * QPointF(0, 0); - p2 = m3 * QPointF(300, 0); - p3 = m3 * QPointF(0, 150); - p4 = m3 * QPointF(300, 150); - p5 = m3 * QVector3D(300, 150, 1); + p1 = m3.map(QPointF(0, 0)); + p2 = m3.map(QPointF(300, 0)); + p3 = m3.map(QPointF(0, 150)); + p4 = m3.map(QPointF(300, 150)); + p5 = m3.map(QVector3D(300, 150, 1)); QVERIFY(qFuzzyCompare(float(p1.x()), -1.0f)); QVERIFY(qFuzzyCompare(float(p1.y()), 1.0f)); QVERIFY(qFuzzyCompare(float(p2.x()), 1.0f)); @@ -2686,11 +2678,11 @@ void tst_QMatrixNxN::ortho() QMatrix4x4 m4; m4.ortho(0, 300, 150, 0, -2, 3); - p1 = m4 * QPointF(0, 0); - p2 = m4 * QPointF(300, 0); - p3 = m4 * QPointF(0, 150); - p4 = m4 * QPointF(300, 150); - p5 = m4 * QVector3D(300, 150, 1); + p1 = m4.map(QPointF(0, 0)); + p2 = m4.map(QPointF(300, 0)); + p3 = m4.map(QPointF(0, 150)); + p4 = m4.map(QPointF(300, 150)); + p5 = m4.map(QVector3D(300, 150, 1)); QVERIFY(qFuzzyCompare(float(p1.x()), -1.0f)); QVERIFY(qFuzzyCompare(float(p1.y()), 1.0f)); QVERIFY(qFuzzyCompare(float(p2.x()), 1.0f)); @@ -2718,11 +2710,11 @@ void tst_QMatrixNxN::frustum() { QMatrix4x4 m1; m1.frustum(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); - QVector3D p1 = m1 * QVector3D(-1.0f, -1.0f, 1.0f); - QVector3D p2 = m1 * QVector3D(1.0f, -1.0f, 1.0f); - QVector3D p3 = m1 * QVector3D(-1.0f, 1.0f, 1.0f); - QVector3D p4 = m1 * QVector3D(1.0f, 1.0f, 1.0f); - QVector3D p5 = m1 * QVector3D(0.0f, 0.0f, 2.0f); + QVector3D p1 = m1.map(QVector3D(-1.0f, -1.0f, 1.0f)); + QVector3D p2 = m1.map(QVector3D(1.0f, -1.0f, 1.0f)); + QVector3D p3 = m1.map(QVector3D(-1.0f, 1.0f, 1.0f)); + QVector3D p4 = m1.map(QVector3D(1.0f, 1.0f, 1.0f)); + QVector3D p5 = m1.map(QVector3D(0.0f, 0.0f, 2.0f)); QVERIFY(qFuzzyCompare(p1.x(), -1.0f)); QVERIFY(qFuzzyCompare(p1.y(), -1.0f)); QVERIFY(qFuzzyCompare(p1.z(), -1.0f)); @@ -2754,11 +2746,11 @@ void tst_QMatrixNxN::perspective() { QMatrix4x4 m1; m1.perspective(45.0f, 1.0f, -1.0f, 1.0f); - QVector3D p1 = m1 * QVector3D(-1.0f, -1.0f, 1.0f); - QVector3D p2 = m1 * QVector3D(1.0f, -1.0f, 1.0f); - QVector3D p3 = m1 * QVector3D(-1.0f, 1.0f, 1.0f); - QVector3D p4 = m1 * QVector3D(1.0f, 1.0f, 1.0f); - QVector3D p5 = m1 * QVector3D(0.0f, 0.0f, 2.0f); + QVector3D p1 = m1.map(QVector3D(-1.0f, -1.0f, 1.0f)); + QVector3D p2 = m1.map(QVector3D(1.0f, -1.0f, 1.0f)); + QVector3D p3 = m1.map(QVector3D(-1.0f, 1.0f, 1.0f)); + QVector3D p4 = m1.map(QVector3D(1.0f, 1.0f, 1.0f)); + QVector3D p5 = m1.map(QVector3D(0.0f, 0.0f, 2.0f)); QVERIFY(qFuzzyCompare(p1.x(), 2.41421f)); QVERIFY(qFuzzyCompare(p1.y(), 2.41421f)); QVERIFY(qFuzzyCompare(p1.z(), -1.0f)); @@ -2824,25 +2816,25 @@ void tst_QMatrixNxN::flipCoordinates() { QMatrix4x4 m1; m1.flipCoordinates(); - QVector3D p1 = m1 * QVector3D(2, 3, 4); + QVector3D p1 = m1.map(QVector3D(2, 3, 4)); QVERIFY(p1 == QVector3D(2, -3, -4)); QMatrix4x4 m2; m2.scale(2.0f, 3.0f, 1.0f); m2.flipCoordinates(); - QVector3D p2 = m2 * QVector3D(2, 3, 4); + QVector3D p2 = m2.map(QVector3D(2, 3, 4)); QVERIFY(p2 == QVector3D(4, -9, -4)); QMatrix4x4 m3; m3.translate(2.0f, 3.0f, 1.0f); m3.flipCoordinates(); - QVector3D p3 = m3 * QVector3D(2, 3, 4); + QVector3D p3 = m3.map(QVector3D(2, 3, 4)); QVERIFY(p3 == QVector3D(4, 0, -3)); QMatrix4x4 m4; m4.rotate(90.0f, 0.0f, 0.0f, 1.0f); m4.flipCoordinates(); - QVector3D p4 = m4 * QVector3D(2, 3, 4); + QVector3D p4 = m4.map(QVector3D(2, 3, 4)); QVERIFY(p4 == QVector3D(3, 2, -4)); } @@ -3044,7 +3036,7 @@ void tst_QMatrixNxN::convertQTransform() QCOMPARE(p1.y(), 150.0 + 2.0); QMatrix4x4 m2(m1); - QPointF p2 = m2 * QPointF(100.0, 150.0); + QPointF p2 = m2.map(QPointF(100.0, 150.0)); QCOMPARE((double)p2.x(), 100.0 - 3.5); QCOMPARE((double)p2.y(), 150.0 + 2.0); QCOMPARE(m1, m2.toTransform()); @@ -3056,7 +3048,7 @@ void tst_QMatrixNxN::convertQTransform() QCOMPARE(p3.y(), -2.0 * 150.0); QMatrix4x4 m4(m3); - QPointF p4 = m4 * QPointF(100.0, 150.0); + QPointF p4 = m4.map(QPointF(100.0, 150.0)); QCOMPARE((double)p4.x(), 1.5 * 100.0); QCOMPARE((double)p4.y(), -2.0 * 150.0); QCOMPARE(m3, m4.toTransform()); @@ -3066,7 +3058,7 @@ void tst_QMatrixNxN::convertQTransform() QPointF p5 = m5.map(QPointF(100.0, 150.0)); QMatrix4x4 m6(m5); - QPointF p6 = m6 * QPointF(100.0, 150.0); + QPointF p6 = m6.map(QPointF(100.0, 150.0)); QVERIFY(qFuzzyCompare(float(p5.x()), float(p6.x()))); QVERIFY(qFuzzyCompare(float(p5.y()), float(p6.y()))); @@ -3316,9 +3308,9 @@ void tst_QMatrixNxN::properties() void tst_QMatrixNxN::metaTypes() { - QCOMPARE(QMetaType::type("QMatrix4x4"), int(QMetaType::QMatrix4x4)); + QCOMPARE(QMetaType::fromName("QMatrix4x4").id(), int(QMetaType::QMatrix4x4)); - QCOMPARE(QByteArray(QMetaType::typeName(QMetaType::QMatrix4x4)), + QCOMPARE(QByteArray(QMetaType(QMetaType::QMatrix4x4).name()), QByteArray("QMatrix4x4")); QVERIFY(QMetaType::isRegistered(QMetaType::QMatrix4x4)); @@ -3326,6 +3318,58 @@ void tst_QMatrixNxN::metaTypes() QCOMPARE(qMetaTypeId<QMatrix4x4>(), int(QMetaType::QMatrix4x4)); } +#if QT_DEPRECATED_SINCE(6, 1) +void tst_QMatrixNxN::deprecatedMultiplications() +{ + QMatrix4x4 m; + m.scale(1.0f, 2.0f, 3.0f); + // QMatrix4x4 and QVector3D + { + QVector3D v(4.0f, 5.0f, 6.0f); + { + // QMatrix4x4 * QVector3D + QT_IGNORE_DEPRECATIONS(const QVector3D v1 = m * v;) + const QVector3D v2 = m.map(v); + + QCOMPARE(v1.x(), v2.x()); + QCOMPARE(v1.y(), v2.y()); + QCOMPARE(v1.z(), v2.z()); + } + { + // QVector3D * QMatrix4x4 + QT_IGNORE_DEPRECATIONS(const QVector3D v1 = v * m;) + + QVector4D v4(v, 1.0); + const QVector4D v2 = v4 * m; + + QCOMPARE(v1.x(), v2.x()); + QCOMPARE(v1.y(), v2.y()); + QCOMPARE(v1.z(), v2.z()); + } + } + { + // QMatrix4x4 * QPoint + const QPoint p(4, 5); + + QT_IGNORE_DEPRECATIONS(const QPoint p1 = m * p;) + const QPoint p2 = m.map(p); + + QCOMPARE(p1.x(), p2.x()); + QCOMPARE(p1.y(), p2.y()); + } + { + // QMatrix4x4 * QPointF + const QPointF p(4.0f, 5.0f); + + QT_IGNORE_DEPRECATIONS(const QPointF p1 = m * p;) + const QPointF p2 = m.map(p); + + QCOMPARE(p1.x(), p2.x()); + QCOMPARE(p1.y(), p2.y()); + } +} +#endif // QT_DEPRECATED_SINCE(6, 1) + QTEST_APPLESS_MAIN(tst_QMatrixNxN) #include "tst_qmatrixnxn.moc" diff --git a/tests/auto/gui/math3d/qquaternion/CMakeLists.txt b/tests/auto/gui/math3d/qquaternion/CMakeLists.txt index fbeb76abdd..205865faba 100644 --- a/tests/auto/gui/math3d/qquaternion/CMakeLists.txt +++ b/tests/auto/gui/math3d/qquaternion/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qquaternion.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qquaternion Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qquaternion LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qquaternion SOURCES tst_qquaternion.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp b/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp index 4229fa1017..8cdc06354e 100644 --- a/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp +++ b/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp @@ -1,30 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses #include <QTest> #include <QtCore/qmath.h> @@ -600,7 +577,7 @@ void tst_QQuaternion::multiply_data() for (float x = -1.0f; x <= 1.0f; x += 0.5f) for (float y = -1.0f; y <= 1.0f; y += 0.5f) for (float z = -1.0f; z <= 1.0f; z += 0.5f) { - QTest::newRow("exhaustive") + QTest::addRow("exhaustive: (%.1f, %.1f, %.1f), %.1f", x, y, z, w) << x << y << z << w << z << w << y << x; } @@ -987,28 +964,6 @@ void tst_QQuaternion::rotationTo() QVERIFY(myFuzzyCompare(vec2, from)); } -static QByteArray testnameForAxis(const QVector3D &axis) -{ - QByteArray testname; - if (axis == QVector3D()) { - testname = "null"; - } else { - if (axis.x()) { - testname += axis.x() < 0 ? '-' : '+'; - testname += 'X'; - } - if (axis.y()) { - testname += axis.y() < 0 ? '-' : '+'; - testname += 'Y'; - } - if (axis.z()) { - testname += axis.z() < 0 ? '-' : '+'; - testname += 'Z'; - } - } - return testname; -} - // Test quaternion convertion to and from orthonormal axes. void tst_QQuaternion::fromDirection_data() { @@ -1031,7 +986,10 @@ void tst_QQuaternion::fromDirection_data() QVector3D xAxis, yAxis, zAxis; q.getAxes(&xAxis, &yAxis, &zAxis); - QTest::newRow("dir: " + testnameForAxis(zAxis) + ", up: " + testnameForAxis(yAxis)) + QTest::addRow("ortho dirs: (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f)", + xAxis.x(), xAxis.y(), xAxis.z(), + yAxis.x(), yAxis.y(), yAxis.z(), + zAxis.x(), zAxis.y(), zAxis.z()) << zAxis * 10.0f << yAxis * 10.0f; } @@ -1050,7 +1008,10 @@ void tst_QQuaternion::fromDirection_data() QVector3D xAxis, yAxis, zAxis; q.getAxes(&xAxis, &yAxis, &zAxis); - QTest::newRow("dir: " + testnameForAxis(zAxis) + ", up: null") + QTest::addRow("bad dirs: (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f)", + xAxis.x(), xAxis.y(), xAxis.z(), + yAxis.x(), yAxis.y(), yAxis.z(), + zAxis.x(), zAxis.y(), zAxis.z()) << zAxis * 10.0f << QVector3D(); } } @@ -1110,6 +1071,35 @@ void tst_QQuaternion::fromEulerAngles_data() QTest::newRow("complex") << 30.0f << 240.0f << -45.0f << QQuaternion(-0.531976f, -0.43968f, 0.723317f, -0.02226f); + + // Three gimbal_lock cases are not unique for the conversions from quaternion + // to euler, Qt will use only XY rotations for these cases. + // For example, QQuaternion(0.5f, 0.5f, -0.5f, 0.5f) can be EulerXYZ(90.0f, 0.0f, 90.0f), too. + // But Qt will always convert it to EulerXYZ(90.0f, -90.0f, 0.0f) without Z-rotation. + QTest::newRow("gimbal_lock_1") + << 90.0f << -90.0f << 0.0f << QQuaternion(0.5f, 0.5f, -0.5f, 0.5f); + + QTest::newRow("gimbal_lock_2") + << 90.0f << 40.0f << 0.0f << QQuaternion(0.664463f, 0.664463f, 0.241845f, -0.241845f); + + QTest::newRow("gimbal_lock_3") << 90.0f << 170.0f << 0.0f + << QQuaternion(0.0616285f, 0.0616285f, 0.704416f, -0.704416f); + + // These four examples have a fraction of errors that would bypass normalize() threshold + // and could make Gimbal lock detection fail. + QTest::newRow("gimbal_lock_fraction_1") + << -90.0f << 90.001152f << 0.0f << QQuaternion(0.499989986f, -0.5f, 0.5f, 0.5f); + + QTest::newRow("gimbal_lock_fraction_2") + << -90.0f << -179.999985f << 0.0f + << QQuaternion(1.00000001e-07f, 1.00000001e-10f, -0.707106769f, -0.707105756f); + + QTest::newRow("gimbal_lock_fraction_3") + << -90.0f << 90.0011597f << 0.0f << QQuaternion(0.499989986f, -0.49999994f, 0.5f, 0.5f); + + QTest::newRow("gimbal_lock_fraction_4") + << -90.0f << -180.0f << 0.0f + << QQuaternion(9.99999996e-12f, 9.99999996e-12f, -0.707106769f, -0.707096756f); } void tst_QQuaternion::fromEulerAngles() { diff --git a/tests/auto/gui/math3d/qvectornd/CMakeLists.txt b/tests/auto/gui/math3d/qvectornd/CMakeLists.txt index c29550463a..5de1ff11e6 100644 --- a/tests/auto/gui/math3d/qvectornd/CMakeLists.txt +++ b/tests/auto/gui/math3d/qvectornd/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qvectornd.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qvectornd Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qvectornd LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qvectornd SOURCES tst_qvectornd.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) diff --git a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp index c7bcb9d262..3272ffac0e 100644 --- a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp +++ b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp @@ -1,30 +1,38 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QVector2D> +#include <QVector3D> +#include <QVector4D> +#ifdef QVARIANT_H +# error "This test requires qvector{2,3,4}d.h to not include qvariant.h" +#endif + +// don't assume <type_traits> +template <typename T, typename U> +constexpr inline bool my_is_same_v = false; +template <typename T> +constexpr inline bool my_is_same_v<T, T> = true; + +#define CHECK(cvref) \ + static_assert(my_is_same_v<decltype(get<0>(std::declval<QVector2D cvref >())), float cvref >); \ + static_assert(my_is_same_v<decltype(get<1>(std::declval<QVector2D cvref >())), float cvref >); \ + \ + static_assert(my_is_same_v<decltype(get<0>(std::declval<QVector3D cvref >())), float cvref >); \ + static_assert(my_is_same_v<decltype(get<1>(std::declval<QVector3D cvref >())), float cvref >); \ + static_assert(my_is_same_v<decltype(get<2>(std::declval<QVector3D cvref >())), float cvref >); \ + \ + static_assert(my_is_same_v<decltype(get<0>(std::declval<QVector4D cvref >())), float cvref >); \ + static_assert(my_is_same_v<decltype(get<1>(std::declval<QVector4D cvref >())), float cvref >); \ + static_assert(my_is_same_v<decltype(get<2>(std::declval<QVector4D cvref >())), float cvref >); \ + static_assert(my_is_same_v<decltype(get<3>(std::declval<QVector4D cvref >())), float cvref >) + +CHECK(&); +CHECK(const &); +CHECK(&&); +CHECK(const &&); + +#undef CHECK #include <QTest> #include <QtCore/qmath.h> |