mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-14 12:28:58 +07:00
qua: dot, length, length2, normalize
This commit is contained in:
@@ -167,5 +167,29 @@ namespace vmath_hpp
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Geometric Functions
|
||||
//
|
||||
|
||||
namespace vmath_hpp
|
||||
{
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr T dot(const qua<T>& xs, const qua<T>& ys) {
|
||||
return dot(vec{xs}, vec{ys});
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] T length(const qua<T>& xs) {
|
||||
return length(vec{xs});
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr T length2(const qua<T>& xs) {
|
||||
return length2(vec{xs});
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr qua<T> normalize(const qua<T>& xs) {
|
||||
return qua(normalize(vec{xs}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,4 +69,16 @@ TEST_CASE("vmath/qua_fun") {
|
||||
REQUIRE_FALSE(any(isinf(fqua(1,1,1,1))));
|
||||
REQUIRE(all(isfinite(fqua(1,1,1,1))));
|
||||
}
|
||||
|
||||
SUBCASE("Geometric Functions") {
|
||||
STATIC_REQUIRE(dot(qua(1,2,3,4),qua(3,4,5,6)) == 50);
|
||||
|
||||
REQUIRE(length(fqua(10.f,0.f,0.f,0.f)) == uapprox(10.f));
|
||||
REQUIRE(length(fqua(-10.f,0.f,0.f,0.f)) == uapprox(10.f));
|
||||
|
||||
STATIC_REQUIRE(length2(fqua(10.f,0.f,0.f,0.f)) == uapprox(100.f));
|
||||
STATIC_REQUIRE(length2(fqua(-10.f,0.f,0.f,0.f)) == uapprox(100.f));
|
||||
|
||||
REQUIRE(normalize(fqua(0.5f,0.f,0.f,0.f)).v == uapprox3(1.f,0.f,0.f));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user