]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/shape.h
Implement bounding boxes with a separate class
[libs/math.git] / source / geometry / shape.h
index 1f8176418a4e9a948b460701e6e682d56ae31771..bbe255f9054f919792ca748a7c25468b62bfabc8 100644 (file)
@@ -8,7 +8,7 @@ namespace Msp {
 namespace Geometry {
 
 template<typename T, unsigned D>
-class HyperBox;
+class BoundingBox;
 
 template<typename T, unsigned D>
 class Ray;
@@ -16,6 +16,11 @@ class Ray;
 template<typename T, unsigned D>
 class SurfacePoint;
 
+/**
+Base class and interface for geometric shapes.  Shapes may be bounded or
+unbounded.  They are always considered to be solid, i.e. have a distinct inside
+and an outside.
+*/
 template<typename T, unsigned D>
 class Shape
 {
@@ -26,16 +31,22 @@ 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;
 };
 
 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);