From dbc67a01ced7fcbd55e8341f9a35deea2968c795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 28 Nov 2020 17:20:23 +0100 Subject: [PATCH] Math: reorder test to be in the same order as in the header. --- src/Magnum/Math/Test/IntersectionTest.cpp | 96 +++++++++++------------ 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/src/Magnum/Math/Test/IntersectionTest.cpp b/src/Magnum/Math/Test/IntersectionTest.cpp index e7a436142..90c276525 100644 --- a/src/Magnum/Math/Test/IntersectionTest.cpp +++ b/src/Magnum/Math/Test/IntersectionTest.cpp @@ -42,6 +42,7 @@ struct IntersectionTest: Corrade::TestSuite::Tester { void pointFrustum(); void rangeFrustum(); + void rayRange(); void aabbFrustum(); void sphereFrustum(); @@ -51,7 +52,6 @@ struct IntersectionTest: Corrade::TestSuite::Tester { void sphereConeView(); void sphereConeViewNotRigid(); void rangeCone(); - void rayRange(); void aabbCone(); }; @@ -73,6 +73,7 @@ IntersectionTest::IntersectionTest() { &IntersectionTest::pointFrustum, &IntersectionTest::rangeFrustum, + &IntersectionTest::rayRange, &IntersectionTest::aabbFrustum, &IntersectionTest::sphereFrustum, @@ -82,7 +83,6 @@ IntersectionTest::IntersectionTest() { &IntersectionTest::sphereConeView, &IntersectionTest::sphereConeViewNotRigid, &IntersectionTest::rangeCone, - &IntersectionTest::rayRange, &IntersectionTest::aabbCone}); } @@ -181,6 +181,52 @@ void IntersectionTest::rangeFrustum() { CORRADE_VERIFY(!Intersection::rangeFrustum(Range3D{Vector3{-10.0f}, Vector3{-5.0f}}, frustum)); } +void IntersectionTest::rayRange() { + const Vector3 origin{2.0f, 2.0f, 2.0f}; + const Range3D range{{-1.0f, -1.0f, -1.0f}, + { 1.0f, 1.0f, 1.0f}}; + + const Vector3 center{0.0f, 0.0f, 1.0f}; + const Vector3 edge{0.0f, -1.0f, 1.0f}; + const Vector3 corner{-1.0f, -1.0f, 1.0f}; + const Float eps = 1e-6f; + + /* intersection at face center */ + const Vector3 direction1 = center - origin; + const Vector3 invDir1 = 1.0f/direction1; + CORRADE_VERIFY(Intersection::rayRange(origin, invDir1, range)); + + /* intersection close to edge */ + const Vector3 direction2 = edge + Vector3{0.0f, eps, 0.0f} - origin; + const Vector3 invDir2 = 1.0f/direction2; + CORRADE_VERIFY(Intersection::rayRange(origin, invDir2, range)); + + /* no intersection close to edge */ + const Vector3 direction3 = edge - Vector3{0.0f, eps, 0.0f} - origin; + const Vector3 invDir3 = 1.0f/direction3; + CORRADE_VERIFY(!Intersection::rayRange(origin, invDir3, range)); + + /* intersection close to corner */ + const Vector3 direction4 = corner + Vector3{eps, eps, 0.0f} - origin; + const Vector3 invDir4 = 1.0f/direction4; + CORRADE_VERIFY(Intersection::rayRange(origin, invDir4, range)); + + /* no intersection close to corner */ + const Vector3 direction5 = corner - Vector3{eps, eps, 0.0f} - origin; + const Vector3 invDir5 = 1.0f/direction5; + CORRADE_VERIFY(!Intersection::rayRange(origin, invDir5, range)); + + /* divide by zero test with intersection */ + const Vector3 direction6{0.0f, 0.0f, -1.0f}; + const Vector3 invDir6 = 1.0f/direction6; + CORRADE_VERIFY(Intersection::rayRange({0.0f, 0.0f, 2.0f}, invDir6, range)); + + /* divide by zero test without intersection */ + const Vector3 direction7{0.0f, 0.0f, 1.0f}; + const Vector3 invDir7 = 1.0f/direction7; + CORRADE_VERIFY(!Intersection::rayRange(origin, invDir7, range)); +} + void IntersectionTest::aabbFrustum() { const Frustum frustum{ {1.0f, 0.0f, 0.0f, 0.0f}, @@ -436,52 +482,6 @@ void IntersectionTest::rangeCone() { center, normal, angle)); } -void IntersectionTest::rayRange() { - const Vector3 origin{2.0f, 2.0f, 2.0f}; - const Range3D range{{-1.0f, -1.0f, -1.0f}, - { 1.0f, 1.0f, 1.0f}}; - - const Vector3 center{0.0f, 0.0f, 1.0f}; - const Vector3 edge{0.0f, -1.0f, 1.0f}; - const Vector3 corner{-1.0f, -1.0f, 1.0f}; - const Float eps = 1e-6f; - - /* intersection at face center */ - const Vector3 direction1 = center - origin; - const Vector3 invDir1 = 1.0f/direction1; - CORRADE_VERIFY(Intersection::rayRange(origin, invDir1, range)); - - /* intersection close to edge */ - const Vector3 direction2 = edge + Vector3{0.0f, eps, 0.0f} - origin; - const Vector3 invDir2 = 1.0f/direction2; - CORRADE_VERIFY(Intersection::rayRange(origin, invDir2, range)); - - /* no intersection close to edge */ - const Vector3 direction3 = edge - Vector3{0.0f, eps, 0.0f} - origin; - const Vector3 invDir3 = 1.0f/direction3; - CORRADE_VERIFY(!Intersection::rayRange(origin, invDir3, range)); - - /* intersection close to corner */ - const Vector3 direction4 = corner + Vector3{eps, eps, 0.0f} - origin; - const Vector3 invDir4 = 1.0f/direction4; - CORRADE_VERIFY(Intersection::rayRange(origin, invDir4, range)); - - /* no intersection close to corner */ - const Vector3 direction5 = corner - Vector3{eps, eps, 0.0f} - origin; - const Vector3 invDir5 = 1.0f/direction5; - CORRADE_VERIFY(!Intersection::rayRange(origin, invDir5, range)); - - /* divide by zero test with intersection */ - const Vector3 direction6{0.0f, 0.0f, -1.0f}; - const Vector3 invDir6 = 1.0f/direction6; - CORRADE_VERIFY(Intersection::rayRange({0.0f, 0.0f, 2.0f}, invDir6, range)); - - /* divide by zero test without intersection */ - const Vector3 direction7{0.0f, 0.0f, 1.0f}; - const Vector3 invDir7 = 1.0f/direction7; - CORRADE_VERIFY(!Intersection::rayRange(origin, invDir7, range)); -} - void IntersectionTest::aabbCone() { const Vector3 center{1.0f, -2.0f, 1.3f}; const Vector3 normal{0.453154f, 0.422618f, 0.784886f};