qua: dot, length, length2, normalize

This commit is contained in:
BlackMATov
2021-01-26 01:57:39 +07:00
parent 341e3dd0a3
commit 4a8c69e4f4
2 changed files with 36 additions and 0 deletions

View File

@@ -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}));
} }
} }

View File

@@ -69,4 +69,16 @@ TEST_CASE("vmath/qua_fun") {
REQUIRE_FALSE(any(isinf(fqua(1,1,1,1)))); REQUIRE_FALSE(any(isinf(fqua(1,1,1,1))));
REQUIRE(all(isfinite(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));
}
} }