From b83290208f5baaff469ab59b24fe11705c0a9f9d Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Mon, 7 Dec 2020 20:18:09 +0700 Subject: [PATCH] revert relational operators to functions --- README.md | 264 +++++++++++++++++----------- headers/vmath.hpp/vmath_fun.hpp | 36 ++++ headers/vmath.hpp/vmath_mat_fun.hpp | 194 ++++++++++++-------- headers/vmath.hpp/vmath_vec_fun.hpp | 194 ++++++++++++-------- untests/vmath_ext_tests.cpp | 15 ++ untests/vmath_mat_fun_tests.cpp | 42 +++-- untests/vmath_mat_tests.cpp | 10 ++ untests/vmath_vec_fun_tests.cpp | 42 +++-- untests/vmath_vec_tests.cpp | 10 ++ 9 files changed, 531 insertions(+), 276 deletions(-) diff --git a/README.md b/README.md index 5347efd..b1c9f86 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,7 @@ Most functions and types are based on the HLSL ([High-Level Shading Language for - [Vector Types](#Vector-Types) - [Matrix Types](#Matrix-Types) - [Vector Operators](#Vector-Operators) -- [Vector Relational Operators](#Vector-Relational-Operators) - [Matrix Operators](#Matrix-Operators) -- [Matrix Relational Operators](#Matrix-Relational-Operators) - [Angle and Trigonometry Functions](#Angle-and-Trigonometry-Functions) - [Exponential Functions](#Exponential-Functions) - [Common Functions](#Common-Functions) @@ -545,6 +543,8 @@ constexpr vec operator||(const vec& xs, const vec& template < typename T, size_t Size > constexpr bool operator==(const vec& xs, const vec& ys); +// operator!= + template < typename T, size_t Size > constexpr bool operator!=(const vec& xs, const vec& ys); @@ -554,54 +554,6 @@ template < typename T, size_t Size > constexpr bool operator<(const vec& xs, const vec& ys); ``` -### Vector Relational Operators - -```cpp -// operator< - -template < typename T, size_t Size > -constexpr vec operator<(const vec& xs, T y); - -template < typename T, size_t Size > -constexpr vec operator<(T x, const vec& ys); - -template < typename T, size_t Size > -constexpr vec operator<(const vec& xs, const vec& ys); - -// operator<= - -template < typename T, size_t Size > -constexpr vec operator<=(const vec& xs, T y); - -template < typename T, size_t Size > -constexpr vec operator<=(T x, const vec& ys); - -template < typename T, size_t Size > -constexpr vec operator<=(const vec& xs, const vec& ys); - -// operator> - -template < typename T, size_t Size > -constexpr vec operator>(const vec& xs, T y); - -template < typename T, size_t Size > -constexpr vec operator>(T x, const vec& ys); - -template < typename T, size_t Size > -constexpr vec operator>(const vec& xs, const vec& ys); - -// operator>= - -template < typename T, size_t Size > -constexpr vec operator>=(const vec& xs, T y); - -template < typename T, size_t Size > -constexpr vec operator>=(T x, const vec& ys); - -template < typename T, size_t Size > -constexpr vec operator>=(const vec& xs, const vec& ys); -``` - ### Matrix Operators ```cpp @@ -780,6 +732,8 @@ constexpr mat operator||(const mat& xs, const mat& template < typename T, size_t Size > constexpr bool operator==(const mat& xs, const mat& ys); +// operator!= + template < typename T, size_t Size > constexpr bool operator!=(const mat& xs, const mat& ys); @@ -789,54 +743,6 @@ template < typename T, size_t Size > constexpr bool operator<(const mat& xs, const mat& ys); ``` -### Matrix Relational Operators - -```cpp -// operator< - -template < typename T, size_t Size > -constexpr mat operator<(const mat& xs, T y); - -template < typename T, size_t Size > -constexpr mat operator<(T x, const mat& ys); - -template < typename T, size_t Size > -constexpr mat operator<(const mat& xs, const mat& ys); - -// operator<= - -template < typename T, size_t Size > -constexpr mat operator<=(const mat& xs, T y); - -template < typename T, size_t Size > -constexpr mat operator<=(T x, const mat& ys); - -template < typename T, size_t Size > -constexpr mat operator<=(const mat& xs, const mat& ys); - -// operator> - -template < typename T, size_t Size > -constexpr mat operator>(const mat& xs, T y); - -template < typename T, size_t Size > -constexpr mat operator>(T x, const mat& ys); - -template < typename T, size_t Size > -constexpr mat operator>(const mat& xs, const mat& ys); - -// operator>= - -template < typename T, size_t Size > -constexpr mat operator>=(const mat& xs, T y); - -template < typename T, size_t Size > -constexpr mat operator>=(T x, const mat& ys); - -template < typename T, size_t Size > -constexpr mat operator>=(const mat& xs, const mat& ys); -``` - ### Angle and Trigonometry Functions #### Scalar @@ -1265,17 +1171,41 @@ constexpr bool approx(T x, T y) noexcept; template < arithmetic T > constexpr bool approx(T x, T y, T epsilon) noexcept; + +template < arithmetic T > +constexpr bool less(T x, T y) noexcept; + +template < arithmetic T > +constexpr bool less_equal(T x, T y) noexcept; + +template < arithmetic T > +constexpr bool greater(T x, T y) noexcept; + +template < arithmetic T > +constexpr bool greater_equal(T x, T y) noexcept; + +template < arithmetic T > +constexpr bool equal_to(T x, T y) noexcept; + +template < arithmetic T > +constexpr bool not_equal_to(T x, T y) noexcept; ``` #### Vector ```cpp +// any + template < typename T, size_t Size > constexpr bool any(const vec& xs); +// all + template < typename T, size_t Size > constexpr bool all(const vec& xs); +// approx + template < typename T, size_t Size > constexpr vec approx(const vec& xs, T y); @@ -1293,17 +1223,89 @@ constexpr vec approx(T x, const vec& ys, T epsilon); template < typename T, size_t Size > constexpr vec approx(const vec& xs, const vec& ys, T epsilon); + +// less + +template < typename T, size_t Size > +constexpr vec less(const vec& xs, T y); + +template < typename T, size_t Size > +constexpr vec less(T x, const vec& ys); + +template < typename T, size_t Size > +constexpr vec less(const vec& xs, const vec& ys); + +// less_equal + +template < typename T, size_t Size > +constexpr vec less_equal(const vec& xs, T y); + +template < typename T, size_t Size > +constexpr vec less_equal(T x, const vec& ys); + +template < typename T, size_t Size > +constexpr vec less_equal(const vec& xs, const vec& ys); + +// greater + +template < typename T, size_t Size > +constexpr vec greater(const vec& xs, T y); + +template < typename T, size_t Size > +constexpr vec greater(T x, const vec& ys); + +template < typename T, size_t Size > +constexpr vec greater(const vec& xs, const vec& ys); + +// greater_equal + +template < typename T, size_t Size > +constexpr vec greater_equal(const vec& xs, T y); + +template < typename T, size_t Size > +constexpr vec greater_equal(T x, const vec& ys); + +template < typename T, size_t Size > +constexpr vec greater_equal(const vec& xs, const vec& ys); + +// equal_to + +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); + +// not_equal_to + +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); ``` #### Matrix ```cpp +// any + template < typename T, size_t Size > constexpr bool any(const mat& xs); +// all + template < typename T, size_t Size > constexpr bool all(const mat& xs); +// approx + template < typename T, size_t Size > constexpr mat approx(const mat& xs, T y); @@ -1321,6 +1323,72 @@ constexpr mat approx(T x, const mat& ys, T epsilon); template < typename T, size_t Size > constexpr mat approx(const mat& xs, const mat& ys, T epsilon); + +// less + +template < typename T, std::size_t Size > +constexpr mat less(const mat& xs, T y); + +template < typename T, std::size_t Size > +constexpr mat less(T x, const mat& ys); + +template < typename T, std::size_t Size > +constexpr mat less(const mat& xs, const mat& ys); + +// less_equal + +template < typename T, std::size_t Size > +constexpr mat less_equal(const mat& xs, T y); + +template < typename T, std::size_t Size > +constexpr mat less_equal(T x, const mat& ys); + +template < typename T, std::size_t Size > +constexpr mat less_equal(const mat& xs, const mat& ys); + +// greater + +template < typename T, std::size_t Size > +constexpr mat greater(const mat& xs, T y); + +template < typename T, std::size_t Size > +constexpr mat greater(T x, const mat& ys); + +template < typename T, std::size_t Size > +constexpr mat greater(const mat& xs, const mat& ys); + +// greater_equal + +template < typename T, std::size_t Size > +constexpr mat greater_equal(const mat& xs, T y); + +template < typename T, std::size_t Size > +constexpr mat greater_equal(T x, const mat& ys); + +template < typename T, std::size_t Size > +constexpr mat greater_equal(const mat& xs, const mat& ys); + +// equal_to + +template < typename T, std::size_t Size > +constexpr mat equal_to(const mat& xs, T y); + +template < typename T, std::size_t Size > +constexpr mat equal_to(T x, const mat& ys); + +template < typename T, std::size_t Size > +constexpr mat equal_to(const mat& xs, const mat& ys); + +// not_equal_to + +template < typename T, std::size_t Size > +constexpr mat not_equal_to(const mat& xs, T y); + +template < typename T, std::size_t Size > +constexpr mat not_equal_to(T x, const mat& ys); + +template < typename T, std::size_t Size > +constexpr mat not_equal_to(const mat& xs, const mat& ys); ``` ### Matrix Functions diff --git a/headers/vmath.hpp/vmath_fun.hpp b/headers/vmath.hpp/vmath_fun.hpp index 8be46f3..997e657 100644 --- a/headers/vmath.hpp/vmath_fun.hpp +++ b/headers/vmath.hpp/vmath_fun.hpp @@ -438,4 +438,40 @@ namespace vmath_hpp return abs(x - y) <= epsilon; } } + + template < typename T > + [[nodiscard]] std::enable_if_t, bool> + constexpr less(T x, T y) noexcept { + return x < y; + } + + template < typename T > + [[nodiscard]] std::enable_if_t, bool> + constexpr less_equal(T x, T y) noexcept { + return x <= y; + } + + template < typename T > + [[nodiscard]] std::enable_if_t, bool> + constexpr greater(T x, T y) noexcept { + return x > y; + } + + template < typename T > + [[nodiscard]] std::enable_if_t, bool> + constexpr greater_equal(T x, T y) noexcept { + return x >= y; + } + + template < typename T > + [[nodiscard]] std::enable_if_t, bool> + constexpr equal_to(T x, T y) noexcept { + return x == y; + } + + template < typename T > + [[nodiscard]] std::enable_if_t, bool> + constexpr not_equal_to(T x, T y) noexcept { + return x != y; + } } diff --git a/headers/vmath.hpp/vmath_mat_fun.hpp b/headers/vmath.hpp/vmath_mat_fun.hpp index c02ee3e..572f7f1 100644 --- a/headers/vmath.hpp/vmath_mat_fun.hpp +++ b/headers/vmath.hpp/vmath_mat_fun.hpp @@ -463,84 +463,28 @@ namespace vmath_hpp }, true, xs, ys); } + // operator!= + template < typename T, std::size_t Size > [[nodiscard]] constexpr bool operator!=(const mat& xs, const mat& ys) { - return !(xs == ys); + return fold_join([](bool acc, const vec& x, const vec& y){ + return acc || (x != y); + }, false, xs, ys); } -} -// -// Relational Operators -// - -namespace vmath_hpp -{ // operator< template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator<(const mat& xs, T y) { - return map_join([y](const vec& x){ return x < y; }, xs); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator<(T x, const mat& ys) { - return map_join([x](const vec& y){ return x < y; }, ys); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator<(const mat& xs, const mat& ys) { - return map_join([](const vec& x, const vec& y){ return x < y; }, xs, ys); - } - - // operator<= - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator<=(const mat& xs, T y) { - return map_join([y](const vec& x){ return x <= y; }, xs); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator<=(T x, const mat& ys) { - return map_join([x](const vec& y){ return x <= y; }, ys); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator<=(const mat& xs, const mat& ys) { - return map_join([](const vec& x, const vec& y){ return x <= y; }, xs, ys); - } - - // operator> - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator>(const mat& xs, T y) { - return map_join([y](const vec& x){ return x > y; }, xs); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator>(T x, const mat& ys) { - return map_join([x](const vec& y){ return x > y; }, ys); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator>(const mat& xs, const mat& ys) { - return map_join([](const vec& x, const vec& y){ return x > y; }, xs, ys); - } - - // operator>= - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator>=(const mat& xs, T y) { - return map_join([y](const vec& x){ return x >= y; }, xs); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator>=(T x, const mat& ys) { - return map_join([x](const vec& y){ return x >= y; }, ys); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr mat operator>=(const mat& xs, const mat& ys) { - return map_join([](const vec& x, const vec& y){ return x >= y; }, xs, ys); + [[nodiscard]] constexpr bool operator<(const mat& xs, const mat& ys) { + for ( std::size_t i = 0; i < Size; ++i ) { + if ( xs[i] < ys[i] ) { + return true; + } + if ( ys[i] < xs[i] ) { + return false; + } + } + return false; } } @@ -550,16 +494,22 @@ namespace vmath_hpp namespace vmath_hpp { + // any + 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); } + // all + 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); } + // approx + template < typename T, std::size_t Size > [[nodiscard]] constexpr mat approx(const mat& xs, T y) { return map_join([y](const vec& x){ return approx(x, y); }, xs); @@ -589,6 +539,108 @@ namespace vmath_hpp [[nodiscard]] constexpr mat approx(const mat& xs, const mat& ys, T epsilon) { return map_join([epsilon](const vec& x, const vec& y){ return approx(x, y, epsilon); }, xs, ys); } + + // less + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat less(const mat& xs, T y) { + return map_join([y](const vec& x){ return less(x, y); }, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat less(T x, const mat& ys) { + return map_join([x](const vec& y){ return less(x, y); }, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat less(const mat& xs, const mat& ys) { + return map_join([](const vec& x, const vec& y){ return less(x, y); }, xs, ys); + } + + // less_equal + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat less_equal(const mat& xs, T y) { + return map_join([y](const vec& x){ return less_equal(x, y); }, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat less_equal(T x, const mat& ys) { + return map_join([x](const vec& y){ return less_equal(x, y); }, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat less_equal(const mat& xs, const mat& ys) { + return map_join([](const vec& x, const vec& y){ return less_equal(x, y); }, xs, ys); + } + + // greater + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat greater(const mat& xs, T y) { + return map_join([y](const vec& x){ return greater(x, y); }, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat greater(T x, const mat& ys) { + return map_join([x](const vec& y){ return greater(x, y); }, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat greater(const mat& xs, const mat& ys) { + return map_join([](const vec& x, const vec& y){ return greater(x, y); }, xs, ys); + } + + // greater_equal + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat greater_equal(const mat& xs, T y) { + return map_join([y](const vec& x){ return greater_equal(x, y); }, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat greater_equal(T x, const mat& ys) { + return map_join([x](const vec& y){ return greater_equal(x, y); }, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat greater_equal(const mat& xs, const mat& ys) { + return map_join([](const vec& x, const vec& y){ return greater_equal(x, y); }, xs, ys); + } + + // equal_to + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat equal_to(const mat& xs, T y) { + return map_join([y](const vec& x){ return equal_to(x, y); }, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat equal_to(T x, const mat& ys) { + return map_join([x](const vec& y){ return equal_to(x, y); }, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat equal_to(const mat& xs, const mat& ys) { + return map_join([](const vec& x, const vec& y){ return equal_to(x, y); }, xs, ys); + } + + // not_equal_to + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat not_equal_to(const mat& xs, T y) { + return map_join([y](const vec& x){ return not_equal_to(x, y); }, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat not_equal_to(T x, const mat& ys) { + return map_join([x](const vec& y){ return not_equal_to(x, y); }, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr mat not_equal_to(const mat& xs, const mat& ys) { + return map_join([](const vec& x, const vec& y){ return not_equal_to(x, y); }, xs, ys); + } } // diff --git a/headers/vmath.hpp/vmath_vec_fun.hpp b/headers/vmath.hpp/vmath_vec_fun.hpp index 94af7cb..82396de 100644 --- a/headers/vmath.hpp/vmath_vec_fun.hpp +++ b/headers/vmath.hpp/vmath_vec_fun.hpp @@ -432,84 +432,28 @@ namespace vmath_hpp }, true, xs, ys); } + // operator!= + template < typename T, std::size_t Size > [[nodiscard]] constexpr bool operator!=(const vec& xs, const vec& ys) { - return !(xs == ys); + return fold_join([](bool acc, T x, T y){ + return acc || x != y; + }, false, xs, ys); } -} -// -// Relational Operators -// - -namespace vmath_hpp -{ // operator< template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator<(const vec& xs, T y) { - return map_join([y](T x){ return x < y; }, xs); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator<(T x, const vec& ys) { - return map_join([x](T y){ return x < y; }, ys); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator<(const vec& xs, const vec& ys) { - return map_join([](T x, T y){ return x < y; }, xs, ys); - } - - // operator<= - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator<=(const vec& xs, T y) { - return map_join([y](T x){ return x <= y; }, xs); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator<=(T x, const vec& ys) { - return map_join([x](T y){ return x <= y; }, ys); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator<=(const vec& xs, const vec& ys) { - return map_join([](T x, T y){ return x <= y; }, xs, ys); - } - - // operator> - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator>(const vec& xs, T y) { - return map_join([y](T x){ return x > y; }, xs); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator>(T x, const vec& ys) { - return map_join([x](T y){ return x > y; }, ys); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator>(const vec& xs, const vec& ys) { - return map_join([](T x, T y){ return x > y; }, xs, ys); - } - - // operator>= - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator>=(const vec& xs, T y) { - return map_join([y](T x){ return x >= y; }, xs); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator>=(T x, const vec& ys) { - return map_join([x](T y){ return x >= y; }, ys); - } - - template < typename T, std::size_t Size > - [[nodiscard]] constexpr vec operator>=(const vec& xs, const vec& ys) { - return map_join([](T x, T y){ return x >= y; }, xs, ys); + [[nodiscard]] constexpr bool operator<(const vec& xs, const vec& ys) { + for ( std::size_t i = 0; i < Size; ++i ) { + if ( xs[i] < ys[i] ) { + return true; + } + if ( ys[i] < xs[i] ) { + return false; + } + } + return false; } } @@ -903,16 +847,22 @@ namespace vmath_hpp namespace vmath_hpp { + // any + 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); } + // all + template < typename T, std::size_t Size > [[nodiscard]] constexpr bool all(const vec& xs) { return fold_join([](bool acc, T x){ return acc && all(x); }, true, xs); } + // approx + template < typename T, std::size_t Size > [[nodiscard]] constexpr vec approx(const vec& xs, T y) { return map_join([y](T x){ return approx(x, y); }, xs); @@ -942,4 +892,106 @@ namespace vmath_hpp [[nodiscard]] constexpr vec approx(const vec& xs, const vec& ys, T epsilon) { return map_join([epsilon](T x, T y){ return approx(x, y, epsilon); }, xs, ys); } + + // less + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec less(const vec& xs, T y) { + return map_join([y](T x){ return less(x, y); }, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec less(T x, const vec& ys) { + return map_join([x](T y){ return less(x, y); }, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec less(const vec& xs, const vec& ys) { + return map_join([](T x, T y){ return less(x, y); }, xs, ys); + } + + // less_equal + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec less_equal(const vec& xs, T y) { + return map_join([y](T x){ return less_equal(x, y); }, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec less_equal(T x, const vec& ys) { + return map_join([x](T y){ return less_equal(x, y); }, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec less_equal(const vec& xs, const vec& ys) { + return map_join([](T x, T y){ return less_equal(x, y); }, xs, ys); + } + + // greater + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec greater(const vec& xs, T y) { + return map_join([y](T x){ return greater(x, y); }, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec greater(T x, const vec& ys) { + return map_join([x](T y){ return greater(x, y); }, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec greater(const vec& xs, const vec& ys) { + return map_join([](T x, T y){ return greater(x, y); }, xs, ys); + } + + // greater_equal + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec greater_equal(const vec& xs, T y) { + return map_join([y](T x){ return greater_equal(x, y); }, xs); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec greater_equal(T x, const vec& ys) { + return map_join([x](T y){ return greater_equal(x, y); }, ys); + } + + template < typename T, std::size_t Size > + [[nodiscard]] constexpr vec greater_equal(const vec& xs, const vec& ys) { + return map_join([](T x, T y){ return greater_equal(x, y); }, xs, ys); + } + + // 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); + } + + // 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); + } } diff --git a/untests/vmath_ext_tests.cpp b/untests/vmath_ext_tests.cpp index 2fb0071..0c6ee8c 100644 --- a/untests/vmath_ext_tests.cpp +++ b/untests/vmath_ext_tests.cpp @@ -7,6 +7,8 @@ #include "vmath_tests.hpp" #include "doctest/doctest.hpp" +#include +#include #include #include @@ -62,6 +64,19 @@ TEST_CASE("vmath/ext") { REQUIRE(std::hash{}({1,2,3,4}) == std::hash{}({1,2,3,4})); REQUIRE_FALSE(std::hash{}({1,2,3,4}) == std::hash{}({1,2,4,3})); + { + std::set s; + s.insert(int2(1,2)); + REQUIRE(s.count(int2(1,2)) > 0); + REQUIRE_FALSE(s.count(int2(1,1)) > 0); + } + { + std::map s; + s.emplace(int2(1,2),3); + s.emplace(int2(2,3),5); + REQUIRE(s[int2(1,2)] == 3); + REQUIRE(s[int2(2,3)] == 5); + } { std::unordered_set s; s.insert(int2(1,2)); diff --git a/untests/vmath_mat_fun_tests.cpp b/untests/vmath_mat_fun_tests.cpp index 39a17ea..6c249f3 100644 --- a/untests/vmath_mat_fun_tests.cpp +++ b/untests/vmath_mat_fun_tests.cpp @@ -163,24 +163,6 @@ TEST_CASE("vmath/mat_fun") { } } - SUBCASE("relational operators") { - STATIC_REQUIRE((int2x2(1,1,1,1) < int2x2(0,1,2,3)) == bool2x2(false, false, true, true)); - STATIC_REQUIRE((int2x2(0,1,2,3) < 1) == bool2x2(true, false, false, false)); - STATIC_REQUIRE((1 < int2x2(0,1,2,3)) == bool2x2(false, false, true, true)); - - STATIC_REQUIRE((int2x2(1,1,1,1) <= int2x2(0,1,2,3)) == bool2x2(false, true, true, true)); - STATIC_REQUIRE((int2x2(0,1,2,3) <= 1) == bool2x2(true, true, false, false)); - STATIC_REQUIRE((1 <= int2x2(0,1,2,3)) == bool2x2(false, true, true, true)); - - STATIC_REQUIRE((int2x2(1,1,1,1) > int2x2(0,1,2,3)) == bool2x2(true, false, false, false)); - STATIC_REQUIRE((int2x2(0,1,2,3) > 1) == bool2x2(false, false, true, true)); - STATIC_REQUIRE((1 > int2x2(0,1,2,3)) == bool2x2(true, false, false, false)); - - STATIC_REQUIRE((int2x2(1,1,1,1) >= int2x2(0,1,2,3)) == bool2x2(true, true, false, false)); - STATIC_REQUIRE((int2x2(0,1,2,3) >= 1) == bool2x2(false, true, true, true)); - 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))); @@ -217,6 +199,30 @@ TEST_CASE("vmath/mat_fun") { STATIC_REQUIRE(approx(int2x2(1,1,1,1), int2x2(0,1,2,3), 2) == bool2x2(true, true, true, true)); STATIC_REQUIRE(approx(int2x2(0,1,2,3), 1, 2) == bool2x2(true, true, true, true)); STATIC_REQUIRE(approx(1, int2x2(0,1,2,3), 2) == bool2x2(true, true, true, true)); + + STATIC_REQUIRE(less(int2x2(1,1,1,1), int2x2(0,1,2,3)) == bool2x2(false, false, true, true)); + STATIC_REQUIRE(less(int2x2(0,1,2,3), 1) == bool2x2(true, false, false, false)); + STATIC_REQUIRE(less(1, int2x2(0,1,2,3)) == bool2x2(false, false, true, true)); + + STATIC_REQUIRE(less_equal(int2x2(1,1,1,1), int2x2(0,1,2,3)) == bool2x2(false, true, true, true)); + STATIC_REQUIRE(less_equal(int2x2(0,1,2,3), 1) == bool2x2(true, true, false, false)); + STATIC_REQUIRE(less_equal(1, int2x2(0,1,2,3)) == bool2x2(false, true, true, true)); + + STATIC_REQUIRE(greater(int2x2(1,1,1,1), int2x2(0,1,2,3)) == bool2x2(true, false, false, false)); + STATIC_REQUIRE(greater(int2x2(0,1,2,3), 1) == bool2x2(false, false, true, true)); + STATIC_REQUIRE(greater(1, int2x2(0,1,2,3)) == bool2x2(true, false, false, false)); + + STATIC_REQUIRE(greater_equal(int2x2(1,1,1,1), int2x2(0,1,2,3)) == bool2x2(true, true, false, false)); + STATIC_REQUIRE(greater_equal(int2x2(0,1,2,3), 1) == bool2x2(false, true, true, true)); + STATIC_REQUIRE(greater_equal(1, int2x2(0,1,2,3)) == bool2x2(true, true, false, false)); + + STATIC_REQUIRE(equal_to(int2x2(1,1,1,1), int2x2(0,1,2,3)) == bool2x2(false, true, false, false)); + STATIC_REQUIRE(equal_to(int2x2(0,1,2,3),1) == bool2x2(false, true, false, false)); + STATIC_REQUIRE(equal_to(1,int2x2(0,1,2,3)) == bool2x2(false, true, false, false)); + + STATIC_REQUIRE(not_equal_to(int2x2(1,1,1,1), int2x2(0,1,2,3)) == bool2x2(true, false, true, true)); + STATIC_REQUIRE(not_equal_to(int2x2(0,1,2,3),1) == bool2x2(true, false, true, true)); + STATIC_REQUIRE(not_equal_to(1,int2x2(0,1,2,3)) == bool2x2(true, false, true, true)); } SUBCASE("transpose") { diff --git a/untests/vmath_mat_tests.cpp b/untests/vmath_mat_tests.cpp index e582dda..fed8be3 100644 --- a/untests/vmath_mat_tests.cpp +++ b/untests/vmath_mat_tests.cpp @@ -270,4 +270,14 @@ TEST_CASE("vmath/mat") { STATIC_REQUIRE(int2x2(1,2,3,4) != int2x2(2,2,3,4)); STATIC_REQUIRE(int2x2(1,2,3,4) != int2x2(1,3,3,4)); } + + SUBCASE("operator<") { + STATIC_REQUIRE_FALSE(int2x2(1,2,3,4) < int2x2(1,2,3,4)); + + STATIC_REQUIRE(int2x2(1,1,3,4) < int2x2(1,2,3,4)); + STATIC_REQUIRE_FALSE(int2x2(1,2,3,4) < int2x2(1,1,3,4)); + + STATIC_REQUIRE(int2x2(0,3,3,4) < int2x2(1,2,3,4)); + STATIC_REQUIRE_FALSE(int2x2(1,2,3,4) < int2x2(0,3,3,4)); + } } diff --git a/untests/vmath_vec_fun_tests.cpp b/untests/vmath_vec_fun_tests.cpp index 5405ef9..de4bf97 100644 --- a/untests/vmath_vec_fun_tests.cpp +++ b/untests/vmath_vec_fun_tests.cpp @@ -129,24 +129,6 @@ TEST_CASE("vmath/vec_fun") { } } - SUBCASE("Relational Operators") { - STATIC_REQUIRE((int3(1,1,1) < int3(0,1,2)) == bool3(false, false, true)); - STATIC_REQUIRE((int3(0,1,2) < 1) == bool3(true, false, false)); - STATIC_REQUIRE((1 < int3(0,1,2)) == bool3(false, false, true)); - - STATIC_REQUIRE((int3(1,1,1) <= int3(0,1,2)) == bool3(false, true, true)); - STATIC_REQUIRE((int3(0,1,2) <= 1) == bool3(true, true, false)); - STATIC_REQUIRE((1 <= int3(0,1,2)) == bool3(false, true, true)); - - STATIC_REQUIRE((int3(1,1,1) > int3(0,1,2)) == bool3(true, false, false)); - STATIC_REQUIRE((int3(0,1,2) > 1) == bool3(false, false, true)); - STATIC_REQUIRE((1 > int3(0,1,2)) == bool3(true, false, false)); - - STATIC_REQUIRE((int3(1,1,1) >= int3(0,1,2)) == bool3(true, true, false)); - STATIC_REQUIRE((int3(0,1,2) >= 1) == bool3(false, true, true)); - STATIC_REQUIRE((1 >= int3(0,1,2)) == bool3(true, true, false)); - } - SUBCASE("Angle and Trigonometry Functions") { STATIC_REQUIRE(radians(degrees(float2(12.13f))) == uapprox2(12.13f)); STATIC_REQUIRE(degrees(radians(float2(12.13f))) == uapprox2(12.13f)); @@ -304,5 +286,29 @@ TEST_CASE("vmath/vec_fun") { STATIC_REQUIRE(approx(int4(1,1,1,1), int4(0,1,2,3), 2) == bool4(true, true, true, true)); STATIC_REQUIRE(approx(int4(0,1,2,3), 1, 2) == bool4(true, true, true, true)); STATIC_REQUIRE(approx(1, int4(0,1,2,3), 2) == bool4(true, true, true, true)); + + STATIC_REQUIRE(less(int3(1,1,1), int3(0,1,2)) == bool3(false, false, true)); + STATIC_REQUIRE(less(int3(0,1,2), 1) == bool3(true, false, false)); + STATIC_REQUIRE(less(1, int3(0,1,2)) == bool3(false, false, true)); + + STATIC_REQUIRE(less_equal(int3(1,1,1), int3(0,1,2)) == bool3(false, true, true)); + STATIC_REQUIRE(less_equal(int3(0,1,2), 1) == bool3(true, true, false)); + STATIC_REQUIRE(less_equal(1, int3(0,1,2)) == bool3(false, true, true)); + + STATIC_REQUIRE(greater(int3(1,1,1), int3(0,1,2)) == bool3(true, false, false)); + STATIC_REQUIRE(greater(int3(0,1,2), 1) == bool3(false, false, true)); + STATIC_REQUIRE(greater(1, int3(0,1,2)) == bool3(true, false, false)); + + STATIC_REQUIRE(greater_equal(int3(1,1,1), int3(0,1,2)) == bool3(true, true, false)); + STATIC_REQUIRE(greater_equal(int3(0,1,2), 1) == bool3(false, true, true)); + STATIC_REQUIRE(greater_equal(1, int3(0,1,2)) == bool3(true, true, false)); + + 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(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)); } } diff --git a/untests/vmath_vec_tests.cpp b/untests/vmath_vec_tests.cpp index 673683c..39e3a38 100644 --- a/untests/vmath_vec_tests.cpp +++ b/untests/vmath_vec_tests.cpp @@ -267,4 +267,14 @@ TEST_CASE("vmath/vec") { STATIC_REQUIRE(int2(1,2) != int2(2,2)); STATIC_REQUIRE(int2(1,2) != int2(1,3)); } + + SUBCASE("operator<") { + STATIC_REQUIRE_FALSE(int2(1,2) < int2(1,2)); + + STATIC_REQUIRE(int2(1,1) < int2(1,2)); + STATIC_REQUIRE_FALSE(int2(1,2) < int2(1,1)); + + STATIC_REQUIRE(int2(0,3) < int2(1,2)); + STATIC_REQUIRE_FALSE(int2(1,2) < int2(0,3)); + } }