diff --git a/README.md b/README.md index cfdabd3..59a6165 100644 --- a/README.md +++ b/README.md @@ -1254,69 +1254,73 @@ vec refract(const vec& i, const vec& n, T eta); #### Scalar ```cpp -template < arithmetic T > -constexpr bool equal_to(T x, T y) noexcept; - -template < arithmetic T > -constexpr bool equal_to(T x, T y, T epsilon) noexcept; - -template < arithmetic T > -constexpr bool not_equal_to(T x, T y) noexcept; - -template < arithmetic T > -constexpr bool not_equal_to(T x, T y, T epsilon) noexcept; - template < arithmetic T > constexpr bool any(T x) noexcept; template < arithmetic T > constexpr bool all(T x) noexcept; + +template < arithmetic T > +constexpr bool approximately(T x, T y) noexcept; + +template < arithmetic T > +constexpr bool approximately(T x, T y, T epsilon) noexcept; ``` #### Vector ```cpp -template < typename T, size_t Size > -constexpr vec equal_to(const vec& xs, T y); - -template < typename T, size_t Size > -constexpr vec equal_to(T x, const vec& ys); - -template < typename T, size_t Size > -constexpr vec equal_to(const vec& xs, const vec& ys); - -template < typename T, size_t Size > -constexpr vec equal_to(const vec& xs, T y, T epsilon); - -template < typename T, size_t Size > -constexpr vec equal_to(T x, const vec& ys, T epsilon); - -template < typename T, size_t Size > -constexpr vec equal_to(const vec& xs, const vec& ys, T epsilon); - -template < typename T, size_t Size > -constexpr vec not_equal_to(const vec& xs, T y); - -template < typename T, size_t Size > -constexpr vec not_equal_to(T x, const vec& ys); - -template < typename T, size_t Size > -constexpr vec not_equal_to(const vec& xs, const vec& ys); - -template < typename T, size_t Size > -constexpr vec not_equal_to(const vec& xs, T y, T epsilon); - -template < typename T, size_t Size > -constexpr vec not_equal_to(T x, const vec& ys, T epsilon); - -template < typename T, size_t Size > -constexpr vec not_equal_to(const vec& xs, const vec& ys, T epsilon); - template < typename T, size_t Size > constexpr bool any(const vec& xs); template < typename T, size_t Size > constexpr bool all(const vec& xs); + +template < typename T, size_t Size > +constexpr vec approximately(const vec& xs, T y); + +template < typename T, size_t Size > +constexpr vec approximately(T x, const vec& ys); + +template < typename T, size_t Size > +constexpr vec approximately(const vec& xs, const vec& ys); + +template < typename T, size_t Size > +constexpr vec approximately(const vec& xs, T y, T epsilon); + +template < typename T, size_t Size > +constexpr vec approximately(T x, const vec& ys, T epsilon); + +template < typename T, size_t Size > +constexpr vec approximately(const vec& xs, const vec& ys, T epsilon); +``` + +#### Matrix + +```cpp +template < typename T, size_t Size > +constexpr bool any(const mat& xs); + +template < typename T, size_t Size > +constexpr bool all(const mat& xs); + +template < typename T, size_t Size > +constexpr mat approximately(const mat& xs, T y); + +template < typename T, size_t Size > +constexpr mat approximately(T x, const mat& ys); + +template < typename T, size_t Size > +constexpr mat approximately(const mat& xs, const mat& ys); + +template < typename T, size_t Size > +constexpr mat approximately(const mat& xs, T y, T epsilon); + +template < typename T, size_t Size > +constexpr mat approximately(T x, const mat& ys, T epsilon); + +template < typename T, size_t Size > +constexpr mat approximately(const mat& xs, const mat& ys, T epsilon); ``` ### Matrix Functions diff --git a/headers/vmath.hpp/vmath_fun.hpp b/headers/vmath.hpp/vmath_fun.hpp index 5fb5d74..38c445a 100644 --- a/headers/vmath.hpp/vmath_fun.hpp +++ b/headers/vmath.hpp/vmath_fun.hpp @@ -399,46 +399,11 @@ namespace vmath_hpp } // -// Scalar Relational Functions +// Relational Functions // namespace vmath_hpp { - template < typename T > - [[nodiscard]] std::enable_if_t, bool> - constexpr equal_to(T x, T y) noexcept { - if constexpr ( std::is_floating_point_v ) { - // http://www.realtimecollisiondetection.net/pubs/Tolerances - const T epsilon = std::numeric_limits::epsilon(); - return abs(x - y) <= epsilon * max(T(1), abs(x), abs(y)); - } else { - return x == y; - } - } - - template < typename T > - [[nodiscard]] std::enable_if_t, bool> - constexpr equal_to(T x, T y, T epsilon) noexcept { - if constexpr ( std::is_floating_point_v ) { - // http://www.realtimecollisiondetection.net/pubs/Tolerances - return abs(x - y) <= epsilon * max(T(1), abs(x), abs(y)); - } else { - return abs(x - y) <= epsilon; - } - } - - template < typename T > - [[nodiscard]] std::enable_if_t, bool> - constexpr not_equal_to(T x, T y) noexcept { - return !equal_to(x, y); - } - - template < typename T > - [[nodiscard]] std::enable_if_t, bool> - constexpr not_equal_to(T x, T y, T epsilon) noexcept { - return !equal_to(x, y, epsilon); - } - template < typename T > [[nodiscard]] std::enable_if_t, bool> constexpr any(T x) noexcept { @@ -450,4 +415,27 @@ namespace vmath_hpp constexpr all(T x) noexcept { return !!x; } + + template < typename T > + [[nodiscard]] std::enable_if_t, bool> + constexpr approximately(T x, T y) noexcept { + if constexpr ( std::is_floating_point_v ) { + // http://www.realtimecollisiondetection.net/pubs/Tolerances + const T epsilon = std::numeric_limits::epsilon(); + return abs(x - y) <= epsilon * max(T(1), abs(x), abs(y)); + } else { + return x == y; + } + } + + template < typename T > + [[nodiscard]] std::enable_if_t, bool> + constexpr approximately(T x, T y, T epsilon) noexcept { + if constexpr ( std::is_floating_point_v ) { + // http://www.realtimecollisiondetection.net/pubs/Tolerances + return abs(x - y) <= epsilon * max(T(1), abs(x), abs(y)); + } else { + return abs(x - y) <= epsilon; + } + } } diff --git a/headers/vmath.hpp/vmath_mat_fun.hpp b/headers/vmath.hpp/vmath_mat_fun.hpp index 137460b..e1fc6f6 100644 --- a/headers/vmath.hpp/vmath_mat_fun.hpp +++ b/headers/vmath.hpp/vmath_mat_fun.hpp @@ -544,6 +544,53 @@ namespace vmath_hpp } } +// +// Relational Functions +// + +namespace vmath_hpp +{ + template < typename T, std::size_t Size > + [[nodiscard]] constexpr bool any(const mat& xs) { + return fold_join([](bool acc, const vec& x){ return acc || any(x); }, false, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr bool all(const mat& xs) { + return fold_join([](bool acc, const vec& x){ return acc && all(x); }, true, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat approximately(const mat& xs, T y) { + return map_join([y](const vec& x){ return approximately(x, y); }, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat approximately(T x, const mat& ys) { + return map_join([x](const vec& y){ return approximately(x, y); }, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat approximately(const mat& xs, const mat& ys) { + return map_join([](const vec& x, const vec& y){ return approximately(x, y); }, xs, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat approximately(const mat& xs, T y, T epsilon) { + return map_join([y, epsilon](const vec& x){ return approximately(x, y, epsilon); }, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat approximately(T x, const mat& ys, T epsilon) { + return map_join([x, epsilon](const vec& y){ return approximately(x, y, epsilon); }, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat approximately(const mat& xs, const mat& ys, T epsilon) { + return map_join([epsilon](const vec& x, const vec& y){ return approximately(x, y, epsilon); }, xs, ys); + } +} + // // Matrix Functions // diff --git a/headers/vmath.hpp/vmath_vec_fun.hpp b/headers/vmath.hpp/vmath_vec_fun.hpp index fb59157..142c792 100644 --- a/headers/vmath.hpp/vmath_vec_fun.hpp +++ b/headers/vmath.hpp/vmath_vec_fun.hpp @@ -898,77 +898,11 @@ namespace vmath_hpp } // -// Vector Relational Functions +// Relational Functions // namespace vmath_hpp { - // equal_to - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec equal_to(const vec& xs, T y) { - return map_join([y](T x){ return equal_to(x, y); }, xs); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec equal_to(T x, const vec& ys) { - return map_join([x](T y){ return equal_to(x, y); }, ys); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec equal_to(const vec& xs, const vec& ys) { - return map_join([](T x, T y){ return equal_to(x, y); }, xs, ys); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec equal_to(const vec& xs, T y, T epsilon) { - return map_join([y, epsilon](T x){ return equal_to(x, y, epsilon); }, xs); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec equal_to(T x, const vec& ys, T epsilon) { - return map_join([x, epsilon](T y){ return equal_to(x, y, epsilon); }, ys); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec equal_to(const vec& xs, const vec& ys, T epsilon) { - return map_join([epsilon](T x, T y){ return equal_to(x, y, epsilon); }, xs, ys); - } - - // not_equal_to - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec not_equal_to(const vec& xs, T y) { - return map_join([y](T x){ return not_equal_to(x, y); }, xs); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec not_equal_to(T x, const vec& ys) { - return map_join([x](T y){ return not_equal_to(x, y); }, ys); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec not_equal_to(const vec& xs, const vec& ys) { - return map_join([](T x, T y){ return not_equal_to(x, y); }, xs, ys); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec not_equal_to(const vec& xs, T y, T epsilon) { - return map_join([y, epsilon](T x){ return not_equal_to(x, y, epsilon); }, xs); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec not_equal_to(T x, const vec& ys, T epsilon) { - return map_join([x, epsilon](T y){ return not_equal_to(x, y, epsilon); }, ys); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec not_equal_to(const vec& xs, const vec& ys, T epsilon) { - return map_join([epsilon](T x, T y){ return not_equal_to(x, y, epsilon); }, xs, ys); - } - - // any/all - template < typename T, std::size_t Size > [[nodiscard]] constexpr bool any(const vec& xs) { return fold_join([](bool acc, T x){ return acc || any(x); }, false, xs); @@ -978,4 +912,34 @@ namespace vmath_hpp [[nodiscard]] constexpr bool all(const vec& xs) { return fold_join([](bool acc, T x){ return acc && all(x); }, true, xs); } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec approximately(const vec& xs, T y) { + return map_join([y](T x){ return approximately(x, y); }, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec approximately(T x, const vec& ys) { + return map_join([x](T y){ return approximately(x, y); }, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec approximately(const vec& xs, const vec& ys) { + return map_join([](T x, T y){ return approximately(x, y); }, xs, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec approximately(const vec& xs, T y, T epsilon) { + return map_join([y, epsilon](T x){ return approximately(x, y, epsilon); }, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec approximately(T x, const vec& ys, T epsilon) { + return map_join([x, epsilon](T y){ return approximately(x, y, epsilon); }, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec approximately(const vec& xs, const vec& ys, T epsilon) { + return map_join([epsilon](T x, T y){ return approximately(x, y, epsilon); }, xs, ys); + } } diff --git a/untests/vmath_fun_tests.cpp b/untests/vmath_fun_tests.cpp index b9634d8..995be87 100644 --- a/untests/vmath_fun_tests.cpp +++ b/untests/vmath_fun_tests.cpp @@ -142,29 +142,7 @@ TEST_CASE("vmath/fun") { REQUIRE(refract(1.f, 2.f, 1.f) == approx(-7.f)); } - SUBCASE("Scalar Relational Functions") { - STATIC_REQUIRE(equal_to(1, 1)); - STATIC_REQUIRE_FALSE(equal_to(0, 1)); - STATIC_REQUIRE_FALSE(equal_to(0, 1, 0)); - STATIC_REQUIRE(equal_to(0, 1, 1)); - - STATIC_REQUIRE(not_equal_to(0, 1)); - STATIC_REQUIRE(not_equal_to(0, 1, 0)); - STATIC_REQUIRE_FALSE(not_equal_to(0, 1, 1)); - STATIC_REQUIRE_FALSE(not_equal_to(1, 1)); - STATIC_REQUIRE_FALSE(not_equal_to(1, 1, 0)); - STATIC_REQUIRE_FALSE(not_equal_to(1, 1, 1)); - - STATIC_REQUIRE(equal_to(1.f, 1.f + std::numeric_limits::epsilon() * 0.5f)); - STATIC_REQUIRE_FALSE(equal_to(1.f, 1.f + std::numeric_limits::epsilon() * 1.5f)); - STATIC_REQUIRE(equal_to(100.f, 100.f + std::numeric_limits::epsilon() * 90.f)); - STATIC_REQUIRE_FALSE(equal_to(100.f, 100.f + std::numeric_limits::epsilon() * 110.f)); - - STATIC_REQUIRE_FALSE(not_equal_to(1.f, 1.f + std::numeric_limits::epsilon() * 0.5f)); - STATIC_REQUIRE(not_equal_to(1.f, 1.f + std::numeric_limits::epsilon() * 1.5f)); - STATIC_REQUIRE_FALSE(not_equal_to(100.f, 100.f + std::numeric_limits::epsilon() * 90.f)); - STATIC_REQUIRE(not_equal_to(100.f, 100.f + std::numeric_limits::epsilon() * 110.f)); - + SUBCASE("Relational Functions") { STATIC_REQUIRE_FALSE(any(false)); STATIC_REQUIRE_FALSE(any(0)); STATIC_REQUIRE(any(true)); @@ -174,5 +152,15 @@ TEST_CASE("vmath/fun") { STATIC_REQUIRE_FALSE(all(0)); STATIC_REQUIRE(all(true)); STATIC_REQUIRE(all(1)); + + STATIC_REQUIRE(approximately(1, 1)); + STATIC_REQUIRE_FALSE(approximately(0, 1)); + STATIC_REQUIRE_FALSE(approximately(0, 1, 0)); + STATIC_REQUIRE(approximately(0, 1, 1)); + + STATIC_REQUIRE(approximately(1.f, 1.f + std::numeric_limits::epsilon() * 0.5f)); + STATIC_REQUIRE_FALSE(approximately(1.f, 1.f + std::numeric_limits::epsilon() * 1.5f)); + STATIC_REQUIRE(approximately(100.f, 100.f + std::numeric_limits::epsilon() * 90.f)); + STATIC_REQUIRE_FALSE(approximately(100.f, 100.f + std::numeric_limits::epsilon() * 110.f)); } } diff --git a/untests/vmath_mat_fun_tests.cpp b/untests/vmath_mat_fun_tests.cpp index 24d919d..2f2322a 100644 --- a/untests/vmath_mat_fun_tests.cpp +++ b/untests/vmath_mat_fun_tests.cpp @@ -181,6 +181,44 @@ TEST_CASE("vmath/mat_fun") { STATIC_REQUIRE((1 >= int2x2(0,1,2,3)) == bool2x2(true, true, false, false)); } + SUBCASE("relational functions") { + STATIC_REQUIRE_FALSE(any(bool2x2(false, false, false, false))); + STATIC_REQUIRE(any(bool2x2(true, false, true, false))); + STATIC_REQUIRE(any(bool2x2(false, true, false, true))); + STATIC_REQUIRE(any(bool2x2(true, true, true, true))); + + STATIC_REQUIRE_FALSE(any(int2x2(0, 0, 0, 0))); + STATIC_REQUIRE(any(int2x2(1, 0, 1, 0))); + STATIC_REQUIRE(any(int2x2(0, 1, 0, 1))); + STATIC_REQUIRE(any(int2x2(1, 1, 1, 1))); + + STATIC_REQUIRE_FALSE(all(bool2x2(false, false, false, false))); + STATIC_REQUIRE_FALSE(all(bool2x2(true, false, true, false))); + STATIC_REQUIRE_FALSE(all(bool2x2(false, true, false, true))); + STATIC_REQUIRE(all(bool2x2(true, true, true, true))); + + STATIC_REQUIRE_FALSE(all(int2x2(0, 0, 0, 0))); + STATIC_REQUIRE_FALSE(all(int2x2(1, 0, 1, 0))); + STATIC_REQUIRE_FALSE(all(int2x2(0, 1, 0, 1))); + STATIC_REQUIRE(all(int2x2(1, 1, 1, 1))); + + STATIC_REQUIRE(approximately(int2x2(1,1,1,1), int2x2(0,1,2,3)) == bool2x2(false, true, false, false)); + STATIC_REQUIRE(approximately(int2x2(0,1,2,3),1) == bool2x2(false, true, false, false)); + STATIC_REQUIRE(approximately(1,int2x2(0,1,2,3)) == bool2x2(false, true, false, false)); + + STATIC_REQUIRE(approximately(int2x2(1,1,1,1), int2x2(0,1,2,3), 0) == bool2x2(false, true, false, false)); + STATIC_REQUIRE(approximately(int2x2(0,1,2,3), 1, 0) == bool2x2(false, true, false, false)); + STATIC_REQUIRE(approximately(1, int2x2(0,1,2,3), 0) == bool2x2(false, true, false, false)); + + STATIC_REQUIRE(approximately(int2x2(1,1,1,1), int2x2(0,1,2,3), 1) == bool2x2(true, true, true, false)); + STATIC_REQUIRE(approximately(int2x2(0,1,2,3), 1, 1) == bool2x2(true, true, true, false)); + STATIC_REQUIRE(approximately(1, int2x2(0,1,2,3), 1) == bool2x2(true, true, true, false)); + + STATIC_REQUIRE(approximately(int2x2(1,1,1,1), int2x2(0,1,2,3), 2) == bool2x2(true, true, true, true)); + STATIC_REQUIRE(approximately(int2x2(0,1,2,3), 1, 2) == bool2x2(true, true, true, true)); + STATIC_REQUIRE(approximately(1, int2x2(0,1,2,3), 2) == bool2x2(true, true, true, true)); + } + SUBCASE("transpose") { STATIC_REQUIRE(transpose(int2x2( 1, 2, @@ -242,7 +280,7 @@ TEST_CASE("vmath/mat_fun") { { constexpr float4x4 m1 = translate(float3(1.f, 2.f, 3.f)); constexpr float4x4 rm1 = inverse(m1); - STATIC_REQUIRE(all(equal_to( + STATIC_REQUIRE(all(approximately( unit4_z * m1 * rm1, unit4_z, approx_epsilon_v))); @@ -252,7 +290,7 @@ TEST_CASE("vmath/mat_fun") { const float3 axis2 = normalize(float3(1.f, 2.f, 3.f)); const float4x4 m2 = rotate(0.5f,axis2); const float4x4 rm2 = inverse(m2); - REQUIRE(all(equal_to( + REQUIRE(all(approximately( unit4_z * m2 * rm2, unit4_z, approx_epsilon_v))); @@ -262,7 +300,7 @@ TEST_CASE("vmath/mat_fun") { const float3 axis3 = normalize(float3(1.f, 2.f, 3.f)); const float3x3 m3 = float3x3(rotate(0.5f,axis3)); const float3x3 rm3 = inverse(m3); - REQUIRE(all(equal_to( + REQUIRE(all(approximately( unit3_z * m3 * rm3, unit3_z, approx_epsilon_v))); @@ -272,7 +310,7 @@ TEST_CASE("vmath/mat_fun") { const float3 axis4 = normalize(float3(0.f, 0.f, 3.f)); const float2x2 m4 = float2x2(rotate(0.5f,axis4)); const float2x2 rm4 = inverse(m4); - REQUIRE(all(equal_to( + REQUIRE(all(approximately( unit2_y * m4 * rm4, unit2_y, approx_epsilon_v))); diff --git a/untests/vmath_tests.hpp b/untests/vmath_tests.hpp index f972f37..4b1353a 100644 --- a/untests/vmath_tests.hpp +++ b/untests/vmath_tests.hpp @@ -73,21 +73,21 @@ namespace vmath_tests template < typename T > constexpr bool operator==(const T& l, const approx& r) { - return equal_to(l, r.value, approx_epsilon_v); + return approximately(l, r.value, approx_epsilon_v); } template < typename T > constexpr bool operator==(const vec& l, const approx2& r) { - return all(equal_to(l, r.value, approx_epsilon_v)); + return all(approximately(l, r.value, approx_epsilon_v)); } template < typename T > constexpr bool operator==(const vec& l, const approx3& r) { - return all(equal_to(l, r.value, approx_epsilon_v)); + return all(approximately(l, r.value, approx_epsilon_v)); } template < typename T > constexpr bool operator==(const vec& l, const approx4& r) { - return all(equal_to(l, r.value, approx_epsilon_v)); + return all(approximately(l, r.value, approx_epsilon_v)); } } diff --git a/untests/vmath_vec_fun_tests.cpp b/untests/vmath_vec_fun_tests.cpp index accb607..e8adc35 100644 --- a/untests/vmath_vec_fun_tests.cpp +++ b/untests/vmath_vec_fun_tests.cpp @@ -268,39 +268,7 @@ TEST_CASE("vmath/vec_fun") { REQUIRE(refract(float2(1.f), float2(2.f), 1.f).x == approx(-15.f)); } - SUBCASE("Vector Relational Functions") { - STATIC_REQUIRE(equal_to(int3(1,1,1), int3(0,1,2)) == bool3(false, true, false)); - STATIC_REQUIRE(equal_to(int3(0,1,2),1) == bool3(false, true, false)); - STATIC_REQUIRE(equal_to(1,int3(0,1,2)) == bool3(false, true, false)); - - STATIC_REQUIRE(equal_to(int4(1,1,1,1), int4(0,1,2,3), 0) == bool4(false, true, false, false)); - STATIC_REQUIRE(equal_to(int4(0,1,2,3), 1, 0) == bool4(false, true, false, false)); - STATIC_REQUIRE(equal_to(1, int4(0,1,2,3), 0) == bool4(false, true, false, false)); - - STATIC_REQUIRE(equal_to(int4(1,1,1,1), int4(0,1,2,3), 1) == bool4(true, true, true, false)); - STATIC_REQUIRE(equal_to(int4(0,1,2,3), 1, 1) == bool4(true, true, true, false)); - STATIC_REQUIRE(equal_to(1, int4(0,1,2,3), 1) == bool4(true, true, true, false)); - - STATIC_REQUIRE(equal_to(int4(1,1,1,1), int4(0,1,2,3), 2) == bool4(true, true, true, true)); - STATIC_REQUIRE(equal_to(int4(0,1,2,3), 1, 2) == bool4(true, true, true, true)); - STATIC_REQUIRE(equal_to(1, int4(0,1,2,3), 2) == bool4(true, true, true, true)); - - STATIC_REQUIRE(not_equal_to(int3(1,1,1), int3(0,1,2)) == bool3(true, false, true)); - STATIC_REQUIRE(not_equal_to(int3(0,1,2),1) == bool3(true, false, true)); - STATIC_REQUIRE(not_equal_to(1,int3(0,1,2)) == bool3(true, false, true)); - - STATIC_REQUIRE(not_equal_to(int4(1,1,1,1), int4(0,1,2,3), 0) == bool4(true, false, true, true)); - STATIC_REQUIRE(not_equal_to(int4(0,1,2,3), 1, 0) == bool4(true, false, true, true)); - STATIC_REQUIRE(not_equal_to(1, int4(0,1,2,3), 0) == bool4(true, false, true, true)); - - STATIC_REQUIRE(not_equal_to(int4(1,1,1,1), int4(0,1,2,3), 1) == bool4(false, false, false, true)); - STATIC_REQUIRE(not_equal_to(int4(0,1,2,3), 1, 1) == bool4(false, false, false, true)); - STATIC_REQUIRE(not_equal_to(1, int4(0,1,2,3), 1) == bool4(false, false, false, true)); - - STATIC_REQUIRE(not_equal_to(int4(1,1,1,1), int4(0,1,2,3), 2) == bool4(false, false, false, false)); - STATIC_REQUIRE(not_equal_to(int4(0,1,2,3), 1, 2) == bool4(false, false, false, false)); - STATIC_REQUIRE(not_equal_to(1, int4(0,1,2,3), 2) == bool4(false, false, false, false)); - + SUBCASE("Relational Functions") { STATIC_REQUIRE_FALSE(any(bool2(false, false))); STATIC_REQUIRE(any(bool2(true, false))); STATIC_REQUIRE(any(bool2(false, true))); @@ -320,5 +288,21 @@ TEST_CASE("vmath/vec_fun") { STATIC_REQUIRE_FALSE(all(int2(1, 0))); STATIC_REQUIRE_FALSE(all(int2(0, 1))); STATIC_REQUIRE(all(int2(1, 1))); + + STATIC_REQUIRE(approximately(int3(1,1,1), int3(0,1,2)) == bool3(false, true, false)); + STATIC_REQUIRE(approximately(int3(0,1,2),1) == bool3(false, true, false)); + STATIC_REQUIRE(approximately(1,int3(0,1,2)) == bool3(false, true, false)); + + STATIC_REQUIRE(approximately(int4(1,1,1,1), int4(0,1,2,3), 0) == bool4(false, true, false, false)); + STATIC_REQUIRE(approximately(int4(0,1,2,3), 1, 0) == bool4(false, true, false, false)); + STATIC_REQUIRE(approximately(1, int4(0,1,2,3), 0) == bool4(false, true, false, false)); + + STATIC_REQUIRE(approximately(int4(1,1,1,1), int4(0,1,2,3), 1) == bool4(true, true, true, false)); + STATIC_REQUIRE(approximately(int4(0,1,2,3), 1, 1) == bool4(true, true, true, false)); + STATIC_REQUIRE(approximately(1, int4(0,1,2,3), 1) == bool4(true, true, true, false)); + + STATIC_REQUIRE(approximately(int4(1,1,1,1), int4(0,1,2,3), 2) == bool4(true, true, true, true)); + STATIC_REQUIRE(approximately(int4(0,1,2,3), 1, 2) == bool4(true, true, true, true)); + STATIC_REQUIRE(approximately(1, int4(0,1,2,3), 2) == bool4(true, true, true, true)); } }