]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/hyperbox.h
Implement bounding boxes with a separate class
[libs/math.git] / source / geometry / hyperbox.h
index 11c197e72ebb059814e0c92f685ac533b72acaa2..da500910e4f100d57f865b644bd719d71a3ee34c 100644 (file)
@@ -5,6 +5,7 @@
 #include <cmath>
 #include <stdexcept>
 #include <msp/linal/vector.h>
+#include "boundingbox.h"
 #include "ray.h"
 #include "shape.h"
 #include "surfacepoint.h"
@@ -31,7 +32,7 @@ public:
        const LinAl::Vector<T, D> &get_dimensions() const { return dimensions; }
        T get_dimension(unsigned) const;
 
-       virtual HyperBox<T, D> get_axis_aligned_bounding_box() const { return *this; }
+       virtual BoundingBox<T, D> get_axis_aligned_bounding_box() const;
        virtual bool contains(const LinAl::Vector<T, D> &) const;
        virtual unsigned get_max_ray_intersections() const { return 2; }
        virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const;
@@ -65,6 +66,13 @@ inline T HyperBox<T, D>::get_dimension(unsigned i) const
        return dimensions[i];
 }
 
+template<typename T, unsigned D>
+inline BoundingBox<T, D> HyperBox<T, D>::get_axis_aligned_bounding_box() const
+{
+       LinAl::Vector<T, D> half_dim = dimensions/T(2);
+       return BoundingBox<T, D>(-half_dim, half_dim);
+}
+
 template<typename T, unsigned D>
 inline bool HyperBox<T, D>::contains(const LinAl::Vector<T, D> &point) const
 {