Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/polygon/interval_concept.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 // Boost.Polygon library interval_concept.hpp header file | |
2 | |
3 // Copyright (c) Intel Corporation 2008. | |
4 // Copyright (c) 2008-2012 Simonson Lucanus. | |
5 // Copyright (c) 2012-2012 Andrii Sydorchuk. | |
6 | |
7 // See http://www.boost.org for updates, documentation, and revision history. | |
8 // Use, modification and distribution is subject to the Boost Software License, | |
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
10 // http://www.boost.org/LICENSE_1_0.txt) | |
11 | |
12 #ifndef BOOST_POLYGON_INTERVAL_CONCEPT_HPP | |
13 #define BOOST_POLYGON_INTERVAL_CONCEPT_HPP | |
14 | |
15 #include "isotropy.hpp" | |
16 #include "interval_traits.hpp" | |
17 | |
18 namespace boost { | |
19 namespace polygon { | |
20 | |
21 struct interval_concept {}; | |
22 | |
23 template <typename ConceptType> | |
24 struct is_interval_concept { | |
25 typedef gtl_no type; | |
26 }; | |
27 | |
28 template <> | |
29 struct is_interval_concept<interval_concept> { | |
30 typedef gtl_yes type; | |
31 }; | |
32 | |
33 template <typename ConceptType> | |
34 struct is_mutable_interval_concept { | |
35 typedef gtl_no type; | |
36 }; | |
37 | |
38 template <> | |
39 struct is_mutable_interval_concept<interval_concept> { | |
40 typedef gtl_yes type; | |
41 }; | |
42 | |
43 template <typename GeometryType, typename BoolType> | |
44 struct interval_coordinate_type_by_concept { | |
45 typedef void type; | |
46 }; | |
47 | |
48 template <typename GeometryType> | |
49 struct interval_coordinate_type_by_concept<GeometryType, gtl_yes> { | |
50 typedef typename interval_traits<GeometryType>::coordinate_type type; | |
51 }; | |
52 | |
53 template <typename GeometryType> | |
54 struct interval_coordinate_type { | |
55 typedef typename interval_coordinate_type_by_concept< | |
56 GeometryType, | |
57 typename is_interval_concept< | |
58 typename geometry_concept<GeometryType>::type | |
59 >::type | |
60 >::type type; | |
61 }; | |
62 | |
63 template <typename GeometryType, typename BoolType> | |
64 struct interval_difference_type_by_concept { | |
65 typedef void type; | |
66 }; | |
67 | |
68 template <typename GeometryType> | |
69 struct interval_difference_type_by_concept<GeometryType, gtl_yes> { | |
70 typedef typename coordinate_traits< | |
71 typename interval_traits<GeometryType>::coordinate_type | |
72 >::coordinate_difference type; | |
73 }; | |
74 | |
75 template <typename GeometryType> | |
76 struct interval_difference_type { | |
77 typedef typename interval_difference_type_by_concept< | |
78 GeometryType, | |
79 typename is_interval_concept< | |
80 typename geometry_concept<GeometryType>::type | |
81 >::type | |
82 >::type type; | |
83 }; | |
84 | |
85 struct y_i_get : gtl_yes {}; | |
86 | |
87 template <typename IntervalType> | |
88 typename enable_if< | |
89 typename gtl_and< | |
90 y_i_get, | |
91 typename is_interval_concept< | |
92 typename geometry_concept<IntervalType>::type | |
93 >::type | |
94 >::type, | |
95 typename interval_coordinate_type<IntervalType>::type | |
96 >::type get(const IntervalType& interval, direction_1d dir) { | |
97 return interval_traits<IntervalType>::get(interval, dir); | |
98 } | |
99 | |
100 struct y_i_set : gtl_yes {}; | |
101 | |
102 template <typename IntervalType> | |
103 typename enable_if< | |
104 typename gtl_and< | |
105 y_i_set, | |
106 typename is_mutable_interval_concept< | |
107 typename geometry_concept<IntervalType>::type | |
108 >::type | |
109 >::type, | |
110 void | |
111 >::type set(IntervalType& interval, direction_1d dir, | |
112 typename interval_mutable_traits<IntervalType>::coordinate_type value) { | |
113 interval_mutable_traits<IntervalType>::set(interval, dir, value); | |
114 } | |
115 | |
116 struct y_i_construct : gtl_yes {}; | |
117 | |
118 template <typename IntervalType> | |
119 typename enable_if< | |
120 typename gtl_and< | |
121 y_i_construct, | |
122 typename is_mutable_interval_concept< | |
123 typename geometry_concept<IntervalType>::type | |
124 >::type | |
125 >::type, | |
126 IntervalType | |
127 >::type construct( | |
128 typename interval_mutable_traits<IntervalType>::coordinate_type low, | |
129 typename interval_mutable_traits<IntervalType>::coordinate_type high) { | |
130 if (low > high) { | |
131 (std::swap)(low, high); | |
132 } | |
133 return interval_mutable_traits<IntervalType>::construct(low, high); | |
134 } | |
135 | |
136 struct y_i_copy_construct : gtl_yes {}; | |
137 | |
138 template <typename IntervalType1, typename IntervalType2> | |
139 typename enable_if< | |
140 typename gtl_and_3< | |
141 y_i_copy_construct, | |
142 typename is_mutable_interval_concept< | |
143 typename geometry_concept<IntervalType1>::type | |
144 >::type, | |
145 typename is_interval_concept< | |
146 typename geometry_concept<IntervalType2>::type | |
147 >::type | |
148 >::type, | |
149 IntervalType1 | |
150 >::type copy_construct(const IntervalType2& interval) { | |
151 return construct<IntervalType1>(get(interval, LOW), get(interval, HIGH)); | |
152 } | |
153 | |
154 struct y_i_assign : gtl_yes {}; | |
155 | |
156 template <typename IntervalType1, typename IntervalType2> | |
157 typename enable_if< | |
158 typename gtl_and_3< | |
159 y_i_assign, | |
160 typename is_mutable_interval_concept< | |
161 typename geometry_concept<IntervalType1>::type | |
162 >::type, | |
163 typename is_interval_concept< | |
164 typename geometry_concept<IntervalType2>::type | |
165 >::type | |
166 >::type, | |
167 IntervalType1 | |
168 >::type& assign(IntervalType1& lvalue, const IntervalType2& rvalue) { | |
169 set(lvalue, LOW, get(rvalue, LOW)); | |
170 set(lvalue, HIGH, get(rvalue, HIGH)); | |
171 return lvalue; | |
172 } | |
173 | |
174 struct y_i_low : gtl_yes {}; | |
175 | |
176 template <typename IntervalType> | |
177 typename enable_if< | |
178 typename gtl_and< | |
179 y_i_low, | |
180 typename is_interval_concept< | |
181 typename geometry_concept<IntervalType>::type | |
182 >::type | |
183 >::type, | |
184 typename interval_coordinate_type<IntervalType>::type | |
185 >::type low(const IntervalType& interval) { | |
186 return get(interval, LOW); | |
187 } | |
188 | |
189 struct y_i_high : gtl_yes {}; | |
190 | |
191 template <typename IntervalType> | |
192 typename enable_if< | |
193 typename gtl_and< | |
194 y_i_high, | |
195 typename is_interval_concept< | |
196 typename geometry_concept<IntervalType>::type | |
197 >::type | |
198 >::type, | |
199 typename interval_coordinate_type<IntervalType>::type | |
200 >::type high(const IntervalType& interval) { | |
201 return get(interval, HIGH); | |
202 } | |
203 | |
204 struct y_i_low2 : gtl_yes {}; | |
205 | |
206 template <typename IntervalType> | |
207 typename enable_if< | |
208 typename gtl_and< | |
209 y_i_low2, | |
210 typename is_mutable_interval_concept< | |
211 typename geometry_concept<IntervalType>::type | |
212 >::type | |
213 >::type, | |
214 void | |
215 >::type low(IntervalType& interval, | |
216 typename interval_mutable_traits<IntervalType>::coordinate_type value) { | |
217 set(interval, LOW, value); | |
218 } | |
219 | |
220 struct y_i_high2 : gtl_yes {}; | |
221 | |
222 template <typename IntervalType> | |
223 typename enable_if< | |
224 typename gtl_and< | |
225 y_i_high2, | |
226 typename is_mutable_interval_concept< | |
227 typename geometry_concept<IntervalType>::type | |
228 >::type | |
229 >::type, | |
230 void | |
231 >::type high(IntervalType& interval, | |
232 typename interval_mutable_traits<IntervalType>::coordinate_type value) { | |
233 set(interval, HIGH, value); | |
234 } | |
235 | |
236 struct y_i_equivalence : gtl_yes {}; | |
237 | |
238 template <typename IntervalType1, typename IntervalType2> | |
239 typename enable_if< | |
240 typename gtl_and_3< | |
241 y_i_equivalence, | |
242 typename is_interval_concept< | |
243 typename geometry_concept<IntervalType1>::type | |
244 >::type, | |
245 typename is_interval_concept< | |
246 typename geometry_concept<IntervalType2>::type | |
247 >::type | |
248 >::type, | |
249 bool | |
250 >::type equivalence( | |
251 const IntervalType1& interval1, | |
252 const IntervalType2& interval2) { | |
253 return (get(interval1, LOW) == get(interval2, LOW)) && | |
254 (get(interval1, HIGH) == get(interval2, HIGH)); | |
255 } | |
256 | |
257 struct y_i_contains : gtl_yes {}; | |
258 | |
259 template <typename IntervalType> | |
260 typename enable_if< | |
261 typename gtl_and< | |
262 y_i_contains, | |
263 typename is_interval_concept< | |
264 typename geometry_concept<IntervalType>::type | |
265 >::type | |
266 >::type, | |
267 bool | |
268 >::type contains( | |
269 const IntervalType& interval, | |
270 typename interval_coordinate_type<IntervalType>::type value, | |
271 bool consider_touch = true ) { | |
272 if (consider_touch) { | |
273 return value <= high(interval) && value >= low(interval); | |
274 } else { | |
275 return value < high(interval) && value > low(interval); | |
276 } | |
277 } | |
278 | |
279 struct y_i_contains2 : gtl_yes {}; | |
280 | |
281 template <typename IntervalType1, typename IntervalType2> | |
282 typename enable_if< | |
283 typename gtl_and_3< | |
284 y_i_contains2, | |
285 typename is_interval_concept< | |
286 typename geometry_concept<IntervalType1>::type | |
287 >::type, | |
288 typename is_interval_concept< | |
289 typename geometry_concept<IntervalType2>::type | |
290 >::type | |
291 >::type, | |
292 bool | |
293 >::type contains( | |
294 const IntervalType1& interval1, | |
295 const IntervalType2& interval2, | |
296 bool consider_touch = true) { | |
297 return contains(interval1, get(interval2, LOW), consider_touch) && | |
298 contains(interval1, get(interval2, HIGH), consider_touch); | |
299 } | |
300 | |
301 struct y_i_center : gtl_yes {}; | |
302 | |
303 template <typename IntervalType> | |
304 typename enable_if< | |
305 typename gtl_and< | |
306 y_i_center, | |
307 typename is_interval_concept< | |
308 typename geometry_concept<IntervalType>::type | |
309 >::type | |
310 >::type, | |
311 typename interval_coordinate_type<IntervalType>::type | |
312 >::type center(const IntervalType& interval) { | |
313 return (high(interval) + low(interval)) / 2; | |
314 } | |
315 | |
316 struct y_i_delta : gtl_yes {}; | |
317 | |
318 template <typename IntervalType> | |
319 typename enable_if< | |
320 typename gtl_and< | |
321 y_i_delta, | |
322 typename is_interval_concept< | |
323 typename geometry_concept<IntervalType>::type | |
324 >::type | |
325 >::type, | |
326 typename interval_difference_type<IntervalType>::type | |
327 >::type delta(const IntervalType& interval) { | |
328 typedef typename interval_difference_type<IntervalType>::type diff_type; | |
329 return static_cast<diff_type>(high(interval)) - | |
330 static_cast<diff_type>(low(interval)); | |
331 } | |
332 | |
333 struct y_i_flip : gtl_yes {}; | |
334 | |
335 template <typename IntervalType> | |
336 typename enable_if< | |
337 typename gtl_and< | |
338 y_i_flip, | |
339 typename is_mutable_interval_concept< | |
340 typename geometry_concept<IntervalType>::type | |
341 >::type | |
342 >::type, | |
343 IntervalType>::type& flip( | |
344 IntervalType& interval, | |
345 typename interval_coordinate_type<IntervalType>::type axis = 0) { | |
346 typename interval_coordinate_type<IntervalType>::type newLow, newHigh; | |
347 newLow = 2 * axis - high(interval); | |
348 newHigh = 2 * axis - low(interval); | |
349 low(interval, newLow); | |
350 high(interval, newHigh); | |
351 return interval; | |
352 } | |
353 | |
354 struct y_i_scale_up : gtl_yes {}; | |
355 | |
356 template <typename IntervalType> | |
357 typename enable_if< | |
358 typename gtl_and< | |
359 y_i_scale_up, | |
360 typename is_mutable_interval_concept< | |
361 typename geometry_concept<IntervalType>::type | |
362 >::type | |
363 >::type, | |
364 IntervalType | |
365 >::type& scale_up( | |
366 IntervalType& interval, | |
367 typename interval_coordinate_type<IntervalType>::type factor) { | |
368 typename interval_coordinate_type<IntervalType>::type newHigh = | |
369 high(interval) * factor; | |
370 low(interval, low(interval) * factor); | |
371 high(interval, (newHigh)); | |
372 return interval; | |
373 } | |
374 | |
375 struct y_i_scale_down : gtl_yes {}; | |
376 | |
377 template <typename IntervalType> | |
378 typename enable_if< | |
379 typename gtl_and< | |
380 y_i_scale_down, | |
381 typename is_mutable_interval_concept< | |
382 typename geometry_concept<IntervalType>::type | |
383 >::type | |
384 >::type, | |
385 IntervalType | |
386 >::type& scale_down( | |
387 IntervalType& interval, | |
388 typename interval_coordinate_type<IntervalType>::type factor) { | |
389 typedef typename interval_coordinate_type<IntervalType>::type Unit; | |
390 typename interval_coordinate_type<IntervalType>::type newHigh = | |
391 high(interval) / factor; | |
392 low(interval, low(interval) / factor); | |
393 high(interval, (newHigh)); | |
394 return interval; | |
395 } | |
396 | |
397 // TODO(asydorchuk): Deprecated. | |
398 struct y_i_scale : gtl_yes {}; | |
399 | |
400 template <typename IntervalType> | |
401 typename enable_if< | |
402 typename gtl_and< | |
403 y_i_scale, | |
404 typename is_mutable_interval_concept< | |
405 typename geometry_concept<IntervalType>::type | |
406 >::type | |
407 >::type, | |
408 IntervalType | |
409 >::type& scale(IntervalType& interval, double factor) { | |
410 typedef typename interval_coordinate_type<IntervalType>::type Unit; | |
411 Unit newHigh = scaling_policy<Unit>::round( | |
412 static_cast<double>(high(interval)) * factor); | |
413 low(interval, scaling_policy<Unit>::round( | |
414 static_cast<double>(low(interval)) * factor)); | |
415 high(interval, (newHigh)); | |
416 return interval; | |
417 } | |
418 | |
419 struct y_i_move : gtl_yes {}; | |
420 | |
421 template <typename IntervalType> | |
422 typename enable_if< | |
423 typename gtl_and< | |
424 y_i_move, | |
425 typename is_mutable_interval_concept< | |
426 typename geometry_concept<IntervalType>::type | |
427 >::type | |
428 >::type, | |
429 IntervalType | |
430 >::type& move( | |
431 IntervalType& interval, | |
432 typename interval_difference_type<IntervalType>::type displacement) { | |
433 typedef typename interval_coordinate_type<IntervalType>::type ctype; | |
434 typedef typename coordinate_traits<ctype>::coordinate_difference Unit; | |
435 low(interval, static_cast<ctype>( | |
436 static_cast<Unit>(low(interval)) + displacement)); | |
437 high(interval, static_cast<ctype>( | |
438 static_cast<Unit>(high(interval)) + displacement)); | |
439 return interval; | |
440 } | |
441 | |
442 struct y_i_convolve : gtl_yes {}; | |
443 | |
444 template <typename IntervalType> | |
445 typename enable_if< | |
446 typename gtl_and< | |
447 y_i_convolve, | |
448 typename is_mutable_interval_concept< | |
449 typename geometry_concept<IntervalType>::type | |
450 >::type | |
451 >::type, | |
452 IntervalType | |
453 >::type& convolve( | |
454 IntervalType& interval, | |
455 typename interval_coordinate_type<IntervalType>::type value) { | |
456 typedef typename interval_coordinate_type<IntervalType>::type Unit; | |
457 Unit newLow = low(interval) + value; | |
458 Unit newHigh = high(interval) + value; | |
459 low(interval, newLow); | |
460 high(interval, newHigh); | |
461 return interval; | |
462 } | |
463 | |
464 struct y_i_deconvolve : gtl_yes {}; | |
465 | |
466 template <typename IntervalType> | |
467 typename enable_if< | |
468 typename gtl_and< | |
469 y_i_deconvolve, | |
470 typename is_mutable_interval_concept< | |
471 typename geometry_concept<IntervalType>::type | |
472 >::type | |
473 >::type, | |
474 IntervalType | |
475 >::type& deconvolve( | |
476 IntervalType& interval, | |
477 typename interval_coordinate_type<IntervalType>::type value) { | |
478 typedef typename interval_coordinate_type<IntervalType>::type Unit; | |
479 Unit newLow = low(interval) - value; | |
480 Unit newHigh = high(interval) - value; | |
481 low(interval, newLow); | |
482 high(interval, newHigh); | |
483 return interval; | |
484 } | |
485 | |
486 struct y_i_convolve2 : gtl_yes {}; | |
487 | |
488 template <typename IntervalType1, typename IntervalType2> | |
489 typename enable_if< | |
490 typename gtl_and_3< | |
491 y_i_convolve2, | |
492 typename is_mutable_interval_concept< | |
493 typename geometry_concept<IntervalType1>::type | |
494 >::type, | |
495 typename is_interval_concept< | |
496 typename geometry_concept<IntervalType2>::type | |
497 >::type | |
498 >::type, | |
499 IntervalType1 | |
500 >::type& convolve(IntervalType1& lvalue, const IntervalType2& rvalue) { | |
501 typedef typename interval_coordinate_type<IntervalType1>::type Unit; | |
502 Unit newLow = low(lvalue) + low(rvalue); | |
503 Unit newHigh = high(lvalue) + high(rvalue); | |
504 low(lvalue, newLow); | |
505 high(lvalue, newHigh); | |
506 return lvalue; | |
507 } | |
508 | |
509 struct y_i_deconvolve2 : gtl_yes {}; | |
510 | |
511 template <typename IntervalType1, typename IntervalType2> | |
512 typename enable_if< | |
513 typename gtl_and_3< | |
514 y_i_deconvolve2, | |
515 typename is_mutable_interval_concept< | |
516 typename geometry_concept<IntervalType1>::type | |
517 >::type, | |
518 typename is_interval_concept< | |
519 typename geometry_concept<IntervalType2>::type | |
520 >::type | |
521 >::type, | |
522 IntervalType1 | |
523 >::type& deconvolve(IntervalType1& lvalue, const IntervalType2& rvalue) { | |
524 typedef typename interval_coordinate_type<IntervalType1>::type Unit; | |
525 Unit newLow = low(lvalue) - low(rvalue); | |
526 Unit newHigh = high(lvalue) - high(rvalue); | |
527 low(lvalue, newLow); | |
528 high(lvalue, newHigh); | |
529 return lvalue; | |
530 } | |
531 | |
532 struct y_i_reconvolve : gtl_yes {}; | |
533 | |
534 template <typename IntervalType1, typename IntervalType2> | |
535 typename enable_if< | |
536 typename gtl_and_3< | |
537 y_i_reconvolve, | |
538 typename is_mutable_interval_concept< | |
539 typename geometry_concept<IntervalType1>::type | |
540 >::type, | |
541 typename is_interval_concept< | |
542 typename geometry_concept<IntervalType2>::type | |
543 >::type | |
544 >::type, | |
545 IntervalType1 | |
546 >::type& reflected_convolve( | |
547 IntervalType1& lvalue, | |
548 const IntervalType2& rvalue) { | |
549 typedef typename interval_coordinate_type<IntervalType1>::type Unit; | |
550 Unit newLow = low(lvalue) - high(rvalue); | |
551 Unit newHigh = high(lvalue) - low(rvalue); | |
552 low(lvalue, newLow); | |
553 high(lvalue, newHigh); | |
554 return lvalue; | |
555 } | |
556 | |
557 struct y_i_redeconvolve : gtl_yes {}; | |
558 | |
559 template <typename IntervalType1, typename IntervalType2> | |
560 typename enable_if< | |
561 typename gtl_and_3< | |
562 y_i_redeconvolve, | |
563 typename is_mutable_interval_concept< | |
564 typename geometry_concept<IntervalType1>::type | |
565 >::type, | |
566 typename is_interval_concept< | |
567 typename geometry_concept<IntervalType2>::type | |
568 >::type | |
569 >::type, | |
570 IntervalType1 | |
571 >::type& reflected_deconvolve( | |
572 IntervalType1& lvalue, | |
573 const IntervalType2& rvalue) { | |
574 typedef typename interval_coordinate_type<IntervalType1>::type Unit; | |
575 Unit newLow = low(lvalue) + high(rvalue); | |
576 Unit newHigh = high(lvalue) + low(rvalue); | |
577 low(lvalue, newLow); | |
578 high(lvalue, newHigh); | |
579 return lvalue; | |
580 } | |
581 | |
582 struct y_i_e_dist1 : gtl_yes {}; | |
583 | |
584 template <typename IntervalType> | |
585 typename enable_if< | |
586 typename gtl_and<y_i_e_dist1, | |
587 typename is_interval_concept< | |
588 typename geometry_concept<IntervalType>::type | |
589 >::type | |
590 >::type, | |
591 typename interval_difference_type<IntervalType>::type | |
592 >::type euclidean_distance( | |
593 const IntervalType& interval, | |
594 typename interval_coordinate_type<IntervalType>::type position) { | |
595 typedef typename interval_difference_type<IntervalType>::type Unit; | |
596 Unit dist[3] = { | |
597 0, | |
598 (Unit)low(interval) - (Unit)position, | |
599 (Unit)position - (Unit)high(interval) | |
600 }; | |
601 return dist[(dist[1] > 0) + ((dist[2] > 0) << 1)]; | |
602 } | |
603 | |
604 struct y_i_e_dist2 : gtl_yes {}; | |
605 | |
606 template <typename IntervalType1, typename IntervalType2> | |
607 typename enable_if< | |
608 typename gtl_and_3< | |
609 y_i_e_dist2, | |
610 typename is_interval_concept< | |
611 typename geometry_concept<IntervalType1>::type | |
612 >::type, | |
613 typename is_interval_concept< | |
614 typename geometry_concept<IntervalType2>::type | |
615 >::type | |
616 >::type, | |
617 typename interval_difference_type<IntervalType1>::type | |
618 >::type euclidean_distance( | |
619 const IntervalType1& interval1, | |
620 const IntervalType2& interval2) { | |
621 typedef typename interval_difference_type<IntervalType1>::type Unit; | |
622 Unit dist[3] = { | |
623 0, | |
624 (Unit)low(interval1) - (Unit)high(interval2), | |
625 (Unit)low(interval2) - (Unit)high(interval1) | |
626 }; | |
627 return dist[(dist[1] > 0) + ((dist[2] > 0) << 1)]; | |
628 } | |
629 | |
630 struct y_i_e_intersects : gtl_yes {}; | |
631 | |
632 template <typename IntervalType1, typename IntervalType2> | |
633 typename enable_if< | |
634 typename gtl_and_3< | |
635 y_i_e_intersects, | |
636 typename is_interval_concept< | |
637 typename geometry_concept<IntervalType1>::type | |
638 >::type, | |
639 typename is_interval_concept< | |
640 typename geometry_concept<IntervalType2>::type | |
641 >::type | |
642 >::type, | |
643 bool | |
644 >::type intersects( | |
645 const IntervalType1& interval1, | |
646 const IntervalType2& interval2, | |
647 bool consider_touch = true) { | |
648 return consider_touch ? | |
649 (low(interval1) <= high(interval2)) && | |
650 (high(interval1) >= low(interval2)) : | |
651 (low(interval1) < high(interval2)) && | |
652 (high(interval1) > low(interval2)); | |
653 } | |
654 | |
655 struct y_i_e_bintersect : gtl_yes {}; | |
656 | |
657 template <typename IntervalType1, typename IntervalType2> | |
658 typename enable_if< | |
659 typename gtl_and_3< | |
660 y_i_e_bintersect, | |
661 typename is_interval_concept< | |
662 typename geometry_concept<IntervalType1>::type | |
663 >::type, | |
664 typename is_interval_concept< | |
665 typename geometry_concept<IntervalType2>::type | |
666 >::type | |
667 >::type, | |
668 bool | |
669 >::type boundaries_intersect( | |
670 const IntervalType1& interval1, | |
671 const IntervalType2& interval2, | |
672 bool consider_touch = true) { | |
673 return (contains(interval1, low(interval2), consider_touch) || | |
674 contains(interval1, high(interval2), consider_touch)) && | |
675 (contains(interval2, low(interval1), consider_touch) || | |
676 contains(interval2, high(interval1), consider_touch)); | |
677 } | |
678 | |
679 struct y_i_intersect : gtl_yes {}; | |
680 | |
681 template <typename IntervalType1, typename IntervalType2> | |
682 typename enable_if< | |
683 typename gtl_and_3< | |
684 y_i_intersect, | |
685 typename is_mutable_interval_concept< | |
686 typename geometry_concept<IntervalType1>::type | |
687 >::type, | |
688 typename is_interval_concept< | |
689 typename geometry_concept<IntervalType2>::type | |
690 >::type | |
691 >::type, | |
692 bool | |
693 >::type intersect( | |
694 IntervalType1& lvalue, | |
695 const IntervalType2& rvalue, | |
696 bool consider_touch = true) { | |
697 typedef typename interval_coordinate_type<IntervalType1>::type Unit; | |
698 Unit lowVal = (std::max)(low(lvalue), low(rvalue)); | |
699 Unit highVal = (std::min)(high(lvalue), high(rvalue)); | |
700 bool valid = consider_touch ? lowVal <= highVal : lowVal < highVal; | |
701 if (valid) { | |
702 low(lvalue, lowVal); | |
703 high(lvalue, highVal); | |
704 } | |
705 return valid; | |
706 } | |
707 | |
708 struct y_i_g_intersect : gtl_yes {}; | |
709 | |
710 // TODO(asydorchuk): Deprecated. | |
711 template <typename IntervalType1, typename IntervalType2> | |
712 typename enable_if< | |
713 typename gtl_and_3< | |
714 y_i_g_intersect, | |
715 typename is_mutable_interval_concept< | |
716 typename geometry_concept<IntervalType1>::type | |
717 >::type, | |
718 typename is_interval_concept< | |
719 typename geometry_concept<IntervalType2>::type | |
720 >::type | |
721 >::type, | |
722 IntervalType1 | |
723 >::type& generalized_intersect( | |
724 IntervalType1& lvalue, | |
725 const IntervalType2& rvalue) { | |
726 typedef typename interval_coordinate_type<IntervalType1>::type Unit; | |
727 Unit coords[4] = {low(lvalue), high(lvalue), low(rvalue), high(rvalue)}; | |
728 // TODO(asydorchuk): consider implementing faster sorting of small | |
729 // fixed length range. | |
730 polygon_sort(coords, coords+4); | |
731 low(lvalue, coords[1]); | |
732 high(lvalue, coords[2]); | |
733 return lvalue; | |
734 } | |
735 | |
736 struct y_i_abuts1 : gtl_yes {}; | |
737 | |
738 template <typename IntervalType1, typename IntervalType2> | |
739 typename enable_if< | |
740 typename gtl_and_3< | |
741 y_i_abuts1, | |
742 typename is_interval_concept< | |
743 typename geometry_concept<IntervalType1>::type | |
744 >::type, | |
745 typename is_interval_concept< | |
746 typename geometry_concept<IntervalType2>::type | |
747 >::type | |
748 >::type, | |
749 bool | |
750 >::type abuts( | |
751 const IntervalType1& interval1, | |
752 const IntervalType2& interval2, | |
753 direction_1d dir) { | |
754 return dir.to_int() ? low(interval2) == high(interval1) : | |
755 low(interval1) == high(interval2); | |
756 } | |
757 | |
758 struct y_i_abuts2 : gtl_yes {}; | |
759 | |
760 template <typename IntervalType1, typename IntervalType2> | |
761 typename enable_if< | |
762 typename gtl_and_3< | |
763 y_i_abuts2, | |
764 typename is_interval_concept< | |
765 typename geometry_concept<IntervalType1>::type | |
766 >::type, | |
767 typename is_interval_concept< | |
768 typename geometry_concept<IntervalType2>::type | |
769 >::type | |
770 >::type, | |
771 bool | |
772 >::type abuts( | |
773 const IntervalType1& interval1, | |
774 const IntervalType2& interval2) { | |
775 return abuts(interval1, interval2, HIGH) || | |
776 abuts(interval1, interval2, LOW); | |
777 } | |
778 | |
779 struct y_i_bloat : gtl_yes {}; | |
780 | |
781 template <typename IntervalType> | |
782 typename enable_if< | |
783 typename gtl_and< | |
784 y_i_bloat, | |
785 typename is_mutable_interval_concept< | |
786 typename geometry_concept<IntervalType>::type | |
787 >::type | |
788 >::type, | |
789 IntervalType | |
790 >::type& bloat( | |
791 IntervalType& interval, | |
792 typename interval_coordinate_type<IntervalType>::type bloating) { | |
793 low(interval, low(interval) - bloating); | |
794 high(interval, high(interval) + bloating); | |
795 return interval; | |
796 } | |
797 | |
798 struct y_i_bloat2 : gtl_yes {}; | |
799 | |
800 template <typename IntervalType> | |
801 typename enable_if< | |
802 typename gtl_and< | |
803 y_i_bloat2, | |
804 typename is_mutable_interval_concept< | |
805 typename geometry_concept<IntervalType>::type | |
806 >::type | |
807 >::type, | |
808 IntervalType | |
809 >::type& bloat( | |
810 IntervalType& interval, | |
811 direction_1d dir, | |
812 typename interval_coordinate_type<IntervalType>::type bloating) { | |
813 set(interval, dir, get(interval, dir) + dir.get_sign() * bloating); | |
814 return interval; | |
815 } | |
816 | |
817 struct y_i_shrink : gtl_yes {}; | |
818 | |
819 template <typename IntervalType> | |
820 typename enable_if< | |
821 typename gtl_and< | |
822 y_i_shrink, | |
823 typename is_mutable_interval_concept< | |
824 typename geometry_concept<IntervalType>::type | |
825 >::type | |
826 >::type, | |
827 IntervalType | |
828 >::type& shrink( | |
829 IntervalType& interval, | |
830 typename interval_coordinate_type<IntervalType>::type shrinking) { | |
831 return bloat(interval, -shrinking); | |
832 } | |
833 | |
834 struct y_i_shrink2 : gtl_yes {}; | |
835 | |
836 template <typename IntervalType> | |
837 typename enable_if< | |
838 typename gtl_and< | |
839 y_i_shrink2, | |
840 typename is_mutable_interval_concept< | |
841 typename geometry_concept<IntervalType>::type | |
842 >::type | |
843 >::type, | |
844 IntervalType | |
845 >::type& shrink( | |
846 IntervalType& interval, | |
847 direction_1d dir, | |
848 typename interval_coordinate_type<IntervalType>::type shrinking) { | |
849 return bloat(interval, dir, -shrinking); | |
850 } | |
851 | |
852 struct y_i_encompass : gtl_yes {}; | |
853 | |
854 template <typename IntervalType1, typename IntervalType2> | |
855 typename enable_if< | |
856 typename gtl_and_3< | |
857 y_i_encompass, | |
858 typename is_mutable_interval_concept< | |
859 typename geometry_concept<IntervalType1>::type | |
860 >::type, | |
861 typename is_interval_concept< | |
862 typename geometry_concept<IntervalType2>::type | |
863 >::type | |
864 >::type, | |
865 bool | |
866 >::type encompass(IntervalType1& interval1, const IntervalType2& interval2) { | |
867 bool retval = !contains(interval1, interval2, true); | |
868 low(interval1, (std::min)(low(interval1), low(interval2))); | |
869 high(interval1, (std::max)(high(interval1), high(interval2))); | |
870 return retval; | |
871 } | |
872 | |
873 struct y_i_encompass2 : gtl_yes {}; | |
874 | |
875 template <typename IntervalType> | |
876 typename enable_if< | |
877 typename gtl_and< | |
878 y_i_encompass2, | |
879 typename is_mutable_interval_concept< | |
880 typename geometry_concept<IntervalType>::type | |
881 >::type | |
882 >::type, | |
883 bool | |
884 >::type encompass( | |
885 IntervalType& interval, | |
886 typename interval_coordinate_type<IntervalType>::type value) { | |
887 bool retval = !contains(interval, value, true); | |
888 low(interval, (std::min)(low(interval), value)); | |
889 high(interval, (std::max)(high(interval), value)); | |
890 return retval; | |
891 } | |
892 | |
893 struct y_i_get_half : gtl_yes {}; | |
894 | |
895 template <typename IntervalType> | |
896 typename enable_if< | |
897 typename gtl_and< | |
898 y_i_get_half, | |
899 typename is_mutable_interval_concept< | |
900 typename geometry_concept<IntervalType>::type | |
901 >::type | |
902 >::type, | |
903 IntervalType | |
904 >::type get_half(const IntervalType& interval, direction_1d dir) { | |
905 typedef typename interval_coordinate_type<IntervalType>::type Unit; | |
906 Unit c = (get(interval, LOW) + get(interval, HIGH)) / 2; | |
907 return construct<IntervalType>( | |
908 (dir == LOW) ? get(interval, LOW) : c, | |
909 (dir == LOW) ? c : get(interval, HIGH)); | |
910 } | |
911 | |
912 struct y_i_join_with : gtl_yes {}; | |
913 | |
914 template <typename IntervalType1, typename IntervalType2> | |
915 typename enable_if< | |
916 typename gtl_and_3< | |
917 y_i_join_with, | |
918 typename is_mutable_interval_concept< | |
919 typename geometry_concept<IntervalType1>::type | |
920 >::type, | |
921 typename is_interval_concept< | |
922 typename geometry_concept<IntervalType2>::type | |
923 >::type>::type, | |
924 bool | |
925 >::type join_with(IntervalType1& interval1, const IntervalType2& interval2) { | |
926 if (abuts(interval1, interval2)) { | |
927 encompass(interval1, interval2); | |
928 return true; | |
929 } | |
930 return false; | |
931 } | |
932 } // polygon | |
933 } // boost | |
934 | |
935 #endif // BOOST_POLYGON_INTERVAL_CONCEPT_HPP |