]> git.sesse.net Git - casparcg/blob - dependencies/boost/boost/polygon/polygon_45_set_traits.hpp
Manually merged pull request #222
[casparcg] / dependencies / boost / boost / polygon / polygon_45_set_traits.hpp
1 /*
2   Copyright 2008 Intel Corporation
3  
4   Use, modification and distribution are subject to the Boost Software License,
5   Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6   http://www.boost.org/LICENSE_1_0.txt).
7 */
8 #ifndef BOOST_POLYGON_POLYGON_45_SET_TRAITS_HPP
9 #define BOOST_POLYGON_POLYGON_45_SET_TRAITS_HPP
10 namespace boost { namespace polygon{
11
12   //default definition of polygon 45 set traits works for any model of polygon 45, polygon 45 with holes or any vector or list thereof
13   template <typename T>
14   struct polygon_45_set_traits {
15     typedef typename get_coordinate_type<T, typename geometry_concept<T>::type >::type coordinate_type;
16     typedef typename get_iterator_type<T>::type iterator_type;
17     typedef T operator_arg_type;
18
19     static inline iterator_type begin(const T& polygon_set) {
20       return get_iterator_type<T>::begin(polygon_set);
21     }
22
23     static inline iterator_type end(const T& polygon_set) {
24       return get_iterator_type<T>::end(polygon_set);
25     }
26
27     static inline bool clean(const T& ) { return false; }
28
29     static inline bool sorted(const T& ) { return false; }
30   };
31
32   template <typename T>
33   struct is_45_polygonal_concept { typedef gtl_no type; };
34   template <>
35   struct is_45_polygonal_concept<polygon_45_concept> { typedef gtl_yes type; };
36   template <>
37   struct is_45_polygonal_concept<polygon_45_with_holes_concept> { typedef gtl_yes type; };
38   template <>
39   struct is_45_polygonal_concept<polygon_45_set_concept> { typedef gtl_yes type; };
40
41   template <typename T>
42   struct is_polygon_45_set_type {
43     typedef typename is_45_polygonal_concept<typename geometry_concept<T>::type>::type type;
44   };
45   template <typename T>
46   struct is_polygon_45_set_type<std::list<T> > { 
47     typedef typename gtl_or<
48       typename is_45_polygonal_concept<typename geometry_concept<std::list<T> >::type>::type,
49       typename is_45_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type;
50   };
51   template <typename T>
52   struct is_polygon_45_set_type<std::vector<T> > { 
53     typedef typename gtl_or<
54       typename is_45_polygonal_concept<typename geometry_concept<std::vector<T> >::type>::type,
55       typename is_45_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type;
56   };
57
58   template <typename T>
59   struct is_mutable_polygon_45_set_type {
60     typedef typename gtl_same_type<polygon_45_set_concept, typename geometry_concept<T>::type>::type type;
61   };
62   template <typename T>
63   struct is_mutable_polygon_45_set_type<std::list<T> > { 
64     typedef typename gtl_or<
65       typename gtl_same_type<polygon_45_set_concept, typename geometry_concept<std::list<T> >::type>::type,
66       typename is_45_polygonal_concept<typename geometry_concept<typename std::list<T>::value_type>::type>::type>::type type;
67   };
68   template <typename T>
69   struct is_mutable_polygon_45_set_type<std::vector<T> > { 
70     typedef typename gtl_or<
71       typename gtl_same_type<polygon_45_set_concept, typename geometry_concept<std::vector<T> >::type>::type,
72       typename is_45_polygonal_concept<typename geometry_concept<typename std::vector<T>::value_type>::type>::type>::type type;
73   };
74
75   template <typename T>
76   bool fracture_holes_45_by_concept() { return false; }
77   template <>
78   inline bool fracture_holes_45_by_concept<polygon_45_concept>() { return true; }
79
80   template <typename T, typename iT>
81   void get_45_polygons_T(T& t, iT begin, iT end) {
82     typedef typename polygon_45_set_traits<T>::coordinate_type Unit;
83     typedef typename geometry_concept<typename T::value_type>::type CType;
84     typename polygon_45_formation<Unit>::Polygon45Formation pf(fracture_holes_45_by_concept<CType>());
85     //std::cout << "FORMING POLYGONS\n";
86     pf.scan(t, begin, end);
87   }
88
89   template <typename T>
90   struct polygon_45_set_mutable_traits {};
91   template <typename T>
92   struct polygon_45_set_mutable_traits<std::list<T> > {
93     template <typename input_iterator_type>
94     static inline void set(std::list<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end) {
95       polygon_set.clear();
96       polygon_45_set_data<typename polygon_45_set_traits<std::list<T> >::coordinate_type> ps;
97       ps.insert(input_begin, input_end);
98       ps.sort();
99       ps.clean();
100       get_45_polygons_T(polygon_set, ps.begin(), ps.end());
101     }
102   };
103   template <typename T>
104   struct polygon_45_set_mutable_traits<std::vector<T> > {
105     template <typename input_iterator_type>
106     static inline void set(std::vector<T>& polygon_set, input_iterator_type input_begin, input_iterator_type input_end) {
107       polygon_set.clear();
108       polygon_45_set_data<typename polygon_45_set_traits<std::list<T> >::coordinate_type> ps;
109       ps.insert(input_begin, input_end);
110       ps.sort();
111       ps.clean();
112       get_45_polygons_T(polygon_set, ps.begin(), ps.end());
113     }
114   };
115
116   template <typename T>
117   struct polygon_45_set_mutable_traits<polygon_45_set_data<T> > {
118     template <typename input_iterator_type>
119     static inline void set(polygon_45_set_data<T>& polygon_set, 
120                            input_iterator_type input_begin, input_iterator_type input_end) {
121       polygon_set.set(input_begin, input_end);
122     }
123   };
124   template <typename T>
125   struct polygon_45_set_traits<polygon_45_set_data<T> > {
126     typedef typename polygon_45_set_data<T>::coordinate_type coordinate_type;
127     typedef typename polygon_45_set_data<T>::iterator_type iterator_type;
128     typedef typename polygon_45_set_data<T>::operator_arg_type operator_arg_type;
129
130     static inline iterator_type begin(const polygon_45_set_data<T>& polygon_set) {
131       return polygon_set.begin();
132     }
133
134     static inline iterator_type end(const polygon_45_set_data<T>& polygon_set) {
135       return polygon_set.end();
136     }
137
138     static inline bool clean(const polygon_45_set_data<T>& polygon_set) { polygon_set.clean(); return true; }
139
140     static inline bool sorted(const polygon_45_set_data<T>& polygon_set) { polygon_set.sort(); return true; }
141
142   };
143 }  
144 }
145 #endif
146