mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-16 22:19:51 +07:00
update singles
This commit is contained in:
@@ -446,13 +446,22 @@ namespace vmath_hpp
|
|||||||
template < typename T >
|
template < typename T >
|
||||||
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, T>
|
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, T>
|
||||||
constexpr distance(T x, T y) noexcept {
|
constexpr distance(T x, T y) noexcept {
|
||||||
return length(y - x);
|
if constexpr ( std::is_unsigned_v<T> ) {
|
||||||
|
return x < y ? (y - x) : (x - y);
|
||||||
|
} else {
|
||||||
|
return length(x - y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, T>
|
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, T>
|
||||||
constexpr distance2(T x, T y) noexcept {
|
constexpr distance2(T x, T y) noexcept {
|
||||||
return length2(y - x);
|
if constexpr ( std::is_unsigned_v<T> ) {
|
||||||
|
const T d = x < y ? (y - x) : (x - y);
|
||||||
|
return d * d;
|
||||||
|
} else {
|
||||||
|
return length2(x - y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
@@ -500,6 +509,12 @@ namespace vmath_hpp
|
|||||||
return !!x;
|
return !!x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, bool>
|
||||||
|
constexpr approx(T x, T y, T epsilon) noexcept {
|
||||||
|
return distance(x, y) <= epsilon;
|
||||||
|
}
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, bool>
|
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, bool>
|
||||||
constexpr approx(T x, T y) noexcept {
|
constexpr approx(T x, T y) noexcept {
|
||||||
@@ -507,24 +522,12 @@ namespace vmath_hpp
|
|||||||
/// REFERENCE:
|
/// REFERENCE:
|
||||||
/// http://www.realtimecollisiondetection.net/pubs/Tolerances
|
/// http://www.realtimecollisiondetection.net/pubs/Tolerances
|
||||||
const T epsilon = std::numeric_limits<T>::epsilon();
|
const T epsilon = std::numeric_limits<T>::epsilon();
|
||||||
return abs(x - y) <= epsilon * max(max(T{1}, abs(x)), abs(y));
|
return approx(x, y, epsilon * max(T{1}, max(abs(x), abs(y))));
|
||||||
} else {
|
} else {
|
||||||
return x == y;
|
return x == y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename T >
|
|
||||||
[[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> ) {
|
|
||||||
/// REFERENCE:
|
|
||||||
/// http://www.realtimecollisiondetection.net/pubs/Tolerances
|
|
||||||
return abs(x - y) <= epsilon * max(max(T{1}, abs(x)), abs(y));
|
|
||||||
} else {
|
|
||||||
return abs(x - y) <= epsilon;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, bool>
|
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, bool>
|
||||||
constexpr less(T x, T y) noexcept {
|
constexpr less(T x, T y) noexcept {
|
||||||
@@ -1767,12 +1770,12 @@ namespace vmath_hpp
|
|||||||
|
|
||||||
template < typename T, std::size_t Size >
|
template < typename T, std::size_t Size >
|
||||||
[[nodiscard]] constexpr T distance(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
[[nodiscard]] constexpr T distance(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
||||||
return length(ys - xs);
|
return length(xs - ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename T, std::size_t Size >
|
template < typename T, std::size_t Size >
|
||||||
[[nodiscard]] constexpr T distance2(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
[[nodiscard]] constexpr T distance2(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
||||||
return length2(ys - xs);
|
return length2(xs - ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename T, typename U
|
template < typename T, typename U
|
||||||
|
|||||||
Reference in New Issue
Block a user