]> git.tdb.fi Git - libs/math.git/blob - source/geometry/intersection.h
0e555b03f7086185076ca904512605b0ae204e08
[libs/math.git] / source / geometry / intersection.h
1 #ifndef MSP_GEOMETRY_INTERSECTION_H_
2 #define MSP_GEOMETRY_INTERSECTION_H_
3
4 #include "compositeshape.h"
5
6 namespace Msp {
7 namespace Geometry {
8
9 template<typename T, unsigned D>
10 struct IntersectionOps
11 {
12         static BoundingBox<T, D> combine_aabb(const BoundingBox<T, D> &a, const BoundingBox<T, D> &b) { return a&b; }
13         static bool shortcircuit(bool c) { return !c; }
14 };
15
16 /**
17 Forms a shape from the common parts of component shapes.
18 */
19 template<typename T, unsigned D>
20 class Intersection: public CompositeShape<T, D, IntersectionOps<T, D> >
21 {
22 private:
23         Intersection() { }
24 public:
25         Intersection(const Shape<T, D> &, const Shape<T, D> &);
26
27         template<typename Iter>
28         static Intersection from_iterator_range(const Iter &, const Iter &);
29
30         virtual Intersection *clone() const;
31 };
32
33 template<typename T, unsigned D>
34 inline Intersection<T, D>::Intersection(const Shape<T, D> &s1, const Shape<T, D> &s2):
35         CompositeShape<T, D, IntersectionOps<T, D> >(s1, s2)
36 { }
37
38 template<typename T, unsigned D>
39 template<typename Iter>
40 inline Intersection<T, D> Intersection<T, D>::from_iterator_range(const Iter &begin, const Iter &end)
41 {
42         Intersection<T, D> shape;
43         shape.init_from_iter_range(begin, end);
44         return shape;
45 }
46
47 template<typename T, unsigned D>
48 inline Intersection<T, D> *Intersection<T, D>::clone() const
49 {
50         return new Intersection<T, D>(*this);
51 }
52
53 } // namespace Geometry
54 } // namespace Msp
55
56 #endif