mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-15 12:39:47 +07:00
fix distance<unsigned>
This commit is contained in:
@@ -339,13 +339,22 @@ namespace vmath_hpp
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, T>
|
||||
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 >
|
||||
[[nodiscard]] std::enable_if_t<std::is_arithmetic_v<T>, T>
|
||||
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 >
|
||||
@@ -396,11 +405,7 @@ namespace vmath_hpp
|
||||
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_unsigned_v<T> ) {
|
||||
return (x < y ? (y - x) : (x - y)) <= epsilon;
|
||||
} else {
|
||||
return abs(x - y) <= epsilon;
|
||||
}
|
||||
return distance(x, y) <= epsilon;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
|
||||
@@ -954,12 +954,12 @@ namespace vmath_hpp
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[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 >
|
||||
[[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
|
||||
|
||||
Reference in New Issue
Block a user