summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2025-06-27 15:15:34 +0200
committerMarc Mutz <[email protected]>2025-07-04 15:31:18 +0200
commit1228575926383b02479130a68989c4571a5c1ef4 (patch)
tree941050e5698ef6a943966ffdc34e56cf65a3ad15 /tests/auto
parentc0b19de6eee4883113f95c36bb20c61dadb70a74 (diff)
QQuaternion: long live Axes / toAxes()
Compilers hate out parameters, so provide a replacement for getAxes(), toAxes(), that returns the result in a struct Axes { x, y, z } instead. Then make getAxes() an inline wrapper around a toAxes() call, porting from Q_ASSERT(x && y && z) to Q_PRE(x); Q_PRE(y); Q_PRE(z); as a drive-by. The separation gives a more detailed error when triggered, and produces a shorter assertion string. Add tests, naturally, and port getAxes() calls that don't test getAxes() to the new function. There appear to be no other in-tree users that could be ported. For symmetry reasons, also add a fromAxes(Axes) overload. Take the argument by value, to avoid the compiler having to deal with aliasing analysis. At worst, pass-by-value is like pass-by-cref, and whether or not the extra copy is added or, since C++17, elided, depends on the specific call. Suppress Clazy's schizophrenic warning, which complains that we don't take (QVector3D, QVector3D, QVector3D) by value, but also if we take struct {QVector x,y,z} by value. [ChangeLog][QtGui][QQuaternion] Added toAxes(), a getAxes() replacement. Task-number: QTBUG-138199 Change-Id: Ie26e16528dc06806e59e54eff2d656a33c322bad Reviewed-by: Volker Hilsheimer <[email protected]>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp b/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp
index bd4a230b78a..d4dc6544a0e 100644
--- a/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp
+++ b/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp
@@ -894,6 +894,13 @@ void tst_QQuaternion::fromAxes()
QQuaternion result = QQuaternion::fromAxisAndAngle(QVector3D(x1, y1, z1), angle);
+ {
+ const auto axes = result.toAxes();
+ QVERIFY(myFuzzyCompare(axes.x, xAxis));
+ QVERIFY(myFuzzyCompare(axes.y, yAxis));
+ QVERIFY(myFuzzyCompare(axes.z, zAxis));
+ }
+
QVector3D axes[3];
result.getAxes(&axes[0], &axes[1], &axes[2]);
QVERIFY(myFuzzyCompare(axes[0], xAxis));
@@ -985,8 +992,7 @@ void tst_QQuaternion::fromDirection_data()
// othonormal up and dir
for (QQuaternion q : orientations) {
- QVector3D xAxis, yAxis, zAxis;
- q.getAxes(&xAxis, &yAxis, &zAxis);
+ const auto [xAxis, yAxis, zAxis] = q.toAxes();
QTest::addRow("ortho dirs: (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f)",
xAxis.x(), xAxis.y(), xAxis.z(),
@@ -1007,8 +1013,7 @@ void tst_QQuaternion::fromDirection_data()
// invalid up
for (QQuaternion q : orientations) {
- QVector3D xAxis, yAxis, zAxis;
- q.getAxes(&xAxis, &yAxis, &zAxis);
+ const auto [xAxis, yAxis, zAxis] = q.toAxes();
QTest::addRow("bad dirs: (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f)",
xAxis.x(), xAxis.y(), xAxis.z(),
@@ -1029,16 +1034,14 @@ void tst_QQuaternion::fromDirection()
QQuaternion result = QQuaternion::fromDirection(direction, up);
QVERIFY(myFuzzyCompare(result, result.normalized()));
- QVector3D xAxis, yAxis, zAxis;
- result.getAxes(&xAxis, &yAxis, &zAxis);
-
- QVERIFY(myFuzzyCompare(zAxis, expectedZ));
+ const auto axes = result.toAxes();
+ QVERIFY(myFuzzyCompare(axes.z, expectedZ));
const QVector3D expectedX = QVector3D::crossProduct(expectedY, expectedZ);
if (!qFuzzyIsNull(expectedX.lengthSquared())) {
- QVERIFY(myFuzzyCompare(xAxis, expectedX));
- QVERIFY(myFuzzyCompare(yAxis, expectedY));
+ QVERIFY(myFuzzyCompare(axes.x, expectedX));
+ QVERIFY(myFuzzyCompare(axes.y, expectedY));
}
}