From 3bdd70261a5b77609f31cc2262e2fa511370dd8d Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sun, 7 Jul 2024 14:48:23 -0700 Subject: AABB empty. --- include/math/aabb2.h | 9 +++++++++ include/math/aabb3.h | 9 +++++++++ 2 files changed, 18 insertions(+) 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 { vec2 max; } aabb2; +/// Construct an empty AABB. +static inline aabb2 aabb2_make_empty() { + return (aabb2){ + .min = vec2_from_scalar(R_MAX), .max = vec2_from_scalar(R_MIN)}; +} + /// Construct an AABB from min and max bounds. static inline aabb2 aabb2_make(vec2 min, vec2 max) { return (aabb2){.min = min, .max = max}; @@ -33,3 +39,6 @@ static inline aabb2 aabb2_add(aabb2 box, vec2 p) { static inline aabb2 aabb2_sum(aabb2 a, aabb2 b) { return (aabb2){.min = vec2_min(a.min, b.min), .max = vec2_max(a.max, b.max)}; } + +/// Return true if the AABB is empty. +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 { vec3 max; } aabb3; +/// Construct an empty AABB. +static inline aabb3 aabb3_make_empty() { + return (aabb3){ + .min = vec3_from_scalar(R_MAX), .max = vec3_from_scalar(R_MIN)}; +} + /// Construct an AABB from min and max bounds. static inline aabb3 aabb3_make(vec3 min, vec3 max) { return (aabb3){.min = min, .max = max}; @@ -33,3 +39,6 @@ static inline aabb3 aabb3_add(aabb3 box, vec3 p) { static inline aabb3 aabb3_sum(aabb3 a, aabb3 b) { return (aabb3){.min = vec3_min(a.min, b.min), .max = vec3_max(a.max, b.max)}; } + +/// Return true if the AABB is empty. +static inline bool aabb3_is_empty(aabb3 a) { return (a.min.x > a.max.x); } -- cgit v1.2.3