Chris@16
|
1 /*
|
Chris@16
|
2 Copyright 2008 Intel Corporation
|
Chris@16
|
3
|
Chris@16
|
4 Use, modification and distribution are subject to the Boost Software License,
|
Chris@16
|
5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
6 http://www.boost.org/LICENSE_1_0.txt).
|
Chris@16
|
7 */
|
Chris@16
|
8 #ifndef BOOST_POLYGON_POLYGON_SET_CONCEPT_HPP
|
Chris@16
|
9 #define BOOST_POLYGON_POLYGON_SET_CONCEPT_HPP
|
Chris@16
|
10 #include "polygon_set_data.hpp"
|
Chris@16
|
11 #include "detail/polygon_simplify.hpp"
|
Chris@16
|
12 namespace boost { namespace polygon{
|
Chris@16
|
13
|
Chris@16
|
14 template <typename T, typename T2>
|
Chris@16
|
15 struct is_either_polygon_set_type {
|
Chris@16
|
16 typedef typename gtl_or<typename is_polygon_set_type<T>::type, typename is_polygon_set_type<T2>::type >::type type;
|
Chris@16
|
17 };
|
Chris@16
|
18
|
Chris@16
|
19 template <typename T>
|
Chris@16
|
20 struct is_any_polygon_set_type {
|
Chris@16
|
21 typedef typename gtl_or<typename is_polygon_45_or_90_set_type<T>::type, typename is_polygon_set_type<T>::type >::type type;
|
Chris@16
|
22 };
|
Chris@16
|
23
|
Chris@16
|
24 template <typename polygon_set_type>
|
Chris@16
|
25 typename enable_if< typename is_any_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
26 typename polygon_set_traits<polygon_set_type>::iterator_type>::type
|
Chris@16
|
27 begin_polygon_set_data(const polygon_set_type& polygon_set) {
|
Chris@16
|
28 return polygon_set_traits<polygon_set_type>::begin(polygon_set);
|
Chris@16
|
29 }
|
Chris@16
|
30
|
Chris@16
|
31 template <typename polygon_set_type>
|
Chris@16
|
32 typename enable_if< typename is_any_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
33 typename polygon_set_traits<polygon_set_type>::iterator_type>::type
|
Chris@16
|
34 end_polygon_set_data(const polygon_set_type& polygon_set) {
|
Chris@16
|
35 return polygon_set_traits<polygon_set_type>::end(polygon_set);
|
Chris@16
|
36 }
|
Chris@16
|
37
|
Chris@16
|
38 template <typename polygon_set_type>
|
Chris@16
|
39 typename enable_if< typename is_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
40 bool>::type
|
Chris@16
|
41 clean(const polygon_set_type& polygon_set) {
|
Chris@16
|
42 return polygon_set_traits<polygon_set_type>::clean(polygon_set);
|
Chris@16
|
43 }
|
Chris@16
|
44
|
Chris@16
|
45 //assign
|
Chris@16
|
46 template <typename polygon_set_type_1, typename polygon_set_type_2>
|
Chris@16
|
47 typename enable_if< typename gtl_and<
|
Chris@16
|
48 typename is_mutable_polygon_set_type<polygon_set_type_1>::type,
|
Chris@16
|
49 typename is_any_polygon_set_type<polygon_set_type_2>::type>::type,
|
Chris@16
|
50 polygon_set_type_1>::type &
|
Chris@16
|
51 assign(polygon_set_type_1& lvalue, const polygon_set_type_2& rvalue) {
|
Chris@16
|
52 if(clean(rvalue))
|
Chris@16
|
53 polygon_set_mutable_traits<polygon_set_type_1>::set(lvalue, begin_polygon_set_data(rvalue), end_polygon_set_data(rvalue));
|
Chris@16
|
54 else {
|
Chris@16
|
55 polygon_set_data<typename polygon_set_traits<polygon_set_type_2>::coordinate_type> ps;
|
Chris@16
|
56 ps.insert(begin_polygon_set_data(rvalue), end_polygon_set_data(rvalue));
|
Chris@16
|
57 ps.clean();
|
Chris@16
|
58 polygon_set_mutable_traits<polygon_set_type_1>::set(lvalue, ps.begin(), ps.end());
|
Chris@16
|
59 }
|
Chris@16
|
60 return lvalue;
|
Chris@16
|
61 }
|
Chris@16
|
62
|
Chris@16
|
63 //get trapezoids
|
Chris@16
|
64 template <typename output_container_type, typename polygon_set_type>
|
Chris@16
|
65 typename enable_if< typename is_mutable_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
66 void>::type
|
Chris@16
|
67 get_trapezoids(output_container_type& output, const polygon_set_type& polygon_set) {
|
Chris@16
|
68 polygon_set_data<typename polygon_set_traits<polygon_set_type>::coordinate_type> ps;
|
Chris@16
|
69 assign(ps, polygon_set);
|
Chris@16
|
70 ps.get_trapezoids(output);
|
Chris@16
|
71 }
|
Chris@16
|
72
|
Chris@16
|
73 //get trapezoids
|
Chris@16
|
74 template <typename output_container_type, typename polygon_set_type>
|
Chris@16
|
75 typename enable_if< typename is_mutable_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
76 void>::type
|
Chris@16
|
77 get_trapezoids(output_container_type& output, const polygon_set_type& polygon_set,
|
Chris@16
|
78 orientation_2d orient) {
|
Chris@16
|
79 polygon_set_data<typename polygon_set_traits<polygon_set_type>::coordinate_type> ps;
|
Chris@16
|
80 assign(ps, polygon_set);
|
Chris@16
|
81 ps.get_trapezoids(output, orient);
|
Chris@16
|
82 }
|
Chris@16
|
83
|
Chris@16
|
84 //equivalence
|
Chris@16
|
85 template <typename polygon_set_type_1, typename polygon_set_type_2>
|
Chris@16
|
86 typename enable_if< typename gtl_and_3 <
|
Chris@16
|
87 typename is_any_polygon_set_type<polygon_set_type_1>::type,
|
Chris@16
|
88 typename is_any_polygon_set_type<polygon_set_type_2>::type,
|
Chris@16
|
89 typename is_either_polygon_set_type<polygon_set_type_1, polygon_set_type_2>::type>::type,
|
Chris@16
|
90 bool>::type
|
Chris@16
|
91 equivalence(const polygon_set_type_1& lvalue,
|
Chris@16
|
92 const polygon_set_type_2& rvalue) {
|
Chris@16
|
93 polygon_set_data<typename polygon_set_traits<polygon_set_type_1>::coordinate_type> ps1;
|
Chris@16
|
94 assign(ps1, lvalue);
|
Chris@16
|
95 polygon_set_data<typename polygon_set_traits<polygon_set_type_2>::coordinate_type> ps2;
|
Chris@16
|
96 assign(ps2, rvalue);
|
Chris@16
|
97 return ps1 == ps2;
|
Chris@16
|
98 }
|
Chris@16
|
99
|
Chris@16
|
100 //clear
|
Chris@16
|
101 template <typename polygon_set_type>
|
Chris@16
|
102 typename enable_if< typename is_mutable_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
103 void>::type
|
Chris@16
|
104 clear(polygon_set_type& polygon_set) {
|
Chris@16
|
105 polygon_set_data<typename polygon_set_traits<polygon_set_type>::coordinate_type> ps;
|
Chris@16
|
106 assign(polygon_set, ps);
|
Chris@16
|
107 }
|
Chris@16
|
108
|
Chris@16
|
109 //empty
|
Chris@16
|
110 template <typename polygon_set_type>
|
Chris@16
|
111 typename enable_if< typename is_mutable_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
112 bool>::type
|
Chris@16
|
113 empty(const polygon_set_type& polygon_set) {
|
Chris@16
|
114 if(clean(polygon_set)) return begin_polygon_set_data(polygon_set) == end_polygon_set_data(polygon_set);
|
Chris@16
|
115 polygon_set_data<typename polygon_set_traits<polygon_set_type>::coordinate_type> ps;
|
Chris@16
|
116 assign(ps, polygon_set);
|
Chris@16
|
117 ps.clean();
|
Chris@16
|
118 return ps.empty();
|
Chris@16
|
119 }
|
Chris@16
|
120
|
Chris@16
|
121 //extents
|
Chris@16
|
122 template <typename polygon_set_type, typename rectangle_type>
|
Chris@16
|
123 typename enable_if< typename gtl_and<
|
Chris@16
|
124 typename is_mutable_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
125 typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
126 bool>::type
|
Chris@16
|
127 extents(rectangle_type& extents_rectangle,
|
Chris@16
|
128 const polygon_set_type& polygon_set) {
|
Chris@16
|
129 clean(polygon_set);
|
Chris@16
|
130 polygon_set_data<typename polygon_set_traits<polygon_set_type>::coordinate_type> ps;
|
Chris@16
|
131 assign(ps, polygon_set);
|
Chris@16
|
132 return ps.extents(extents_rectangle);
|
Chris@16
|
133 }
|
Chris@16
|
134
|
Chris@16
|
135 //area
|
Chris@16
|
136 template <typename polygon_set_type>
|
Chris@16
|
137 typename enable_if< typename is_mutable_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
138 typename coordinate_traits<typename polygon_set_traits<polygon_set_type>::coordinate_type>::area_type>::type
|
Chris@16
|
139 area(const polygon_set_type& polygon_set) {
|
Chris@16
|
140 typedef typename polygon_set_traits<polygon_set_type>::coordinate_type Unit;
|
Chris@16
|
141 typedef polygon_with_holes_data<Unit> p_type;
|
Chris@16
|
142 typedef typename coordinate_traits<Unit>::area_type area_type;
|
Chris@16
|
143 std::vector<p_type> polys;
|
Chris@16
|
144 assign(polys, polygon_set);
|
Chris@16
|
145 area_type retval = (area_type)0;
|
Chris@16
|
146 for(std::size_t i = 0; i < polys.size(); ++i) {
|
Chris@16
|
147 retval += area(polys[i]);
|
Chris@16
|
148 }
|
Chris@16
|
149 return retval;
|
Chris@16
|
150 }
|
Chris@16
|
151
|
Chris@16
|
152 template <typename polygon_set_type>
|
Chris@16
|
153 typename enable_if< typename is_mutable_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
154 std::size_t>::type
|
Chris@16
|
155 simplify(polygon_set_type& polygon_set, typename coordinate_traits<
|
Chris@16
|
156 typename polygon_set_traits<polygon_set_type>::coordinate_type
|
Chris@16
|
157 >::coordinate_distance threshold) {
|
Chris@16
|
158 typedef typename polygon_set_traits<polygon_set_type>::coordinate_type Unit;
|
Chris@16
|
159 typedef polygon_with_holes_data<Unit> p_type;
|
Chris@16
|
160 std::vector<p_type> polys;
|
Chris@16
|
161 assign(polys, polygon_set);
|
Chris@16
|
162 std::size_t retval = 0;
|
Chris@16
|
163 for(std::size_t i = 0; i < polys.size(); ++i) {
|
Chris@16
|
164 retval += detail::simplify_detail::simplify(polys[i].self_.coords_,
|
Chris@16
|
165 polys[i].self_.coords_, threshold);
|
Chris@16
|
166 for(typename std::list<polygon_data<Unit> >::iterator itrh =
|
Chris@16
|
167 polys[i].holes_.begin(); itrh != (polys[i].holes_.end()); ++itrh) {
|
Chris@16
|
168 retval += detail::simplify_detail::simplify((*itrh).coords_,
|
Chris@16
|
169 (*itrh).coords_, threshold);
|
Chris@16
|
170 }
|
Chris@16
|
171 }
|
Chris@16
|
172 assign(polygon_set, polys);
|
Chris@16
|
173 return retval;
|
Chris@16
|
174 }
|
Chris@16
|
175
|
Chris@16
|
176 template <typename polygon_set_type, typename coord_type>
|
Chris@16
|
177 typename enable_if< typename is_mutable_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
178 polygon_set_type>::type &
|
Chris@16
|
179 resize(polygon_set_type& polygon_set, coord_type resizing, bool corner_fill_arcs = false, int num_circle_segments = 0) {
|
Chris@16
|
180 typedef typename polygon_set_traits<polygon_set_type>::coordinate_type Unit;
|
Chris@16
|
181 clean(polygon_set);
|
Chris@16
|
182 polygon_set_data<Unit> ps;
|
Chris@16
|
183 assign(ps, polygon_set);
|
Chris@16
|
184 ps.resize(resizing, corner_fill_arcs,num_circle_segments);
|
Chris@16
|
185 assign(polygon_set, ps);
|
Chris@16
|
186 return polygon_set;
|
Chris@16
|
187 }
|
Chris@16
|
188
|
Chris@16
|
189 template <typename polygon_set_type>
|
Chris@16
|
190 typename enable_if< typename is_mutable_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
191 polygon_set_type>::type &
|
Chris@16
|
192 bloat(polygon_set_type& polygon_set,
|
Chris@16
|
193 typename coordinate_traits<typename polygon_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type bloating) {
|
Chris@16
|
194 return resize(polygon_set, bloating);
|
Chris@16
|
195 }
|
Chris@16
|
196
|
Chris@16
|
197 template <typename polygon_set_type>
|
Chris@16
|
198 typename enable_if< typename is_mutable_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
199 polygon_set_type>::type &
|
Chris@16
|
200 shrink(polygon_set_type& polygon_set,
|
Chris@16
|
201 typename coordinate_traits<typename polygon_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type shrinking) {
|
Chris@16
|
202 return resize(polygon_set, -(typename polygon_set_traits<polygon_set_type>::coordinate_type)shrinking);
|
Chris@16
|
203 }
|
Chris@16
|
204
|
Chris@16
|
205 //interact
|
Chris@16
|
206 template <typename polygon_set_type_1, typename polygon_set_type_2>
|
Chris@16
|
207 typename enable_if< typename gtl_and_3 <
|
Chris@16
|
208 typename is_any_polygon_set_type<polygon_set_type_1>::type,
|
Chris@16
|
209 typename is_any_polygon_set_type<polygon_set_type_2>::type,
|
Chris@16
|
210 typename is_either_polygon_set_type<polygon_set_type_1, polygon_set_type_2>::type>::type,
|
Chris@16
|
211 polygon_set_type_1>::type&
|
Chris@16
|
212 interact(polygon_set_type_1& polygon_set_1, const polygon_set_type_2& polygon_set_2) {
|
Chris@16
|
213 polygon_set_data<typename polygon_set_traits<polygon_set_type_1>::coordinate_type> ps1;
|
Chris@16
|
214 assign(ps1, polygon_set_1);
|
Chris@16
|
215 polygon_set_data<typename polygon_set_traits<polygon_set_type_2>::coordinate_type> ps2;
|
Chris@16
|
216 assign(ps2, polygon_set_2);
|
Chris@16
|
217 ps1.interact(ps2);
|
Chris@16
|
218 assign(polygon_set_1, ps1);
|
Chris@16
|
219 return polygon_set_1;
|
Chris@16
|
220 }
|
Chris@16
|
221
|
Chris@16
|
222 template <typename polygon_set_type>
|
Chris@16
|
223 typename enable_if< typename is_mutable_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
224 polygon_set_type>::type &
|
Chris@16
|
225 scale_up(polygon_set_type& polygon_set,
|
Chris@16
|
226 typename coordinate_traits<typename polygon_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type factor) {
|
Chris@16
|
227 typedef typename polygon_set_traits<polygon_set_type>::coordinate_type Unit;
|
Chris@16
|
228 clean(polygon_set);
|
Chris@16
|
229 polygon_set_data<Unit> ps;
|
Chris@16
|
230 assign(ps, polygon_set);
|
Chris@16
|
231 ps.scale_up(factor);
|
Chris@16
|
232 assign(polygon_set, ps);
|
Chris@16
|
233 return polygon_set;
|
Chris@16
|
234 }
|
Chris@16
|
235
|
Chris@16
|
236 template <typename polygon_set_type>
|
Chris@16
|
237 typename enable_if< typename is_mutable_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
238 polygon_set_type>::type &
|
Chris@16
|
239 scale_down(polygon_set_type& polygon_set,
|
Chris@16
|
240 typename coordinate_traits<typename polygon_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type factor) {
|
Chris@16
|
241 typedef typename polygon_set_traits<polygon_set_type>::coordinate_type Unit;
|
Chris@16
|
242 clean(polygon_set);
|
Chris@16
|
243 polygon_set_data<Unit> ps;
|
Chris@16
|
244 assign(ps, polygon_set);
|
Chris@16
|
245 ps.scale_down(factor);
|
Chris@16
|
246 assign(polygon_set, ps);
|
Chris@16
|
247 return polygon_set;
|
Chris@16
|
248 }
|
Chris@16
|
249
|
Chris@16
|
250 //transform
|
Chris@16
|
251 template <typename polygon_set_type, typename transformation_type>
|
Chris@16
|
252 typename enable_if< typename is_mutable_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
253 polygon_set_type>::type &
|
Chris@16
|
254 transform(polygon_set_type& polygon_set,
|
Chris@16
|
255 const transformation_type& transformation) {
|
Chris@16
|
256 typedef typename polygon_set_traits<polygon_set_type>::coordinate_type Unit;
|
Chris@16
|
257 clean(polygon_set);
|
Chris@16
|
258 polygon_set_data<Unit> ps;
|
Chris@16
|
259 assign(ps, polygon_set);
|
Chris@16
|
260 ps.transform(transformation);
|
Chris@16
|
261 assign(polygon_set, ps);
|
Chris@16
|
262 return polygon_set;
|
Chris@16
|
263 }
|
Chris@16
|
264
|
Chris@16
|
265 //keep
|
Chris@16
|
266 template <typename polygon_set_type>
|
Chris@16
|
267 typename enable_if< typename is_mutable_polygon_set_type<polygon_set_type>::type,
|
Chris@16
|
268 polygon_set_type>::type &
|
Chris@16
|
269 keep(polygon_set_type& polygon_set,
|
Chris@16
|
270 typename coordinate_traits<typename polygon_set_traits<polygon_set_type>::coordinate_type>::area_type min_area,
|
Chris@16
|
271 typename coordinate_traits<typename polygon_set_traits<polygon_set_type>::coordinate_type>::area_type max_area,
|
Chris@16
|
272 typename coordinate_traits<typename polygon_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type min_width,
|
Chris@16
|
273 typename coordinate_traits<typename polygon_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type max_width,
|
Chris@16
|
274 typename coordinate_traits<typename polygon_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type min_height,
|
Chris@16
|
275 typename coordinate_traits<typename polygon_set_traits<polygon_set_type>::coordinate_type>::unsigned_area_type max_height) {
|
Chris@16
|
276 typedef typename polygon_set_traits<polygon_set_type>::coordinate_type Unit;
|
Chris@16
|
277 typedef typename coordinate_traits<Unit>::unsigned_area_type uat;
|
Chris@16
|
278 std::list<polygon_with_holes_data<Unit> > polys;
|
Chris@16
|
279 assign(polys, polygon_set);
|
Chris@16
|
280 typename std::list<polygon_with_holes_data<Unit> >::iterator itr_nxt;
|
Chris@16
|
281 for(typename std::list<polygon_with_holes_data<Unit> >::iterator itr = polys.begin(); itr != polys.end(); itr = itr_nxt){
|
Chris@16
|
282 itr_nxt = itr;
|
Chris@16
|
283 ++itr_nxt;
|
Chris@16
|
284 rectangle_data<Unit> bbox;
|
Chris@16
|
285 extents(bbox, *itr);
|
Chris@16
|
286 uat pwidth = delta(bbox, HORIZONTAL);
|
Chris@16
|
287 if(pwidth > min_width && pwidth <= max_width){
|
Chris@16
|
288 uat pheight = delta(bbox, VERTICAL);
|
Chris@16
|
289 if(pheight > min_height && pheight <= max_height){
|
Chris@16
|
290 typename coordinate_traits<Unit>::area_type parea = area(*itr);
|
Chris@16
|
291 if(parea <= max_area && parea >= min_area) {
|
Chris@16
|
292 continue;
|
Chris@16
|
293 }
|
Chris@16
|
294 }
|
Chris@16
|
295 }
|
Chris@16
|
296 polys.erase(itr);
|
Chris@16
|
297 }
|
Chris@16
|
298 assign(polygon_set, polys);
|
Chris@16
|
299 return polygon_set;
|
Chris@16
|
300 }
|
Chris@16
|
301
|
Chris@16
|
302 namespace operators {
|
Chris@16
|
303
|
Chris@16
|
304 struct yes_ps_ob : gtl_yes {};
|
Chris@16
|
305
|
Chris@16
|
306 template <typename geometry_type_1, typename geometry_type_2>
|
Chris@16
|
307 typename enable_if< typename gtl_and_4 < yes_ps_ob, typename is_any_polygon_set_type<geometry_type_1>::type,
|
Chris@16
|
308 typename is_any_polygon_set_type<geometry_type_2>::type,
|
Chris@16
|
309 typename is_either_polygon_set_type<geometry_type_1, geometry_type_2>::type>::type,
|
Chris@16
|
310 polygon_set_view<geometry_type_1, geometry_type_2, 0> >::type
|
Chris@16
|
311 operator|(const geometry_type_1& lvalue, const geometry_type_2& rvalue) {
|
Chris@16
|
312 return polygon_set_view<geometry_type_1, geometry_type_2, 0>
|
Chris@16
|
313 (lvalue, rvalue);
|
Chris@16
|
314 }
|
Chris@16
|
315
|
Chris@16
|
316 struct yes_ps_op : gtl_yes {};
|
Chris@16
|
317
|
Chris@16
|
318 template <typename geometry_type_1, typename geometry_type_2>
|
Chris@16
|
319 typename enable_if< typename gtl_and_4 < yes_ps_op,
|
Chris@16
|
320 typename gtl_if<typename is_any_polygon_set_type<geometry_type_1>::type>::type,
|
Chris@16
|
321 typename gtl_if<typename is_any_polygon_set_type<geometry_type_2>::type>::type,
|
Chris@16
|
322 typename gtl_if<typename is_either_polygon_set_type<geometry_type_1, geometry_type_2>::type>::type>
|
Chris@16
|
323 ::type, polygon_set_view<geometry_type_1, geometry_type_2, 0> >::type
|
Chris@16
|
324 operator+(const geometry_type_1& lvalue, const geometry_type_2& rvalue) {
|
Chris@16
|
325 return polygon_set_view<geometry_type_1, geometry_type_2, 0>
|
Chris@16
|
326 (lvalue, rvalue);
|
Chris@16
|
327 }
|
Chris@16
|
328
|
Chris@16
|
329 struct yes_ps_os : gtl_yes {};
|
Chris@16
|
330
|
Chris@16
|
331 template <typename geometry_type_1, typename geometry_type_2>
|
Chris@16
|
332 typename enable_if< typename gtl_and_4 < yes_ps_os,
|
Chris@16
|
333 typename is_any_polygon_set_type<geometry_type_1>::type,
|
Chris@16
|
334 typename is_any_polygon_set_type<geometry_type_2>::type,
|
Chris@16
|
335 typename is_either_polygon_set_type<geometry_type_1, geometry_type_2>::type>::type,
|
Chris@16
|
336 polygon_set_view<geometry_type_1, geometry_type_2, 1> >::type
|
Chris@16
|
337 operator*(const geometry_type_1& lvalue, const geometry_type_2& rvalue) {
|
Chris@16
|
338 return polygon_set_view<geometry_type_1, geometry_type_2, 1>
|
Chris@16
|
339 (lvalue, rvalue);
|
Chris@16
|
340 }
|
Chris@16
|
341
|
Chris@16
|
342 struct yes_ps_oa : gtl_yes {};
|
Chris@16
|
343
|
Chris@16
|
344 template <typename geometry_type_1, typename geometry_type_2>
|
Chris@16
|
345 typename enable_if< typename gtl_and_4 < yes_ps_oa,
|
Chris@16
|
346 typename is_any_polygon_set_type<geometry_type_1>::type,
|
Chris@16
|
347 typename is_any_polygon_set_type<geometry_type_2>::type,
|
Chris@16
|
348 typename is_either_polygon_set_type<geometry_type_1, geometry_type_2>::type>::type,
|
Chris@16
|
349 polygon_set_view<geometry_type_1, geometry_type_2, 1> >::type
|
Chris@16
|
350 operator&(const geometry_type_1& lvalue, const geometry_type_2& rvalue) {
|
Chris@16
|
351 return polygon_set_view<geometry_type_1, geometry_type_2, 1>
|
Chris@16
|
352 (lvalue, rvalue);
|
Chris@16
|
353 }
|
Chris@16
|
354
|
Chris@16
|
355 struct yes_ps_ox : gtl_yes {};
|
Chris@16
|
356
|
Chris@16
|
357 template <typename geometry_type_1, typename geometry_type_2>
|
Chris@16
|
358 typename enable_if< typename gtl_and_4 < yes_ps_ox,
|
Chris@16
|
359 typename is_any_polygon_set_type<geometry_type_1>::type,
|
Chris@16
|
360 typename is_any_polygon_set_type<geometry_type_2>::type,
|
Chris@16
|
361 typename is_either_polygon_set_type<geometry_type_1, geometry_type_2>::type>::type,
|
Chris@16
|
362 polygon_set_view<geometry_type_1, geometry_type_2, 2> >::type
|
Chris@16
|
363 operator^(const geometry_type_1& lvalue, const geometry_type_2& rvalue) {
|
Chris@16
|
364 return polygon_set_view<geometry_type_1, geometry_type_2, 2>
|
Chris@16
|
365 (lvalue, rvalue);
|
Chris@16
|
366 }
|
Chris@16
|
367
|
Chris@16
|
368 struct yes_ps_om : gtl_yes {};
|
Chris@16
|
369
|
Chris@16
|
370 template <typename geometry_type_1, typename geometry_type_2>
|
Chris@16
|
371 typename enable_if< typename gtl_and_4 < yes_ps_om,
|
Chris@16
|
372 typename gtl_if<typename is_any_polygon_set_type<geometry_type_1>::type>::type,
|
Chris@16
|
373 typename gtl_if<typename is_any_polygon_set_type<geometry_type_2>::type>::type,
|
Chris@16
|
374 typename gtl_if<typename is_either_polygon_set_type<geometry_type_1, geometry_type_2>::type>::type>
|
Chris@16
|
375 ::type, polygon_set_view<geometry_type_1, geometry_type_2, 3> >::type
|
Chris@16
|
376 operator-(const geometry_type_1& lvalue, const geometry_type_2& rvalue) {
|
Chris@16
|
377 return polygon_set_view<geometry_type_1, geometry_type_2, 3>
|
Chris@16
|
378 (lvalue, rvalue);
|
Chris@16
|
379 }
|
Chris@16
|
380
|
Chris@16
|
381 struct yes_ps_ope : gtl_yes {};
|
Chris@16
|
382
|
Chris@16
|
383 template <typename geometry_type_1, typename geometry_type_2>
|
Chris@16
|
384 typename enable_if< typename gtl_and_4< yes_ps_ope, gtl_yes, typename is_mutable_polygon_set_type<geometry_type_1>::type,
|
Chris@16
|
385 typename is_any_polygon_set_type<geometry_type_2>::type>::type,
|
Chris@16
|
386 geometry_type_1>::type &
|
Chris@16
|
387 operator+=(geometry_type_1& lvalue, const geometry_type_2& rvalue) {
|
Chris@16
|
388 return self_assignment_boolean_op<geometry_type_1, geometry_type_2, 0>(lvalue, rvalue);
|
Chris@16
|
389 }
|
Chris@16
|
390
|
Chris@16
|
391 struct yes_ps_obe : gtl_yes {};
|
Chris@16
|
392
|
Chris@16
|
393 template <typename geometry_type_1, typename geometry_type_2>
|
Chris@16
|
394 typename enable_if< typename gtl_and_3< yes_ps_obe, typename is_mutable_polygon_set_type<geometry_type_1>::type,
|
Chris@16
|
395 typename is_any_polygon_set_type<geometry_type_2>::type>::type,
|
Chris@16
|
396 geometry_type_1>::type &
|
Chris@16
|
397 operator|=(geometry_type_1& lvalue, const geometry_type_2& rvalue) {
|
Chris@16
|
398 return self_assignment_boolean_op<geometry_type_1, geometry_type_2, 0>(lvalue, rvalue);
|
Chris@16
|
399 }
|
Chris@16
|
400
|
Chris@16
|
401 struct yes_ps_ose : gtl_yes {};
|
Chris@16
|
402
|
Chris@16
|
403 template <typename geometry_type_1, typename geometry_type_2>
|
Chris@16
|
404 typename enable_if< typename gtl_and_3< yes_ps_ose, typename is_mutable_polygon_set_type<geometry_type_1>::type,
|
Chris@16
|
405 typename is_any_polygon_set_type<geometry_type_2>::type>::type,
|
Chris@16
|
406 geometry_type_1>::type &
|
Chris@16
|
407 operator*=(geometry_type_1& lvalue, const geometry_type_2& rvalue) {
|
Chris@16
|
408 return self_assignment_boolean_op<geometry_type_1, geometry_type_2, 1>(lvalue, rvalue);
|
Chris@16
|
409 }
|
Chris@16
|
410
|
Chris@16
|
411 struct yes_ps_oae : gtl_yes {};
|
Chris@16
|
412
|
Chris@16
|
413 template <typename geometry_type_1, typename geometry_type_2>
|
Chris@16
|
414 typename enable_if<
|
Chris@16
|
415 typename gtl_and_3< yes_ps_oae, typename is_mutable_polygon_set_type<geometry_type_1>::type,
|
Chris@16
|
416 typename is_any_polygon_set_type<geometry_type_2>::type>::type,
|
Chris@16
|
417 geometry_type_1>::type &
|
Chris@16
|
418 operator&=(geometry_type_1& lvalue, const geometry_type_2& rvalue) {
|
Chris@16
|
419 return self_assignment_boolean_op<geometry_type_1, geometry_type_2, 1>(lvalue, rvalue);
|
Chris@16
|
420 }
|
Chris@16
|
421
|
Chris@16
|
422 struct yes_ps_oxe : gtl_yes {};
|
Chris@16
|
423
|
Chris@16
|
424 template <typename geometry_type_1, typename geometry_type_2>
|
Chris@16
|
425 typename enable_if< typename gtl_and_3< yes_ps_oxe, typename is_mutable_polygon_set_type<geometry_type_1>::type,
|
Chris@16
|
426 typename is_any_polygon_set_type<geometry_type_2>::type>::type,
|
Chris@16
|
427 geometry_type_1>::type &
|
Chris@16
|
428 operator^=(geometry_type_1& lvalue, const geometry_type_2& rvalue) {
|
Chris@16
|
429 return self_assignment_boolean_op<geometry_type_1, geometry_type_2, 2>(lvalue, rvalue);
|
Chris@16
|
430 }
|
Chris@16
|
431
|
Chris@16
|
432 struct yes_ps_ome : gtl_yes {};
|
Chris@16
|
433
|
Chris@16
|
434 template <typename geometry_type_1, typename geometry_type_2>
|
Chris@16
|
435 typename enable_if<
|
Chris@16
|
436 typename gtl_and_3< yes_ps_ome, typename is_mutable_polygon_set_type<geometry_type_1>::type,
|
Chris@16
|
437 typename is_any_polygon_set_type<geometry_type_2>::type>::type,
|
Chris@16
|
438 geometry_type_1>::type &
|
Chris@16
|
439 operator-=(geometry_type_1& lvalue, const geometry_type_2& rvalue) {
|
Chris@16
|
440 return self_assignment_boolean_op<geometry_type_1, geometry_type_2, 3>(lvalue, rvalue);
|
Chris@16
|
441 }
|
Chris@16
|
442
|
Chris@16
|
443 // TODO: Dafna, test these four resizing operators
|
Chris@16
|
444 struct y_ps_rpe : gtl_yes {};
|
Chris@16
|
445
|
Chris@16
|
446 template <typename geometry_type_1, typename coordinate_type_1>
|
Chris@16
|
447 typename enable_if< typename gtl_and_3< y_ps_rpe, typename is_mutable_polygon_set_type<geometry_type_1>::type,
|
Chris@16
|
448 typename gtl_same_type<typename geometry_concept<coordinate_type_1>::type,
|
Chris@16
|
449 coordinate_concept>::type>::type,
|
Chris@16
|
450 geometry_type_1>::type &
|
Chris@16
|
451 operator+=(geometry_type_1& lvalue, coordinate_type_1 rvalue) {
|
Chris@16
|
452 return resize(lvalue, rvalue);
|
Chris@16
|
453 }
|
Chris@16
|
454
|
Chris@16
|
455 struct y_ps_rme : gtl_yes {};
|
Chris@16
|
456
|
Chris@16
|
457 template <typename geometry_type_1, typename coordinate_type_1>
|
Chris@16
|
458 typename enable_if< typename gtl_and_3<y_ps_rme, typename gtl_if<typename is_mutable_polygon_set_type<geometry_type_1>::type>::type,
|
Chris@16
|
459 typename gtl_same_type<typename geometry_concept<coordinate_type_1>::type,
|
Chris@16
|
460 coordinate_concept>::type>::type,
|
Chris@16
|
461 geometry_type_1>::type &
|
Chris@16
|
462 operator-=(geometry_type_1& lvalue, coordinate_type_1 rvalue) {
|
Chris@16
|
463 return resize(lvalue, -rvalue);
|
Chris@16
|
464 }
|
Chris@16
|
465
|
Chris@16
|
466 struct y_ps_rp : gtl_yes {};
|
Chris@16
|
467
|
Chris@16
|
468 template <typename geometry_type_1, typename coordinate_type_1>
|
Chris@16
|
469 typename enable_if< typename gtl_and_3<y_ps_rp, typename gtl_if<typename is_mutable_polygon_set_type<geometry_type_1>::type>::type,
|
Chris@16
|
470 typename gtl_same_type<typename geometry_concept<coordinate_type_1>::type,
|
Chris@16
|
471 coordinate_concept>::type>
|
Chris@16
|
472 ::type, geometry_type_1>::type
|
Chris@16
|
473 operator+(const geometry_type_1& lvalue, coordinate_type_1 rvalue) {
|
Chris@16
|
474 geometry_type_1 retval(lvalue);
|
Chris@16
|
475 retval += rvalue;
|
Chris@16
|
476 return retval;
|
Chris@16
|
477 }
|
Chris@16
|
478
|
Chris@16
|
479 struct y_ps_rm : gtl_yes {};
|
Chris@16
|
480
|
Chris@16
|
481 template <typename geometry_type_1, typename coordinate_type_1>
|
Chris@16
|
482 typename enable_if< typename gtl_and_3<y_ps_rm, typename gtl_if<typename is_mutable_polygon_set_type<geometry_type_1>::type>::type,
|
Chris@16
|
483 typename gtl_same_type<typename geometry_concept<coordinate_type_1>::type,
|
Chris@16
|
484 coordinate_concept>::type>
|
Chris@16
|
485 ::type, geometry_type_1>::type
|
Chris@16
|
486 operator-(const geometry_type_1& lvalue, coordinate_type_1 rvalue) {
|
Chris@16
|
487 geometry_type_1 retval(lvalue);
|
Chris@16
|
488 retval -= rvalue;
|
Chris@16
|
489 return retval;
|
Chris@16
|
490 }
|
Chris@16
|
491
|
Chris@16
|
492
|
Chris@16
|
493 } //end operators namespace
|
Chris@16
|
494
|
Chris@16
|
495 template <typename T>
|
Chris@16
|
496 struct view_of<polygon_45_set_concept, T> {
|
Chris@16
|
497 typedef typename get_coordinate_type<T, typename geometry_concept<T>::type >::type coordinate_type;
|
Chris@16
|
498 T* tp;
|
Chris@16
|
499 std::vector<polygon_45_with_holes_data<coordinate_type> > polys;
|
Chris@16
|
500 view_of(const T& obj) : tp(), polys() {
|
Chris@16
|
501 std::vector<polygon_with_holes_data<coordinate_type> > gpolys;
|
Chris@16
|
502 assign(gpolys, obj);
|
Chris@16
|
503 for(typename std::vector<polygon_with_holes_data<coordinate_type> >::iterator itr = gpolys.begin();
|
Chris@16
|
504 itr != gpolys.end(); ++itr) {
|
Chris@16
|
505 polys.push_back(polygon_45_with_holes_data<coordinate_type>());
|
Chris@16
|
506 assign(polys.back(), view_as<polygon_45_with_holes_concept>(*itr));
|
Chris@16
|
507 }
|
Chris@16
|
508 }
|
Chris@16
|
509 view_of(T& obj) : tp(&obj), polys() {
|
Chris@16
|
510 std::vector<polygon_with_holes_data<coordinate_type> > gpolys;
|
Chris@16
|
511 assign(gpolys, obj);
|
Chris@16
|
512 for(typename std::vector<polygon_with_holes_data<coordinate_type> >::iterator itr = gpolys.begin();
|
Chris@16
|
513 itr != gpolys.end(); ++itr) {
|
Chris@16
|
514 polys.push_back(polygon_45_with_holes_data<coordinate_type>());
|
Chris@16
|
515 assign(polys.back(), view_as<polygon_45_with_holes_concept>(*itr));
|
Chris@16
|
516 }
|
Chris@16
|
517 }
|
Chris@16
|
518
|
Chris@16
|
519 typedef typename std::vector<polygon_45_with_holes_data<coordinate_type> >::const_iterator iterator_type;
|
Chris@16
|
520 typedef view_of operator_arg_type;
|
Chris@16
|
521
|
Chris@16
|
522 inline iterator_type begin() const {
|
Chris@16
|
523 return polys.begin();
|
Chris@16
|
524 }
|
Chris@16
|
525
|
Chris@16
|
526 inline iterator_type end() const {
|
Chris@16
|
527 return polys.end();
|
Chris@16
|
528 }
|
Chris@16
|
529
|
Chris@16
|
530 inline orientation_2d orient() const { return HORIZONTAL; }
|
Chris@16
|
531
|
Chris@16
|
532 inline bool clean() const { return false; }
|
Chris@16
|
533
|
Chris@16
|
534 inline bool sorted() const { return false; }
|
Chris@16
|
535
|
Chris@16
|
536 inline T& get() { return *tp; }
|
Chris@16
|
537 };
|
Chris@16
|
538
|
Chris@16
|
539 template <typename T>
|
Chris@16
|
540 struct polygon_45_set_traits<view_of<polygon_45_set_concept, T> > {
|
Chris@16
|
541 typedef typename view_of<polygon_45_set_concept, T>::coordinate_type coordinate_type;
|
Chris@16
|
542 typedef typename view_of<polygon_45_set_concept, T>::iterator_type iterator_type;
|
Chris@16
|
543 typedef view_of<polygon_45_set_concept, T> operator_arg_type;
|
Chris@16
|
544
|
Chris@16
|
545 static inline iterator_type begin(const view_of<polygon_45_set_concept, T>& polygon_set) {
|
Chris@16
|
546 return polygon_set.begin();
|
Chris@16
|
547 }
|
Chris@16
|
548
|
Chris@16
|
549 static inline iterator_type end(const view_of<polygon_45_set_concept, T>& polygon_set) {
|
Chris@16
|
550 return polygon_set.end();
|
Chris@16
|
551 }
|
Chris@16
|
552
|
Chris@16
|
553 static inline orientation_2d orient(const view_of<polygon_45_set_concept, T>& polygon_set) {
|
Chris@16
|
554 return polygon_set.orient(); }
|
Chris@16
|
555
|
Chris@16
|
556 static inline bool clean(const view_of<polygon_45_set_concept, T>& polygon_set) {
|
Chris@16
|
557 return polygon_set.clean(); }
|
Chris@16
|
558
|
Chris@16
|
559 static inline bool sorted(const view_of<polygon_45_set_concept, T>& polygon_set) {
|
Chris@16
|
560 return polygon_set.sorted(); }
|
Chris@16
|
561
|
Chris@16
|
562 };
|
Chris@16
|
563
|
Chris@16
|
564 template <typename T>
|
Chris@16
|
565 struct geometry_concept<view_of<polygon_45_set_concept, T> > {
|
Chris@16
|
566 typedef polygon_45_set_concept type;
|
Chris@16
|
567 };
|
Chris@16
|
568
|
Chris@16
|
569 template <typename T>
|
Chris@16
|
570 struct get_coordinate_type<view_of<polygon_45_set_concept, T>, polygon_45_set_concept> {
|
Chris@16
|
571 typedef typename view_of<polygon_45_set_concept, T>::coordinate_type type;
|
Chris@16
|
572 };
|
Chris@16
|
573 template <typename T>
|
Chris@16
|
574 struct get_iterator_type_2<view_of<polygon_45_set_concept, T>, polygon_45_set_concept> {
|
Chris@16
|
575 typedef typename view_of<polygon_45_set_concept, T>::iterator_type type;
|
Chris@16
|
576 static type begin(const view_of<polygon_45_set_concept, T>& t) { return t.begin(); }
|
Chris@16
|
577 static type end(const view_of<polygon_45_set_concept, T>& t) { return t.end(); }
|
Chris@16
|
578 };
|
Chris@16
|
579 }
|
Chris@16
|
580 }
|
Chris@16
|
581 #endif
|