]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/hyperbox.h
Add a function to test whether a shapes covers a bounding box
[libs/math.git] / source / geometry / hyperbox.h
index b9fad33d620d205f1a5043e002cb88556cbc6e32..c3bac57d97e3464d20535a66928106079777801a 100644 (file)
@@ -33,6 +33,7 @@ public:
        virtual bool contains(const LinAl::Vector<T, D> &) const;
        virtual unsigned get_max_ray_intersections() const { return 2; }
        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>
@@ -139,6 +140,25 @@ inline unsigned HyperBox<T, D>::get_intersections(const Ray<T, D> &ray, SurfaceP
        return n;
 }
 
+template<typename T, unsigned D>
+inline Coverage HyperBox<T, D>::get_coverage(const BoundingBox<T, D> &bbox) const
+{
+       const LinAl::Vector<T, D> &min_pt = bbox.get_minimum_point();
+       const LinAl::Vector<T, D> &max_pt = bbox.get_maximum_point();
+       LinAl::Vector<T, D> half_dim = dimensions/T(2);
+
+       Coverage coverage = FULL_COVERAGE;
+       for(unsigned i=0; i<D; ++i)
+       {
+               if(max_pt[i]<-half_dim[i] || min_pt[i]>half_dim[i])
+                       return NO_COVERAGE;
+               if(min_pt[i]<-half_dim[i] || max_pt[i]>half_dim[i])
+                       coverage = PARTIAL_COVERAGE;
+       }
+
+       return coverage;
+}
+
 } // namespace Geometry
 } // namespace Msp