]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/negation.h
Use numeric literals in place of M_PI
[libs/math.git] / source / geometry / negation.h
index 6746aed113f487618e0e7f254f088fd8bdc2289e..8e2b3f41a6d7c30681026176330d0ed1a04d965e 100644 (file)
@@ -18,12 +18,15 @@ private:
 
 public:
        Negation(const Shape<T, D> &);
+       Negation(const Negation &);
+       Negation &operator=(const Negation &);
+       ~Negation();
 
        virtual Negation *clone() const;
 
        const Shape<T, D> &get_shape() const { return *shape; }
 
-       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 { return shape->get_max_ray_intersections(); }
        virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const;
@@ -34,6 +37,25 @@ inline Negation<T, D>::Negation(const Shape<T, D> &s):
        shape(s.clone())
 { }
 
+template<typename T, unsigned D>
+inline Negation<T, D>::Negation(const Negation<T, D> &other):
+       shape(other.shape->clone())
+{ }
+
+template<typename T, unsigned D>
+inline Negation<T, D> &Negation<T, D>::operator=(const Negation<T, D> &other)
+{
+       delete shape;
+       shape = other.shape->clone();
+       return *this;
+}
+
+template<typename T, unsigned D>
+inline Negation<T, D>::~Negation()
+{
+       delete shape;
+}
+
 template<typename T, unsigned D>
 inline Negation<T, D> *Negation<T, D>::clone() const
 {
@@ -41,10 +63,9 @@ inline Negation<T, D> *Negation<T, D>::clone() const
 }
 
 template<typename T, unsigned D>
-inline HyperBox<T, D> Negation<T, D>::get_axis_aligned_bounding_box() const
+inline BoundingBox<T, D> Negation<T, D>::get_axis_aligned_bounding_box() const
 {
-       // XXX How do we handle this correctly?  In particular negation of a negation?
-       return HyperBox<T, D>();
+       return ~shape->get_axis_aligned_bounding_box();
 }
 
 template<typename T, unsigned D>
@@ -58,7 +79,10 @@ inline unsigned Negation<T, D>::get_intersections(const Ray<T, D> &ray, SurfaceP
 {
        unsigned count = shape->get_intersections(ray, points, size);
        for(unsigned i=0; i<count; ++i)
+       {
                points[i].normal = -points[i].normal;
+               points[i].entry = !points[i].entry;
+       }
        return count;
 }