|
|
@ -394,17 +394,6 @@ constexpr vector cross(const vector& x, const vector& y) noexc |
|
|
|
template <class T, std::size_t N> |
|
|
|
T distance(const vector<T, N>& p0, const vector<T, N>& p1); |
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the squared distance between two points. The squared distance can be calculated faster than the distance because a call to `std::sqrt` is saved. |
|
|
|
* |
|
|
|
* @param p0 First of two points. |
|
|
|
* @param p1 Second of two points. |
|
|
|
* |
|
|
|
* @return Squared distance between the two points. |
|
|
|
*/ |
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr T distance_squared(const vector<T, N>& p0, const vector<T, N>& p1) noexcept; |
|
|
|
|
|
|
|
/**
|
|
|
|
* Divides a vector by a value. |
|
|
|
* |
|
|
@ -503,24 +492,24 @@ template |
|
|
|
constexpr vector<bool, N> greater_than_equal(const vector<T, N>& x, const vector<T, N>& y) noexcept; |
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the length of a vector. |
|
|
|
* Calculates the inverse length of a vector. |
|
|
|
* |
|
|
|
* @param x Vector of which to calculate the length. |
|
|
|
* @param x Vector of which to calculate the inverse length. |
|
|
|
* |
|
|
|
* @return Length of the vector. |
|
|
|
* @return Inverse length of the vector. |
|
|
|
*/ |
|
|
|
template <class T, std::size_t N> |
|
|
|
T length(const vector<T, N>& x); |
|
|
|
T inv_length(const vector<T, N>& x); |
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the squared length of a vector. The squared length can be calculated faster than the length because a call to `std::sqrt` is saved. |
|
|
|
* Calculates the length of a vector. |
|
|
|
* |
|
|
|
* @param x Vector of which to calculate the squared length. |
|
|
|
* @param x Vector of which to calculate the length. |
|
|
|
* |
|
|
|
* @return Squared length of the vector. |
|
|
|
* @return Length of the vector. |
|
|
|
*/ |
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr T length_squared(const vector<T, N>& x) noexcept; |
|
|
|
T length(const vector<T, N>& x); |
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs a element-wise less-than comparison of two vectors. |
|
|
@ -691,6 +680,27 @@ constexpr vector round(const vector& x); |
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr vector<T, N> sign(const vector<T, N>& x); |
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the square distance between two points. The square distance can be calculated faster than the distance because a call to `std::sqrt` is saved. |
|
|
|
* |
|
|
|
* @param p0 First of two points. |
|
|
|
* @param p1 Second of two points. |
|
|
|
* |
|
|
|
* @return Square distance between the two points. |
|
|
|
*/ |
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr T sqr_distance(const vector<T, N>& p0, const vector<T, N>& p1) noexcept; |
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the square length of a vector. The square length can be calculated faster than the length because a call to `std::sqrt` is saved. |
|
|
|
* |
|
|
|
* @param x Vector of which to calculate the square length. |
|
|
|
* |
|
|
|
* @return Square length of the vector. |
|
|
|
*/ |
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr T sqr_length(const vector<T, N>& x) noexcept; |
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes the square root of each element. |
|
|
|
* |
|
|
@ -819,13 +829,13 @@ constexpr inline bool any(const vector& x) noexcept |
|
|
|
template <class T, std::size_t N, std::size_t... I> |
|
|
|
constexpr inline vector<T, N> ceil(const vector<T, N>& x, std::index_sequence<I...>) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return {std::ceil(x[I])...}; |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr inline vector<T, N> ceil(const vector<T, N>& x) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return ceil(x, std::make_index_sequence<N>{}); |
|
|
|
} |
|
|
|
|
|
|
@ -859,8 +869,8 @@ template |
|
|
|
vector<T, N> clamp_length(const vector<T, N>& x, T max_length) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
T length2 = length_squared(x); |
|
|
|
return (length2 > max_length * max_length) ? (x * max_length / std::sqrt(length2)) : x; |
|
|
|
T length2 = sqr_length(x); |
|
|
|
return (length2 > max_length * max_length) ? (x * (max_length / std::sqrt(length2))) : x; |
|
|
|
} |
|
|
|
|
|
|
|
template <class T> |
|
|
@ -877,16 +887,9 @@ constexpr inline vector cross(const vector& x, const vector& y |
|
|
|
template <class T, std::size_t N> |
|
|
|
inline T distance(const vector<T, N>& p0, const vector<T, N>& p1) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return length(sub(p0, p1)); |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr inline T distance_squared(const vector<T, N>& p0, const vector<T, N>& p1) noexcept |
|
|
|
{ |
|
|
|
return length_squared(sub(p0, p1)); |
|
|
|
} |
|
|
|
|
|
|
|
/// @private
|
|
|
|
template <class T, std::size_t N, std::size_t... I> |
|
|
|
constexpr inline vector<T, N> div(const vector<T, N>& x, const vector<T, N>& y, std::index_sequence<I...>) noexcept |
|
|
@ -956,13 +959,13 @@ constexpr inline vector equal(const vector& x, const vector |
|
|
|
template <class T, std::size_t N, std::size_t... I> |
|
|
|
constexpr inline vector<T, N> floor(const vector<T, N>& x, std::index_sequence<I...>) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return {std::floor(x[I])...}; |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr inline vector<T, N> floor(const vector<T, N>& x) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return floor(x, std::make_index_sequence<N>{}); |
|
|
|
} |
|
|
|
|
|
|
@ -970,13 +973,13 @@ constexpr inline vector floor(const vector& x) |
|
|
|
template <class T, std::size_t N, std::size_t... I> |
|
|
|
constexpr inline vector<T, N> fma(const vector<T, N>& x, const vector<T, N>& y, const vector<T, N>& z, std::index_sequence<I...>) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return {std::fma(x[I], y[I], z[I])...}; |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr inline vector<T, N> fma(const vector<T, N>& x, const vector<T, N>& y, const vector<T, N>& z) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return fma(x, y, z, std::make_index_sequence<N>{}); |
|
|
|
} |
|
|
|
|
|
|
@ -984,13 +987,13 @@ constexpr inline vector fma(const vector& x, const vector& y, |
|
|
|
template <class T, std::size_t N, std::size_t... I> |
|
|
|
constexpr inline vector<T, N> fma(const vector<T, N>& x, T y, T z, std::index_sequence<I...>) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return {std::fma(x[I], y, z)...}; |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr inline vector<T, N> fma(const vector<T, N>& x, T y, T z) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return fma(x, y, z, std::make_index_sequence<N>{}); |
|
|
|
} |
|
|
|
|
|
|
@ -998,13 +1001,13 @@ constexpr inline vector fma(const vector& x, T y, T z) |
|
|
|
template <class T, std::size_t N, std::size_t... I> |
|
|
|
constexpr inline vector<T, N> fract(const vector<T, N>& x, std::index_sequence<I...>) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return {x[I] - std::floor(x[I])...}; |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr inline vector<T, N> fract(const vector<T, N>& x) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return fract(x, std::make_index_sequence<N>{}); |
|
|
|
} |
|
|
|
|
|
|
@ -1035,16 +1038,16 @@ constexpr inline vector greater_than_equal(const vector& x, const |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
inline T length(const vector<T, N>& x) |
|
|
|
inline T inv_length(const vector<T, N>& x) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return std::sqrt(dot(x, x)); |
|
|
|
return T{1} / length(x); |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr inline T length_squared(const vector<T, N>& x) noexcept |
|
|
|
inline T length(const vector<T, N>& x) |
|
|
|
{ |
|
|
|
return dot(x, x); |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return std::sqrt(sqr_length(x)); |
|
|
|
} |
|
|
|
|
|
|
|
/// @private
|
|
|
@ -1115,13 +1118,13 @@ constexpr inline T min(const vector& x) |
|
|
|
template <class T, std::size_t N, std::size_t... I> |
|
|
|
constexpr inline vector<T, N> mod(const vector<T, N>& x, const vector<T, N>& y, std::index_sequence<I...>) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return {std::fmod(x[I], y[I])...}; |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr inline vector<T, N> mod(const vector<T, N>& x, const vector<T, N>& y) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return mod(x, y, std::make_index_sequence<N>{}); |
|
|
|
} |
|
|
|
|
|
|
@ -1129,13 +1132,13 @@ constexpr inline vector mod(const vector& x, const vector& y) |
|
|
|
template <class T, std::size_t N, std::size_t... I> |
|
|
|
constexpr inline vector<T, N> mod(const vector<T, N>& x, T y, std::index_sequence<I...>) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return {std::fmod(x[I], y)...}; |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr inline vector<T, N> mod(const vector<T, N>& x, T y) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return mod(x, y, std::make_index_sequence<N>{}); |
|
|
|
} |
|
|
|
|
|
|
@ -1181,8 +1184,7 @@ constexpr inline vector negate(const vector& x) noexcept |
|
|
|
template <class T, std::size_t N> |
|
|
|
inline vector<T, N> normalize(const vector<T, N>& x) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return mul(x, T{1} / length(x)); |
|
|
|
return mul(x, inv_length(x)); |
|
|
|
} |
|
|
|
|
|
|
|
/// @private
|
|
|
@ -1215,13 +1217,13 @@ constexpr inline vector not_equal(const vector& x, const vector |
|
|
|
template <class T, std::size_t N, std::size_t... I> |
|
|
|
inline vector<T, N> pow(const vector<T, N>& x, const vector<T, N>& y, std::index_sequence<I...>) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return {std::pow(x[I], y[I])...}; |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
inline vector<T, N> pow(const vector<T, N>& x, const vector<T, N>& y) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return pow(x, y, std::make_index_sequence<N>{}); |
|
|
|
} |
|
|
|
|
|
|
@ -1229,13 +1231,13 @@ inline vector pow(const vector& x, const vector& y) |
|
|
|
template <class T, std::size_t N, std::size_t... I> |
|
|
|
inline vector<T, N> pow(const vector<T, N>& x, T y, std::index_sequence<I...>) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return {std::pow(x[I], y)...}; |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
inline vector<T, N> pow(const vector<T, N>& x, T y) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return pow(x, y, std::make_index_sequence<N>{}); |
|
|
|
} |
|
|
|
|
|
|
@ -1243,13 +1245,13 @@ inline vector pow(const vector& x, T y) |
|
|
|
template <class T, std::size_t N, std::size_t... I> |
|
|
|
constexpr inline vector<T, N> round(const vector<T, N>& x, std::index_sequence<I...>) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return {std::round(x[I])...}; |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr inline vector<T, N> round(const vector<T, N>& x) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return round(x, std::make_index_sequence<N>{}); |
|
|
|
} |
|
|
|
|
|
|
@ -1257,28 +1259,40 @@ constexpr inline vector round(const vector& x) |
|
|
|
template <class T, std::size_t N, std::size_t... I> |
|
|
|
constexpr inline vector<T, N> sign(const vector<T, N>& x, std::index_sequence<I...>) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return {std::copysign(T{1}, x[I])...}; |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr inline vector<T, N> sign(const vector<T, N>& x) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return sign(x, std::make_index_sequence<N>{}); |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr inline T sqr_distance(const vector<T, N>& p0, const vector<T, N>& p1) noexcept |
|
|
|
{ |
|
|
|
return sqr_length(sub(p0, p1)); |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr inline T sqr_length(const vector<T, N>& x) noexcept |
|
|
|
{ |
|
|
|
return dot(x, x); |
|
|
|
} |
|
|
|
|
|
|
|
/// @private
|
|
|
|
template <class T, std::size_t N, std::size_t... I> |
|
|
|
inline vector<T, N> sqrt(const vector<T, N>& x, std::index_sequence<I...>) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return {std::sqrt(x[I])...}; |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
inline vector<T, N> sqrt(const vector<T, N>& x, const vector<T, N>& y) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return pow(x, std::make_index_sequence<N>{}); |
|
|
|
return sqrt(x, std::make_index_sequence<N>{}); |
|
|
|
} |
|
|
|
|
|
|
|
/// @private
|
|
|
@ -1343,13 +1357,13 @@ constexpr inline vector swizzle(const vector& x) no |
|
|
|
template <class T, std::size_t N, std::size_t... I> |
|
|
|
constexpr inline vector<T, N> trunc(const vector<T, N>& x, std::index_sequence<I...>) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return {std::trunc(x[I])...}; |
|
|
|
} |
|
|
|
|
|
|
|
template <class T, std::size_t N> |
|
|
|
constexpr inline vector<T, N> trunc(const vector<T, N>& x) |
|
|
|
{ |
|
|
|
static_assert(std::is_floating_point<T>::value); |
|
|
|
return trunc(x, std::make_index_sequence<N>{}); |
|
|
|
} |
|
|
|
|
|
|
|