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