From 483a8558488ae88853f3cd537f0b9152f81a31e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Br=C3=B6nneg=C3=A5rd?= <1162652+rasmusgo@users.noreply.github.com> Date: Mon, 7 Mar 2022 00:00:19 +0100 Subject: [PATCH] Add DistanceSquared to vector.h --- src/math/vector.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/math/vector.h b/src/math/vector.h index e57ccbb6..0af4840b 100644 --- a/src/math/vector.h +++ b/src/math/vector.h @@ -273,6 +273,14 @@ inline float Distance(const Math::Vector &a, const Math::Vector &b) (a.z-b.z)*(a.z-b.z) ); } +//! Returns the squared distance between the ends of two vectors +inline float DistanceSquared(const Math::Vector &a, const Math::Vector &b) +{ + return (a.x-b.x)*(a.x-b.x) + + (a.y-b.y)*(a.y-b.y) + + (a.z-b.z)*(a.z-b.z); +} + //! Clamps the vector \a vec to range between \a min and \a max inline Vector Clamp(const Vector &vec, const Vector &min, const Vector &max) { @@ -285,4 +293,3 @@ inline Vector Clamp(const Vector &vec, const Vector &min, const Vector &max) } // namespace Math -