min(scalar, vector), max(scalar, vector) funcs

This commit is contained in:
BlackMATov
2021-02-13 12:53:29 +07:00
parent bbaa269840
commit 172fd86c3c
3 changed files with 13 additions and 1 deletions

View File

@@ -866,7 +866,7 @@ namespace vmath_hpp
/// REFERENCE:
/// http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/
auto xyzw = T(0.5) * sqrt(max(zero4<T>, {
auto xyzw = T(0.5) * sqrt(max(T(0), vec{
T(1) + m[0][0] - m[1][1] - m[2][2],
T(1) - m[0][0] + m[1][1] - m[2][2],
T(1) - m[0][0] - m[1][1] + m[2][2],

View File

@@ -590,6 +590,11 @@ namespace vmath_hpp
return map_join([y](T x) { return min(x, y); }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<T, Size> min(T x, const vec<T, Size>& ys) {
return map_join([x](T y) { return min(x, y); }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<T, Size> min(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y) { return min(x, y); }, xs, ys);
@@ -605,6 +610,11 @@ namespace vmath_hpp
return map_join([y](T x) { return max(x, y); }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<T, Size> max(T x, const vec<T, Size>& ys) {
return map_join([x](T y) { return max(x, y); }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<T, Size> max(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y) { return max(x, y); }, xs, ys);

View File

@@ -209,10 +209,12 @@ TEST_CASE("vmath/vec_fun") {
STATIC_REQUIRE(min(int2(1,2)) == 1);
STATIC_REQUIRE(min(int2(1,2), 1) == int2(1,1));
STATIC_REQUIRE(min(1, int2(1,2)) == int2(1,1));
STATIC_REQUIRE(min(int2(1,1), int2(0,2)) == int2(0,1));
STATIC_REQUIRE(max(int2(1,2)) == 2);
STATIC_REQUIRE(max(int2(1,2), 1) == int2(1,2));
STATIC_REQUIRE(max(1, int2(1,2)) == int2(1,2));
STATIC_REQUIRE(max(int2(1,1), int2(0,2)) == int2(1,2));
STATIC_REQUIRE(clamp(int2(1,2), 0, 1) == int2(1,1));