/usr/include/boost/polygon/segment_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 | // Boost.Polygon library segment_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_SEGMENT_CONCEPT_HPP
#define BOOST_POLYGON_SEGMENT_CONCEPT_HPP
#include "isotropy.hpp"
#include "segment_traits.hpp"
#include "rectangle_concept.hpp"
namespace boost {
namespace polygon {
struct segment_concept {};
template <typename ConceptType>
struct is_segment_concept {
typedef gtl_no type;
};
template <>
struct is_segment_concept<segment_concept> {
typedef gtl_yes type;
};
template <typename ConceptType>
struct is_mutable_segment_concept {
typedef gtl_no type;
};
template <>
struct is_mutable_segment_concept<segment_concept> {
typedef gtl_yes type;
};
template <typename GeometryType, typename BoolType>
struct segment_distance_type_by_concept {
typedef void type;
};
template <typename GeometryType>
struct segment_distance_type_by_concept<GeometryType, gtl_yes> {
typedef typename coordinate_traits<
typename segment_traits<GeometryType>::coordinate_type
>::coordinate_distance type;
};
template <typename GeometryType>
struct segment_distance_type {
typedef typename segment_distance_type_by_concept<
GeometryType,
typename is_segment_concept<
typename geometry_concept<GeometryType>::type
>::type
>::type type;
};
template <typename GeometryType, typename BoolType>
struct segment_point_type_by_concept {
typedef void type;
};
template <typename GeometryType>
struct segment_point_type_by_concept<GeometryType, gtl_yes> {
typedef typename segment_traits<GeometryType>::point_type type;
};
template <typename GeometryType>
struct segment_point_type {
typedef typename segment_point_type_by_concept<
GeometryType,
typename is_segment_concept<
typename geometry_concept<GeometryType>::type
>::type
>::type type;
};
template <typename GeometryType, typename BoolType>
struct segment_coordinate_type_by_concept {
typedef void type;
};
template <typename GeometryType>
struct segment_coordinate_type_by_concept<GeometryType, gtl_yes> {
typedef typename segment_traits<GeometryType>::coordinate_type type;
};
template <typename GeometryType>
struct segment_coordinate_type {
typedef typename segment_coordinate_type_by_concept<
GeometryType,
typename is_segment_concept<
typename geometry_concept<GeometryType>::type
>::type
>::type type;
};
struct y_s_get : gtl_yes {};
template <typename Segment>
typename enable_if<
typename gtl_and<
y_s_get,
typename is_segment_concept<
typename geometry_concept<Segment>::type
>::type
>::type,
typename segment_point_type<Segment>::type>::type
get(const Segment& segment, direction_1d dir) {
return segment_traits<Segment>::get(segment, dir);
}
struct y_s_set : gtl_yes {};
template <typename Segment, typename Point>
typename enable_if<
typename gtl_and_3<
y_s_set,
typename is_mutable_segment_concept<
typename geometry_concept<Segment>::type
>::type,
typename is_point_concept<
typename geometry_concept<Point>::type
>::type
>::type,
void>::type set(Segment& segment, direction_1d dir, const Point& point) {
segment_mutable_traits<Segment>::set(segment, dir, point);
}
struct y_s_construct : gtl_yes {};
template <typename Segment, typename Point1, typename Point2>
typename enable_if<
typename gtl_and_4<
y_s_construct,
typename is_mutable_segment_concept<
typename geometry_concept<Segment>::type
>::type,
typename is_point_concept<
typename geometry_concept<Point1>::type
>::type,
typename is_point_concept<
typename geometry_concept<Point2>::type
>::type
>::type,
Segment>::type construct(const Point1& low, const Point2& high) {
return segment_mutable_traits<Segment>::construct(low, high);
}
struct y_s_copy_construct : gtl_yes {};
template <typename Segment1, typename Segment2>
typename enable_if<
typename gtl_and_3<
y_s_copy_construct,
typename is_mutable_segment_concept<
typename geometry_concept<Segment1>::type
>::type,
typename is_segment_concept<
typename geometry_concept<Segment2>::type
>::type
>::type,
Segment1>::type copy_construct(const Segment2& segment) {
return construct<Segment1>(get(segment, LOW), get(segment, HIGH));
}
struct y_s_assign : gtl_yes {};
template <typename Segment1, typename Segment2>
typename enable_if<
typename gtl_and_3<
y_s_assign,
typename is_mutable_segment_concept<
typename geometry_concept<Segment1>::type
>::type,
typename is_segment_concept<
typename geometry_concept<Segment2>::type
>::type
>::type,
Segment1>::type& assign(Segment1& segment1, const Segment2& segment2) {
return segment1 = copy_construct<Segment1>(segment2);
}
struct y_s_equivalence : gtl_yes {};
template <typename Segment1, typename Segment2>
typename enable_if<
typename gtl_and_3<
y_s_equivalence,
typename is_segment_concept<
typename geometry_concept<Segment1>::type
>::type,
typename is_segment_concept<
typename geometry_concept<Segment2>::type
>::type
>::type,
bool>::type equivalence(const Segment1& segment1, const Segment2& segment2) {
return get(segment1, LOW) == get(segment2, LOW) &&
get(segment1, HIGH) == get(segment2, HIGH);
}
struct y_s_low : gtl_yes {};
template <typename Segment>
typename enable_if<
typename gtl_and<
y_s_low,
typename is_segment_concept<
typename geometry_concept<Segment>::type
>::type
>::type,
typename segment_point_type<Segment>::type>::type low(const Segment& segment) {
return get(segment, LOW);
}
struct y_s_high : gtl_yes {};
template <typename Segment>
typename enable_if<
typename gtl_and<
y_s_high,
typename is_segment_concept<
typename geometry_concept<Segment>::type
>::type
>::type,
typename segment_point_type<Segment>::type>::type high(const Segment& segment) {
return get(segment, HIGH);
}
struct y_s_center : gtl_yes {};
template <typename Segment>
typename enable_if<
typename gtl_and<
y_s_center,
typename is_segment_concept<
typename geometry_concept<Segment>::type
>::type
>::type,
typename segment_point_type<Segment>::type>::type
center(const Segment& segment) {
return construct<typename segment_point_type<Segment>::type>(
(x(high(segment)) + x(low(segment)))/2,
(y(high(segment)) + y(low(segment)))/2);
}
struct y_s_low2 : gtl_yes {};
template <typename Segment, typename Point>
typename enable_if<
typename gtl_and_3<
y_s_low2,
typename is_mutable_segment_concept<
typename geometry_concept<Segment>::type
>::type,
typename is_point_concept<
typename geometry_concept<Point>::type
>::type
>::type,
void>::type low(Segment& segment, const Point& point) {
set(segment, LOW, point);
}
struct y_s_high2 : gtl_yes {};
template <typename Segment, typename Point>
typename enable_if<
typename gtl_and_3<
y_s_high2,
typename is_mutable_segment_concept<
typename geometry_concept<Segment>::type
>::type,
typename is_point_concept<
typename geometry_concept<Point>::type
>::type
>::type,
void>::type high(Segment& segment, const Point& point) {
set(segment, HIGH, point);
}
struct y_s_orientation1 : gtl_yes {};
// -1 for CW, 0 for collinear and 1 for CCW.
template <typename Segment1, typename Segment2>
typename enable_if<
typename gtl_and_3<
y_s_orientation1,
typename is_segment_concept<
typename geometry_concept<Segment1>::type
>::type,
typename is_segment_concept<
typename geometry_concept<Segment2>::type
>::type
>::type,
int>::type orientation(const Segment1& segment1, const Segment2& segment2) {
typedef typename coordinate_traits<
typename segment_traits<Segment1>::coordinate_type
>::manhattan_area_type int_x2;
typedef typename coordinate_traits<
typename segment_traits<Segment1>::coordinate_type
>::unsigned_area_type uint_x2;
int_x2 a1 = (int_x2)x(high(segment1)) - (int_x2)x(low(segment1));
int_x2 b1 = (int_x2)y(high(segment1)) - (int_x2)y(low(segment1));
int_x2 a2 = (int_x2)x(high(segment2)) - (int_x2)x(low(segment2));
int_x2 b2 = (int_x2)y(high(segment2)) - (int_x2)y(low(segment2));
int sign1 = 0;
int sign2 = 0;
if (a1 && b2)
sign1 = ((a1 > 0) ^ (b2 > 0)) ? -1 : 1;
if (a2 && b1)
sign2 = ((a2 > 0) ^ (b1 > 0)) ? -1 : 1;
if (sign1 != sign2)
return (sign1 < sign2) ? -1 : 1;
uint_x2 a3 = (uint_x2)(a1 < 0 ? -a1 : a1) * (uint_x2)(b2 < 0 ? -b2 : b2);
uint_x2 b3 = (uint_x2)(b1 < 0 ? -b1 : b1) * (uint_x2)(a2 < 0 ? -a2 : a2);
if (a3 == b3)
return 0;
return ((a3 < b3) ^ (sign1 == 1)) ? 1 : -1;
}
struct y_s_orientation2 : gtl_yes {};
// -1 for right, 0 for collinear and 1 for left.
template <typename Segment, typename Point>
typename enable_if<
typename gtl_and_3<
y_s_orientation2,
typename is_segment_concept<
typename geometry_concept<Segment>::type
>::type,
typename is_point_concept<
typename geometry_concept<Point>::type
>::type
>::type,
int>::type orientation(const Segment& segment, const Point& point) {
Segment segment2 = construct<Segment>(high(segment), point);
return orientation(segment, segment2);
}
struct y_s_contains : gtl_yes {};
template <typename Segment, typename Point>
typename enable_if<
typename gtl_and_3<
y_s_contains,
typename is_segment_concept<
typename geometry_concept<Segment>::type
>::type,
typename is_point_concept<
typename geometry_concept<Point>::type
>::type
>::type,
bool>::type contains(const Segment& segment,
const Point& point, bool consider_touch = true ) {
if (orientation(segment, point))
return false;
rectangle_data<typename segment_coordinate_type<Segment>::type> rect;
set_points(rect, low(segment), high(segment));
if (!contains(rect, point, true))
return false;
if (!consider_touch &&
(equivalence(low(segment), point) ||
equivalence(high(segment), point)))
return false;
return true;
}
struct y_s_contains2 : gtl_yes {};
template <typename Segment1, typename Segment2>
typename enable_if<
typename gtl_and_3<
y_s_contains2,
typename is_segment_concept<
typename geometry_concept<Segment1>::type
>::type,
typename is_segment_concept<
typename geometry_concept<Segment2>::type
>::type
>::type,
bool>::type contains(const Segment1& segment1,
const Segment2& segment2, bool consider_touch = true) {
return contains(segment1, get(segment2, LOW), consider_touch) &&
contains(segment1, get(segment2, HIGH), consider_touch);
}
struct y_s_length : gtl_yes {};
template <typename Segment>
typename enable_if<
typename gtl_and<
y_s_length,
typename is_segment_concept<
typename geometry_concept<Segment>::type
>::type
>::type,
typename segment_distance_type<Segment>::type>::type
length(const Segment& segment) {
return euclidean_distance(low(segment), high(segment));
}
struct y_s_scale_up : gtl_yes {};
template <typename Segment>
typename enable_if<
typename gtl_and<
y_s_scale_up,
typename is_mutable_segment_concept<
typename geometry_concept<Segment>::type
>::type
>::type,
Segment>::type& scale_up(Segment& segment,
typename coordinate_traits<
typename segment_coordinate_type<Segment>::type
>::unsigned_area_type factor) {
typename segment_point_type<Segment>::type l = low(segment);
typename segment_point_type<Segment>::type h = high(segment);
low(segment, scale_up(l, factor));
high(segment, scale_up(h, factor));
return segment;
}
struct y_s_scale_down : gtl_yes {};
template <typename Segment>
typename enable_if<
typename gtl_and<
y_s_scale_down,
typename is_mutable_segment_concept<
typename geometry_concept<Segment>::type
>::type
>::type,
Segment>::type& scale_down(Segment& segment,
typename coordinate_traits<
typename segment_coordinate_type<Segment>::type
>::unsigned_area_type factor) {
typename segment_point_type<Segment>::type l = low(segment);
typename segment_point_type<Segment>::type h = high(segment);
low(segment, scale_down(l, factor));
high(segment, scale_down(h, factor));
return segment;
}
struct y_s_scale : gtl_yes {};
template <typename Segment, typename Scale>
typename enable_if<
typename gtl_and<
y_s_scale,
typename is_mutable_segment_concept<
typename geometry_concept<Segment>::type
>::type
>::type,
Segment>::type& scale(Segment& segment, const Scale& sc) {
typename segment_point_type<Segment>::type l = low(segment);
typename segment_point_type<Segment>::type h = high(segment);
low(segment, scale(l, sc));
high(segment, scale(h, sc));
return segment;
}
struct y_s_transform : gtl_yes {};
template <typename Segment, typename Transform>
typename enable_if<
typename gtl_and<
y_s_transform,
typename is_mutable_segment_concept<
typename geometry_concept<Segment>::type
>::type
>::type,
Segment>::type& transform(Segment& segment, const Transform& tr) {
typename segment_point_type<Segment>::type l = low(segment);
typename segment_point_type<Segment>::type h = high(segment);
low(segment, transform(l, tr));
high(segment, transform(h, tr));
return segment;
}
struct y_s_move : gtl_yes {};
template <typename Segment>
typename enable_if<
typename gtl_and<
y_s_move,
typename is_mutable_segment_concept<
typename geometry_concept<Segment>::type
>::type
>::type,
Segment>::type& move(Segment& segment, orientation_2d orient,
typename segment_coordinate_type<Segment>::type displacement) {
typename segment_point_type<Segment>::type l = low(segment);
typename segment_point_type<Segment>::type h = high(segment);
low(segment, move(l, orient, displacement));
high(segment, move(h, orient, displacement));
return segment;
}
struct y_s_convolve : gtl_yes {};
template <typename Segment, typename Point>
typename enable_if<
typename gtl_and_3<
y_s_convolve,
typename is_mutable_segment_concept<
typename geometry_concept<Segment>::type
>::type,
typename is_point_concept<
typename geometry_concept<Point>::type
>::type
>::type,
Segment>::type& convolve(Segment& segment, const Point& point) {
typename segment_point_type<Segment>::type l = low(segment);
typename segment_point_type<Segment>::type h = high(segment);
low(segment, convolve(l, point));
high(segment, convolve(h, point));
return segment;
}
struct y_s_deconvolve : gtl_yes {};
template <typename Segment, typename Point>
typename enable_if<
typename gtl_and_3<
y_s_deconvolve,
typename is_mutable_segment_concept<
typename geometry_concept<Segment>::type
>::type,
typename is_point_concept<
typename geometry_concept<Point>::type
>::type
>::type,
Segment>::type& deconvolve(Segment& segment, const Point& point) {
typename segment_point_type<Segment>::type l = low(segment);
typename segment_point_type<Segment>::type h = high(segment);
low(segment, deconvolve(l, point));
high(segment, deconvolve(h, point));
return segment;
}
struct y_s_abuts1 : gtl_yes {};
template <typename Segment1, typename Segment2>
typename enable_if<
typename gtl_and_3<
y_s_abuts1,
typename is_segment_concept<
typename geometry_concept<Segment1>::type
>::type,
typename is_segment_concept<
typename geometry_concept<Segment2>::type
>::type
>::type,
bool>::type abuts(const Segment1& segment1,
const Segment2& segment2, direction_1d dir) {
return dir.to_int() ? equivalence(low(segment2) , high(segment1)) :
equivalence(low(segment1) , high(segment2));
}
struct y_s_abuts2 : gtl_yes {};
template <typename Segment1, typename Segment2>
typename enable_if<
typename gtl_and_3<
y_s_abuts2,
typename is_segment_concept<
typename geometry_concept<Segment1>::type
>::type,
typename is_segment_concept<
typename geometry_concept<Segment2>::type
>::type
>::type,
bool>::type abuts(const Segment1& segment1, const Segment2& segment2) {
return abuts(segment1, segment2, HIGH) || abuts(segment1, segment2, LOW);
}
struct y_s_e_intersects : gtl_yes {};
template <typename Segment1, typename Segment2>
typename enable_if<
typename gtl_and_3<
y_s_e_intersects,
typename is_segment_concept<
typename geometry_concept<Segment1>::type
>::type,
typename is_segment_concept<
typename geometry_concept<Segment2>::type
>::type
>::type,
bool
>::type intersects(const Segment1& segment1, const Segment2& segment2,
bool consider_touch = true) {
rectangle_data<typename segment_coordinate_type<Segment1>::type> rect1, rect2;
set_points(rect1, low(segment1), high(segment1));
set_points(rect2, low(segment2), high(segment2));
// Check if axis-parallel rectangles containing segments intersect.
if (!intersects(rect1, rect2, true))
return false;
int or1_1 = orientation(segment1, low(segment2));
int or1_2 = orientation(segment1, high(segment2));
if (or1_1 * or1_2 > 0)
return false;
int or2_1 = orientation(segment2, low(segment1));
int or2_2 = orientation(segment2, high(segment1));
if (or2_1 * or2_2 > 0)
return false;
if (consider_touch || (or1_1 && or1_2) || (or2_1 && or2_2))
return true;
if (or1_1 || or1_2)
return false;
return intersects(vertical(rect1), vertical(rect2), false) ||
intersects(horizontal(rect1), horizontal(rect2), false);
}
struct y_s_e_dist : gtl_yes {};
template <typename Segment, typename Point>
typename enable_if<
typename gtl_and_3<
y_s_e_dist,
typename is_segment_concept<
typename geometry_concept<Segment>::type
>::type,
typename is_point_concept<
typename geometry_concept<Point>::type
>::type
>::type,
typename segment_distance_type<Segment>::type>::type
euclidean_distance(const Segment& segment, const Point& point) {
typedef typename segment_distance_type<Segment>::type Unit;
Unit x1 = x(low(segment));
Unit y1 = y(low(segment));
Unit x2 = x(high(segment));
Unit y2 = y(high(segment));
Unit X = x(point);
Unit Y = y(point);
Unit A = X - x1;
Unit B = Y - y1;
Unit C = x2 - x1;
Unit D = y2 - y1;
Unit param = (A * C + B * D);
Unit length_sq = C * C + D * D;
if (param > length_sq) {
return euclidean_distance(high(segment), point);
} else if (param < 0.0) {
return euclidean_distance(low(segment), point);
}
if (length_sq == 0.0)
return 0.0;
Unit denom = std::sqrt(length_sq);
Unit result = (A * D - C * B) / denom;
return (result < 0.0) ? -result : result;
}
struct y_s_e_dist2 : gtl_yes {};
template <typename Segment1, typename Segment2>
typename enable_if<
typename gtl_and_3<
y_s_e_dist2,
typename is_segment_concept<
typename geometry_concept<Segment1>::type
>::type,
typename is_segment_concept<
typename geometry_concept<Segment2>::type
>::type
>::type,
typename segment_distance_type<Segment1>::type>::type
euclidean_distance(const Segment1& segment1, const Segment2& segment2) {
if (intersects(segment1, segment2))
return 0.0;
typename segment_distance_type<Segment1>::type
result1 = euclidean_distance(segment1, low(segment2)),
result2 = euclidean_distance(segment1, high(segment2)),
result3 = euclidean_distance(segment2, low(segment1)),
result4 = euclidean_distance(segment2, high(segment1));
if (result2 < result1)
result1 = result2;
if (result4 < result3)
result3 = result4;
return (result1 < result3) ? result1 : result3;
}
} // polygon
} // boost
#endif // BOOST_POLYGON_SEGMENT_CONCEPT_HPP
|