]> git.tdb.fi Git - libs/math.git/blob - source/geometry/union.h
738f1f240f3de600dac9d63e1e048fe786bc3d75
[libs/math.git] / source / geometry / union.h
1 #ifndef MSP_GEOMETRY_UNION_H_
2 #define MSP_GEOMETRY_UNION_H_
3
4 #include "compositeshape.h"
5
6 namespace Msp {
7 namespace Geometry {
8
9 template<typename T, unsigned D>
10 struct UnionOps
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 Joins component shapes together into one.
18 */
19 template<typename T, unsigned D>
20 class Union: public CompositeShape<T, D, UnionOps<T, D> >
21 {
22 private:
23         Union() { }
24 public:
25         Union(const Shape<T, D> &, const Shape<T, D> &);
26
27         template<typename Iter>
28         static Union from_iterator_range(const Iter &, const Iter &);
29
30         virtual Union *clone() const;
31 };
32
33 template<typename T, unsigned D>
34 inline Union<T, D>::Union(const Shape<T, D> &s1, const Shape<T, D> &s2):
35         CompositeShape<T, D, UnionOps<T, D> >(s1, s2)
36 { }
37
38 template<typename T, unsigned D>
39 template<typename Iter>
40 inline Union<T, D> Union<T, D>::from_iterator_range(const Iter &begin, const Iter &end)
41 {
42         Union<T, D> shape;
43         shape.init_from_iter_range(begin, end);
44         return shape;
45 }
46
47 template<typename T, unsigned D>
48 inline Union<T, D> *Union<T, D>::clone() const
49 {
50         return new Union<T, D>(*this);
51 }
52
53 } // namespace Geometry
54 } // namespace Msp
55
56 #endif