1 #ifndef MSP_GEOMETRY_INTERSECTION_H_
2 #define MSP_GEOMETRY_INTERSECTION_H_
4 #include "compositeshape.h"
9 template<typename T, unsigned D>
10 struct IntersectionOps
12 static BoundingBox<T, D> combine_aabb(const BoundingBox<T, D> &a, const BoundingBox<T, D> &b) { return a&b; }
13 static Coverage combine_coverage(Coverage a, Coverage b) { return ((a==PARTIAL_COVERAGE && b==a) ? UNCERTAIN_COVERAGE : std::min(a, b)); }
14 static bool shortcircuit(bool c) { return !c; }
18 Forms a shape from the common parts of component shapes.
20 template<typename T, unsigned D>
21 class Intersection: public CompositeShape<T, D, IntersectionOps<T, D> >
26 Intersection(const Shape<T, D> &, const Shape<T, D> &);
28 template<typename Iter>
29 static Intersection from_iterator_range(const Iter &, const Iter &);
31 virtual Intersection *clone() const;
34 template<typename T, unsigned D>
35 inline Intersection<T, D>::Intersection(const Shape<T, D> &s1, const Shape<T, D> &s2):
36 CompositeShape<T, D, IntersectionOps<T, D> >(s1, s2)
39 template<typename T, unsigned D>
40 template<typename Iter>
41 inline Intersection<T, D> Intersection<T, D>::from_iterator_range(const Iter &begin, const Iter &end)
43 Intersection<T, D> shape;
44 shape.init_from_iter_range(begin, end);
48 template<typename T, unsigned D>
49 inline Intersection<T, D> *Intersection<T, D>::clone() const
51 return new Intersection<T, D>(*this);
54 } // namespace Geometry