From 96f83e33c523a91093825f4dc1ed6e79315d1578 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 6 May 2019 20:57:25 -0700 Subject: v3f: add distance: v3f_distance() v3f_distance_sq() variant omits the sqrtf(), which is often a possible optimization when e.g. comparing distances; just operate uniformly with squares of the distances. --- v3f.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'v3f.h') diff --git a/v3f.h b/v3f.h index 3011182..d169e76 100644 --- a/v3f.h +++ b/v3f.h @@ -157,6 +157,20 @@ static inline float v3f_length(const v3f_t *v) } +static inline float v3f_distance(const v3f_t *a, const v3f_t *b) +{ + return v3f_length(v3f_sub(&(v3f_t){}, a, b)); +} + + +static inline float v3f_distance_sq(const v3f_t *a, const v3f_t *b) +{ + v3f_t d = _v3f_sub(a, b); + + return v3f_dot(&d, &d); +} + + static inline v3f_t _v3f_normalize(const v3f_t *v) { return _v3f_mult_scalar(v, 1.0f / v3f_length(v)); -- cgit v1.2.3