diff options
author | Laszlo Papp <lpapp@kde.org> | 2013-03-15 04:54:43 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-15 18:37:51 +0100 |
commit | d8bef6bb2e7523112781ad81e0268fa67b610c3b (patch) | |
tree | c6d56eb8d8648a7a987dd77a166d526a00c5435b /tests | |
parent | 379886d24b9b0a88930dc479db2217c15381814f (diff) |
Add a minor convenience for calculating the distance to a point
Change-Id: I312727bf6858ead6c30fe20bf3abc5afc73a3a14
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp index 5cd597aeb8..56f9ad5cb7 100644 --- a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp +++ b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp @@ -128,6 +128,8 @@ private slots: void crossProduct(); void normal_data(); void normal(); + void distanceToPoint_data(); + void distanceToPoint(); void distanceToPlane_data(); void distanceToPlane(); void distanceToLine_data(); @@ -1788,6 +1790,59 @@ void tst_QVectorND::normal() QVERIFY(QVector3D::normal(point, v1 + point, v2 + point) == v3.normalized()); } +// Test distance to point calculations. +void tst_QVectorND::distanceToPoint_data() +{ + QTest::addColumn<float>("x1"); // Point to test for distance + QTest::addColumn<float>("y1"); + QTest::addColumn<float>("z1"); + QTest::addColumn<float>("x2"); // Point to test against + QTest::addColumn<float>("y2"); + QTest::addColumn<float>("z2"); + + QTest::addColumn<float>("distance"); + + QTest::newRow("null") + << 0.0f << 0.0f << 0.0f + << 0.0f << 0.0f << 1.0f + << 1.0f; + + QTest::newRow("on point") + << 0.0f << 0.0f << 0.0f + << 0.0f << 0.0f << 0.0f + << 0.0f; + + QTest::newRow("off point") + << 0.0f << 0.0f << 0.0f + << 0.0f << 0.0f << 1.0f + << 1.0f; + + QTest::newRow("off point 2") + << 0.0f << 0.0f << 0.0f + << 0.0f << 2.0f << 0.0f + << 2.0f; + + QTest::newRow("minus point") + << 0.0f << 0.0f << 0.0f + << 0.0f << -2.0f << 0.0f + << 2.0f; +} +void tst_QVectorND::distanceToPoint() +{ + QFETCH(float, x1); + QFETCH(float, y1); + QFETCH(float, z1); + QFETCH(float, x2); + QFETCH(float, y2); + QFETCH(float, z2); + QFETCH(float, distance); + + QVector3D v1(x1, y1, z1); + QVector3D v2(x2, y2, z2); + + QCOMPARE(v1.distanceToPoint(v2), distance); +} + // Test distance to plane calculations. void tst_QVectorND::distanceToPlane_data() { |