]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/compositeshape.h
Add a function to test whether a shapes covers a bounding box
[libs/math.git] / source / geometry / compositeshape.h
index e9aeadcfe73df68657fab07473d15a6fba2f25a6..00ae55d0ad7b83e8d67a3f15867d75c6419a6903 100644 (file)
@@ -38,6 +38,7 @@ public:
        virtual bool contains(const LinAl::Vector<T, D> &) const;
        virtual unsigned get_max_ray_intersections() const { return max_isect; }
        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, typename O>
@@ -190,6 +191,23 @@ inline unsigned CompositeShape<T, D, O>::get_intersections(const Ray<T, D> &ray,
        return n;
 }
 
+template<typename T, unsigned D, typename O>
+inline Coverage CompositeShape<T, D, O>::get_coverage(const BoundingBox<T, D> &bbox) const
+{
+       Coverage coverage = NO_COVERAGE;
+       for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i)
+       {
+               Coverage c = (*i)->get_coverage(bbox);
+               if(i==shapes.begin() || Ops::shortcircuit(c>coverage))
+                       coverage = c;
+
+               if(coverage!=PARTIAL_COVERAGE && Ops::shortcircuit(coverage==FULL_COVERAGE))
+                       break;
+       }
+
+       return coverage;
+}
+
 } // namespace Geometry
 } // namespace Msp