]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/extrudedshape.h
Implement bounding boxes with a separate class
[libs/math.git] / source / geometry / extrudedshape.h
index 83933b0808a02f32d8febcce5eee8c8a23ad85d0..de582e3d26bf278139600aca6c3cc1d15609a798 100644 (file)
@@ -31,7 +31,7 @@ public:
        const Shape<T, D-1> &get_base() const { return *base; }
        T get_length() const { return length; }
 
-       virtual HyperBox<T, D> get_axis_aligned_bounding_box() const;
+       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;
        virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const;
@@ -74,10 +74,12 @@ inline ExtrudedShape<T, D> *ExtrudedShape<T, D>::clone() const
 }
 
 template<typename T, unsigned D>
-inline HyperBox<T, D> ExtrudedShape<T, D>::get_axis_aligned_bounding_box() const
+inline BoundingBox<T, D> ExtrudedShape<T, D>::get_axis_aligned_bounding_box() const
 {
-       HyperBox<T, D-1> base_bbox = base->get_axis_aligned_bounding_box();
-       return HyperBox<T, D>(LinAl::Vector<T, D>(base_bbox.get_dimensions(), length));
+       BoundingBox<T, D-1> base_bbox = base->get_axis_aligned_bounding_box();
+       T half_length = length/T(2);
+       return BoundingBox<T, D>(LinAl::Vector<T, D>(base_bbox.get_minimum_point(), -half_length),
+               LinAl::Vector<T, D>(base_bbox.get_maximum_point(), half_length));
 }
 
 template<typename T, unsigned D>