From 3bc710987a74ec3b2c8245bfad5344796a56ad0e Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Tue, 19 Jul 2011 20:16:36 +0300 Subject: [PATCH] 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 --- vector.h | 5 +++++ 1 file changed, 5 insertions(+) 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) { -- 2.44.0