revert relational operators to functions

This commit is contained in:
BlackMATov
2020-12-07 20:18:09 +07:00
parent 975015bcab
commit b83290208f
9 changed files with 531 additions and 276 deletions

264
README.md
View File

@@ -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<bool, Size> operator||(const vec<T, Size>& xs, const vec<T, Size>&
template < typename T, size_t Size >
constexpr bool operator==(const vec<T, Size>& xs, const vec<T, Size>& ys);
// operator!=
template < typename T, size_t Size >
constexpr bool operator!=(const vec<T, Size>& xs, const vec<T, Size>& ys);
@@ -554,54 +554,6 @@ template < typename T, size_t Size >
constexpr bool operator<(const vec<T, Size>& xs, const vec<T, Size>& ys);
```
### Vector Relational Operators
```cpp
// operator<
template < typename T, size_t Size >
constexpr vec<bool, Size> operator<(const vec<T, Size>& xs, T y);
template < typename T, size_t Size >
constexpr vec<bool, Size> operator<(T x, const vec<T, Size>& ys);
template < typename T, size_t Size >
constexpr vec<bool, Size> operator<(const vec<T, Size>& xs, const vec<T, Size>& ys);
// operator<=
template < typename T, size_t Size >
constexpr vec<bool, Size> operator<=(const vec<T, Size>& xs, T y);
template < typename T, size_t Size >
constexpr vec<bool, Size> operator<=(T x, const vec<T, Size>& ys);
template < typename T, size_t Size >
constexpr vec<bool, Size> operator<=(const vec<T, Size>& xs, const vec<T, Size>& ys);
// operator>
template < typename T, size_t Size >
constexpr vec<bool, Size> operator>(const vec<T, Size>& xs, T y);
template < typename T, size_t Size >
constexpr vec<bool, Size> operator>(T x, const vec<T, Size>& ys);
template < typename T, size_t Size >
constexpr vec<bool, Size> operator>(const vec<T, Size>& xs, const vec<T, Size>& ys);
// operator>=
template < typename T, size_t Size >
constexpr vec<bool, Size> operator>=(const vec<T, Size>& xs, T y);
template < typename T, size_t Size >
constexpr vec<bool, Size> operator>=(T x, const vec<T, Size>& ys);
template < typename T, size_t Size >
constexpr vec<bool, Size> operator>=(const vec<T, Size>& xs, const vec<T, Size>& ys);
```
### Matrix Operators
```cpp
@@ -780,6 +732,8 @@ constexpr mat<bool, Size> operator||(const mat<T, Size>& xs, const mat<T, Size>&
template < typename T, size_t Size >
constexpr bool operator==(const mat<T, Size>& xs, const mat<T, Size>& ys);
// operator!=
template < typename T, size_t Size >
constexpr bool operator!=(const mat<T, Size>& xs, const mat<T, Size>& ys);
@@ -789,54 +743,6 @@ template < typename T, size_t Size >
constexpr bool operator<(const mat<T, Size>& xs, const mat<T, Size>& ys);
```
### Matrix Relational Operators
```cpp
// operator<
template < typename T, size_t Size >
constexpr mat<bool, Size> operator<(const mat<T, Size>& xs, T y);
template < typename T, size_t Size >
constexpr mat<bool, Size> operator<(T x, const mat<T, Size>& ys);
template < typename T, size_t Size >
constexpr mat<bool, Size> operator<(const mat<T, Size>& xs, const mat<T, Size>& ys);
// operator<=
template < typename T, size_t Size >
constexpr mat<bool, Size> operator<=(const mat<T, Size>& xs, T y);
template < typename T, size_t Size >
constexpr mat<bool, Size> operator<=(T x, const mat<T, Size>& ys);
template < typename T, size_t Size >
constexpr mat<bool, Size> operator<=(const mat<T, Size>& xs, const mat<T, Size>& ys);
// operator>
template < typename T, size_t Size >
constexpr mat<bool, Size> operator>(const mat<T, Size>& xs, T y);
template < typename T, size_t Size >
constexpr mat<bool, Size> operator>(T x, const mat<T, Size>& ys);
template < typename T, size_t Size >
constexpr mat<bool, Size> operator>(const mat<T, Size>& xs, const mat<T, Size>& ys);
// operator>=
template < typename T, size_t Size >
constexpr mat<bool, Size> operator>=(const mat<T, Size>& xs, T y);
template < typename T, size_t Size >
constexpr mat<bool, Size> operator>=(T x, const mat<T, Size>& ys);
template < typename T, size_t Size >
constexpr mat<bool, Size> operator>=(const mat<T, Size>& xs, const mat<T, Size>& 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<T, Size>& xs);
// all
template < typename T, size_t Size >
constexpr bool all(const vec<T, Size>& xs);
// approx
template < typename T, size_t Size >
constexpr vec<bool, Size> approx(const vec<T, Size>& xs, T y);
@@ -1293,17 +1223,89 @@ constexpr vec<bool, Size> approx(T x, const vec<T, Size>& ys, T epsilon);
template < typename T, size_t Size >
constexpr vec<bool, Size> approx(const vec<T, Size>& xs, const vec<T, Size>& ys, T epsilon);
// less
template < typename T, size_t Size >
constexpr vec<bool, Size> less(const vec<T, Size>& xs, T y);
template < typename T, size_t Size >
constexpr vec<bool, Size> less(T x, const vec<T, Size>& ys);
template < typename T, size_t Size >
constexpr vec<bool, Size> less(const vec<T, Size>& xs, const vec<T, Size>& ys);
// less_equal
template < typename T, size_t Size >
constexpr vec<bool, Size> less_equal(const vec<T, Size>& xs, T y);
template < typename T, size_t Size >
constexpr vec<bool, Size> less_equal(T x, const vec<T, Size>& ys);
template < typename T, size_t Size >
constexpr vec<bool, Size> less_equal(const vec<T, Size>& xs, const vec<T, Size>& ys);
// greater
template < typename T, size_t Size >
constexpr vec<bool, Size> greater(const vec<T, Size>& xs, T y);
template < typename T, size_t Size >
constexpr vec<bool, Size> greater(T x, const vec<T, Size>& ys);
template < typename T, size_t Size >
constexpr vec<bool, Size> greater(const vec<T, Size>& xs, const vec<T, Size>& ys);
// greater_equal
template < typename T, size_t Size >
constexpr vec<bool, Size> greater_equal(const vec<T, Size>& xs, T y);
template < typename T, size_t Size >
constexpr vec<bool, Size> greater_equal(T x, const vec<T, Size>& ys);
template < typename T, size_t Size >
constexpr vec<bool, Size> greater_equal(const vec<T, Size>& xs, const vec<T, Size>& ys);
// equal_to
template < typename T, size_t Size >
constexpr vec<bool, Size> equal_to(const vec<T, Size>& xs, T y);
template < typename T, size_t Size >
constexpr vec<bool, Size> equal_to(T x, const vec<T, Size>& ys);
template < typename T, size_t Size >
constexpr vec<bool, Size> equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys);
// not_equal_to
template < typename T, size_t Size >
constexpr vec<bool, Size> not_equal_to(const vec<T, Size>& xs, T y);
template < typename T, size_t Size >
constexpr vec<bool, Size> not_equal_to(T x, const vec<T, Size>& ys);
template < typename T, size_t Size >
constexpr vec<bool, Size> not_equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys);
```
#### Matrix
```cpp
// any
template < typename T, size_t Size >
constexpr bool any(const mat<T, Size>& xs);
// all
template < typename T, size_t Size >
constexpr bool all(const mat<T, Size>& xs);
// approx
template < typename T, size_t Size >
constexpr mat<bool, Size> approx(const mat<T, Size>& xs, T y);
@@ -1321,6 +1323,72 @@ constexpr mat<bool, Size> approx(T x, const mat<T, Size>& ys, T epsilon);
template < typename T, size_t Size >
constexpr mat<bool, Size> approx(const mat<T, Size>& xs, const mat<T, Size>& ys, T epsilon);
// less
template < typename T, std::size_t Size >
constexpr mat<bool, Size> less(const mat<T, Size>& xs, T y);
template < typename T, std::size_t Size >
constexpr mat<bool, Size> less(T x, const mat<T, Size>& ys);
template < typename T, std::size_t Size >
constexpr mat<bool, Size> less(const mat<T, Size>& xs, const mat<T, Size>& ys);
// less_equal
template < typename T, std::size_t Size >
constexpr mat<bool, Size> less_equal(const mat<T, Size>& xs, T y);
template < typename T, std::size_t Size >
constexpr mat<bool, Size> less_equal(T x, const mat<T, Size>& ys);
template < typename T, std::size_t Size >
constexpr mat<bool, Size> less_equal(const mat<T, Size>& xs, const mat<T, Size>& ys);
// greater
template < typename T, std::size_t Size >
constexpr mat<bool, Size> greater(const mat<T, Size>& xs, T y);
template < typename T, std::size_t Size >
constexpr mat<bool, Size> greater(T x, const mat<T, Size>& ys);
template < typename T, std::size_t Size >
constexpr mat<bool, Size> greater(const mat<T, Size>& xs, const mat<T, Size>& ys);
// greater_equal
template < typename T, std::size_t Size >
constexpr mat<bool, Size> greater_equal(const mat<T, Size>& xs, T y);
template < typename T, std::size_t Size >
constexpr mat<bool, Size> greater_equal(T x, const mat<T, Size>& ys);
template < typename T, std::size_t Size >
constexpr mat<bool, Size> greater_equal(const mat<T, Size>& xs, const mat<T, Size>& ys);
// equal_to
template < typename T, std::size_t Size >
constexpr mat<bool, Size> equal_to(const mat<T, Size>& xs, T y);
template < typename T, std::size_t Size >
constexpr mat<bool, Size> equal_to(T x, const mat<T, Size>& ys);
template < typename T, std::size_t Size >
constexpr mat<bool, Size> equal_to(const mat<T, Size>& xs, const mat<T, Size>& ys);
// not_equal_to
template < typename T, std::size_t Size >
constexpr mat<bool, Size> not_equal_to(const mat<T, Size>& xs, T y);
template < typename T, std::size_t Size >
constexpr mat<bool, Size> not_equal_to(T x, const mat<T, Size>& ys);
template < typename T, std::size_t Size >
constexpr mat<bool, Size> not_equal_to(const mat<T, Size>& xs, const mat<T, Size>& ys);
```
### Matrix Functions

View File

@@ -438,4 +438,40 @@ namespace vmath_hpp
return abs(x - y) <= epsilon;
}
}
template < typename T >
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, bool>
constexpr less(T x, T y) noexcept {
return x < y;
}
template < typename T >
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, bool>
constexpr less_equal(T x, T y) noexcept {
return x <= y;
}
template < typename T >
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, bool>
constexpr greater(T x, T y) noexcept {
return x > y;
}
template < typename T >
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, bool>
constexpr greater_equal(T x, T y) noexcept {
return x >= y;
}
template < typename T >
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, bool>
constexpr equal_to(T x, T y) noexcept {
return x == y;
}
template < typename T >
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, bool>
constexpr not_equal_to(T x, T y) noexcept {
return x != y;
}
}

View File

@@ -463,84 +463,28 @@ namespace vmath_hpp
}, true, xs, ys);
}
// operator!=
template < typename T, std::size_t Size >
[[nodiscard]] constexpr bool operator!=(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return !(xs == ys);
return fold_join([](bool acc, const vec<T, Size>& x, const vec<T, Size>& y){
return acc || (x != y);
}, false, xs, ys);
}
}
//
// Relational Operators
//
namespace vmath_hpp
{
// operator<
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> operator<(const mat<T, Size>& xs, T y) {
return map_join([y](const vec<T, Size>& x){ return x < y; }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> operator<(T x, const mat<T, Size>& ys) {
return map_join([x](const vec<T, Size>& y){ return x < y; }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> operator<(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return x < y; }, xs, ys);
}
// operator<=
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> operator<=(const mat<T, Size>& xs, T y) {
return map_join([y](const vec<T, Size>& x){ return x <= y; }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> operator<=(T x, const mat<T, Size>& ys) {
return map_join([x](const vec<T, Size>& y){ return x <= y; }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> operator<=(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return x <= y; }, xs, ys);
}
// operator>
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> operator>(const mat<T, Size>& xs, T y) {
return map_join([y](const vec<T, Size>& x){ return x > y; }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> operator>(T x, const mat<T, Size>& ys) {
return map_join([x](const vec<T, Size>& y){ return x > y; }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> operator>(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return x > y; }, xs, ys);
}
// operator>=
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> operator>=(const mat<T, Size>& xs, T y) {
return map_join([y](const vec<T, Size>& x){ return x >= y; }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> operator>=(T x, const mat<T, Size>& ys) {
return map_join([x](const vec<T, Size>& y){ return x >= y; }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> operator>=(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return x >= y; }, xs, ys);
[[nodiscard]] constexpr bool operator<(const mat<T, Size>& xs, const mat<T, Size>& 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<T, Size>& xs) {
return fold_join([](bool acc, const vec<T, Size>& x){ return acc || any(x); }, false, xs);
}
// all
template < typename T, std::size_t Size >
[[nodiscard]] constexpr bool all(const mat<T, Size>& xs) {
return fold_join([](bool acc, const vec<T, Size>& x){ return acc && all(x); }, true, xs);
}
// approx
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> approx(const mat<T, Size>& xs, T y) {
return map_join([y](const vec<T, Size>& x){ return approx(x, y); }, xs);
@@ -589,6 +539,108 @@ namespace vmath_hpp
[[nodiscard]] constexpr mat<bool, Size> approx(const mat<T, Size>& xs, const mat<T, Size>& ys, T epsilon) {
return map_join([epsilon](const vec<T, Size>& x, const vec<T, Size>& y){ return approx(x, y, epsilon); }, xs, ys);
}
// less
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> less(const mat<T, Size>& xs, T y) {
return map_join([y](const vec<T, Size>& x){ return less(x, y); }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> less(T x, const mat<T, Size>& ys) {
return map_join([x](const vec<T, Size>& y){ return less(x, y); }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> less(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return less(x, y); }, xs, ys);
}
// less_equal
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> less_equal(const mat<T, Size>& xs, T y) {
return map_join([y](const vec<T, Size>& x){ return less_equal(x, y); }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> less_equal(T x, const mat<T, Size>& ys) {
return map_join([x](const vec<T, Size>& y){ return less_equal(x, y); }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> less_equal(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return less_equal(x, y); }, xs, ys);
}
// greater
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> greater(const mat<T, Size>& xs, T y) {
return map_join([y](const vec<T, Size>& x){ return greater(x, y); }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> greater(T x, const mat<T, Size>& ys) {
return map_join([x](const vec<T, Size>& y){ return greater(x, y); }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> greater(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return greater(x, y); }, xs, ys);
}
// greater_equal
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> greater_equal(const mat<T, Size>& xs, T y) {
return map_join([y](const vec<T, Size>& x){ return greater_equal(x, y); }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> greater_equal(T x, const mat<T, Size>& ys) {
return map_join([x](const vec<T, Size>& y){ return greater_equal(x, y); }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> greater_equal(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return greater_equal(x, y); }, xs, ys);
}
// equal_to
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> equal_to(const mat<T, Size>& xs, T y) {
return map_join([y](const vec<T, Size>& x){ return equal_to(x, y); }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> equal_to(T x, const mat<T, Size>& ys) {
return map_join([x](const vec<T, Size>& y){ return equal_to(x, y); }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> equal_to(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return equal_to(x, y); }, xs, ys);
}
// not_equal_to
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> not_equal_to(const mat<T, Size>& xs, T y) {
return map_join([y](const vec<T, Size>& x){ return not_equal_to(x, y); }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> not_equal_to(T x, const mat<T, Size>& ys) {
return map_join([x](const vec<T, Size>& y){ return not_equal_to(x, y); }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> not_equal_to(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return not_equal_to(x, y); }, xs, ys);
}
}
//

View File

@@ -432,84 +432,28 @@ namespace vmath_hpp
}, true, xs, ys);
}
// operator!=
template < typename T, std::size_t Size >
[[nodiscard]] constexpr bool operator!=(const vec<T, Size>& xs, const vec<T, Size>& 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<bool, Size> operator<(const vec<T, Size>& xs, T y) {
return map_join([y](T x){ return x < y; }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> operator<(T x, const vec<T, Size>& ys) {
return map_join([x](T y){ return x < y; }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> operator<(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y){ return x < y; }, xs, ys);
}
// operator<=
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> operator<=(const vec<T, Size>& xs, T y) {
return map_join([y](T x){ return x <= y; }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> operator<=(T x, const vec<T, Size>& ys) {
return map_join([x](T y){ return x <= y; }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> operator<=(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y){ return x <= y; }, xs, ys);
}
// operator>
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> operator>(const vec<T, Size>& xs, T y) {
return map_join([y](T x){ return x > y; }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> operator>(T x, const vec<T, Size>& ys) {
return map_join([x](T y){ return x > y; }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> operator>(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y){ return x > y; }, xs, ys);
}
// operator>=
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> operator>=(const vec<T, Size>& xs, T y) {
return map_join([y](T x){ return x >= y; }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> operator>=(T x, const vec<T, Size>& ys) {
return map_join([x](T y){ return x >= y; }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> operator>=(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y){ return x >= y; }, xs, ys);
[[nodiscard]] constexpr bool operator<(const vec<T, Size>& xs, const vec<T, Size>& 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<T, Size>& 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<T, Size>& 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<bool, Size> approx(const vec<T, Size>& xs, T y) {
return map_join([y](T x){ return approx(x, y); }, xs);
@@ -942,4 +892,106 @@ namespace vmath_hpp
[[nodiscard]] constexpr vec<bool, Size> approx(const vec<T, Size>& xs, const vec<T, Size>& 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<bool, Size> less(const vec<T, Size>& xs, T y) {
return map_join([y](T x){ return less(x, y); }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> less(T x, const vec<T, Size>& ys) {
return map_join([x](T y){ return less(x, y); }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> less(const vec<T, Size>& xs, const vec<T, Size>& 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<bool, Size> less_equal(const vec<T, Size>& 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<bool, Size> less_equal(T x, const vec<T, Size>& ys) {
return map_join([x](T y){ return less_equal(x, y); }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> less_equal(const vec<T, Size>& xs, const vec<T, Size>& 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<bool, Size> greater(const vec<T, Size>& xs, T y) {
return map_join([y](T x){ return greater(x, y); }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> greater(T x, const vec<T, Size>& ys) {
return map_join([x](T y){ return greater(x, y); }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> greater(const vec<T, Size>& xs, const vec<T, Size>& 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<bool, Size> greater_equal(const vec<T, Size>& 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<bool, Size> greater_equal(T x, const vec<T, Size>& ys) {
return map_join([x](T y){ return greater_equal(x, y); }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> greater_equal(const vec<T, Size>& xs, const vec<T, Size>& 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<bool, Size> equal_to(const vec<T, Size>& 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<bool, Size> equal_to(T x, const vec<T, Size>& ys) {
return map_join([x](T y){ return equal_to(x, y); }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> equal_to(const vec<T, Size>& xs, const vec<T, Size>& 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<bool, Size> not_equal_to(const vec<T, Size>& 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<bool, Size> not_equal_to(T x, const vec<T, Size>& ys) {
return map_join([x](T y){ return not_equal_to(x, y); }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> not_equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y){ return not_equal_to(x, y); }, xs, ys);
}
}

View File

@@ -7,6 +7,8 @@
#include "vmath_tests.hpp"
#include "doctest/doctest.hpp"
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
@@ -62,6 +64,19 @@ TEST_CASE("vmath/ext") {
REQUIRE(std::hash<int2x2>{}({1,2,3,4}) == std::hash<int2x2>{}({1,2,3,4}));
REQUIRE_FALSE(std::hash<int2x2>{}({1,2,3,4}) == std::hash<int2x2>{}({1,2,4,3}));
{
std::set<int2> s;
s.insert(int2(1,2));
REQUIRE(s.count(int2(1,2)) > 0);
REQUIRE_FALSE(s.count(int2(1,1)) > 0);
}
{
std::map<int2, int> 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<int2> s;
s.insert(int2(1,2));

View File

@@ -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") {

View File

@@ -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));
}
}

View File

@@ -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));
}
}

View File

@@ -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));
}
}