annotate DEPENDENCIES/generic/include/boost/polygon/interval_concept.hpp @ 125:34e428693f5d vext

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