Add functions to return the squared length of a vector: Comparing two squared values prevents two computionally heavy sqrt calls.

This commit is contained in:
Erik Hofman
2022-04-25 10:48:07 +02:00
parent fa2b5911b7
commit 6719a8e3d5
3 changed files with 25 additions and 0 deletions

View File

@@ -231,6 +231,14 @@ T
norm(const SGVec2<T>& v)
{ return simd4::magnitude(v.simd2()); }
/// The squared euclidean norm of the vector
/// Comparing two squared values prevents two computionally heavy sqrt calls.
template<typename T>
inline
T
norm2(const SGVec2<T>& v)
{ return simd4::magnitude2(v.simd2()); }
/// The euclidean norm of the vector, that is what most people call length
template<typename T>
inline

View File

@@ -301,6 +301,15 @@ T
norm(const SGVec3<T>& v)
{ return simd4::magnitude(v.simd3()); }
/// The squared euclidean norm of the vector
/// Comparing two squared values prevents two computionally heavy sqrt calls.
template<typename T>
inline
T
norm2(const SGVec3<T>& v)
{ return simd4::magnitude2(v.simd3()); }
/// The euclidean norm of the vector, that is what most people call length
template<typename T>
inline

View File

@@ -249,6 +249,14 @@ T
norm(const SGVec4<T>& v)
{ return simd4::magnitude(v.simd4()); }
/// The squared euclidean norm of the vector
/// Comparing two squared values prevents two computionally heavy sqrt calls.
template<typename T>
inline
T
norm2(const SGVec4<T>& v)
{ return simd4::magnitude2(v.simd4()); }
/// The euclidean norm of the vector, that is what most people call length
template<typename T>
inline