summary refs log tree commit diff
path: root/src/Math/Vector.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Math/Vector.hpp')
-rw-r--r--src/Math/Vector.hpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Math/Vector.hpp b/src/Math/Vector.hpp
index acbfa98..7d07d5c 100644
--- a/src/Math/Vector.hpp
+++ b/src/Math/Vector.hpp
@@ -68,8 +68,12 @@ struct Vector {
         return reduce([](auto x, auto y) { return x + y; });
     }
 
+    T magnitude_squared() const {
+        return map([](auto x) { return x * x;}).sum();
+    }
+
     T magnitude() const {
-        return sqrt(map([](auto x) { return x * x;}).sum());
+        return sqrt(magnitude_squared());
     }
 
     Vector normalize() const {
@@ -81,6 +85,10 @@ struct Vector {
         return (*this - other).magnitude();
     }
 
+    T distance_squared(const Vector other) const {
+        return (*this - other).magnitude_squared();
+    }
+
     Vector<3, T> any_orthogonal() {
         if (Vector a{y(), -x(), 0.0f}; a != zero()) return a;
         if (Vector b{z(), 0.0f, -x()}; b != zero()) return b;