]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/halfspace.h
Add a function to test whether a shapes covers a bounding box
[libs/math.git] / source / geometry / halfspace.h
index b439851bd5adaf3a7067c7f91f5bf8308bb01166..09ec62ce600b9258b1044a0113a61251f5c424aa 100644 (file)
@@ -28,6 +28,7 @@ public:
        virtual bool contains(const LinAl::Vector<T, D> &) const;
        virtual unsigned get_max_ray_intersections() const { return 1; }
        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>
@@ -85,6 +86,25 @@ inline unsigned HalfSpace<T, D>::get_intersections(const Ray<T, D> &ray, Surface
        return 0;
 }
 
+template<typename T, unsigned D>
+inline Coverage HalfSpace<T, D>::get_coverage(const BoundingBox<T, D> &bbox) const
+{
+       LinAl::Vector<T, D> low_point;
+       LinAl::Vector<T, D> high_point;
+       for(unsigned i=0; i<D; ++i)
+       {
+               low_point[i] = (normal[i]>=T(0) ? bbox.get_minimum_coordinate(i) : bbox.get_maximum_coordinate(i));
+               high_point[i] = (normal[i]>=T(0) ? bbox.get_maximum_coordinate(i) : bbox.get_minimum_coordinate(i));
+       }
+
+       if(contains(high_point))
+               return FULL_COVERAGE;
+       else if(contains(low_point))
+               return PARTIAL_COVERAGE;
+       else
+               return NO_COVERAGE;
+}
+
 } // namespace Geometry
 } // namespace Msp