aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuya Nishihara <yuya.nishihara@qt.io>2021-07-16 11:50:06 +0900
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-07-21 15:38:12 +0000
commitf02227ebdc75284b7171b4f2579239679d5836d5 (patch)
tree2823843981f8387b48bdf117d92d4038267e19f7
parent72d0145ba418dde732dbb974ae59606dacd54f9e (diff)
Add tests of matrix4x4 transformation functions
These functions have been added at ded64d0368 "Make the qml/js matrix4x4 type more useful." Let's add some tests as I want to add another overload of rotate() function. Change-Id: I12e5970b8e3a6709e9f794c9713feb277cc8c449 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit b4866c499a6b2d1f42b77f08287988b01118c9f6) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/matrix4x4_invokables.qml54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/data/matrix4x4_invokables.qml b/tests/auto/qml/qqmlvaluetypes/data/matrix4x4_invokables.qml
index aa26956922..09f1d472b7 100644
--- a/tests/auto/qml/qqmlvaluetypes/data/matrix4x4_invokables.qml
+++ b/tests/auto/qml/qqmlvaluetypes/data/matrix4x4_invokables.qml
@@ -10,6 +10,59 @@ Item {
property variant v2: Qt.vector3d(1,2,3)
property real factor: 2.23
+ function testTransformation() {
+ let m = Qt.matrix4x4();
+
+ m.scale(1, 2, 4);
+ if (m !== Qt.matrix4x4(1, 0, 0, 0,
+ 0, 2, 0, 0,
+ 0, 0, 4, 0,
+ 0, 0, 0, 1))
+ return false;
+ m.scale(Qt.vector3d(-8, -4, -2));
+ if (m !== Qt.matrix4x4(-8, 0, 0, 0,
+ 0,-8, 0, 0,
+ 0, 0, -8, 0,
+ 0, 0, 0, 1))
+ return false;
+ m.scale(-1 / 8);
+ if (m !== Qt.matrix4x4())
+ return false;
+
+ m.rotate(180, Qt.vector3d(1, 0, 0));
+ if (m !== Qt.matrix4x4(1, 0, 0, 0,
+ 0, -1, 0, 0,
+ 0, 0, -1, 0,
+ 0, 0, 0, 1))
+ return false;
+ m.rotate(180, Qt.vector3d(0, 1, 0));
+ if (m !== Qt.matrix4x4(-1, 0, 0, 0,
+ 0, -1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1))
+ return false;
+ m.rotate(180, Qt.vector3d(0, 0, 1));
+ if (m !== Qt.matrix4x4())
+ return false;
+
+ m.translate(Qt.vector3d(1, 2, 4));
+ if (m !== Qt.matrix4x4(1, 0, 0, 1,
+ 0, 1, 0, 2,
+ 0, 0, 1, 4,
+ 0, 0, 0, 1))
+ return false;
+
+ m = Qt.matrix4x4();
+ m.lookAt(Qt.vector3d(1, 2, 4), Qt.vector3d(1, 2, 0), Qt.vector3d(0, 1, 0));
+ if (m !== Qt.matrix4x4(1, 0, 0, -1,
+ 0, 1, 0, -2,
+ 0, 0, 1, -4,
+ 0, 0, 0, 1))
+ return false;
+
+ return true;
+ }
+
Component.onCompleted: {
success = true;
if (m1.times(m2) != Qt.matrix4x4(26, 26, 26, 26, 52, 52, 52, 52, 78, 78, 78, 78, 104, 104, 104, 104)) success = false;
@@ -27,5 +80,6 @@ Item {
if (m1.transposed() != Qt.matrix4x4(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4)) success = false;
if (m1.fuzzyEquals(m2)) success = false;
if (!m1.fuzzyEquals(m2, 10)) success = false;
+ if (!testTransformation()) success = false;
}
}