]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/shape.h
Add a function to test whether a shapes covers a bounding box
[libs/math.git] / source / geometry / shape.h
index 3f52613bef98d9df47e3c935fd4ddca213e98b82..ded8f13d8b7464b896e8d0510fe8146de2e68a85 100644 (file)
@@ -3,18 +3,19 @@
 
 #include <vector>
 #include <msp/linal/vector.h>
+#include "boundingbox.h"
+#include "ray.h"
+#include "surfacepoint.h"
 
 namespace Msp {
 namespace Geometry {
 
-template<typename T, unsigned D>
-class HyperBox;
-
-template<typename T, unsigned D>
-class Ray;
-
-template<typename T, unsigned D>
-class SurfacePoint;
+enum Coverage
+{
+       NO_COVERAGE,
+       PARTIAL_COVERAGE,
+       FULL_COVERAGE
+};
 
 /**
 Base class and interface for geometric shapes.  Shapes may be bounded or
@@ -31,16 +32,23 @@ public:
 
        virtual Shape *clone() const = 0;
 
-       virtual HyperBox<T, D> get_axis_aligned_bounding_box() const = 0;
+       virtual BoundingBox<T, D> get_axis_aligned_bounding_box() const = 0;
        virtual bool contains(const LinAl::Vector<T, D> &) const = 0;
-       virtual bool check_intersection(const Ray<T, D> &) const = 0;
+       bool check_intersection(const Ray<T, D> &) const;
        virtual unsigned get_max_ray_intersections() const = 0;
        virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const = 0;
        std::vector<SurfacePoint<T, D> > get_intersections(const Ray<T, D> &) const;
+       virtual Coverage get_coverage(const BoundingBox<T, D> &) const = 0;
 };
 
 template<typename T, unsigned D>
-std::vector<SurfacePoint<T, D> > Shape<T, D>::get_intersections(const Ray<T, D> &ray) const
+inline bool Shape<T, D>::check_intersection(const Ray<T, D> &ray) const
+{
+       return get_intersections(ray, 0, 1);
+}
+
+template<typename T, unsigned D>
+inline std::vector<SurfacePoint<T, D> > Shape<T, D>::get_intersections(const Ray<T, D> &ray) const
 {
        unsigned max_isect = get_max_ray_intersections();
        std::vector<SurfacePoint<T, D> > points(max_isect);