]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/compositeshape.h
Implement the missing assignment operator in CompositeShape
[libs/math.git] / source / geometry / compositeshape.h
index 50075d923b70c3c38f6671ae6ed585fe75f95ec1..55467d762993add17cbc4fe74ae7bfda2f776c22 100644 (file)
@@ -22,14 +22,14 @@ protected:
 
        CompositeShape() { }
        CompositeShape(const Shape<T, D> &, const Shape<T, D> &);
-       CompositeShape(const CompositeShape &);
-       CompositeShape &operator=(const CompositeShape &);
        template<typename Iter>
        void init_from_iter_range(const Iter &, const Iter &);
+       CompositeShape(const CompositeShape &);
+       CompositeShape &operator=(const CompositeShape &);
 public:
        virtual ~CompositeShape();
 
-       virtual HyperBox<T, D> get_axis_aligned_bounding_box() const;
+       virtual BoundingBox<T, D> get_axis_aligned_bounding_box() const;
        virtual bool contains(const LinAl::Vector<T, D> &) const;
        virtual unsigned get_max_ray_intersections() const;
        virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const;
@@ -55,11 +55,22 @@ inline void CompositeShape<T, D, O>::init_from_iter_range(const Iter &begin, con
 }
 
 template<typename T, unsigned D, typename O>
-inline CompositeShape<T, D, O>::CompositeShape(const CompositeShape<T, D, O> &other)
+inline CompositeShape<T, D, O>::CompositeShape(const CompositeShape<T, D, O> &other):
+       shapes(other.shapes)
 {
-       shapes.reserve(other.shapes.size());
-       for(typename ShapeArray::const_iterator i=other.shapes.begin(); i!=other.shapes.end(); ++i)
-               shapes.push_back((*i)->clone());
+       for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i)
+               *i = (*i)->clone();
+}
+
+template<typename T, unsigned D, typename O>
+inline CompositeShape<T, D, O> &CompositeShape<T, D, O>::operator=(const CompositeShape<T, D, O> &other)
+{
+       for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i)
+               delete *i;
+
+       shapes = other.shapes;
+       for(typename ShapeArray::iterator i=shapes.begin(); i!=shapes.end(); ++i)
+               *i = (*i)->clone();
 }
 
 template<typename T, unsigned D, typename O>
@@ -70,9 +81,9 @@ inline CompositeShape<T, D, O>::~CompositeShape()
 }
 
 template<typename T, unsigned D, typename O>
-inline HyperBox<T, D> CompositeShape<T, D, O>::get_axis_aligned_bounding_box() const
+inline BoundingBox<T, D> CompositeShape<T, D, O>::get_axis_aligned_bounding_box() const
 {
-       HyperBox<T, D> aabb;
+       BoundingBox<T, D> aabb;
        for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i)
        {
                if(i==shapes.begin())