aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-07-07 14:48:23 -0700
committer3gg <3gg@shellblade.net>2024-07-07 14:48:23 -0700
commit3bdd70261a5b77609f31cc2262e2fa511370dd8d (patch)
tree7ee34183720e09b48e0236d556a5487b584c7055 /include
parent9306828192644cf367aeec30c00cc6bc178edb62 (diff)
AABB empty.
Diffstat (limited to 'include')
-rw-r--r--include/math/aabb2.h9
-rw-r--r--include/math/aabb3.h9
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.
13static 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.
13static inline aabb2 aabb2_make(vec2 min, vec2 max) { 19static 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) {
33static inline aabb2 aabb2_sum(aabb2 a, aabb2 b) { 39static 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.
44static 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.
13static 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.
13static inline aabb3 aabb3_make(vec3 min, vec3 max) { 19static 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) {
33static inline aabb3 aabb3_sum(aabb3 a, aabb3 b) { 39static 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.
44static inline bool aabb3_is_empty(aabb3 a) { return (a.min.x > a.max.x); }