]> git.tdb.fi Git - libs/math.git/blob - source/geometry/negation.h
Put the common #includes in shape.h
[libs/math.git] / source / geometry / negation.h
1 #ifndef MSP_GEOMETRY_NEGATION_H_
2 #define MSP_GEOMETRY_NEGATION_H_
3
4 #include "shape.h"
5
6 namespace Msp {
7 namespace Geometry {
8
9 /**
10 Negates a shape.  Not particulary useful on its own, but can be used together
11 with Intersection to cut holes.
12 */
13 template<typename T, unsigned D>
14 class Negation: public Shape<T, D>
15 {
16 private:
17         Shape<T, D> *shape;
18
19 public:
20         Negation(const Shape<T, D> &);
21
22         virtual Negation *clone() const;
23
24         const Shape<T, D> &get_shape() const { return *shape; }
25
26         virtual BoundingBox<T, D> get_axis_aligned_bounding_box() const;
27         virtual bool contains(const LinAl::Vector<T, D> &) const;
28         virtual unsigned get_max_ray_intersections() const { return shape->get_max_ray_intersections(); }
29         virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const;
30 };
31
32 template<typename T, unsigned D>
33 inline Negation<T, D>::Negation(const Shape<T, D> &s):
34         shape(s.clone())
35 { }
36
37 template<typename T, unsigned D>
38 inline Negation<T, D> *Negation<T, D>::clone() const
39 {
40         return new Negation<T, D>(*shape);
41 }
42
43 template<typename T, unsigned D>
44 inline BoundingBox<T, D> Negation<T, D>::get_axis_aligned_bounding_box() const
45 {
46         return ~shape->get_axis_aligned_bounding_box();
47 }
48
49 template<typename T, unsigned D>
50 inline bool Negation<T, D>::contains(const LinAl::Vector<T, D> &point) const
51 {
52         return !shape->contains(point);
53 }
54
55 template<typename T, unsigned D>
56 inline unsigned Negation<T, D>::get_intersections(const Ray<T, D> &ray, SurfacePoint<T, D> *points, unsigned size) const
57 {
58         unsigned count = shape->get_intersections(ray, points, size);
59         for(unsigned i=0; i<count; ++i)
60                 points[i].normal = -points[i].normal;
61         return count;
62 }
63
64 } // namespace Geometry
65 } // namespace Msp
66
67 #endif