diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2014-09-03 15:55:19 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2015-10-25 11:03:56 -0400 |
commit | b554b20c8d59d6046bdcec7c79fb61cd0e65811c (patch) | |
tree | a6c6f257cfaffcec953be7c0cce180f7a8855c68 /libdimension/dimension/math/aabb.h | |
parent | b2cf35c26d5263f3079480208429e3a1d7dd2373 (diff) | |
download | dimension-b554b20c8d59d6046bdcec7c79fb61cd0e65811c.tar.xz |
math: Make vectors have an array instead of different fields.
Diffstat (limited to 'libdimension/dimension/math/aabb.h')
-rw-r--r-- | libdimension/dimension/math/aabb.h | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/libdimension/dimension/math/aabb.h b/libdimension/dimension/math/aabb.h index 14cc575..4eb7870 100644 --- a/libdimension/dimension/math/aabb.h +++ b/libdimension/dimension/math/aabb.h @@ -57,8 +57,8 @@ DMNSN_INLINE dmnsn_aabb dmnsn_zero_aabb(void) { dmnsn_aabb box = { - { DMNSN_INFINITY, DMNSN_INFINITY, DMNSN_INFINITY }, - { -DMNSN_INFINITY, -DMNSN_INFINITY, -DMNSN_INFINITY } + { { DMNSN_INFINITY, DMNSN_INFINITY, DMNSN_INFINITY } }, + { { -DMNSN_INFINITY, -DMNSN_INFINITY, -DMNSN_INFINITY } } }; return box; } @@ -68,8 +68,8 @@ DMNSN_INLINE dmnsn_aabb dmnsn_infinite_aabb(void) { dmnsn_aabb box = { - { -DMNSN_INFINITY, -DMNSN_INFINITY, -DMNSN_INFINITY }, - { DMNSN_INFINITY, DMNSN_INFINITY, DMNSN_INFINITY } + { { -DMNSN_INFINITY, -DMNSN_INFINITY, -DMNSN_INFINITY } }, + { { DMNSN_INFINITY, DMNSN_INFINITY, DMNSN_INFINITY } } }; return box; } @@ -94,15 +94,26 @@ dmnsn_symmetric_aabb(dmnsn_vector r) DMNSN_INLINE bool dmnsn_aabb_contains(dmnsn_aabb box, dmnsn_vector p) { - return (p.x >= box.min.x && p.y >= box.min.y && p.z >= box.min.z) - && (p.x <= box.max.x && p.y <= box.max.y && p.z <= box.max.z); + for (unsigned int i = 0; i < 3; ++i) { + if (p.n[i] < box.min.n[i]) { + return false; + } + } + + for (unsigned int i = 0; i < 3; ++i) { + if (p.n[i] > box.max.n[i]) { + return false; + } + } + + return true; } /** Return whether a bounding box is infinite. */ DMNSN_INLINE bool dmnsn_aabb_is_infinite(dmnsn_aabb box) { - return box.min.x == -DMNSN_INFINITY; + return box.min.n[0] == -DMNSN_INFINITY; } /** |