scalar relational functions

This commit is contained in:
BlackMATov
2020-11-26 01:52:24 +07:00
parent 8dc6878f5c
commit 4505a5899b
2 changed files with 76 additions and 0 deletions

View File

@@ -178,3 +178,52 @@ namespace vmath_hpp
return T(k >= T(0)) * (eta * i - (eta * d + sqrt(k)) * n);
}
}
//
// Scalar Relational Functions
//
namespace vmath_hpp
{
template < typename T >
constexpr bool less(const T& x, const T& y) {
return x < y;
}
template < typename T >
constexpr bool less_equal(const T& x, const T& y) {
return x <= y;
}
template < typename T >
constexpr bool greater(const T& x, const T& y) {
return x > y;
}
template < typename T >
constexpr bool greater_equal(const T& x, const T& y) {
return x >= y;
}
template < typename T >
constexpr bool equal_to(const T& x, const T& y) {
return x == y;
}
template < typename T >
constexpr bool not_equal_to(const T& x, const T& y) {
return x != y;
}
constexpr bool any(bool x) noexcept {
return x;
}
constexpr bool all(bool x) noexcept {
return x;
}
constexpr bool not_(bool x) noexcept {
return !x;
}
}

View File

@@ -130,4 +130,31 @@ TEST_CASE("vmath/fun") {
STATIC_REQUIRE(reflect(1.f, 2.f) == approx(-7.f));
REQUIRE(refract(1.f, 2.f, 1.f) == approx(-7.f));
}
SECTION("Scalar Relational Functions") {
STATIC_REQUIRE(less(0, 1));
STATIC_REQUIRE(less_equal(0, 1));
STATIC_REQUIRE_FALSE(less(1, 1));
STATIC_REQUIRE(less_equal(1, 1));
STATIC_REQUIRE(greater(1, 0));
STATIC_REQUIRE(greater_equal(1, 0));
STATIC_REQUIRE_FALSE(greater(1, 1));
STATIC_REQUIRE(greater_equal(1, 1));
STATIC_REQUIRE_FALSE(equal_to(0, 1));
STATIC_REQUIRE(equal_to(1, 1));
STATIC_REQUIRE(not_equal_to(0, 1));
STATIC_REQUIRE_FALSE(not_equal_to(1, 1));
STATIC_REQUIRE_FALSE(any(false));
STATIC_REQUIRE(any(true));
STATIC_REQUIRE_FALSE(all(false));
STATIC_REQUIRE(all(true));
STATIC_REQUIRE_FALSE(not_(true));
STATIC_REQUIRE(not_(false));
}
}