diff options
author | 3gg <3gg@shellblade.net> | 2024-07-07 14:48:23 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2024-07-07 14:48:23 -0700 |
commit | 3bdd70261a5b77609f31cc2262e2fa511370dd8d (patch) | |
tree | 7ee34183720e09b48e0236d556a5487b584c7055 | |
parent | 9306828192644cf367aeec30c00cc6bc178edb62 (diff) |
AABB empty.
-rw-r--r-- | include/math/aabb2.h | 9 | ||||
-rw-r--r-- | include/math/aabb3.h | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/include/math/aabb2.h b/include/math/aabb2.h index edb6cb6..916b1ba 100644 --- a/include/math/aabb2.h +++ b/include/math/aabb2.h | |||
@@ -9,6 +9,12 @@ typedef struct aabb2 { | |||
9 | vec2 max; | 9 | vec2 max; |
10 | } aabb2; | 10 | } aabb2; |
11 | 11 | ||
12 | /// Construct an empty AABB. | ||
13 | static inline aabb2 aabb2_make_empty() { | ||
14 | return (aabb2){ | ||
15 | .min = vec2_from_scalar(R_MAX), .max = vec2_from_scalar(R_MIN)}; | ||
16 | } | ||
17 | |||
12 | /// Construct an AABB from min and max bounds. | 18 | /// Construct an AABB from min and max bounds. |
13 | static inline aabb2 aabb2_make(vec2 min, vec2 max) { | 19 | static inline aabb2 aabb2_make(vec2 min, vec2 max) { |
14 | return (aabb2){.min = min, .max = max}; | 20 | return (aabb2){.min = min, .max = max}; |
@@ -33,3 +39,6 @@ static inline aabb2 aabb2_add(aabb2 box, vec2 p) { | |||
33 | static inline aabb2 aabb2_sum(aabb2 a, aabb2 b) { | 39 | static inline aabb2 aabb2_sum(aabb2 a, aabb2 b) { |
34 | return (aabb2){.min = vec2_min(a.min, b.min), .max = vec2_max(a.max, b.max)}; | 40 | return (aabb2){.min = vec2_min(a.min, b.min), .max = vec2_max(a.max, b.max)}; |
35 | } | 41 | } |
42 | |||
43 | /// Return true if the AABB is empty. | ||
44 | static inline bool aabb2_is_empty(aabb2 a) { return (a.min.x > a.max.x); } | ||
diff --git a/include/math/aabb3.h b/include/math/aabb3.h index 0b0005c..f4c9338 100644 --- a/include/math/aabb3.h +++ b/include/math/aabb3.h | |||
@@ -9,6 +9,12 @@ typedef struct aabb3 { | |||
9 | vec3 max; | 9 | vec3 max; |
10 | } aabb3; | 10 | } aabb3; |
11 | 11 | ||
12 | /// Construct an empty AABB. | ||
13 | static inline aabb3 aabb3_make_empty() { | ||
14 | return (aabb3){ | ||
15 | .min = vec3_from_scalar(R_MAX), .max = vec3_from_scalar(R_MIN)}; | ||
16 | } | ||
17 | |||
12 | /// Construct an AABB from min and max bounds. | 18 | /// Construct an AABB from min and max bounds. |
13 | static inline aabb3 aabb3_make(vec3 min, vec3 max) { | 19 | static inline aabb3 aabb3_make(vec3 min, vec3 max) { |
14 | return (aabb3){.min = min, .max = max}; | 20 | return (aabb3){.min = min, .max = max}; |
@@ -33,3 +39,6 @@ static inline aabb3 aabb3_add(aabb3 box, vec3 p) { | |||
33 | static inline aabb3 aabb3_sum(aabb3 a, aabb3 b) { | 39 | static inline aabb3 aabb3_sum(aabb3 a, aabb3 b) { |
34 | return (aabb3){.min = vec3_min(a.min, b.min), .max = vec3_max(a.max, b.max)}; | 40 | return (aabb3){.min = vec3_min(a.min, b.min), .max = vec3_max(a.max, b.max)}; |
35 | } | 41 | } |
42 | |||
43 | /// Return true if the AABB is empty. | ||
44 | static inline bool aabb3_is_empty(aabb3 a) { return (a.min.x > a.max.x); } | ||