From 4fb903bd8ee6c420e6862d3668e240e057cd9664 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Tue, 9 Aug 2016 17:56:55 -0600 Subject: [PATCH] common: add more AABB functions --- common/mathlib.c | 13 +++++++++++++ include/common/mathlib.h | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/common/mathlib.c b/common/mathlib.c index 28701647..bad1df51 100644 --- a/common/mathlib.c +++ b/common/mathlib.c @@ -124,3 +124,16 @@ void AABB_Expand(vec3_t mins, vec3_t maxs, const vec3_t pt) { maxs[i] = qmax(maxs[i], pt[i]); } } + +void AABB_Size(const vec3_t mins, const vec3_t maxs, vec3_t size_out) { + for (int i=0; i<3; i++) { + size_out[i] = maxs[i] - mins[i]; + } +} + +void AABB_Grow(vec3_t mins, vec3_t maxs, const vec3_t size) { + for (int i=0; i<3; i++) { + mins[i] -= size[i]; + maxs[i] += size[i]; + } +} diff --git a/include/common/mathlib.h b/include/common/mathlib.h index a3823dc0..d3fb87f9 100644 --- a/include/common/mathlib.h +++ b/include/common/mathlib.h @@ -182,7 +182,9 @@ void RandomDir(vec3_t dir); bool AABBsDisjoint(const vec3_t minsA, const vec3_t maxsA, const vec3_t minsB, const vec3_t maxsB); void AABB_Init(vec3_t mins, vec3_t maxs, const vec3_t pt); void AABB_Expand(vec3_t mins, vec3_t maxs, const vec3_t pt); - +void AABB_Size(const vec3_t mins, const vec3_t maxs, vec3_t size_out); +void AABB_Grow(vec3_t mins, vec3_t maxs, const vec3_t size); + #ifdef __cplusplus } #endif