more refs

This commit is contained in:
BlackMATov
2021-02-03 12:58:17 +07:00
parent 7e62c77436
commit 337a1a6672
2 changed files with 13 additions and 2 deletions

View File

@@ -433,7 +433,8 @@ namespace vmath_hpp
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, bool>
constexpr approx(T x, T y) noexcept {
if constexpr ( std::is_floating_point_v<T> ) {
// http://www.realtimecollisiondetection.net/pubs/Tolerances
/// REFERENCE:
/// http://www.realtimecollisiondetection.net/pubs/Tolerances
const T epsilon = std::numeric_limits<T>::epsilon();
return abs(x - y) <= epsilon * max({T(1), abs(x), abs(y)});
} else {
@@ -445,7 +446,8 @@ namespace vmath_hpp
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, bool>
constexpr approx(T x, T y, T epsilon) noexcept {
if constexpr ( std::is_floating_point_v<T> ) {
// http://www.realtimecollisiondetection.net/pubs/Tolerances
/// REFERENCE:
/// http://www.realtimecollisiondetection.net/pubs/Tolerances
return abs(x - y) <= epsilon * max({T(1), abs(x), abs(y)});
} else {
return abs(x - y) <= epsilon;

View File

@@ -76,6 +76,9 @@ namespace vmath_hpp
template < typename T >
[[nodiscard]] constexpr vec<T, 3> operator*(const vec<T, 3>& xs, const qua<T>& ys) {
/// REFERENCE:
/// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/transforms/
const vec qv2 = cross(ys.v, xs) * T(2);
return xs + qv2 * ys.s + cross(ys.v, qv2);
}
@@ -87,6 +90,9 @@ namespace vmath_hpp
template < typename T >
[[nodiscard]] constexpr qua<T> operator*(const qua<T>& xs, const qua<T>& ys) {
/// REFERENCE:
/// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/arithmetic/
return {
cross(ys.v, xs.v) + ys.s * xs.v + xs.s * ys.v,
ys.s * xs.s - dot(ys.v, xs.v)};
@@ -180,6 +186,9 @@ namespace vmath_hpp
template < typename T >
[[nodiscard]] qua<T> slerp(const qua<T>& unit_xs, const qua<T>& unit_ys, T a) {
/// REFERENCE:
/// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
const T raw_cos_theta = dot(unit_xs, unit_ys);
const T raw_cos_theta_sign = sign(raw_cos_theta);