]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/extrudedshape.h
Use the coverage function to calculate tighter bounding boxes
[libs/math.git] / source / geometry / extrudedshape.h
index 78dfa4911463e57951eaa0ca4524c223ab9ce9b5..fd4597b9b1a5c935f50a3eb3a6e02296cd3f3a9f 100644 (file)
@@ -31,10 +31,11 @@ public:
        const Shape<T, D-1> &get_base() const { return *base; }
        T get_length() const { return length; }
 
-       virtual BoundingBox<T, D> get_axis_aligned_bounding_box() const;
+       virtual BoundingBox<T, D> get_axis_aligned_bounding_box(unsigned = 0) 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;
+       virtual Coverage get_coverage(const BoundingBox<T, D> &) const;
 };
 
 template<typename T, unsigned D>
@@ -74,9 +75,9 @@ inline ExtrudedShape<T, D> *ExtrudedShape<T, D>::clone() const
 }
 
 template<typename T, unsigned D>
-inline BoundingBox<T, D> ExtrudedShape<T, D>::get_axis_aligned_bounding_box() const
+inline BoundingBox<T, D> ExtrudedShape<T, D>::get_axis_aligned_bounding_box(unsigned detail) const
 {
-       BoundingBox<T, D-1> base_bbox = base->get_axis_aligned_bounding_box();
+       BoundingBox<T, D-1> base_bbox = base->get_axis_aligned_bounding_box(detail);
        T half_length = length/T(2);
        return BoundingBox<T, D>(compose(base_bbox.get_minimum_point(), -half_length),
                compose(base_bbox.get_maximum_point(), half_length));
@@ -187,6 +188,24 @@ inline unsigned ExtrudedShape<T, D>::get_intersections(const Ray<T, D> &ray, Sur
        return n;
 }
 
+template<typename T, unsigned D>
+inline Coverage ExtrudedShape<T, D>::get_coverage(const BoundingBox<T, D> &bbox) const
+{
+       T half_length = length/T(2);
+       if(bbox.get_maximum_coordinate(D-1)<-half_length || bbox.get_minimum_coordinate(D-1)>half_length)
+               return NO_COVERAGE;
+
+       BoundingBox<T, D-1> base_bbox(bbox.get_minimum_point().template slice<D-1>(0), bbox.get_maximum_point().template slice<D-1>(0));
+       Coverage coverage = base->get_coverage(base_bbox);
+       if(coverage==NO_COVERAGE)
+               return NO_COVERAGE;
+
+       if(bbox.get_minimum_coordinate(D-1)<-half_length || bbox.get_maximum_coordinate(D-1)>half_length)
+               return PARTIAL_COVERAGE;
+       else
+               return coverage;
+}
+
 } // namespace Geometry
 } // namespace Msp