summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/math3d
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/math3d')
-rw-r--r--tests/auto/gui/math3d/CMakeLists.txt3
-rw-r--r--tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt13
-rw-r--r--tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp252
-rw-r--r--tests/auto/gui/math3d/qquaternion/CMakeLists.txt11
-rw-r--r--tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp132
-rw-r--r--tests/auto/gui/math3d/qvectornd/CMakeLists.txt11
-rw-r--r--tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp62
7 files changed, 274 insertions, 210 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 275c684815..e761f8cb3c 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));
@@ -2367,10 +2343,10 @@ void tst_QMatrixNxN::rotate4x4()
ROTATE4(2.0f, 3.0f, 0.0f, 1.0f, p1x, p1y, p1z, p1w);
p1x /= p1w;
p1y /= p1w;
- p1z /= p1w;
+ Q_UNUSED(p1z);
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));
}
@@ -2871,24 +2863,6 @@ void tst_QMatrixNxN::convertGeneric()
QVERIFY(isSame(m10, conv4x4));
}
-// Copy of "flagBits" in qmatrix4x4.h.
-enum {
- Identity = 0x0000, // Identity matrix
- Translation = 0x0001, // Contains a translation
- Scale = 0x0002, // Contains a scale
- Rotation2D = 0x0004, // Contains a rotation about the Z axis
- Rotation = 0x0008, // Contains an arbitrary rotation
- Perspective = 0x0010, // Last row is different from (0, 0, 0, 1)
- General = 0x001f // General matrix, unknown contents
-};
-
-// Structure that allows direct access to "flagBits" for testing.
-struct Matrix4x4
-{
- float m[4][4];
- int flagBits;
-};
-
// Test the inferring of special matrix types.
void tst_QMatrixNxN::optimize_data()
{
@@ -2896,11 +2870,11 @@ void tst_QMatrixNxN::optimize_data()
QTest::addColumn<int>("flagBits");
QTest::newRow("null")
- << (void *)nullValues4 << (int)General;
+ << (void *)nullValues4 << int{QMatrix4x4::General};
QTest::newRow("identity")
- << (void *)identityValues4 << (int)Identity;
+ << (void *)identityValues4 << int{QMatrix4x4::Identity};
QTest::newRow("unique")
- << (void *)uniqueValues4 << (int)General;
+ << (void *)uniqueValues4 << int{QMatrix4x4::General};
static float scaleValues[16] = {
2.0f, 0.0f, 0.0f, 0.0f,
@@ -2909,7 +2883,7 @@ void tst_QMatrixNxN::optimize_data()
0.0f, 0.0f, 0.0f, 1.0f
};
QTest::newRow("scale")
- << (void *)scaleValues << (int)Scale;
+ << (void *)scaleValues << int{QMatrix4x4::Scale};
static float translateValues[16] = {
1.0f, 0.0f, 0.0f, 2.0f,
@@ -2918,7 +2892,7 @@ void tst_QMatrixNxN::optimize_data()
0.0f, 0.0f, 0.0f, 1.0f
};
QTest::newRow("translate")
- << (void *)translateValues << (int)Translation;
+ << (void *)translateValues << int{QMatrix4x4::Translation};
static float scaleTranslateValues[16] = {
1.0f, 0.0f, 0.0f, 2.0f,
@@ -2927,7 +2901,7 @@ void tst_QMatrixNxN::optimize_data()
0.0f, 0.0f, 0.0f, 1.0f
};
QTest::newRow("scaleTranslate")
- << (void *)scaleTranslateValues << (int)(Scale | Translation);
+ << (void *)scaleTranslateValues << int{QMatrix4x4::Scale | QMatrix4x4::Translation};
static float rotateValues[16] = {
0.0f, 1.0f, 0.0f, 0.0f,
@@ -2936,7 +2910,7 @@ void tst_QMatrixNxN::optimize_data()
0.0f, 0.0f, 0.0f, 1.0f
};
QTest::newRow("rotate")
- << (void *)rotateValues << (int)Rotation2D;
+ << (void *)rotateValues << int{QMatrix4x4::Rotation2D};
// Left-handed system, not a simple rotation.
static float scaleRotateValues[16] = {
@@ -2946,7 +2920,7 @@ void tst_QMatrixNxN::optimize_data()
0.0f, 0.0f, 0.0f, 1.0f
};
QTest::newRow("scaleRotate")
- << (void *)scaleRotateValues << (int)(Scale | Rotation2D);
+ << (void *)scaleRotateValues << int{QMatrix4x4::Scale | QMatrix4x4::Rotation2D};
static float matrix2x2Values[16] = {
1.0f, 2.0f, 0.0f, 0.0f,
@@ -2955,7 +2929,7 @@ void tst_QMatrixNxN::optimize_data()
0.0f, 0.0f, 0.0f, 1.0f
};
QTest::newRow("matrix2x2")
- << (void *)matrix2x2Values << (int)(Scale | Rotation2D);
+ << (void *)matrix2x2Values << int{QMatrix4x4::Scale | QMatrix4x4::Rotation2D};
static float matrix3x3Values[16] = {
1.0f, 2.0f, 4.0f, 0.0f,
@@ -2964,7 +2938,7 @@ void tst_QMatrixNxN::optimize_data()
0.0f, 0.0f, 0.0f, 1.0f
};
QTest::newRow("matrix3x3")
- << (void *)matrix3x3Values << (int)(Scale | Rotation2D | Rotation);
+ << (void *)matrix3x3Values << int{QMatrix4x4::Scale | QMatrix4x4::Rotation2D | QMatrix4x4::Rotation};
static float rotateTranslateValues[16] = {
0.0f, 1.0f, 0.0f, 1.0f,
@@ -2973,7 +2947,7 @@ void tst_QMatrixNxN::optimize_data()
0.0f, 0.0f, 0.0f, 1.0f
};
QTest::newRow("rotateTranslate")
- << (void *)rotateTranslateValues << (int)(Translation | Rotation2D);
+ << (void *)rotateTranslateValues << int{QMatrix4x4::Translation | QMatrix4x4::Rotation2D};
// Left-handed system, not a simple rotation.
static float scaleRotateTranslateValues[16] = {
@@ -2983,7 +2957,7 @@ void tst_QMatrixNxN::optimize_data()
0.0f, 0.0f, 0.0f, 1.0f
};
QTest::newRow("scaleRotateTranslate")
- << (void *)scaleRotateTranslateValues << (int)(Translation | Scale | Rotation2D);
+ << (void *)scaleRotateTranslateValues << int{QMatrix4x4::Translation | QMatrix4x4::Scale | QMatrix4x4::Rotation2D};
static float belowValues[16] = {
1.0f, 0.0f, 0.0f, 0.0f,
@@ -2992,7 +2966,7 @@ void tst_QMatrixNxN::optimize_data()
4.0f, 0.0f, 0.0f, 1.0f
};
QTest::newRow("below")
- << (void *)belowValues << (int)General;
+ << (void *)belowValues << int{QMatrix4x4::General};
}
void tst_QMatrixNxN::optimize()
{
@@ -3002,7 +2976,7 @@ void tst_QMatrixNxN::optimize()
QMatrix4x4 m((const float *)mValues);
m.optimize();
- QCOMPARE(reinterpret_cast<Matrix4x4 *>(&m)->flagBits, flagBits);
+ QCOMPARE(m.flagBits, flagBits);
}
void tst_QMatrixNxN::columnsAndRows()
@@ -3062,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());
@@ -3074,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());
@@ -3084,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())));
@@ -3334,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));
@@ -3344,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 b9ba7278da..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;
}
@@ -905,7 +882,7 @@ void tst_QQuaternion::fromAxes_data()
QTest::newRow("complex")
<< 1.0f << 2.0f << -3.0f << 45.0f
- << QVector3D(0.728028, -0.525105, -0.440727) << QVector3D(0.608789, 0.790791, 0.0634566) << QVector3D(0.315202, -0.314508, 0.895395);
+ << QVector3D(0.728028f, -0.525105f, -0.440727f) << QVector3D(0.608789f, 0.790791f, 0.0634566f) << QVector3D(0.315202f, -0.314508f, 0.895395f);
}
void tst_QQuaternion::fromAxes()
{
@@ -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();
}
}
@@ -1085,35 +1046,67 @@ void tst_QQuaternion::fromEulerAngles_data()
QTest::addColumn<float>("yaw");
QTest::addColumn<float>("roll");
+ QTest::addColumn<QQuaternion>("quaternion");
+
QTest::newRow("null")
- << 0.0f << 0.0f << 0.0f;
+ << 0.0f << 0.0f << 0.0f << QQuaternion(1.0f, 0.0f, 0.0f, 0.0f);
QTest::newRow("xonly")
- << 90.0f << 0.0f << 0.0f;
+ << 90.0f << 0.0f << 0.0f << QQuaternion(0.707107f, 0.707107f, 0.0f, 0.0f);
QTest::newRow("yonly")
- << 0.0f << 180.0f << 0.0f;
+ << 0.0f << 180.0f << 0.0f << QQuaternion(0.0f, 0.0f, 1.0f, 0.0f);
QTest::newRow("zonly")
- << 0.0f << 0.0f << 270.0f;
+ << 0.0f << 0.0f << 270.0f << QQuaternion(-0.707107f, 0.0f, 0.0f, 0.707107f);
QTest::newRow("x+z")
- << 30.0f << 0.0f << 45.0f;
+ << 30.0f << 0.0f << 45.0f << QQuaternion(0.892399f, 0.239118f, -0.099046f, 0.369644f);
QTest::newRow("x+y")
- << 30.0f << 90.0f << 0.0f;
+ << 30.0f << 90.0f << 0.0f << QQuaternion(0.683013f, 0.183013f, 0.683013f, -0.183013f);
QTest::newRow("y+z")
- << 0.0f << 45.0f << 30.0f;
+ << 0.0f << 45.0f << 30.0f << QQuaternion(0.892399f, 0.099046f, 0.369644f, 0.239118f);
QTest::newRow("complex")
- << 30.0f << 240.0f << -45.0f;
+ << 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()
{
QFETCH(float, pitch);
QFETCH(float, yaw);
QFETCH(float, roll);
+ QFETCH(QQuaternion, quaternion);
// Use a straight-forward implementation of the algorithm at:
// http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q60
@@ -1129,11 +1122,22 @@ void tst_QQuaternion::fromEulerAngles()
QVERIFY(myFuzzyCompare(answer.z(), result.z()));
QVERIFY(myFuzzyCompare(answer.scalar(), result.scalar()));
+ // quaternion should be the same as the result
+ QVERIFY(myFuzzyCompare(answer.x(), quaternion.x()));
+ QVERIFY(myFuzzyCompare(answer.y(), quaternion.y()));
+ QVERIFY(myFuzzyCompare(answer.z(), quaternion.z()));
+ QVERIFY(myFuzzyCompare(answer.scalar(), quaternion.scalar()));
+
{
QVector3D answerEulerAngles = answer.toEulerAngles();
QVERIFY(myFuzzyCompareDegrees(answerEulerAngles.x(), pitch));
QVERIFY(myFuzzyCompareDegrees(answerEulerAngles.y(), yaw));
QVERIFY(myFuzzyCompareDegrees(answerEulerAngles.z(), roll));
+
+ QVector3D quaternionEulerAngles = quaternion.toEulerAngles();
+ QVERIFY(myFuzzyCompareDegrees(quaternionEulerAngles.x(), pitch));
+ QVERIFY(myFuzzyCompareDegrees(quaternionEulerAngles.y(), yaw));
+ QVERIFY(myFuzzyCompareDegrees(quaternionEulerAngles.z(), roll));
}
answer = QQuaternion::fromEulerAngles(pitch, yaw, roll);
@@ -1148,6 +1152,12 @@ void tst_QQuaternion::fromEulerAngles()
QVERIFY(myFuzzyCompareDegrees(answerPitch, pitch));
QVERIFY(myFuzzyCompareDegrees(answerYaw, yaw));
QVERIFY(myFuzzyCompareDegrees(answerRoll, roll));
+
+ float quaternionPitch, quaternionYaw, quaternionRoll;
+ quaternion.getEulerAngles(&quaternionPitch, &quaternionYaw, &quaternionRoll);
+ QVERIFY(myFuzzyCompareDegrees(quaternionPitch, pitch));
+ QVERIFY(myFuzzyCompareDegrees(quaternionYaw, yaw));
+ QVERIFY(myFuzzyCompareDegrees(quaternionRoll, roll));
}
}
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>