]> 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 7aeedb0cd146e30e761e3c88b41d54dde680cdfb..de582e3d26bf278139600aca6c3cc1d15609a798 100644 (file)
@@ -31,9 +31,8 @@ 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 bool check_intersection(const Ray<T, D> &) const;
        virtual unsigned get_max_ray_intersections() const;
        virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const;
 };
@@ -75,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>
@@ -92,12 +93,6 @@ inline bool ExtrudedShape<T, D>::contains(const LinAl::Vector<T, D> &point) cons
        return base->contains(LinAl::Vector<T, D-1>(point));
 }
 
-template<typename T, unsigned D>
-inline bool ExtrudedShape<T, D>::check_intersection(const Ray<T, D> &ray) const
-{
-       return get_intersections(ray, 0, 1);
-}
-
 template<typename T, unsigned D>
 inline unsigned ExtrudedShape<T, D>::get_max_ray_intersections() const
 {