1 #ifndef MSP_GEOMETRY_NEGATION_H_
2 #define MSP_GEOMETRY_NEGATION_H_
10 Negates a shape. Not particulary useful on its own, but can be used together
11 with Intersection to cut holes.
13 template<typename T, unsigned D>
14 class Negation: public Shape<T, D>
20 Negation(const Shape<T, D> &);
21 Negation(const Negation &);
22 Negation &operator=(const Negation &);
25 virtual Negation *clone() const;
27 const Shape<T, D> &get_shape() const { return *shape; }
29 virtual BoundingBox<T, D> get_axis_aligned_bounding_box() const;
30 virtual bool contains(const LinAl::Vector<T, D> &) const;
31 virtual unsigned get_max_ray_intersections() const { return shape->get_max_ray_intersections(); }
32 virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const;
35 template<typename T, unsigned D>
36 inline Negation<T, D>::Negation(const Shape<T, D> &s):
40 template<typename T, unsigned D>
41 inline Negation<T, D>::Negation(const Negation<T, D> &other):
42 shape(other.shape->clone())
45 template<typename T, unsigned D>
46 inline Negation<T, D> &Negation<T, D>::operator=(const Negation<T, D> &other)
49 shape = other.shape->clone();
53 template<typename T, unsigned D>
54 inline Negation<T, D>::~Negation()
59 template<typename T, unsigned D>
60 inline Negation<T, D> *Negation<T, D>::clone() const
62 return new Negation<T, D>(*shape);
65 template<typename T, unsigned D>
66 inline BoundingBox<T, D> Negation<T, D>::get_axis_aligned_bounding_box() const
68 return ~shape->get_axis_aligned_bounding_box();
71 template<typename T, unsigned D>
72 inline bool Negation<T, D>::contains(const LinAl::Vector<T, D> &point) const
74 return !shape->contains(point);
77 template<typename T, unsigned D>
78 inline unsigned Negation<T, D>::get_intersections(const Ray<T, D> &ray, SurfacePoint<T, D> *points, unsigned size) const
80 unsigned count = shape->get_intersections(ray, points, size);
81 for(unsigned i=0; i<count; ++i)
83 points[i].normal = -points[i].normal;
84 points[i].entry = !points[i].entry;
89 } // namespace Geometry