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(unsigned = 0) 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;
33 virtual Coverage get_coverage(const BoundingBox<T, D> &) const;
36 template<typename T, unsigned D>
37 inline Negation<T, D>::Negation(const Shape<T, D> &s):
41 template<typename T, unsigned D>
42 inline Negation<T, D>::Negation(const Negation<T, D> &other):
43 shape(other.shape->clone())
46 template<typename T, unsigned D>
47 inline Negation<T, D> &Negation<T, D>::operator=(const Negation<T, D> &other)
50 shape = other.shape->clone();
54 template<typename T, unsigned D>
55 inline Negation<T, D>::~Negation()
60 template<typename T, unsigned D>
61 inline Negation<T, D> *Negation<T, D>::clone() const
63 return new Negation<T, D>(*shape);
66 template<typename T, unsigned D>
67 inline BoundingBox<T, D> Negation<T, D>::get_axis_aligned_bounding_box(unsigned detail) const
69 return ~shape->get_axis_aligned_bounding_box(detail);
72 template<typename T, unsigned D>
73 inline bool Negation<T, D>::contains(const LinAl::Vector<T, D> &point) const
75 return !shape->contains(point);
78 template<typename T, unsigned D>
79 inline unsigned Negation<T, D>::get_intersections(const Ray<T, D> &ray, SurfacePoint<T, D> *points, unsigned size) const
81 unsigned count = shape->get_intersections(ray, points, size);
82 for(unsigned i=0; i<count; ++i)
84 points[i].normal = -points[i].normal;
85 points[i].entry = !points[i].entry;
90 template<typename T, unsigned D>
91 inline Coverage Negation<T, D>::get_coverage(const BoundingBox<T, D> &bbox) const
93 Coverage coverage = shape->get_coverage(bbox);
94 if(coverage==FULL_COVERAGE)
96 else if(coverage==NO_COVERAGE)
102 } // namespace Geometry