diff --git a/simgear/math/SGVec2.hxx b/simgear/math/SGVec2.hxx index d9e4439f..87c6fe2f 100644 --- a/simgear/math/SGVec2.hxx +++ b/simgear/math/SGVec2.hxx @@ -231,6 +231,14 @@ T norm(const SGVec2& v) { return simd4::magnitude(v.simd2()); } +/// The squared euclidean norm of the vector +/// Comparing two squared values prevents two computionally heavy sqrt calls. +template +inline +T +norm2(const SGVec2& v) +{ return simd4::magnitude2(v.simd2()); } + /// The euclidean norm of the vector, that is what most people call length template inline diff --git a/simgear/math/SGVec3.hxx b/simgear/math/SGVec3.hxx index 514f9575..aa1061b8 100644 --- a/simgear/math/SGVec3.hxx +++ b/simgear/math/SGVec3.hxx @@ -301,6 +301,15 @@ T norm(const SGVec3& v) { return simd4::magnitude(v.simd3()); } +/// The squared euclidean norm of the vector +/// Comparing two squared values prevents two computionally heavy sqrt calls. +template +inline +T +norm2(const SGVec3& v) +{ return simd4::magnitude2(v.simd3()); } + + /// The euclidean norm of the vector, that is what most people call length template inline diff --git a/simgear/math/SGVec4.hxx b/simgear/math/SGVec4.hxx index b62561ab..bd66389f 100644 --- a/simgear/math/SGVec4.hxx +++ b/simgear/math/SGVec4.hxx @@ -249,6 +249,14 @@ T norm(const SGVec4& v) { return simd4::magnitude(v.simd4()); } +/// The squared euclidean norm of the vector +/// Comparing two squared values prevents two computionally heavy sqrt calls. +template +inline +T +norm2(const SGVec4& v) +{ return simd4::magnitude2(v.simd4()); } + /// The euclidean norm of the vector, that is what most people call length template inline