mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-15 04:35:25 +07:00
operator! for vector and matrix, relational functions with scalars
This commit is contained in:
116
README.md
116
README.md
@@ -373,6 +373,11 @@ using ptrdiff4x4 = mat<std::ptrdiff_t, 4>;
|
|||||||
template < typename T, size_t Size >
|
template < typename T, size_t Size >
|
||||||
constexpr vec<T, Size> operator-(const vec<T, Size>& xs);
|
constexpr vec<T, Size> operator-(const vec<T, Size>& xs);
|
||||||
|
|
||||||
|
// !operator
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> operator!(const vec<T, Size>& xs);
|
||||||
|
|
||||||
// operator+
|
// operator+
|
||||||
|
|
||||||
template < typename T, size_t Size >
|
template < typename T, size_t Size >
|
||||||
@@ -471,6 +476,11 @@ constexpr bool operator<(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
|||||||
template < typename T, size_t Size >
|
template < typename T, size_t Size >
|
||||||
constexpr mat<T, Size> operator-(const mat<T, Size>& xs);
|
constexpr mat<T, Size> operator-(const mat<T, Size>& xs);
|
||||||
|
|
||||||
|
// !operator
|
||||||
|
|
||||||
|
template < typename T, size_t Size >
|
||||||
|
constexpr mat<bool, Size> operator!(const mat<T, Size>& xs);
|
||||||
|
|
||||||
// operator+
|
// operator+
|
||||||
|
|
||||||
template < typename T, size_t Size >
|
template < typename T, size_t Size >
|
||||||
@@ -569,9 +579,9 @@ constexpr bool operator<(const mat<T, Size>& xs, const mat<T, Size>& ys);
|
|||||||
|
|
||||||
### Angle and Trigonometry Functions
|
### Angle and Trigonometry Functions
|
||||||
|
|
||||||
```cpp
|
#### Scalar
|
||||||
// Scalar
|
|
||||||
|
|
||||||
|
```cpp
|
||||||
template < floating_point T >
|
template < floating_point T >
|
||||||
constexpr T radians(T degrees) noexcept;
|
constexpr T radians(T degrees) noexcept;
|
||||||
|
|
||||||
@@ -622,9 +632,11 @@ std::pair<T, T> sincos(T x) noexcept;
|
|||||||
|
|
||||||
template < floating_point T >
|
template < floating_point T >
|
||||||
void sincos(T x, T* s, T* c) noexcept;
|
void sincos(T x, T* s, T* c) noexcept;
|
||||||
|
```
|
||||||
|
|
||||||
// Vector
|
#### Vector
|
||||||
|
|
||||||
|
```cpp
|
||||||
template < typename T, size_t Size >
|
template < typename T, size_t Size >
|
||||||
constexpr vec<T, Size> radians(const vec<T, Size>& degrees);
|
constexpr vec<T, Size> radians(const vec<T, Size>& degrees);
|
||||||
|
|
||||||
@@ -676,9 +688,9 @@ void sincos(const vec<T, Size>& xs, vec<T, Size>* ss, vec<T, Size>* cs);
|
|||||||
|
|
||||||
### Exponential Functions
|
### Exponential Functions
|
||||||
|
|
||||||
```cpp
|
#### Scalar
|
||||||
// Scalar
|
|
||||||
|
|
||||||
|
```cpp
|
||||||
template < floating_point T >
|
template < floating_point T >
|
||||||
T pow(T x, T y) noexcept;
|
T pow(T x, T y) noexcept;
|
||||||
|
|
||||||
@@ -699,9 +711,11 @@ T sqrt(T x) noexcept;
|
|||||||
|
|
||||||
template < floating_point T >
|
template < floating_point T >
|
||||||
T rsqrt(T x) noexcept;
|
T rsqrt(T x) noexcept;
|
||||||
|
```
|
||||||
|
|
||||||
// Vector
|
#### Vector
|
||||||
|
|
||||||
|
```cpp
|
||||||
template < typename T, size_t Size >
|
template < typename T, size_t Size >
|
||||||
vec<T, Size> pow(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
vec<T, Size> pow(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||||
|
|
||||||
@@ -726,9 +740,9 @@ vec<T, Size> rsqrt(const vec<T, Size>& xs);
|
|||||||
|
|
||||||
### Common Functions
|
### Common Functions
|
||||||
|
|
||||||
```cpp
|
#### Scalar
|
||||||
// Scalar
|
|
||||||
|
|
||||||
|
```cpp
|
||||||
template < arithmetic T >
|
template < arithmetic T >
|
||||||
constexpr T abs(T x) noexcept;
|
constexpr T abs(T x) noexcept;
|
||||||
|
|
||||||
@@ -803,9 +817,11 @@ T frexp(T x, int* exp) noexcept;
|
|||||||
|
|
||||||
template < floating_point T >
|
template < floating_point T >
|
||||||
T ldexp(T x, int exp) noexcept;
|
T ldexp(T x, int exp) noexcept;
|
||||||
|
```
|
||||||
|
|
||||||
// Vector
|
#### Vector
|
||||||
|
|
||||||
|
```cpp
|
||||||
template < typename T, size_t Size >
|
template < typename T, size_t Size >
|
||||||
constexpr vec<T, Size> abs(const vec<T, Size>& xs);
|
constexpr vec<T, Size> abs(const vec<T, Size>& xs);
|
||||||
|
|
||||||
@@ -905,9 +921,9 @@ vec<T, Size> ldexp(const vec<T, Size>& xs, const vec<int, Size>& exps);
|
|||||||
|
|
||||||
### Geometric Functions
|
### Geometric Functions
|
||||||
|
|
||||||
```cpp
|
#### Scalar
|
||||||
// Scalar
|
|
||||||
|
|
||||||
|
```cpp
|
||||||
template < arithmetic T >
|
template < arithmetic T >
|
||||||
constexpr T dot(T x, T y) noexcept;
|
constexpr T dot(T x, T y) noexcept;
|
||||||
|
|
||||||
@@ -934,9 +950,11 @@ constexpr T reflect(T i, T n) noexcept;
|
|||||||
|
|
||||||
template < floating_point T >
|
template < floating_point T >
|
||||||
T refract(T i, T n, T eta) noexcept;
|
T refract(T i, T n, T eta) noexcept;
|
||||||
|
```
|
||||||
|
|
||||||
// Vector
|
#### Vector
|
||||||
|
|
||||||
|
```cpp
|
||||||
template < typename T, size_t Size >
|
template < typename T, size_t Size >
|
||||||
constexpr T dot(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
constexpr T dot(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||||
|
|
||||||
@@ -973,9 +991,9 @@ vec<T, Size> refract(const vec<T, Size>& i, const vec<T, Size>& n, T eta);
|
|||||||
|
|
||||||
### Relational Functions
|
### Relational Functions
|
||||||
|
|
||||||
```cpp
|
#### Scalar
|
||||||
// Scalar
|
|
||||||
|
|
||||||
|
```cpp
|
||||||
template < arithmetic T >
|
template < arithmetic T >
|
||||||
constexpr bool less(T x, T y) noexcept;
|
constexpr bool less(T x, T y) noexcept;
|
||||||
|
|
||||||
@@ -1005,31 +1023,81 @@ constexpr bool any(T x) noexcept;
|
|||||||
|
|
||||||
template < arithmetic T >
|
template < arithmetic T >
|
||||||
constexpr bool all(T x) noexcept;
|
constexpr bool all(T x) noexcept;
|
||||||
|
```
|
||||||
|
|
||||||
// Vector
|
#### Vector
|
||||||
|
|
||||||
template < typename T, size_t Size >
|
```cpp
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> less(const vec<T, Size>& xs, T y);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> less(T x, const vec<T, Size>& ys);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
constexpr vec<bool, Size> less(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
constexpr vec<bool, Size> less(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||||
|
|
||||||
template < typename T, size_t Size >
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> less_equal(const vec<T, Size>& xs, T y);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> less_equal(T x, const vec<T, Size>& ys);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
constexpr vec<bool, Size> less_equal(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
constexpr vec<bool, Size> less_equal(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||||
|
|
||||||
template < typename T, size_t Size >
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> greater(const vec<T, Size>& xs, T y);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> greater(T x, const vec<T, Size>& ys);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
constexpr vec<bool, Size> greater(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
constexpr vec<bool, Size> greater(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||||
|
|
||||||
template < typename T, size_t Size >
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> greater_equal(const vec<T, Size>& xs, T y);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> greater_equal(T x, const vec<T, Size>& ys);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
constexpr vec<bool, Size> greater_equal(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
constexpr vec<bool, Size> greater_equal(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||||
|
|
||||||
template < typename T, size_t Size >
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> equal_to(const vec<T, Size>& xs, T y);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> equal_to(T x, const vec<T, Size>& ys);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
constexpr vec<bool, Size> equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
constexpr vec<bool, Size> equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||||
|
|
||||||
template < typename T, size_t Size >
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> equal_to(const vec<T, Size>& xs, T y, T epsilon);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> equal_to(T x, const vec<T, Size>& ys, T epsilon);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
constexpr vec<bool, Size> equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys, T epsilon);
|
constexpr vec<bool, Size> equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys, T epsilon);
|
||||||
|
|
||||||
template < typename T, size_t Size >
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> not_equal_to(const vec<T, Size>& xs, T y);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> not_equal_to(T x, const vec<T, Size>& ys);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
constexpr vec<bool, Size> not_equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
constexpr vec<bool, Size> not_equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys);
|
||||||
|
|
||||||
template < typename T, size_t Size >
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> not_equal_to(const vec<T, Size>& xs, T y, T epsilon);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
|
constexpr vec<bool, Size> not_equal_to(T x, const vec<T, Size>& ys, T epsilon);
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
constexpr vec<bool, Size> not_equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys, T epsilon);
|
constexpr vec<bool, Size> not_equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys, T epsilon);
|
||||||
|
|
||||||
template < typename T, size_t Size >
|
template < typename T, size_t Size >
|
||||||
@@ -1192,8 +1260,6 @@ constexpr mat<T, 4> scale(const mat<T, 4>& m, T x, T y, T z);
|
|||||||
template < typename T >
|
template < typename T >
|
||||||
constexpr mat<T, 4> scale(const mat<T, 4>& m, const vec<T, 3>& v);
|
constexpr mat<T, 4> scale(const mat<T, 4>& m, const vec<T, 3>& v);
|
||||||
|
|
||||||
// look_at
|
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
mat<T, 4> look_at_lh(const vec<T, 3>& eye, const vec<T, 3>& at, const vec<T, 3>& up);
|
mat<T, 4> look_at_lh(const vec<T, 3>& eye, const vec<T, 3>& at, const vec<T, 3>& up);
|
||||||
|
|
||||||
|
|||||||
@@ -199,6 +199,13 @@ namespace vmath_hpp
|
|||||||
return map_join([](const vec<T, Size>& x){ return -x; }, xs);
|
return map_join([](const vec<T, Size>& x){ return -x; }, xs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// !operator
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
|
[[nodiscard]] constexpr mat<bool, Size> operator!(const mat<T, Size>& xs) {
|
||||||
|
return map_join([](const vec<T, Size>& x){ return !x; }, xs);
|
||||||
|
}
|
||||||
|
|
||||||
// operator+
|
// operator+
|
||||||
|
|
||||||
template < typename T, std::size_t Size >
|
template < typename T, std::size_t Size >
|
||||||
|
|||||||
@@ -172,6 +172,13 @@ namespace vmath_hpp
|
|||||||
return map_join([](T x){ return -x; }, xs);
|
return map_join([](T x){ return -x; }, xs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// !operator
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
|
[[nodiscard]] constexpr vec<bool, Size> operator!(const vec<T, Size>& xs) {
|
||||||
|
return map_join([](T x){ return !x; }, xs);
|
||||||
|
}
|
||||||
|
|
||||||
// operator+
|
// operator+
|
||||||
|
|
||||||
template < typename T, std::size_t Size >
|
template < typename T, std::size_t Size >
|
||||||
@@ -708,46 +715,140 @@ namespace vmath_hpp
|
|||||||
|
|
||||||
namespace vmath_hpp
|
namespace vmath_hpp
|
||||||
{
|
{
|
||||||
|
// 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 >
|
template < typename T, std::size_t Size >
|
||||||
[[nodiscard]] constexpr vec<bool, Size> less(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
[[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);
|
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 >
|
template < typename T, std::size_t Size >
|
||||||
[[nodiscard]] constexpr vec<bool, Size> less_equal(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
[[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);
|
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 >
|
template < typename T, std::size_t Size >
|
||||||
[[nodiscard]] constexpr vec<bool, Size> greater(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
[[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);
|
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 >
|
template < typename T, std::size_t Size >
|
||||||
[[nodiscard]] constexpr vec<bool, Size> greater_equal(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
[[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);
|
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 >
|
template < typename T, std::size_t Size >
|
||||||
[[nodiscard]] constexpr vec<bool, Size> equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
[[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);
|
return map_join([](T x, T y){ return equal_to(x, y); }, xs, ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template < typename T, std::size_t Size >
|
||||||
|
[[nodiscard]] constexpr vec<bool, Size> equal_to(const vec<T, Size>& 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<bool, Size> equal_to(T x, const vec<T, Size>& ys, T epsilon) {
|
||||||
|
return map_join([x, epsilon](T y){ return equal_to(x, y, epsilon); }, ys);
|
||||||
|
}
|
||||||
|
|
||||||
template < typename T, std::size_t Size >
|
template < typename T, std::size_t Size >
|
||||||
[[nodiscard]] constexpr vec<bool, Size> equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys, T epsilon) {
|
[[nodiscard]] constexpr vec<bool, Size> equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys, T epsilon) {
|
||||||
return map_join([epsilon](T x, T y){ return equal_to(x, y, epsilon); }, xs, ys);
|
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<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 >
|
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) {
|
[[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);
|
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<bool, Size> not_equal_to(const vec<T, Size>& 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<bool, Size> not_equal_to(T x, const vec<T, Size>& 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 >
|
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, T epsilon) {
|
[[nodiscard]] constexpr vec<bool, Size> not_equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys, T epsilon) {
|
||||||
return map_join([epsilon](T x, T y){ return not_equal_to(x, y, epsilon); }, xs, ys);
|
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 >
|
template < typename T, std::size_t Size >
|
||||||
[[nodiscard]] constexpr bool any(const vec<T, Size>& xs) {
|
[[nodiscard]] constexpr bool any(const vec<T, Size>& xs) {
|
||||||
return fold_join([](bool acc, T x){ return acc || any(x); }, false, xs);
|
return fold_join([](bool acc, T x){ return acc || any(x); }, false, xs);
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ TEST_CASE("vmath/mat_fun") {
|
|||||||
|
|
||||||
SUBCASE("operators") {
|
SUBCASE("operators") {
|
||||||
STATIC_REQUIRE(-int2x2(1,2,3,4) == int2x2(-1,-2,-3,-4));
|
STATIC_REQUIRE(-int2x2(1,2,3,4) == int2x2(-1,-2,-3,-4));
|
||||||
|
STATIC_REQUIRE(!int2x2(-1,0,1,2) == bool2x2(false,true,false,false));
|
||||||
|
|
||||||
STATIC_REQUIRE(int2x2(1,2,3,4) + 2 == int2x2(3,4,5,6));
|
STATIC_REQUIRE(int2x2(1,2,3,4) + 2 == int2x2(3,4,5,6));
|
||||||
STATIC_REQUIRE(int2x2(1,2,3,4) - 2 == int2x2(-1,0,1,2));
|
STATIC_REQUIRE(int2x2(1,2,3,4) - 2 == int2x2(-1,0,1,2));
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ TEST_CASE("vmath/vec_fun") {
|
|||||||
|
|
||||||
SUBCASE("Operators") {
|
SUBCASE("Operators") {
|
||||||
STATIC_REQUIRE(-int2(1,-2) == int2(-1,2));
|
STATIC_REQUIRE(-int2(1,-2) == int2(-1,2));
|
||||||
|
STATIC_REQUIRE(!int3(-1,0,1) == bool3(false, true, false));
|
||||||
|
|
||||||
STATIC_REQUIRE(int2(1,2) + 3 == int2(4,5));
|
STATIC_REQUIRE(int2(1,2) + 3 == int2(4,5));
|
||||||
STATIC_REQUIRE(int2(1,2) - 3 == int2(-2,-1));
|
STATIC_REQUIRE(int2(1,2) - 3 == int2(-2,-1));
|
||||||
@@ -211,20 +212,52 @@ TEST_CASE("vmath/vec_fun") {
|
|||||||
|
|
||||||
SUBCASE("Vector Relational Functions") {
|
SUBCASE("Vector Relational Functions") {
|
||||||
STATIC_REQUIRE(less(int3(1,1,1), int3(0,1,2)) == bool3(false, false, 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(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(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(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(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(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(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(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(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(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(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(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));
|
||||||
|
|
||||||
STATIC_REQUIRE_FALSE(any(bool2(false, false)));
|
STATIC_REQUIRE_FALSE(any(bool2(false, false)));
|
||||||
STATIC_REQUIRE(any(bool2(true, false)));
|
STATIC_REQUIRE(any(bool2(true, false)));
|
||||||
|
|||||||
Reference in New Issue
Block a user