diff --git a/src/Magnum/Math/Frustum.h b/src/Magnum/Math/Frustum.h index 7311354e9..5f53078cd 100644 --- a/src/Magnum/Math/Frustum.h +++ b/src/Magnum/Math/Frustum.h @@ -181,6 +181,24 @@ template template constexpr Frustum::Frustum(const Frustum< Vector4{other[4]}, Vector4{other[5]}} {} +namespace Implementation { + +template struct StrictWeakOrdering> { + bool operator()(const Frustum& a, const Frustum& b) const { + StrictWeakOrdering> o; + for(std::size_t i = 0; i < 6; ++i) { + if(o(a[i], b[i])) + return true; + if(o(b[i], a[i])) + return false; + } + + return false; /* a and b are equivalent */ + } +}; + +} + }} #endif diff --git a/src/Magnum/Math/Test/FrustumTest.cpp b/src/Magnum/Math/Test/FrustumTest.cpp index 729642ad5..f76f6b934 100644 --- a/src/Magnum/Math/Test/FrustumTest.cpp +++ b/src/Magnum/Math/Test/FrustumTest.cpp @@ -29,6 +29,7 @@ #include #include "Magnum/Math/Frustum.h" +#include "Magnum/Math/StrictWeakOrdering.h" struct Frstm { float data[24]; @@ -77,6 +78,8 @@ struct FrustumTest: Corrade::TestSuite::Tester { void compare(); + void strictWeakOrdering(); + void debug(); }; @@ -98,6 +101,8 @@ FrustumTest::FrustumTest() { &FrustumTest::compare, + &FrustumTest::strictWeakOrdering, + &FrustumTest::debug}); } @@ -310,6 +315,40 @@ void FrustumTest::compare() { CORRADE_VERIFY(a != c); } +void FrustumTest::strictWeakOrdering() { + StrictWeakOrdering o; + const Frustum a{ + {1.0f, 1.0f, 2.0f, 2.0f}, + {5.0f, 5.0f, 6.0f, 5.0f}, + {5.0f, 5.0f, 6.0f, 5.0f}, + {5.0f, 5.0f, 6.0f, 5.0f}, + {5.0f, 5.0f, 6.0f, 5.0f}, + {3.0f, 1.0f, 2.0f, 4.0f}}; + const Frustum b{ + {2.0f, 1.0f, 2.0f, 3.0f}, + {5.0f, 5.0f, 6.0f, 5.0f}, + {5.0f, 5.0f, 6.0f, 5.0f}, + {5.0f, 5.0f, 6.0f, 5.0f}, + {5.0f, 5.0f, 6.0f, 5.0f}, + {4.0f, 1.0f, 2.0f, 5.0f}}; + const Frustum c{ + {1.0f, 1.0f, 2.0f, 2.0f}, + {5.0f, 5.0f, 6.0f, 5.0f}, + {5.0f, 5.0f, 6.0f, 5.0f}, + {5.0f, 5.0f, 6.0f, 5.0f}, + {5.0f, 5.0f, 6.0f, 5.0f}, + {3.0f, 1.0f, 2.0f, 5.0f}}; + + CORRADE_VERIFY( o(a, b)); + CORRADE_VERIFY(!o(b, a)); + CORRADE_VERIFY( o(a, c)); + CORRADE_VERIFY(!o(c, a)); + CORRADE_VERIFY( o(c, b)); + CORRADE_VERIFY(!o(b, c)); + + CORRADE_VERIFY(!o(a, a)); +} + void FrustumTest::debug() { Frustum frustum{ {-1.0f, 2.0f, -3.0f, 0.1f},