From: Timo Kokkonen Date: Tue, 19 Jul 2011 17:16:36 +0000 (+0300) Subject: vector.h: Introduce vector_abs_squared() X-Git-Url: http://git.itanic.dy.fi/?p=sdl-planets;a=commitdiff_plain;h=3bc710987a74ec3b2c8245bfad5344796a56ad0e vector.h: Introduce vector_abs_squared() 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 --- diff --git a/vector.h b/vector.h index 875cd35..d3e265c 100644 --- 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) {