summaryrefslogtreecommitdiff
path: root/v3f.h
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2019-05-06 20:57:25 -0700
committerVito Caputo <vcaputo@pengaru.com>2019-05-06 20:57:25 -0700
commit96f83e33c523a91093825f4dc1ed6e79315d1578 (patch)
tree323a0ed3b8f70512c7a46c19f5b33820ae19d38e /v3f.h
parentf62314fba6050d14e14d70e8556d77b35c36b3c6 (diff)
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.
Diffstat (limited to 'v3f.h')
-rw-r--r--v3f.h14
1 files changed, 14 insertions, 0 deletions
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));
© All Rights Reserved