summary refs log tree commit diff
path: root/src/Math/AABB.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Math/AABB.hpp')
-rw-r--r--src/Math/AABB.hpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Math/AABB.hpp b/src/Math/AABB.hpp
index 11d26a8..19aa81c 100644
--- a/src/Math/AABB.hpp
+++ b/src/Math/AABB.hpp
@@ -8,6 +8,31 @@ struct AABB {
     AABB(Vector<3> min, Vector<3> max) : min(min), max(max) {}
     explicit AABB(Vector<3> max) : max(max) {}
 
+    Vector<3> size() const { return max - min; }
+    Vector<3> center() const { return (min + max) / 2; }
+
+    Bool contains(Vector<3> point) const {
+        return point.x() >= min.x() && point.x() <= max.x()
+            && point.y() >= min.y() && point.y() <= max.y()
+            && point.z() >= min.z() && point.z() <= max.z();
+    }
+
+    Bool intersects_on_x(AABB other) const {
+        return min.x() <= other.max.x() && max.x() >= other.min.x();
+    }
+
+    Bool intersects_on_y(AABB other) const {
+        return min.y() <= other.max.y() && max.y() >= other.min.y();
+    }
+
+    Bool intersects_on_z(AABB other) const {
+        return min.z() <= other.max.z() && max.z() >= other.min.z();
+    }
+
+    Bool collides(AABB other) const {
+        return intersects_on_x(other) && intersects_on_y(other) && intersects_on_z(other);
+    }
+
     std::array<Vector<3>, 8> corners() const {
         return {{
             {min.x(), min.y(), min.z()},
@@ -23,5 +48,12 @@ struct AABB {
 
     AABB offset(Vector<3> by) const { return {min + by, max + by}; }
 
+    AABB sum(AABB with) const {
+        auto new_size = size() + with.size();
+        return {center() - new_size / 2, center() + new_size / 2};
+    }
+
+    AABB cast_box(Vector<3> v, AABB against) const;
+
     Vector<3> min, max;
 };