qua: approx, equal_to, not_equal_to

This commit is contained in:
BlackMATov
2021-01-26 01:59:17 +07:00
parent 4a8c69e4f4
commit 4279552522
2 changed files with 43 additions and 0 deletions

View File

@@ -193,3 +193,36 @@ namespace vmath_hpp
return qua(normalize(vec{xs})); return qua(normalize(vec{xs}));
} }
} }
//
// Relational Functions
//
namespace vmath_hpp
{
// approx
template < typename T >
[[nodiscard]] constexpr vec<bool, 4> approx(const qua<T>& xs, const qua<T>& ys) {
return approx(vec{xs}, vec{ys});
}
template < typename T >
[[nodiscard]] constexpr vec<bool, 4> approx(const qua<T>& xs, const qua<T>& ys, T epsilon) {
return approx(vec{xs}, vec{ys}, epsilon);
}
// equal_to
template < typename T >
[[nodiscard]] constexpr vec<bool, 4> equal_to(const qua<T>& xs, const qua<T>& ys) {
return equal_to(vec{xs}, vec{ys});
}
// not_equal_to
template < typename T >
[[nodiscard]] constexpr vec<bool, 4> not_equal_to(const qua<T>& xs, const qua<T>& ys) {
return not_equal_to(vec{xs}, vec{ys});
}
}

View File

@@ -81,4 +81,14 @@ TEST_CASE("vmath/qua_fun") {
REQUIRE(normalize(fqua(0.5f,0.f,0.f,0.f)).v == uapprox3(1.f,0.f,0.f)); REQUIRE(normalize(fqua(0.5f,0.f,0.f,0.f)).v == uapprox3(1.f,0.f,0.f));
} }
SUBCASE("Relational Functions") {
STATIC_REQUIRE(approx(qua(1,1,1,1), qua(0,1,2,3)) == bool4(false, true, false, false));
STATIC_REQUIRE(approx(qua(1,1,1,1), qua(0,1,2,3), 0) == bool4(false, true, false, false));
STATIC_REQUIRE(approx(qua(1,1,1,1), qua(0,1,2,3), 1) == bool4(true, true, true, false));
STATIC_REQUIRE(approx(qua(1,1,1,1), qua(0,1,2,3), 2) == bool4(true, true, true, true));
STATIC_REQUIRE(equal_to(qua(1,1,1,1), qua(0,1,2,3)) == bool4(false, true, false, false));
STATIC_REQUIRE(not_equal_to(qua(1,1,1,1), qua(0,1,2,3)) == bool4(true, false, true, true));
}
} }