X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fcompositeshape.h;h=4c640be22f4c5045076b9659ce7734d517f1127c;hb=09cc3a8648dd20e9a07d669b353c4a120b67c1c4;hp=50b04e80c506e93f7dc995187140e871dec66e27;hpb=827b227ae53884109b6885ccd1424dda8c0b3725;p=libs%2Fmath.git diff --git a/source/geometry/compositeshape.h b/source/geometry/compositeshape.h index 50b04e8..4c640be 100644 --- a/source/geometry/compositeshape.h +++ b/source/geometry/compositeshape.h @@ -1,7 +1,9 @@ #ifndef MSP_GEOMETRY_COMPOSITESHAPE_H_ #define MSP_GEOMETRY_COMPOSITESHAPE_H_ +#include #include +#include "boundingbox.h" #include "shape.h" namespace Msp { @@ -19,16 +21,17 @@ protected: ShapeArray shapes; + CompositeShape() { } CompositeShape(const Shape &, const Shape &); - CompositeShape(const ShapeArray &); CompositeShape(const CompositeShape &); CompositeShape &operator=(const CompositeShape &); + template + void init_from_iter_range(const Iter &, const Iter &); public: virtual ~CompositeShape(); - virtual HyperBox get_axis_aligned_bounding_box() const; + virtual BoundingBox get_axis_aligned_bounding_box() const; virtual bool contains(const LinAl::Vector &) const; - virtual bool check_intersection(const Ray &) const; virtual unsigned get_max_ray_intersections() const; virtual unsigned get_intersections(const Ray &, SurfacePoint *, unsigned) const; }; @@ -42,13 +45,21 @@ inline CompositeShape::CompositeShape(const Shape &s1, const Shap } template -inline CompositeShape::CompositeShape(const ShapeArray &s) +template +inline void CompositeShape::init_from_iter_range(const Iter &begin, const Iter &end) { - if(s.empty()) - throw std::invalid_argument("CompositeShape::CompositeShape"); + if(begin==end) + throw std::invalid_argument("CompositeShape::init_from_iter_range"); - shapes.reserve(s.size()); - for(typename ShapeArray::const_iterator i=s.begin(); i!=s.end(); ++i) + for(Iter i=begin; i!=end; ++i) + shapes.push_back((*i)->clone()); +} + +template +inline CompositeShape::CompositeShape(const CompositeShape &other) +{ + shapes.reserve(other.shapes.size()); + for(typename ShapeArray::const_iterator i=other.shapes.begin(); i!=other.shapes.end(); ++i) shapes.push_back((*i)->clone()); } @@ -60,9 +71,9 @@ inline CompositeShape::~CompositeShape() } template -inline HyperBox CompositeShape::get_axis_aligned_bounding_box() const +inline BoundingBox CompositeShape::get_axis_aligned_bounding_box() const { - HyperBox aabb; + BoundingBox aabb; for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i) { if(i==shapes.begin()) @@ -86,12 +97,6 @@ inline bool CompositeShape::contains(const LinAl::Vector &point) return inside; } -template -inline bool CompositeShape::check_intersection(const Ray &ray) const -{ - return get_intersections(ray, 0, 1); -} - template inline unsigned CompositeShape::get_max_ray_intersections() const {