comparison DEPENDENCIES/generic/include/boost/polygon/polygon_traits.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
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_TRAITS_HPP
9 #define BOOST_POLYGON_POLYGON_TRAITS_HPP
10 namespace boost { namespace polygon{
11
12 template <typename T, typename enable = gtl_yes>
13 struct polygon_90_traits {
14 typedef typename T::coordinate_type coordinate_type;
15 typedef typename T::compact_iterator_type compact_iterator_type;
16
17 // Get the begin iterator
18 static inline compact_iterator_type begin_compact(const T& t) {
19 return t.begin_compact();
20 }
21
22 // Get the end iterator
23 static inline compact_iterator_type end_compact(const T& t) {
24 return t.end_compact();
25 }
26
27 // Get the number of sides of the polygon
28 static inline std::size_t size(const T& t) {
29 return t.size();
30 }
31
32 // Get the winding direction of the polygon
33 static inline winding_direction winding(const T&) {
34 return unknown_winding;
35 }
36 };
37
38 template <typename T>
39 struct polygon_traits_general {
40 typedef typename T::coordinate_type coordinate_type;
41 typedef typename T::iterator_type iterator_type;
42 typedef typename T::point_type point_type;
43
44 // Get the begin iterator
45 static inline iterator_type begin_points(const T& t) {
46 return t.begin();
47 }
48
49 // Get the end iterator
50 static inline iterator_type end_points(const T& t) {
51 return t.end();
52 }
53
54 // Get the number of sides of the polygon
55 static inline std::size_t size(const T& t) {
56 return t.size();
57 }
58
59 // Get the winding direction of the polygon
60 static inline winding_direction winding(const T&) {
61 return unknown_winding;
62 }
63 };
64
65 template <typename T>
66 struct polygon_traits_90 {
67 typedef typename polygon_90_traits<T>::coordinate_type coordinate_type;
68 typedef iterator_compact_to_points<typename polygon_90_traits<T>::compact_iterator_type, point_data<coordinate_type> > iterator_type;
69 typedef point_data<coordinate_type> point_type;
70
71 // Get the begin iterator
72 static inline iterator_type begin_points(const T& t) {
73 return iterator_type(polygon_90_traits<T>::begin_compact(t),
74 polygon_90_traits<T>::end_compact(t));
75 }
76
77 // Get the end iterator
78 static inline iterator_type end_points(const T& t) {
79 return iterator_type(polygon_90_traits<T>::end_compact(t),
80 polygon_90_traits<T>::end_compact(t));
81 }
82
83 // Get the number of sides of the polygon
84 static inline std::size_t size(const T& t) {
85 return polygon_90_traits<T>::size(t);
86 }
87
88 // Get the winding direction of the polygon
89 static inline winding_direction winding(const T& t) {
90 return polygon_90_traits<T>::winding(t);
91 }
92 };
93
94 #ifndef BOOST_VERY_LITTLE_SFINAE
95
96 template <typename T, typename enable = gtl_yes>
97 struct polygon_traits {};
98
99 template <typename T>
100 struct polygon_traits<T,
101 typename gtl_or_4<
102 typename gtl_same_type<typename geometry_concept<T>::type, polygon_concept>::type,
103 typename gtl_same_type<typename geometry_concept<T>::type, polygon_45_concept>::type,
104 typename gtl_same_type<typename geometry_concept<T>::type, polygon_with_holes_concept>::type,
105 typename gtl_same_type<typename geometry_concept<T>::type, polygon_45_with_holes_concept>::type
106 >::type> : public polygon_traits_general<T> {};
107
108 template <typename T>
109 struct polygon_traits< T,
110 typename gtl_or<
111 typename gtl_same_type<typename geometry_concept<T>::type, polygon_90_concept>::type,
112 typename gtl_same_type<typename geometry_concept<T>::type, polygon_90_with_holes_concept>::type
113 >::type > : public polygon_traits_90<T> {};
114
115 #else
116
117 template <typename T, typename T_IF, typename T_ELSE>
118 struct gtl_ifelse {};
119 template <typename T_IF, typename T_ELSE>
120 struct gtl_ifelse<gtl_no, T_IF, T_ELSE> {
121 typedef T_ELSE type;
122 };
123 template <typename T_IF, typename T_ELSE>
124 struct gtl_ifelse<gtl_yes, T_IF, T_ELSE> {
125 typedef T_IF type;
126 };
127
128 template <typename T, typename enable = gtl_yes>
129 struct polygon_traits {};
130
131 template <typename T>
132 struct polygon_traits<T, typename gtl_or<typename gtl_or_4<
133 typename gtl_same_type<typename geometry_concept<T>::type, polygon_concept>::type,
134 typename gtl_same_type<typename geometry_concept<T>::type, polygon_45_concept>::type,
135 typename gtl_same_type<typename geometry_concept<T>::type, polygon_with_holes_concept>::type,
136 typename gtl_same_type<typename geometry_concept<T>::type, polygon_45_with_holes_concept>::type
137 >::type, typename gtl_or<
138 typename gtl_same_type<typename geometry_concept<T>::type, polygon_90_concept>::type,
139 typename gtl_same_type<typename geometry_concept<T>::type, polygon_90_with_holes_concept>::type
140 >::type>::type > : public gtl_ifelse<typename gtl_or<
141 typename gtl_same_type<typename geometry_concept<T>::type, polygon_90_concept>::type,
142 typename gtl_same_type<typename geometry_concept<T>::type, polygon_90_with_holes_concept>::type >::type,
143 polygon_traits_90<T>,
144 polygon_traits_general<T> >::type {
145 };
146
147 #endif
148
149 template <typename T, typename enable = void>
150 struct polygon_with_holes_traits {
151 typedef typename T::iterator_holes_type iterator_holes_type;
152 typedef typename T::hole_type hole_type;
153
154 // Get the begin iterator
155 static inline iterator_holes_type begin_holes(const T& t) {
156 return t.begin_holes();
157 }
158
159 // Get the end iterator
160 static inline iterator_holes_type end_holes(const T& t) {
161 return t.end_holes();
162 }
163
164 // Get the number of holes
165 static inline std::size_t size_holes(const T& t) {
166 return t.size_holes();
167 }
168 };
169
170 template <typename T, typename enable = void>
171 struct polygon_90_mutable_traits {
172
173 // Set the data of a polygon with the unique coordinates in an iterator, starting with an x
174 template <typename iT>
175 static inline T& set_compact(T& t, iT input_begin, iT input_end) {
176 t.set_compact(input_begin, input_end);
177 return t;
178 }
179
180 };
181
182 template <typename T>
183 struct polygon_90_mutable_traits<T, typename gtl_same_type<polygon_concept, typename geometry_concept<T>::type>::type> {
184 // Set the data of a polygon with the unique coordinates in an iterator, starting with an x
185 template <typename iT>
186 static inline T& set_compact(T& t, iT input_begin, iT input_end) {
187 typedef iterator_points_to_compact<iT, typename polygon_traits<T>::point_type> iTp;
188 t.set_points(iTp(polygon_traits<T>::begin_points(t)), iTp(polygon_traits<T>::end_points(t)));
189 return t;
190 }
191 };
192
193 template <typename T, typename enable = void>
194 struct polygon_mutable_traits {
195
196 // Set the data of a polygon with the unique coordinates in an iterator, starting with an x
197 template <typename iT>
198 static inline T& set_points(T& t, iT input_begin, iT input_end) {
199 t.set(input_begin, input_end);
200 return t;
201 }
202
203 };
204
205 template <typename T, typename enable = void>
206 struct polygon_with_holes_mutable_traits {
207
208 // Set the data of a polygon with the unique coordinates in an iterator, starting with an x
209 template <typename iT>
210 static inline T& set_holes(T& t, iT inputBegin, iT inputEnd) {
211 t.set_holes(inputBegin, inputEnd);
212 return t;
213 }
214
215 };
216 }
217 }
218 #include "isotropy.hpp"
219
220 //point
221 #include "point_data.hpp"
222 #include "point_traits.hpp"
223 #include "point_concept.hpp"
224
225 //interval
226 #include "interval_data.hpp"
227 #include "interval_traits.hpp"
228 #include "interval_concept.hpp"
229
230 //rectangle
231 #include "rectangle_data.hpp"
232 #include "rectangle_traits.hpp"
233 #include "rectangle_concept.hpp"
234
235 //algorithms needed by polygon types
236 #include "detail/iterator_points_to_compact.hpp"
237 #include "detail/iterator_compact_to_points.hpp"
238
239 //polygons
240 #include "polygon_45_data.hpp"
241 #include "polygon_data.hpp"
242 #include "polygon_90_data.hpp"
243 #include "polygon_90_with_holes_data.hpp"
244 #include "polygon_45_with_holes_data.hpp"
245 #include "polygon_with_holes_data.hpp"
246
247 namespace boost { namespace polygon{
248 struct polygon_concept {};
249 struct polygon_with_holes_concept {};
250 struct polygon_45_concept {};
251 struct polygon_45_with_holes_concept {};
252 struct polygon_90_concept {};
253 struct polygon_90_with_holes_concept {};
254
255
256 template <typename T>
257 struct is_polygon_90_type {
258 typedef typename geometry_concept<T>::type GC;
259 typedef typename gtl_same_type<polygon_90_concept, GC>::type type;
260 };
261
262 template <typename T>
263 struct is_polygon_45_type {
264 typedef typename geometry_concept<T>::type GC;
265 typedef typename gtl_or<typename is_polygon_90_type<T>::type,
266 typename gtl_same_type<polygon_45_concept, GC>::type>::type type;
267 };
268
269 template <typename T>
270 struct is_polygon_type {
271 typedef typename geometry_concept<T>::type GC;
272 typedef typename gtl_or<typename is_polygon_45_type<T>::type,
273 typename gtl_same_type<polygon_concept, GC>::type>::type type;
274 };
275
276 template <typename T>
277 struct is_polygon_90_with_holes_type {
278 typedef typename geometry_concept<T>::type GC;
279 typedef typename gtl_or<typename is_polygon_90_type<T>::type,
280 typename gtl_same_type<polygon_90_with_holes_concept, GC>::type>::type type;
281 };
282
283 template <typename T>
284 struct is_polygon_45_with_holes_type {
285 typedef typename geometry_concept<T>::type GC;
286 typedef typename gtl_or_3<typename is_polygon_90_with_holes_type<T>::type,
287 typename is_polygon_45_type<T>::type,
288 typename gtl_same_type<polygon_45_with_holes_concept, GC>::type>::type type;
289 };
290
291 template <typename T>
292 struct is_polygon_with_holes_type {
293 typedef typename geometry_concept<T>::type GC;
294 typedef typename gtl_or_3<typename is_polygon_45_with_holes_type<T>::type,
295 typename is_polygon_type<T>::type,
296 typename gtl_same_type<polygon_with_holes_concept, GC>::type>::type type;
297 };
298
299 template <typename T>
300 struct is_mutable_polygon_90_type {
301 typedef typename geometry_concept<T>::type GC;
302 typedef typename gtl_same_type<polygon_90_concept, GC>::type type;
303 };
304
305 template <typename T>
306 struct is_mutable_polygon_45_type {
307 typedef typename geometry_concept<T>::type GC;
308 typedef typename gtl_same_type<polygon_45_concept, GC>::type type;
309 };
310
311 template <typename T>
312 struct is_mutable_polygon_type {
313 typedef typename geometry_concept<T>::type GC;
314 typedef typename gtl_same_type<polygon_concept, GC>::type type;
315 };
316
317 template <typename T>
318 struct is_mutable_polygon_90_with_holes_type {
319 typedef typename geometry_concept<T>::type GC;
320 typedef typename gtl_same_type<polygon_90_with_holes_concept, GC>::type type;
321 };
322
323 template <typename T>
324 struct is_mutable_polygon_45_with_holes_type {
325 typedef typename geometry_concept<T>::type GC;
326 typedef typename gtl_same_type<polygon_45_with_holes_concept, GC>::type type;
327 };
328
329 template <typename T>
330 struct is_mutable_polygon_with_holes_type {
331 typedef typename geometry_concept<T>::type GC;
332 typedef typename gtl_same_type<polygon_with_holes_concept, GC>::type type;
333 };
334
335 template <typename T>
336 struct is_any_mutable_polygon_with_holes_type {
337 typedef typename gtl_or_3<typename is_mutable_polygon_90_with_holes_type<T>::type,
338 typename is_mutable_polygon_45_with_holes_type<T>::type,
339 typename is_mutable_polygon_with_holes_type<T>::type>::type type;
340 };
341 template <typename T>
342 struct is_any_mutable_polygon_without_holes_type {
343 typedef typename gtl_or_3<
344 typename is_mutable_polygon_90_type<T>::type,
345 typename is_mutable_polygon_45_type<T>::type,
346 typename is_mutable_polygon_type<T>::type>::type type; };
347
348 template <typename T>
349 struct is_any_mutable_polygon_type {
350 typedef typename gtl_or<typename is_any_mutable_polygon_with_holes_type<T>::type,
351 typename is_any_mutable_polygon_without_holes_type<T>::type>::type type;
352 };
353
354 template <typename T>
355 struct polygon_from_polygon_with_holes_type {};
356 template <>
357 struct polygon_from_polygon_with_holes_type<polygon_with_holes_concept> { typedef polygon_concept type; };
358 template <>
359 struct polygon_from_polygon_with_holes_type<polygon_45_with_holes_concept> { typedef polygon_45_concept type; };
360 template <>
361 struct polygon_from_polygon_with_holes_type<polygon_90_with_holes_concept> { typedef polygon_90_concept type; };
362
363 template <>
364 struct geometry_domain<polygon_45_concept> { typedef forty_five_domain type; };
365 template <>
366 struct geometry_domain<polygon_45_with_holes_concept> { typedef forty_five_domain type; };
367 template <>
368 struct geometry_domain<polygon_90_concept> { typedef manhattan_domain type; };
369 template <>
370 struct geometry_domain<polygon_90_with_holes_concept> { typedef manhattan_domain type; };
371
372 template <typename domain_type, typename coordinate_type>
373 struct distance_type_by_domain { typedef typename coordinate_traits<coordinate_type>::coordinate_distance type; };
374 template <typename coordinate_type>
375 struct distance_type_by_domain<manhattan_domain, coordinate_type> {
376 typedef typename coordinate_traits<coordinate_type>::coordinate_difference type; };
377
378 // \brief Sets the boundary of the polygon to the points in the iterator range
379 // \tparam T A type that models polygon_concept
380 // \tparam iT Iterator type over objects that model point_concept
381 // \param t The polygon to set
382 // \param begin_points The start of the range of points
383 // \param end_points The end of the range of points
384
385 /// \relatesalso polygon_concept
386 template <typename T, typename iT>
387 typename enable_if <typename is_any_mutable_polygon_type<T>::type, T>::type &
388 set_points(T& t, iT begin_points, iT end_points) {
389 polygon_mutable_traits<T>::set_points(t, begin_points, end_points);
390 return t;
391 }
392
393 // \brief Sets the boundary of the polygon to the non-redundant coordinates in the iterator range
394 // \tparam T A type that models polygon_90_concept
395 // \tparam iT Iterator type over objects that model coordinate_concept
396 // \param t The polygon to set
397 // \param begin_compact_coordinates The start of the range of coordinates
398 // \param end_compact_coordinates The end of the range of coordinates
399
400 /// \relatesalso polygon_90_concept
401 template <typename T, typename iT>
402 typename enable_if <typename gtl_or<
403 typename is_mutable_polygon_90_type<T>::type,
404 typename is_mutable_polygon_90_with_holes_type<T>::type>::type, T>::type &
405 set_compact(T& t, iT begin_compact_coordinates, iT end_compact_coordinates) {
406 polygon_90_mutable_traits<T>::set_compact(t, begin_compact_coordinates, end_compact_coordinates);
407 return t;
408 }
409
410 /// \relatesalso polygon_with_holes_concept
411 template <typename T, typename iT>
412 typename enable_if< typename gtl_and <
413 typename is_any_mutable_polygon_with_holes_type<T>::type,
414 typename gtl_different_type<typename geometry_domain<typename geometry_concept<T>::type>::type,
415 manhattan_domain>::type>::type,
416 T>::type &
417 set_compact(T& t, iT begin_compact_coordinates, iT end_compact_coordinates) {
418 iterator_compact_to_points<iT, point_data<typename polygon_traits<T>::coordinate_type> >
419 itrb(begin_compact_coordinates, end_compact_coordinates),
420 itre(end_compact_coordinates, end_compact_coordinates);
421 return set_points(t, itrb, itre);
422 }
423
424 /// \relatesalso polygon_with_holes_concept
425 template <typename T, typename iT>
426 typename enable_if <typename is_any_mutable_polygon_with_holes_type<T>::type, T>::type &
427 set_holes(T& t, iT begin_holes, iT end_holes) {
428 polygon_with_holes_mutable_traits<T>::set_holes(t, begin_holes, end_holes);
429 return t;
430 }
431
432 /// \relatesalso polygon_90_concept
433 template <typename T>
434 typename polygon_90_traits<T>::compact_iterator_type
435 begin_compact(const T& polygon,
436 typename enable_if<
437 typename gtl_and <typename is_polygon_with_holes_type<T>::type,
438 typename gtl_same_type<typename geometry_domain<typename geometry_concept<T>::type>::type,
439 manhattan_domain>::type>::type>::type * = 0
440 ) {
441 return polygon_90_traits<T>::begin_compact(polygon);
442 }
443
444 /// \relatesalso polygon_90_concept
445 template <typename T>
446 typename polygon_90_traits<T>::compact_iterator_type
447 end_compact(const T& polygon,
448 typename enable_if<
449 typename gtl_and <typename is_polygon_with_holes_type<T>::type,
450 typename gtl_same_type<typename geometry_domain<typename geometry_concept<T>::type>::type,
451 manhattan_domain>::type>::type>::type * = 0
452 ) {
453 return polygon_90_traits<T>::end_compact(polygon);
454 }
455
456 /// \relatesalso polygon_concept
457 template <typename T>
458 typename enable_if < typename gtl_if<
459 typename is_polygon_with_holes_type<T>::type>::type,
460 typename polygon_traits<T>::iterator_type>::type
461 begin_points(const T& polygon) {
462 return polygon_traits<T>::begin_points(polygon);
463 }
464
465 /// \relatesalso polygon_concept
466 template <typename T>
467 typename enable_if < typename gtl_if<
468 typename is_polygon_with_holes_type<T>::type>::type,
469 typename polygon_traits<T>::iterator_type>::type
470 end_points(const T& polygon) {
471 return polygon_traits<T>::end_points(polygon);
472 }
473
474 /// \relatesalso polygon_concept
475 template <typename T>
476 typename enable_if <typename is_polygon_with_holes_type<T>::type,
477 std::size_t>::type
478 size(const T& polygon) {
479 return polygon_traits<T>::size(polygon);
480 }
481
482 /// \relatesalso polygon_with_holes_concept
483 template <typename T>
484 typename enable_if < typename gtl_if<
485 typename is_polygon_with_holes_type<T>::type>::type,
486 typename polygon_with_holes_traits<T>::iterator_holes_type>::type
487 begin_holes(const T& polygon) {
488 return polygon_with_holes_traits<T>::begin_holes(polygon);
489 }
490
491 /// \relatesalso polygon_with_holes_concept
492 template <typename T>
493 typename enable_if < typename gtl_if<
494 typename is_polygon_with_holes_type<T>::type>::type,
495 typename polygon_with_holes_traits<T>::iterator_holes_type>::type
496 end_holes(const T& polygon) {
497 return polygon_with_holes_traits<T>::end_holes(polygon);
498 }
499
500 /// \relatesalso polygon_with_holes_concept
501 template <typename T>
502 typename enable_if <typename is_polygon_with_holes_type<T>::type,
503 std::size_t>::type
504 size_holes(const T& polygon) {
505 return polygon_with_holes_traits<T>::size_holes(polygon);
506 }
507
508 // \relatesalso polygon_concept
509 template <typename T1, typename T2>
510 typename enable_if<
511 typename gtl_and< typename is_mutable_polygon_type<T1>::type,
512 typename is_polygon_type<T2>::type>::type, T1>::type &
513 assign(T1& lvalue, const T2& rvalue) {
514 polygon_mutable_traits<T1>::set_points(lvalue, polygon_traits<T2>::begin_points(rvalue),
515 polygon_traits<T2>::end_points(rvalue));
516 return lvalue;
517 }
518
519 // \relatesalso polygon_with_holes_concept
520 template <typename T1, typename T2>
521 typename enable_if<
522 typename gtl_and< typename is_mutable_polygon_with_holes_type<T1>::type,
523 typename is_polygon_with_holes_type<T2>::type>::type, T1>::type &
524 assign(T1& lvalue, const T2& rvalue) {
525 polygon_mutable_traits<T1>::set_points(lvalue, polygon_traits<T2>::begin_points(rvalue),
526 polygon_traits<T2>::end_points(rvalue));
527 polygon_with_holes_mutable_traits<T1>::set_holes(lvalue, polygon_with_holes_traits<T2>::begin_holes(rvalue),
528 polygon_with_holes_traits<T2>::end_holes(rvalue));
529 return lvalue;
530 }
531
532 // \relatesalso polygon_45_concept
533 template <typename T1, typename T2>
534 typename enable_if< typename gtl_and< typename is_mutable_polygon_45_type<T1>::type, typename is_polygon_45_type<T2>::type>::type, T1>::type &
535 assign(T1& lvalue, const T2& rvalue) {
536 polygon_mutable_traits<T1>::set_points(lvalue, polygon_traits<T2>::begin_points(rvalue),
537 polygon_traits<T2>::end_points(rvalue));
538 return lvalue;
539 }
540
541 // \relatesalso polygon_45_with_holes_concept
542 template <typename T1, typename T2>
543 typename enable_if<
544 typename gtl_and< typename is_mutable_polygon_45_with_holes_type<T1>::type,
545 typename is_polygon_45_with_holes_type<T2>::type>::type, T1>::type &
546 assign(T1& lvalue, const T2& rvalue) {
547 polygon_mutable_traits<T1>::set_points(lvalue, polygon_traits<T2>::begin_points(rvalue),
548 polygon_traits<T2>::end_points(rvalue));
549 polygon_with_holes_mutable_traits<T1>::set_holes(lvalue, polygon_with_holes_traits<T2>::begin_holes(rvalue),
550 polygon_with_holes_traits<T2>::end_holes(rvalue));
551 return lvalue;
552 }
553
554 // \relatesalso polygon_90_concept
555 template <typename T1, typename T2>
556 typename enable_if<
557 typename gtl_and< typename is_mutable_polygon_90_type<T1>::type,
558 typename is_polygon_90_type<T2>::type>::type, T1>::type &
559 assign(T1& lvalue, const T2& rvalue) {
560 polygon_90_mutable_traits<T1>::set_compact(lvalue, polygon_90_traits<T2>::begin_compact(rvalue),
561 polygon_90_traits<T2>::end_compact(rvalue));
562 return lvalue;
563 }
564
565 // \relatesalso polygon_90_with_holes_concept
566 template <typename T1, typename T2>
567 typename enable_if<
568 typename gtl_and< typename is_mutable_polygon_90_with_holes_type<T1>::type,
569 typename is_polygon_90_with_holes_type<T2>::type>::type, T1>::type &
570 assign(T1& lvalue, const T2& rvalue) {
571 polygon_90_mutable_traits<T1>::set_compact(lvalue, polygon_90_traits<T2>::begin_compact(rvalue),
572 polygon_90_traits<T2>::end_compact(rvalue));
573 polygon_with_holes_mutable_traits<T1>::set_holes(lvalue, polygon_with_holes_traits<T2>::begin_holes(rvalue),
574 polygon_with_holes_traits<T2>::end_holes(rvalue));
575 return lvalue;
576 }
577
578 // \relatesalso polygon_90_concept
579 template <typename T1, typename T2>
580 typename enable_if<
581 typename gtl_and< typename is_any_mutable_polygon_type<T1>::type,
582 typename is_rectangle_concept<typename geometry_concept<T2>::type>::type>::type, T1>::type &
583 assign(T1& polygon, const T2& rect) {
584 typedef point_data<typename polygon_traits<T1>::coordinate_type> PT;
585 PT points[4] = {PT(xl(rect), yl(rect)), PT(xh(rect), yl(rect)), PT(xh(rect), yh(rect)), PT(xl(rect), yh(rect))};
586 set_points(polygon, points, points+4);
587 return polygon;
588 }
589
590 /// \relatesalso polygon_90_concept
591 template <typename polygon_type, typename point_type>
592 typename enable_if< typename gtl_and< typename is_mutable_polygon_90_type<polygon_type>::type,
593 typename is_point_concept<typename geometry_concept<point_type>::type>::type>::type,
594 polygon_type>::type &
595 convolve(polygon_type& polygon, const point_type& point) {
596 std::vector<typename polygon_90_traits<polygon_type>::coordinate_type> coords;
597 coords.reserve(size(polygon));
598 bool pingpong = true;
599 for(typename polygon_90_traits<polygon_type>::compact_iterator_type iter = begin_compact(polygon);
600 iter != end_compact(polygon); ++iter) {
601 coords.push_back((*iter) + (pingpong ? x(point) : y(point)));
602 pingpong = !pingpong;
603 }
604 polygon_90_mutable_traits<polygon_type>::set_compact(polygon, coords.begin(), coords.end());
605 return polygon;
606 }
607
608 /// \relatesalso polygon_concept
609 template <typename polygon_type, typename point_type>
610 typename enable_if< typename gtl_and< typename gtl_or<
611 typename is_mutable_polygon_45_type<polygon_type>::type,
612 typename is_mutable_polygon_type<polygon_type>::type>::type,
613 typename is_point_concept<typename geometry_concept<point_type>::type>::type>::type,
614 polygon_type>::type &
615 convolve(polygon_type& polygon, const point_type& point) {
616 std::vector<typename std::iterator_traits<typename polygon_traits<polygon_type>::iterator_type>::value_type> points;
617 points.reserve(size(polygon));
618 for(typename polygon_traits<polygon_type>::iterator_type iter = begin_points(polygon);
619 iter != end_points(polygon); ++iter) {
620 points.push_back(*iter);
621 convolve(points.back(), point);
622 }
623 polygon_mutable_traits<polygon_type>::set_points(polygon, points.begin(), points.end());
624 return polygon;
625 }
626
627 /// \relatesalso polygon_with_holes_concept
628 template <typename polygon_type, typename point_type>
629 typename enable_if<
630 typename gtl_and< typename is_any_mutable_polygon_with_holes_type<polygon_type>::type,
631 typename is_point_concept<typename geometry_concept<point_type>::type>::type>::type,
632 polygon_type>::type &
633 convolve(polygon_type& polygon, const point_type& point) {
634 typedef typename polygon_with_holes_traits<polygon_type>::hole_type hole_type;
635 hole_type h;
636 set_points(h, begin_points(polygon), end_points(polygon));
637 convolve(h, point);
638 std::vector<hole_type> holes;
639 holes.reserve(size_holes(polygon));
640 for(typename polygon_with_holes_traits<polygon_type>::iterator_holes_type itr = begin_holes(polygon);
641 itr != end_holes(polygon); ++itr) {
642 holes.push_back(*itr);
643 convolve(holes.back(), point);
644 }
645 assign(polygon, h);
646 set_holes(polygon, holes.begin(), holes.end());
647 return polygon;
648 }
649
650 /// \relatesalso polygon_concept
651 template <typename T>
652 typename enable_if< typename is_any_mutable_polygon_type<T>::type, T>::type &
653 move(T& polygon, orientation_2d orient, typename polygon_traits<T>::coordinate_type displacement) {
654 typedef typename polygon_traits<T>::coordinate_type Unit;
655 if(orient == HORIZONTAL) return convolve(polygon, point_data<Unit>(displacement, Unit(0)));
656 return convolve(polygon, point_data<Unit>(Unit(0), displacement));
657 }
658
659 /// \relatesalso polygon_concept
660 /// \brief Applies a transformation to the polygon.
661 /// \tparam polygon_type A type that models polygon_concept
662 /// \tparam transform_type A type that may be either axis_transformation or transformation or that overloads point_concept::transform
663 /// \param polygon The polygon to transform
664 /// \param tr The transformation to apply
665 template <typename polygon_type, typename transform_type>
666 typename enable_if< typename is_any_mutable_polygon_without_holes_type<polygon_type>::type, polygon_type>::type &
667 transform(polygon_type& polygon, const transform_type& tr) {
668 std::vector<typename std::iterator_traits<typename polygon_traits<polygon_type>::iterator_type>::value_type> points;
669 points.reserve(size(polygon));
670 for(typename polygon_traits<polygon_type>::iterator_type iter = begin_points(polygon);
671 iter != end_points(polygon); ++iter) {
672 points.push_back(*iter);
673 transform(points.back(), tr);
674 }
675 polygon_mutable_traits<polygon_type>::set_points(polygon, points.begin(), points.end());
676 return polygon;
677 }
678
679 /// \relatesalso polygon_with_holes_concept
680 template <typename T, typename transform_type>
681 typename enable_if< typename is_any_mutable_polygon_with_holes_type<T>::type, T>::type &
682 transform(T& polygon, const transform_type& tr) {
683 typedef typename polygon_with_holes_traits<T>::hole_type hole_type;
684 hole_type h;
685 set_points(h, begin_points(polygon), end_points(polygon));
686 transform(h, tr);
687 std::vector<hole_type> holes;
688 holes.reserve(size_holes(polygon));
689 for(typename polygon_with_holes_traits<T>::iterator_holes_type itr = begin_holes(polygon);
690 itr != end_holes(polygon); ++itr) {
691 holes.push_back(*itr);
692 transform(holes.back(), tr);
693 }
694 assign(polygon, h);
695 set_holes(polygon, holes.begin(), holes.end());
696 return polygon;
697 }
698
699 template <typename polygon_type>
700 typename enable_if< typename is_any_mutable_polygon_without_holes_type<polygon_type>::type, polygon_type>::type &
701 scale_up(polygon_type& polygon, typename coordinate_traits<typename polygon_traits<polygon_type>::coordinate_type>::unsigned_area_type factor) {
702 std::vector<typename std::iterator_traits<typename polygon_traits<polygon_type>::iterator_type>::value_type> points;
703 points.reserve(size(polygon));
704 for(typename polygon_traits<polygon_type>::iterator_type iter = begin_points(polygon);
705 iter != end_points(polygon); ++iter) {
706 points.push_back(*iter);
707 scale_up(points.back(), factor);
708 }
709 polygon_mutable_traits<polygon_type>::set_points(polygon, points.begin(), points.end());
710 return polygon;
711 }
712
713 template <typename T>
714 typename enable_if< typename is_any_mutable_polygon_with_holes_type<T>::type, T>::type &
715 scale_up(T& polygon, typename coordinate_traits<typename polygon_traits<T>::coordinate_type>::unsigned_area_type factor) {
716 typedef typename polygon_with_holes_traits<T>::hole_type hole_type;
717 hole_type h;
718 set_points(h, begin_points(polygon), end_points(polygon));
719 scale_up(h, factor);
720 std::vector<hole_type> holes;
721 holes.reserve(size_holes(polygon));
722 for(typename polygon_with_holes_traits<T>::iterator_holes_type itr = begin_holes(polygon);
723 itr != end_holes(polygon); ++itr) {
724 holes.push_back(*itr);
725 scale_up(holes.back(), factor);
726 }
727 assign(polygon, h);
728 set_holes(polygon, holes.begin(), holes.end());
729 return polygon;
730 }
731
732 //scale non-45 down
733 template <typename polygon_type>
734 typename enable_if<
735 typename gtl_and< typename is_any_mutable_polygon_without_holes_type<polygon_type>::type,
736 typename gtl_not<typename gtl_same_type
737 < forty_five_domain,
738 typename geometry_domain<typename geometry_concept<polygon_type>::type>::type>::type>::type>::type,
739 polygon_type>::type &
740 scale_down(polygon_type& polygon, typename coordinate_traits<typename polygon_traits<polygon_type>::coordinate_type>::unsigned_area_type factor) {
741 std::vector<typename std::iterator_traits<typename polygon_traits<polygon_type>::iterator_type>::value_type> points;
742 points.reserve(size(polygon));
743 for(typename polygon_traits<polygon_type>::iterator_type iter = begin_points(polygon);
744 iter != end_points(polygon); ++iter) {
745 points.push_back(*iter);
746 scale_down(points.back(), factor);
747 }
748 polygon_mutable_traits<polygon_type>::set_points(polygon, points.begin(), points.end());
749 return polygon;
750 }
751
752 template <typename Unit>
753 Unit local_abs(Unit value) { return value < 0 ? (Unit)-value : value; }
754
755 template <typename Unit>
756 void snap_point_vector_to_45(std::vector<point_data<Unit> >& pts) {
757 typedef point_data<Unit> Point;
758 if(pts.size() < 3) { pts.clear(); return; }
759 typename std::vector<point_data<Unit> >::iterator endLocation = std::unique(pts.begin(), pts.end());
760 if(endLocation != pts.end()){
761 pts.resize(endLocation - pts.begin());
762 }
763 if(pts.back() == pts[0]) pts.pop_back();
764 //iterate over point triplets
765 int numPts = pts.size();
766 bool wrap_around = false;
767 for(int i = 0; i < numPts; ++i) {
768 Point& pt1 = pts[i];
769 Point& pt2 = pts[(i + 1) % numPts];
770 Point& pt3 = pts[(i + 2) % numPts];
771 //check if non-45 edge
772 Unit deltax = x(pt2) - x(pt1);
773 Unit deltay = y(pt2) - y(pt1);
774 if(deltax && deltay &&
775 local_abs(deltax) != local_abs(deltay)) {
776 //adjust the middle point
777 Unit ndx = x(pt3) - x(pt2);
778 Unit ndy = y(pt3) - y(pt2);
779 if(ndx && ndy) {
780 Unit diff = local_abs(local_abs(deltax) - local_abs(deltay));
781 Unit halfdiff = diff/2;
782 if((deltax > 0 && deltay > 0) ||
783 (deltax < 0 && deltay < 0)) {
784 //previous edge is rising slope
785 if(local_abs(deltax + halfdiff + (diff % 2)) ==
786 local_abs(deltay - halfdiff)) {
787 x(pt2, x(pt2) + halfdiff + (diff % 2));
788 y(pt2, y(pt2) - halfdiff);
789 } else if(local_abs(deltax - halfdiff - (diff % 2)) ==
790 local_abs(deltay + halfdiff)) {
791 x(pt2, x(pt2) - halfdiff - (diff % 2));
792 y(pt2, y(pt2) + halfdiff);
793 } else{
794 //std::cout << "fail1\n";
795 }
796 } else {
797 //previous edge is falling slope
798 if(local_abs(deltax + halfdiff + (diff % 2)) ==
799 local_abs(deltay + halfdiff)) {
800 x(pt2, x(pt2) + halfdiff + (diff % 2));
801 y(pt2, y(pt2) + halfdiff);
802 } else if(local_abs(deltax - halfdiff - (diff % 2)) ==
803 local_abs(deltay - halfdiff)) {
804 x(pt2, x(pt2) - halfdiff - (diff % 2));
805 y(pt2, y(pt2) - halfdiff);
806 } else {
807 //std::cout << "fail2\n";
808 }
809 }
810 if(i == numPts - 1 && (diff % 2)) {
811 //we have a wrap around effect
812 if(!wrap_around) {
813 wrap_around = true;
814 i = -1;
815 }
816 }
817 } else if(ndx) {
818 //next edge is horizontal
819 //find the x value for pt1 that would make the abs(deltax) == abs(deltay)
820 Unit newDeltaX = local_abs(deltay);
821 if(deltax < 0) newDeltaX *= -1;
822 x(pt2, x(pt1) + newDeltaX);
823 } else { //ndy
824 //next edge is vertical
825 //find the y value for pt1 that would make the abs(deltax) == abs(deltay)
826 Unit newDeltaY = local_abs(deltax);
827 if(deltay < 0) newDeltaY *= -1;
828 y(pt2, y(pt1) + newDeltaY);
829 }
830 }
831 }
832 }
833
834 template <typename polygon_type>
835 typename enable_if< typename is_any_mutable_polygon_without_holes_type<polygon_type>::type, polygon_type>::type &
836 snap_to_45(polygon_type& polygon) {
837 std::vector<typename std::iterator_traits<typename polygon_traits<polygon_type>::iterator_type>::value_type> points;
838 points.reserve(size(polygon));
839 for(typename polygon_traits<polygon_type>::iterator_type iter = begin_points(polygon);
840 iter != end_points(polygon); ++iter) {
841 points.push_back(*iter);
842 }
843 snap_point_vector_to_45(points);
844 polygon_mutable_traits<polygon_type>::set_points(polygon, points.begin(), points.end());
845 return polygon;
846 }
847
848 template <typename polygon_type>
849 typename enable_if< typename is_any_mutable_polygon_with_holes_type<polygon_type>::type, polygon_type>::type &
850 snap_to_45(polygon_type& polygon) {
851 typedef typename polygon_with_holes_traits<polygon_type>::hole_type hole_type;
852 hole_type h;
853 set_points(h, begin_points(polygon), end_points(polygon));
854 snap_to_45(h);
855 std::vector<hole_type> holes;
856 holes.reserve(size_holes(polygon));
857 for(typename polygon_with_holes_traits<polygon_type>::iterator_holes_type itr = begin_holes(polygon);
858 itr != end_holes(polygon); ++itr) {
859 holes.push_back(*itr);
860 snap_to_45(holes.back());
861 }
862 assign(polygon, h);
863 set_holes(polygon, holes.begin(), holes.end());
864 return polygon;
865 }
866
867 //scale specifically 45 down
868 template <typename polygon_type>
869 typename enable_if<
870 typename gtl_and< typename is_any_mutable_polygon_without_holes_type<polygon_type>::type,
871 typename gtl_same_type
872 < forty_five_domain,
873 typename geometry_domain<typename geometry_concept<polygon_type>::type>::type>::type>::type,
874 polygon_type>::type &
875 scale_down(polygon_type& polygon, typename coordinate_traits<typename polygon_traits<polygon_type>::coordinate_type>::unsigned_area_type factor) {
876 std::vector<typename std::iterator_traits<typename polygon_traits<polygon_type>::iterator_type>::value_type> points;
877 points.reserve(size(polygon));
878 for(typename polygon_traits<polygon_type>::iterator_type iter = begin_points(polygon);
879 iter != end_points(polygon); ++iter) {
880 points.push_back(*iter);
881 scale_down(points.back(), factor);
882 }
883 snap_point_vector_to_45(points);
884 polygon_mutable_traits<polygon_type>::set_points(polygon, points.begin(), points.end());
885 return polygon;
886 }
887
888 template <typename T>
889 typename enable_if< typename is_any_mutable_polygon_with_holes_type<T>::type, T>::type &
890 scale_down(T& polygon, typename coordinate_traits<typename polygon_traits<T>::coordinate_type>::unsigned_area_type factor) {
891 typedef typename polygon_with_holes_traits<T>::hole_type hole_type;
892 hole_type h;
893 set_points(h, begin_points(polygon), end_points(polygon));
894 scale_down(h, factor);
895 std::vector<hole_type> holes;
896 holes.reserve(size_holes(polygon));
897 for(typename polygon_with_holes_traits<T>::iterator_holes_type itr = begin_holes(polygon);
898 itr != end_holes(polygon); ++itr) {
899 holes.push_back(*itr);
900 scale_down(holes.back(), factor);
901 }
902 assign(polygon, h);
903 set_holes(polygon, holes.begin(), holes.end());
904 return polygon;
905 }
906
907 //scale non-45
908 template <typename polygon_type>
909 typename enable_if<
910 typename gtl_and< typename is_any_mutable_polygon_without_holes_type<polygon_type>::type,
911 typename gtl_not<typename gtl_same_type
912 < forty_five_domain,
913 typename geometry_domain<typename geometry_concept<polygon_type>::type>::type>::type>::type>::type,
914 polygon_type>::type &
915 scale(polygon_type& polygon, double factor) {
916 std::vector<typename std::iterator_traits<typename polygon_traits<polygon_type>::iterator_type>::value_type> points;
917 points.reserve(size(polygon));
918 for(typename polygon_traits<polygon_type>::iterator_type iter = begin_points(polygon);
919 iter != end_points(polygon); ++iter) {
920 points.push_back(*iter);
921 scale(points.back(), anisotropic_scale_factor<double>(factor, factor));
922 }
923 polygon_mutable_traits<polygon_type>::set_points(polygon, points.begin(), points.end());
924 return polygon;
925 }
926
927 //scale specifically 45
928 template <typename polygon_type>
929 polygon_type&
930 scale(polygon_type& polygon, double factor,
931 typename enable_if<
932 typename gtl_and< typename is_any_mutable_polygon_without_holes_type<polygon_type>::type,
933 typename gtl_same_type
934 < forty_five_domain,
935 typename geometry_domain<typename geometry_concept<polygon_type>::type>::type>::type>::type>::type * = 0
936 ) {
937 std::vector<typename std::iterator_traits<typename polygon_traits<polygon_type>::iterator_type>::value_type> points;
938 points.reserve(size(polygon));
939 for(typename polygon_traits<polygon_type>::iterator_type iter = begin_points(polygon);
940 iter != end_points(polygon); ++iter) {
941 points.push_back(*iter);
942 scale(points.back(), anisotropic_scale_factor<double>(factor, factor));
943 }
944 snap_point_vector_to_45(points);
945 polygon_mutable_traits<polygon_type>::set_points(polygon, points.begin(), points.end());
946 return polygon;
947 }
948
949 template <typename T>
950 T&
951 scale(T& polygon, double factor,
952 typename enable_if< typename is_any_mutable_polygon_with_holes_type<T>::type>::type * = 0
953 ) {
954 typedef typename polygon_with_holes_traits<T>::hole_type hole_type;
955 hole_type h;
956 set_points(h, begin_points(polygon), end_points(polygon));
957 scale(h, factor);
958 std::vector<hole_type> holes;
959 holes.reserve(size_holes(polygon));
960 for(typename polygon_with_holes_traits<T>::iterator_holes_type itr = begin_holes(polygon);
961 itr != end_holes(polygon); ++itr) {
962 holes.push_back(*itr);
963 scale(holes.back(), factor);
964 }
965 assign(polygon, h);
966 set_holes(polygon, holes.begin(), holes.end());
967 return polygon;
968 }
969
970 template <typename iterator_type, typename area_type>
971 static area_type
972 point_sequence_area(iterator_type begin_range, iterator_type end_range) {
973 typedef typename std::iterator_traits<iterator_type>::value_type point_type;
974 typedef typename point_traits<point_type>::coordinate_type Unit;
975 if(begin_range == end_range) return area_type(0);
976 point_type first = *begin_range;
977 point_type previous = first;
978 ++begin_range;
979 // Initialize trapezoid base line
980 area_type y_base = (area_type)y(first);
981 // Initialize area accumulator
982
983 area_type area(0);
984 while (begin_range != end_range) {
985 area_type x1 = (area_type)x(previous);
986 area_type x2 = (area_type)x(*begin_range);
987 #ifdef BOOST_POLYGON_ICC
988 #pragma warning (push)
989 #pragma warning (disable:1572)
990 #endif
991 if(x1 != x2) {
992 #ifdef BOOST_POLYGON_ICC
993 #pragma warning (pop)
994 #endif
995 // do trapezoid area accumulation
996 area += (x2 - x1) * (((area_type)y(*begin_range) - y_base) +
997 ((area_type)y(previous) - y_base)) / 2;
998 }
999 previous = *begin_range;
1000 // go to next point
1001 ++begin_range;
1002 }
1003 //wrap around to evaluate the edge between first and last if not closed
1004 if(!equivalence(first, previous)) {
1005 area_type x1 = (area_type)x(previous);
1006 area_type x2 = (area_type)x(first);
1007 area += (x2 - x1) * (((area_type)y(first) - y_base) +
1008 ((area_type)y(previous) - y_base)) / 2;
1009 }
1010 return area;
1011 }
1012
1013 template <typename T>
1014 typename enable_if<
1015 typename is_polygon_with_holes_type<T>::type,
1016 typename area_type_by_domain< typename geometry_domain<typename geometry_concept<T>::type>::type,
1017 typename polygon_traits<T>::coordinate_type>::type>::type
1018 area(const T& polygon) {
1019 typedef typename area_type_by_domain< typename geometry_domain<typename geometry_concept<T>::type>::type,
1020 typename polygon_traits<T>::coordinate_type>::type area_type;
1021 area_type retval = point_sequence_area<typename polygon_traits<T>::iterator_type, area_type>
1022 (begin_points(polygon), end_points(polygon));
1023 if(retval < 0) retval *= -1;
1024 for(typename polygon_with_holes_traits<T>::iterator_holes_type itr =
1025 polygon_with_holes_traits<T>::begin_holes(polygon);
1026 itr != polygon_with_holes_traits<T>::end_holes(polygon); ++itr) {
1027 area_type tmp_area = point_sequence_area
1028 <typename polygon_traits<typename polygon_with_holes_traits<T>::hole_type>::iterator_type, area_type>
1029 (begin_points(*itr), end_points(*itr));
1030 if(tmp_area < 0) tmp_area *= -1;
1031 retval -= tmp_area;
1032 }
1033 return retval;
1034 }
1035
1036 template <typename iT>
1037 bool point_sequence_is_45(iT itr, iT itr_end) {
1038 typedef typename std::iterator_traits<iT>::value_type Point;
1039 typedef typename point_traits<Point>::coordinate_type Unit;
1040 if(itr == itr_end) return true;
1041 Point firstPt = *itr;
1042 Point prevPt = firstPt;
1043 ++itr;
1044 while(itr != itr_end) {
1045 Point pt = *itr;
1046 Unit deltax = x(pt) - x(prevPt);
1047 Unit deltay = y(pt) - y(prevPt);
1048 if(deltax && deltay &&
1049 local_abs(deltax) != local_abs(deltay))
1050 return false;
1051 prevPt = pt;
1052 ++itr;
1053 }
1054 Unit deltax = x(firstPt) - x(prevPt);
1055 Unit deltay = y(firstPt) - y(prevPt);
1056 if(deltax && deltay &&
1057 local_abs(deltax) != local_abs(deltay))
1058 return false;
1059 return true;
1060 }
1061
1062 template <typename polygon_type>
1063 typename enable_if< typename is_polygon_with_holes_type<polygon_type>::type, bool>::type
1064 is_45(const polygon_type& polygon) {
1065 typename polygon_traits<polygon_type>::iterator_type itr = begin_points(polygon), itr_end = end_points(polygon);
1066 if(!point_sequence_is_45(itr, itr_end)) return false;
1067 typename polygon_with_holes_traits<polygon_type>::iterator_holes_type itrh = begin_holes(polygon), itrh_end = end_holes(polygon);
1068 typedef typename polygon_with_holes_traits<polygon_type>::hole_type hole_type;
1069 for(; itrh != itrh_end; ++ itrh) {
1070 typename polygon_traits<hole_type>::iterator_type itr1 = begin_points(polygon), itr1_end = end_points(polygon);
1071 if(!point_sequence_is_45(itr1, itr1_end)) return false;
1072 }
1073 return true;
1074 }
1075
1076 template <typename distance_type, typename iterator_type>
1077 distance_type point_sequence_distance(iterator_type itr, iterator_type itr_end) {
1078 typedef distance_type Unit;
1079 typedef iterator_type iterator;
1080 typedef typename std::iterator_traits<iterator>::value_type point_type;
1081 Unit return_value = Unit(0);
1082 point_type previous_point, first_point;
1083 if(itr == itr_end) return return_value;
1084 previous_point = first_point = *itr;
1085 ++itr;
1086 for( ; itr != itr_end; ++itr) {
1087 point_type current_point = *itr;
1088 return_value += (Unit)euclidean_distance(current_point, previous_point);
1089 previous_point = current_point;
1090 }
1091 return_value += (Unit)euclidean_distance(previous_point, first_point);
1092 return return_value;
1093 }
1094
1095 template <typename T>
1096 typename distance_type_by_domain
1097 <typename geometry_domain<typename geometry_concept<T>::type>::type, typename polygon_traits<T>::coordinate_type>::type
1098 perimeter(const T& polygon,
1099 typename enable_if<
1100 typename is_polygon_with_holes_type<T>::type>::type * = 0
1101 ) {
1102 typedef typename distance_type_by_domain
1103 <typename geometry_domain<typename geometry_concept<T>::type>::type, typename polygon_traits<T>::coordinate_type>::type Unit;
1104 typedef typename polygon_traits<T>::iterator_type iterator;
1105 iterator itr = begin_points(polygon);
1106 iterator itr_end = end_points(polygon);
1107 Unit return_value = point_sequence_distance<Unit, iterator>(itr, itr_end);
1108 for(typename polygon_with_holes_traits<T>::iterator_holes_type itr_holes = begin_holes(polygon);
1109 itr_holes != end_holes(polygon); ++itr_holes) {
1110 typedef typename polygon_traits<typename polygon_with_holes_traits<T>::hole_type>::iterator_type hitertype;
1111 return_value += point_sequence_distance<Unit, hitertype>(begin_points(*itr_holes), end_points(*itr_holes));
1112 }
1113 return return_value;
1114 }
1115
1116 template <typename T>
1117 typename enable_if <typename is_polygon_with_holes_type<T>::type,
1118 direction_1d>::type
1119 winding(const T& polygon) {
1120 winding_direction wd = polygon_traits<T>::winding(polygon);
1121 if(wd != unknown_winding) {
1122 return wd == clockwise_winding ? CLOCKWISE: COUNTERCLOCKWISE;
1123 }
1124 typedef typename area_type_by_domain< typename geometry_domain<typename geometry_concept<T>::type>::type,
1125 typename polygon_traits<T>::coordinate_type>::type area_type;
1126 return point_sequence_area<typename polygon_traits<T>::iterator_type, area_type>(begin_points(polygon), end_points(polygon)) < 0 ?
1127 COUNTERCLOCKWISE : CLOCKWISE;
1128 }
1129
1130 template <typename T, typename input_point_type>
1131 typename enable_if<
1132 typename gtl_and< typename is_polygon_90_type<T>::type,
1133 typename gtl_same_type<typename geometry_concept<input_point_type>::type, point_concept>::type>::type,
1134 bool>::type
1135 contains(const T& polygon, const input_point_type& point, bool consider_touch = true) {
1136 typedef T polygon_type;
1137 typedef typename polygon_traits<polygon_type>::coordinate_type coordinate_type;
1138 typedef typename polygon_traits<polygon_type>::iterator_type iterator;
1139 typedef typename std::iterator_traits<iterator>::value_type point_type;
1140 coordinate_type point_x = x(point);
1141 coordinate_type point_y = y(point);
1142 bool inside = false;
1143 for (iterator iter = begin_points(polygon); iter != end_points(polygon);) {
1144 point_type curr_point = *iter;
1145 ++iter;
1146 point_type next_point = (iter == end_points(polygon)) ? *begin_points(polygon) : *iter;
1147 if (x(curr_point) == x(next_point)) {
1148 if (x(curr_point) > point_x) {
1149 continue;
1150 }
1151 coordinate_type min_y = (std::min)(y(curr_point), y(next_point));
1152 coordinate_type max_y = (std::max)(y(curr_point), y(next_point));
1153 if (point_y > min_y && point_y < max_y) {
1154 if (x(curr_point) == point_x) {
1155 return consider_touch;
1156 }
1157 inside ^= true;
1158 }
1159 } else {
1160 coordinate_type min_x = (std::min)(x(curr_point), x(next_point));
1161 coordinate_type max_x = (std::max)(x(curr_point), x(next_point));
1162 if (point_x >= min_x && point_x <= max_x) {
1163 if (y(curr_point) == point_y) {
1164 return consider_touch;
1165 }
1166 }
1167 }
1168 }
1169 return inside;
1170 }
1171
1172 //TODO: refactor to expose as user APIs
1173 template <typename Unit>
1174 struct edge_utils {
1175 typedef point_data<Unit> Point;
1176 typedef std::pair<Point, Point> half_edge;
1177
1178 class less_point : public std::binary_function<Point, Point, bool> {
1179 public:
1180 inline less_point() {}
1181 inline bool operator () (const Point& pt1, const Point& pt2) const {
1182 if(pt1.get(HORIZONTAL) < pt2.get(HORIZONTAL)) return true;
1183 if(pt1.get(HORIZONTAL) == pt2.get(HORIZONTAL)) {
1184 if(pt1.get(VERTICAL) < pt2.get(VERTICAL)) return true;
1185 }
1186 return false;
1187 }
1188 };
1189
1190 static inline bool between(Point pt, Point pt1, Point pt2) {
1191 less_point lp;
1192 if(lp(pt1, pt2))
1193 return lp(pt, pt2) && lp(pt1, pt);
1194 return lp(pt, pt1) && lp(pt2, pt);
1195 }
1196
1197 template <typename area_type>
1198 static inline bool equal_slope(area_type dx1, area_type dy1, area_type dx2, area_type dy2) {
1199 typedef typename coordinate_traits<Unit>::unsigned_area_type unsigned_product_type;
1200 unsigned_product_type cross_1 = (unsigned_product_type)(dx2 < 0 ? -dx2 :dx2) * (unsigned_product_type)(dy1 < 0 ? -dy1 : dy1);
1201 unsigned_product_type cross_2 = (unsigned_product_type)(dx1 < 0 ? -dx1 :dx1) * (unsigned_product_type)(dy2 < 0 ? -dy2 : dy2);
1202 int dx1_sign = dx1 < 0 ? -1 : 1;
1203 int dx2_sign = dx2 < 0 ? -1 : 1;
1204 int dy1_sign = dy1 < 0 ? -1 : 1;
1205 int dy2_sign = dy2 < 0 ? -1 : 1;
1206 int cross_1_sign = dx2_sign * dy1_sign;
1207 int cross_2_sign = dx1_sign * dy2_sign;
1208 return cross_1 == cross_2 && (cross_1_sign == cross_2_sign || cross_1 == 0);
1209 }
1210
1211 static inline bool equal_slope(const Unit& x, const Unit& y,
1212 const Point& pt1, const Point& pt2) {
1213 const Point* pts[2] = {&pt1, &pt2};
1214 typedef typename coordinate_traits<Unit>::manhattan_area_type at;
1215 at dy2 = (at)pts[1]->get(VERTICAL) - (at)y;
1216 at dy1 = (at)pts[0]->get(VERTICAL) - (at)y;
1217 at dx2 = (at)pts[1]->get(HORIZONTAL) - (at)x;
1218 at dx1 = (at)pts[0]->get(HORIZONTAL) - (at)x;
1219 return equal_slope(dx1, dy1, dx2, dy2);
1220 }
1221
1222 template <typename area_type>
1223 static inline bool less_slope(area_type dx1, area_type dy1, area_type dx2, area_type dy2) {
1224 //reflext x and y slopes to right hand side half plane
1225 if(dx1 < 0) {
1226 dy1 *= -1;
1227 dx1 *= -1;
1228 } else if(dx1 == 0) {
1229 //if the first slope is vertical the first cannot be less
1230 return false;
1231 }
1232 if(dx2 < 0) {
1233 dy2 *= -1;
1234 dx2 *= -1;
1235 } else if(dx2 == 0) {
1236 //if the second slope is vertical the first is always less unless it is also vertical, in which case they are equal
1237 return dx1 != 0;
1238 }
1239 typedef typename coordinate_traits<Unit>::unsigned_area_type unsigned_product_type;
1240 unsigned_product_type cross_1 = (unsigned_product_type)(dx2 < 0 ? -dx2 :dx2) * (unsigned_product_type)(dy1 < 0 ? -dy1 : dy1);
1241 unsigned_product_type cross_2 = (unsigned_product_type)(dx1 < 0 ? -dx1 :dx1) * (unsigned_product_type)(dy2 < 0 ? -dy2 : dy2);
1242 int dx1_sign = dx1 < 0 ? -1 : 1;
1243 int dx2_sign = dx2 < 0 ? -1 : 1;
1244 int dy1_sign = dy1 < 0 ? -1 : 1;
1245 int dy2_sign = dy2 < 0 ? -1 : 1;
1246 int cross_1_sign = dx2_sign * dy1_sign;
1247 int cross_2_sign = dx1_sign * dy2_sign;
1248 if(cross_1_sign < cross_2_sign) return true;
1249 if(cross_2_sign < cross_1_sign) return false;
1250 if(cross_1_sign == -1) return cross_2 < cross_1;
1251 return cross_1 < cross_2;
1252 }
1253
1254 static inline bool less_slope(const Unit& x, const Unit& y,
1255 const Point& pt1, const Point& pt2) {
1256 const Point* pts[2] = {&pt1, &pt2};
1257 //compute y value on edge from pt_ to pts[1] at the x value of pts[0]
1258 typedef typename coordinate_traits<Unit>::manhattan_area_type at;
1259 at dy2 = (at)pts[1]->get(VERTICAL) - (at)y;
1260 at dy1 = (at)pts[0]->get(VERTICAL) - (at)y;
1261 at dx2 = (at)pts[1]->get(HORIZONTAL) - (at)x;
1262 at dx1 = (at)pts[0]->get(HORIZONTAL) - (at)x;
1263 return less_slope(dx1, dy1, dx2, dy2);
1264 }
1265
1266 //return -1 below, 0 on and 1 above line
1267 //assumes point is on x interval of segment
1268 static inline int on_above_or_below(Point pt, const half_edge& he) {
1269 if(pt == he.first || pt == he.second) return 0;
1270 if(equal_slope(pt.get(HORIZONTAL), pt.get(VERTICAL), he.first, he.second)) return 0;
1271 bool less_result = less_slope(pt.get(HORIZONTAL), pt.get(VERTICAL), he.first, he.second);
1272 int retval = less_result ? -1 : 1;
1273 less_point lp;
1274 if(lp(he.second, he.first)) retval *= -1;
1275 if(!between(pt, he.first, he.second)) retval *= -1;
1276 return retval;
1277 }
1278 };
1279
1280 template <typename T, typename input_point_type>
1281 typename enable_if<
1282 typename gtl_and< typename is_any_mutable_polygon_with_holes_type<T>::type,
1283 typename gtl_same_type<typename geometry_concept<input_point_type>::type, point_concept>::type>::type,
1284 bool>::type
1285 contains(const T& polygon, const input_point_type& point, bool consider_touch = true) {
1286 typedef typename polygon_with_holes_traits<T>::iterator_holes_type holes_iterator;
1287 bool isInside = contains( view_as< typename polygon_from_polygon_with_holes_type<
1288 typename geometry_concept<T>::type>::type>( polygon ), point, consider_touch );
1289 if(!isInside) return false; //no need to check holes
1290 holes_iterator itH = begin_holes( polygon );
1291 while( itH != end_holes( polygon ) ) {
1292 if( contains( *itH, point, !consider_touch ) ) {
1293 isInside = false;
1294 break;
1295 }
1296 ++itH;
1297 }
1298 return isInside;
1299 }
1300
1301 template <typename T, typename input_point_type>
1302 typename enable_if<
1303 typename gtl_and_3<
1304 typename is_polygon_type<T>::type,
1305 typename gtl_different_type<typename geometry_domain<typename geometry_concept<T>::type>::type, manhattan_domain>::type,
1306 typename gtl_same_type<typename geometry_concept<input_point_type>::type, point_concept>::type>::type,
1307 bool>::type
1308 contains(const T& polygon, const input_point_type& point, bool consider_touch = true) {
1309 typedef typename point_traits<input_point_type>::coordinate_type Unit;
1310 typedef point_data<Unit> Point;
1311 typedef std::pair<Point, Point> half_edge;
1312 typedef typename polygon_traits<T>::iterator_type iterator;
1313 iterator itr = begin_points(polygon);
1314 iterator itrEnd = end_points(polygon);
1315 half_edge he;
1316 if(itr == itrEnd) return false;
1317 assign(he.first, *itr);
1318 Point firstPt;
1319 assign(firstPt, *itr);
1320 ++itr;
1321 if(itr == itrEnd) return false;
1322 bool done = false;
1323 int above = 0;
1324 while(!done) {
1325 Point currentPt;
1326 if(itr == itrEnd) {
1327 done = true;
1328 currentPt = firstPt;
1329 } else {
1330 assign(currentPt, *itr);
1331 ++itr;
1332 }
1333 if(currentPt == he.first) {
1334 continue;
1335 } else {
1336 he.second = currentPt;
1337 if(equivalence(point, currentPt)) return consider_touch;
1338 Unit xmin = (std::min)(x(he.first), x(he.second));
1339 Unit xmax = (std::max)(x(he.first), x(he.second));
1340 if(x(point) >= xmin && x(point) < xmax) { //double counts if <= xmax
1341 Point tmppt;
1342 assign(tmppt, point);
1343 int oabedge = edge_utils<Unit>::on_above_or_below(tmppt, he);
1344 if(oabedge == 0) return consider_touch;
1345 if(oabedge == 1) ++above;
1346 } else if(x(point) == xmax) {
1347 if(x(point) == xmin) {
1348 Unit ymin = (std::min)(y(he.first), y(he.second));
1349 Unit ymax = (std::max)(y(he.first), y(he.second));
1350 Unit ypt = y(point);
1351 if(ypt <= ymax && ypt >= ymin)
1352 return consider_touch;
1353 } else {
1354 Point tmppt;
1355 assign(tmppt, point);
1356 if( edge_utils<Unit>::on_above_or_below(tmppt, he) == 0 ) {
1357 return consider_touch;
1358 }
1359 }
1360 }
1361 }
1362 he.first = he.second;
1363 }
1364 return above % 2 != 0; //if the point is above an odd number of edges is must be inside polygon
1365 }
1366
1367 /*
1368 template <typename T, typename input_point_type>
1369 typename enable_if<
1370 typename gtl_and_3<
1371 typename is_polygon_with_holes_type<T>::type,
1372 typename gtl_different_type<typename geometry_domain<typename geometry_concept<T>::type>::type, manhattan_domain>::type,
1373 typename gtl_same_type<typename geometry_concept<input_point_type>::type, point_concept>::type>::type,
1374 bool>::type
1375 contains(const T& polygon, const input_point_type& point, bool consider_touch = true) {
1376 typedef typename point_traits<input_point_type>::coordinate_type Unit;
1377 typedef point_data<Unit> Point;
1378 typedef std::pair<Point, Point> half_edge;
1379 typedef typename polygon_traits<T>::iterator_type iterator;
1380 iterator itr = begin_points(polygon);
1381 iterator itrEnd = end_points(polygon);
1382 half_edge he;
1383 if(itr == itrEnd) return false;
1384 assign(he.first, *itr);
1385 Point firstPt;
1386 assign(firstPt, *itr);
1387 ++itr;
1388 if(itr == itrEnd) return false;
1389 bool done = false;
1390 int above = 0;
1391 while(!done) {
1392 Point currentPt;
1393 if(itr == itrEnd) {
1394 done = true;
1395 currentPt = firstPt;
1396 } else {
1397 assign(currentPt, *itr);
1398 ++itr;
1399 }
1400 if(currentPt == he.first) {
1401 continue;
1402 } else {
1403 he.second = currentPt;
1404 if(equivalence(point, currentPt)) return consider_touch;
1405 Unit xmin = (std::min)(x(he.first), x(he.second));
1406 Unit xmax = (std::max)(x(he.first), x(he.second));
1407 if(x(point) >= xmin && x(point) < xmax) { //double counts if <= xmax
1408 Point tmppt;
1409 assign(tmppt, point);
1410 int oabedge = edge_utils<Unit>::on_above_or_below(tmppt, he);
1411 if(oabedge == 0) return consider_touch;
1412 if(oabedge == 1) ++above;
1413 }
1414 }
1415 he.first = he.second;
1416 }
1417 return above % 2 != 0; //if the point is above an odd number of edges is must be inside polygon
1418 }
1419 */
1420
1421 template <typename T1, typename T2>
1422 typename enable_if<
1423 typename gtl_and< typename is_mutable_point_concept<typename geometry_concept<T1>::type>::type,
1424 typename is_polygon_with_holes_type<T2>::type>::type,
1425 bool>::type
1426 center(T1& center_point, const T2& polygon) {
1427 typedef typename polygon_traits<T2>::coordinate_type coordinate_type;
1428 rectangle_data<coordinate_type> bbox;
1429 extents(bbox, polygon);
1430 return center(center_point, bbox);
1431 }
1432
1433 template <typename T1, typename T2>
1434 typename enable_if<
1435 typename gtl_and< typename is_mutable_rectangle_concept<typename geometry_concept<T1>::type>::type,
1436 typename is_polygon_with_holes_type<T2>::type>::type,
1437 bool>::type
1438 extents(T1& bounding_box, const T2& polygon) {
1439 typedef typename polygon_traits<T2>::iterator_type iterator;
1440 bool first_iteration = true;
1441 iterator itr_end = end_points(polygon);
1442 for(iterator itr = begin_points(polygon); itr != itr_end; ++itr) {
1443 if(first_iteration) {
1444 set_points(bounding_box, *itr, *itr);
1445 first_iteration = false;
1446 } else {
1447 encompass(bounding_box, *itr);
1448 }
1449 }
1450 if(first_iteration) return false;
1451 return true;
1452 }
1453
1454 template <class T>
1455 template <class T2>
1456 polygon_90_data<T>& polygon_90_data<T>::operator=(const T2& rvalue) {
1457 assign(*this, rvalue);
1458 return *this;
1459 }
1460
1461 template <class T>
1462 template <class T2>
1463 polygon_45_data<T>& polygon_45_data<T>::operator=(const T2& rvalue) {
1464 assign(*this, rvalue);
1465 return *this;
1466 }
1467
1468 template <class T>
1469 template <class T2>
1470 polygon_data<T>& polygon_data<T>::operator=(const T2& rvalue) {
1471 assign(*this, rvalue);
1472 return *this;
1473 }
1474
1475 template <class T>
1476 template <class T2>
1477 polygon_90_with_holes_data<T>& polygon_90_with_holes_data<T>::operator=(const T2& rvalue) {
1478 assign(*this, rvalue);
1479 return *this;
1480 }
1481
1482 template <class T>
1483 template <class T2>
1484 polygon_45_with_holes_data<T>& polygon_45_with_holes_data<T>::operator=(const T2& rvalue) {
1485 assign(*this, rvalue);
1486 return *this;
1487 }
1488
1489 template <class T>
1490 template <class T2>
1491 polygon_with_holes_data<T>& polygon_with_holes_data<T>::operator=(const T2& rvalue) {
1492 assign(*this, rvalue);
1493 return *this;
1494 }
1495
1496 template <typename T>
1497 struct geometry_concept<polygon_data<T> > {
1498 typedef polygon_concept type;
1499 };
1500 template <typename T>
1501 struct geometry_concept<polygon_45_data<T> > {
1502 typedef polygon_45_concept type;
1503 };
1504 template <typename T>
1505 struct geometry_concept<polygon_90_data<T> > {
1506 typedef polygon_90_concept type;
1507 };
1508 template <typename T>
1509 struct geometry_concept<polygon_with_holes_data<T> > {
1510 typedef polygon_with_holes_concept type;
1511 };
1512 template <typename T>
1513 struct geometry_concept<polygon_45_with_holes_data<T> > {
1514 typedef polygon_45_with_holes_concept type;
1515 };
1516 template <typename T>
1517 struct geometry_concept<polygon_90_with_holes_data<T> > {
1518 typedef polygon_90_with_holes_concept type;
1519 };
1520
1521 // template <typename T> struct polygon_with_holes_traits<polygon_90_data<T> > {
1522 // typedef polygon_90_data<T> hole_type;
1523 // typedef const hole_type* iterator_holes_type;
1524 // static inline iterator_holes_type begin_holes(const hole_type& t) { return &t; }
1525 // static inline iterator_holes_type end_holes(const hole_type& t) { return &t; }
1526 // static inline std::size_t size_holes(const hole_type& t) { return 0; }
1527 // };
1528 // template <typename T> struct polygon_with_holes_traits<polygon_45_data<T> > {
1529 // typedef polygon_45_data<T> hole_type;
1530 // typedef const hole_type* iterator_holes_type;
1531 // static inline iterator_holes_type begin_holes(const hole_type& t) { return &t; }
1532 // static inline iterator_holes_type end_holes(const hole_type& t) { return &t; }
1533 // static inline std::size_t size_holes(const hole_type& t) { return 0; }
1534 // };
1535 // template <typename T> struct polygon_with_holes_traits<polygon_data<T> > {
1536 // typedef polygon_data<T> hole_type;
1537 // typedef const hole_type* iterator_holes_type;
1538 // static inline iterator_holes_type begin_holes(const hole_type& t) { return &t; }
1539 // static inline iterator_holes_type end_holes(const hole_type& t) { return &t; }
1540 // static inline std::size_t size_holes(const hole_type& t) { return 0; }
1541 // };
1542 template <typename T> struct get_void {};
1543 template <> struct get_void<gtl_yes> { typedef void type; };
1544
1545 template <typename T> struct polygon_with_holes_traits<
1546 T, typename get_void<typename is_any_mutable_polygon_without_holes_type<T>::type>::type > {
1547 typedef T hole_type;
1548 typedef const hole_type* iterator_holes_type;
1549 static inline iterator_holes_type begin_holes(const hole_type& t) { return &t; }
1550 static inline iterator_holes_type end_holes(const hole_type& t) { return &t; }
1551 static inline std::size_t size_holes(const hole_type& t) { return 0; }
1552 };
1553
1554 template <typename T>
1555 struct view_of<rectangle_concept, T> {
1556 typedef typename polygon_traits<T>::coordinate_type coordinate_type;
1557 typedef interval_data<coordinate_type> interval_type;
1558 rectangle_data<coordinate_type> rect;
1559 view_of(const T& obj) : rect() {
1560 point_data<coordinate_type> pts[2];
1561 typename polygon_traits<T>::iterator_type itr =
1562 begin_points(obj), itre = end_points(obj);
1563 if(itr == itre) return;
1564 assign(pts[0], *itr);
1565 ++itr;
1566 if(itr == itre) return;
1567 ++itr;
1568 if(itr == itre) return;
1569 assign(pts[1], *itr);
1570 set_points(rect, pts[0], pts[1]);
1571 }
1572 inline interval_type get(orientation_2d orient) const {
1573 return rect.get(orient); }
1574 };
1575
1576 template <typename T>
1577 struct geometry_concept<view_of<rectangle_concept, T> > {
1578 typedef rectangle_concept type;
1579 };
1580
1581 template <typename T>
1582 struct view_of<polygon_45_concept, T> {
1583 const T* t;
1584 view_of(const T& obj) : t(&obj) {}
1585 typedef typename polygon_traits<T>::coordinate_type coordinate_type;
1586 typedef typename polygon_traits<T>::iterator_type iterator_type;
1587 typedef typename polygon_traits<T>::point_type point_type;
1588
1589 /// Get the begin iterator
1590 inline iterator_type begin() const {
1591 return polygon_traits<T>::begin_points(*t);
1592 }
1593
1594 /// Get the end iterator
1595 inline iterator_type end() const {
1596 return polygon_traits<T>::end_points(*t);
1597 }
1598
1599 /// Get the number of sides of the polygon
1600 inline std::size_t size() const {
1601 return polygon_traits<T>::size(*t);
1602 }
1603
1604 /// Get the winding direction of the polygon
1605 inline winding_direction winding() const {
1606 return polygon_traits<T>::winding(*t);
1607 }
1608 };
1609
1610 template <typename T>
1611 struct geometry_concept<view_of<polygon_45_concept, T> > {
1612 typedef polygon_45_concept type;
1613 };
1614
1615 template <typename T>
1616 struct view_of<polygon_90_concept, T> {
1617 const T* t;
1618 view_of(const T& obj) : t(&obj) {}
1619 typedef typename polygon_traits<T>::coordinate_type coordinate_type;
1620 typedef typename polygon_traits<T>::iterator_type iterator_type;
1621 typedef typename polygon_traits<T>::point_type point_type;
1622 typedef iterator_points_to_compact<iterator_type, point_type> compact_iterator_type;
1623
1624 /// Get the begin iterator
1625 inline compact_iterator_type begin_compact() const {
1626 return compact_iterator_type(polygon_traits<T>::begin_points(*t),
1627 polygon_traits<T>::end_points(*t));
1628 }
1629
1630 /// Get the end iterator
1631 inline compact_iterator_type end_compact() const {
1632 return compact_iterator_type(polygon_traits<T>::end_points(*t),
1633 polygon_traits<T>::end_points(*t));
1634 }
1635
1636 /// Get the number of sides of the polygon
1637 inline std::size_t size() const {
1638 return polygon_traits<T>::size(*t);
1639 }
1640
1641 /// Get the winding direction of the polygon
1642 inline winding_direction winding() const {
1643 return polygon_traits<T>::winding(*t);
1644 }
1645 };
1646
1647 template <typename T>
1648 struct geometry_concept<view_of<polygon_90_concept, T> > {
1649 typedef polygon_90_concept type;
1650 };
1651
1652 template <typename T>
1653 struct view_of<polygon_45_with_holes_concept, T> {
1654 const T* t;
1655 view_of(const T& obj) : t(&obj) {}
1656 typedef typename polygon_traits<T>::coordinate_type coordinate_type;
1657 typedef typename polygon_traits<T>::iterator_type iterator_type;
1658 typedef typename polygon_traits<T>::point_type point_type;
1659 typedef view_of<polygon_45_concept, typename polygon_with_holes_traits<T>::hole_type> hole_type;
1660 struct iterator_holes_type {
1661 typedef std::forward_iterator_tag iterator_category;
1662 typedef hole_type value_type;
1663 typedef std::ptrdiff_t difference_type;
1664 typedef const hole_type* pointer; //immutable
1665 typedef const hole_type& reference; //immutable
1666 typedef typename polygon_with_holes_traits<T>::iterator_holes_type iht;
1667 iht internal_itr;
1668 iterator_holes_type() : internal_itr() {}
1669 iterator_holes_type(iht iht_in) : internal_itr(iht_in) {}
1670 inline iterator_holes_type& operator++() {
1671 ++internal_itr;
1672 return *this;
1673 }
1674 inline const iterator_holes_type operator++(int) {
1675 iterator_holes_type tmp(*this);
1676 ++(*this);
1677 return tmp;
1678 }
1679 inline bool operator==(const iterator_holes_type& that) const {
1680 return (internal_itr == that.internal_itr);
1681 }
1682 inline bool operator!=(const iterator_holes_type& that) const {
1683 return (internal_itr != that.internal_itr);
1684 }
1685 inline value_type operator*() const {
1686 return view_as<polygon_45_concept>(*internal_itr);
1687 }
1688 };
1689
1690 /// Get the begin iterator
1691 inline iterator_type begin() const {
1692 return polygon_traits<T>::begin_points(*t);
1693 }
1694
1695 /// Get the end iterator
1696 inline iterator_type end() const {
1697 return polygon_traits<T>::end_points(*t);
1698 }
1699
1700 /// Get the number of sides of the polygon
1701 inline std::size_t size() const {
1702 return polygon_traits<T>::size(*t);
1703 }
1704
1705 /// Get the winding direction of the polygon
1706 inline winding_direction winding() const {
1707 return polygon_traits<T>::winding(*t);
1708 }
1709
1710 /// Get the begin iterator
1711 inline iterator_holes_type begin_holes() const {
1712 return polygon_with_holes_traits<T>::begin_holes(*t);
1713 }
1714
1715 /// Get the end iterator
1716 inline iterator_holes_type end_holes() const {
1717 return polygon_with_holes_traits<T>::end_holes(*t);
1718 }
1719
1720 /// Get the number of sides of the polygon
1721 inline std::size_t size_holes() const {
1722 return polygon_with_holes_traits<T>::size_holes(*t);
1723 }
1724
1725 };
1726
1727 template <typename T>
1728 struct geometry_concept<view_of<polygon_45_with_holes_concept, T> > {
1729 typedef polygon_45_with_holes_concept type;
1730 };
1731
1732 template <typename T>
1733 struct view_of<polygon_90_with_holes_concept, T> {
1734 const T* t;
1735 view_of(const T& obj) : t(&obj) {}
1736 typedef typename polygon_traits<T>::coordinate_type coordinate_type;
1737 typedef typename polygon_traits<T>::iterator_type iterator_type;
1738 typedef typename polygon_traits<T>::point_type point_type;
1739 typedef iterator_points_to_compact<iterator_type, point_type> compact_iterator_type;
1740 typedef view_of<polygon_90_concept, typename polygon_with_holes_traits<T>::hole_type> hole_type;
1741 struct iterator_holes_type {
1742 typedef std::forward_iterator_tag iterator_category;
1743 typedef hole_type value_type;
1744 typedef std::ptrdiff_t difference_type;
1745 typedef const hole_type* pointer; //immutable
1746 typedef const hole_type& reference; //immutable
1747 typedef typename polygon_with_holes_traits<T>::iterator_holes_type iht;
1748 iht internal_itr;
1749 iterator_holes_type() : internal_itr() {}
1750 iterator_holes_type(iht iht_in) : internal_itr(iht_in) {}
1751 inline iterator_holes_type& operator++() {
1752 ++internal_itr;
1753 return *this;
1754 }
1755 inline const iterator_holes_type operator++(int) {
1756 iterator_holes_type tmp(*this);
1757 ++(*this);
1758 return tmp;
1759 }
1760 inline bool operator==(const iterator_holes_type& that) const {
1761 return (internal_itr == that.internal_itr);
1762 }
1763 inline bool operator!=(const iterator_holes_type& that) const {
1764 return (internal_itr != that.internal_itr);
1765 }
1766 inline value_type operator*() const {
1767 return view_as<polygon_90_concept>(*internal_itr);
1768 }
1769 };
1770
1771 /// Get the begin iterator
1772 inline compact_iterator_type begin_compact() const {
1773 return compact_iterator_type(polygon_traits<T>::begin_points(*t),
1774 polygon_traits<T>::end_points(*t));
1775 }
1776
1777 /// Get the end iterator
1778 inline compact_iterator_type end_compact() const {
1779 return compact_iterator_type(polygon_traits<T>::end_points(*t),
1780 polygon_traits<T>::end_points(*t));
1781 }
1782
1783 /// Get the number of sides of the polygon
1784 inline std::size_t size() const {
1785 return polygon_traits<T>::size(*t);
1786 }
1787
1788 /// Get the winding direction of the polygon
1789 inline winding_direction winding() const {
1790 return polygon_traits<T>::winding(*t);
1791 }
1792
1793 /// Get the begin iterator
1794 inline iterator_holes_type begin_holes() const {
1795 return polygon_with_holes_traits<T>::begin_holes(*t);
1796 }
1797
1798 /// Get the end iterator
1799 inline iterator_holes_type end_holes() const {
1800 return polygon_with_holes_traits<T>::end_holes(*t);
1801 }
1802
1803 /// Get the number of sides of the polygon
1804 inline std::size_t size_holes() const {
1805 return polygon_with_holes_traits<T>::size_holes(*t);
1806 }
1807
1808 };
1809
1810 template <typename T>
1811 struct geometry_concept<view_of<polygon_90_with_holes_concept, T> > {
1812 typedef polygon_90_with_holes_concept type;
1813 };
1814
1815 template <typename T>
1816 struct view_of<polygon_concept, T> {
1817 const T* t;
1818 view_of(const T& obj) : t(&obj) {}
1819 typedef typename polygon_traits<T>::coordinate_type coordinate_type;
1820 typedef typename polygon_traits<T>::iterator_type iterator_type;
1821 typedef typename polygon_traits<T>::point_type point_type;
1822
1823 /// Get the begin iterator
1824 inline iterator_type begin() const {
1825 return polygon_traits<T>::begin_points(*t);
1826 }
1827
1828 /// Get the end iterator
1829 inline iterator_type end() const {
1830 return polygon_traits<T>::end_points(*t);
1831 }
1832
1833 /// Get the number of sides of the polygon
1834 inline std::size_t size() const {
1835 return polygon_traits<T>::size(*t);
1836 }
1837
1838 /// Get the winding direction of the polygon
1839 inline winding_direction winding() const {
1840 return polygon_traits<T>::winding(*t);
1841 }
1842 };
1843
1844 template <typename T>
1845 struct geometry_concept<view_of<polygon_concept, T> > {
1846 typedef polygon_concept type;
1847 };
1848 }
1849 }
1850
1851 #endif