]> git.itanic.dy.fi Git - sdl-planets/commitdiff
vector.h: Introduce vector_abs_squared()
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Tue, 19 Jul 2011 17:16:36 +0000 (20:16 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Tue, 19 Jul 2011 17:16:36 +0000 (20:16 +0300)
This function is identical to vector_abs but it returns the squared
distance instead. The advantage of this function is that the one
square root calculation canb e omitted. If the actual distance is not
important, this function is faster than the one which returns the
absolute distance.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
vector.h

index 875cd3579f156faa03d1a3aa35413a5dd5e372d5..d3e265cb948b62316ef52ab2ae75f6b9fa573e33 100644 (file)
--- a/vector.h
+++ b/vector.h
@@ -33,6 +33,11 @@ static inline double vector_abs(const struct vector *a)
        return sqrt(a->x * a->x + a->y * a->y);
 }
 
+static inline double vector_abs_squared(const struct vector *a)
+{
+       return a->x * a->x + a->y * a->y;
+}
+
 static inline void vector_scale(const struct vector *a, const double b,
                                struct vector *res)
 {