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> &);
22 virtual Negation *clone() const;
24 const Shape<T, D> &get_shape() const { return *shape; }
26 virtual HyperBox<T, D> get_axis_aligned_bounding_box() const;
27 virtual bool contains(const LinAl::Vector<T, D> &) const;
28 virtual bool check_intersection(const Ray<T, D> &) const;
29 virtual unsigned get_max_ray_intersections() const { return shape->get_max_ray_intersections(); }
30 virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const;
33 template<typename T, unsigned D>
34 inline Negation<T, D>::Negation(const Shape<T, D> &s):
38 template<typename T, unsigned D>
39 inline Negation<T, D> *Negation<T, D>::clone() const
41 return new Negation<T, D>(*shape);
44 template<typename T, unsigned D>
45 inline HyperBox<T, D> Negation<T, D>::get_axis_aligned_bounding_box() const
47 // XXX How do we handle this correctly? In particular negation of a negation?
48 return HyperBox<T, D>();
51 template<typename T, unsigned D>
52 inline bool Negation<T, D>::contains(const LinAl::Vector<T, D> &point) const
54 return !shape->contains(point);
57 template<typename T, unsigned D>
58 inline bool Negation<T, D>::check_intersection(const Ray<T, D> &ray) const
60 return get_intersections(ray, 0, 1);
63 template<typename T, unsigned D>
64 inline unsigned Negation<T, D>::get_intersections(const Ray<T, D> &ray, SurfacePoint<T, D> *points, unsigned size) const
66 unsigned count = shape->get_intersections(ray, points, size);
67 for(unsigned i=0; i<count; ++i)
68 points[i].normal = -points[i].normal;
72 } // namespace Geometry