annotate 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
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 typedef typename interval_coordinate_type<IntervalType>::type Unit;
Chris@16 390 typename interval_coordinate_type<IntervalType>::type newHigh =
Chris@16 391 high(interval) / factor;
Chris@16 392 low(interval, low(interval) / factor);
Chris@16 393 high(interval, (newHigh));
Chris@16 394 return interval;
Chris@16 395 }
Chris@16 396
Chris@16 397 // TODO(asydorchuk): Deprecated.
Chris@16 398 struct y_i_scale : gtl_yes {};
Chris@16 399
Chris@16 400 template <typename IntervalType>
Chris@16 401 typename enable_if<
Chris@16 402 typename gtl_and<
Chris@16 403 y_i_scale,
Chris@16 404 typename is_mutable_interval_concept<
Chris@16 405 typename geometry_concept<IntervalType>::type
Chris@16 406 >::type
Chris@16 407 >::type,
Chris@16 408 IntervalType
Chris@16 409 >::type& scale(IntervalType& interval, double factor) {
Chris@16 410 typedef typename interval_coordinate_type<IntervalType>::type Unit;
Chris@16 411 Unit newHigh = scaling_policy<Unit>::round(
Chris@16 412 static_cast<double>(high(interval)) * factor);
Chris@16 413 low(interval, scaling_policy<Unit>::round(
Chris@16 414 static_cast<double>(low(interval)) * factor));
Chris@16 415 high(interval, (newHigh));
Chris@16 416 return interval;
Chris@16 417 }
Chris@16 418
Chris@16 419 struct y_i_move : gtl_yes {};
Chris@16 420
Chris@16 421 template <typename IntervalType>
Chris@16 422 typename enable_if<
Chris@16 423 typename gtl_and<
Chris@16 424 y_i_move,
Chris@16 425 typename is_mutable_interval_concept<
Chris@16 426 typename geometry_concept<IntervalType>::type
Chris@16 427 >::type
Chris@16 428 >::type,
Chris@16 429 IntervalType
Chris@16 430 >::type& move(
Chris@16 431 IntervalType& interval,
Chris@16 432 typename interval_difference_type<IntervalType>::type displacement) {
Chris@16 433 typedef typename interval_coordinate_type<IntervalType>::type ctype;
Chris@16 434 typedef typename coordinate_traits<ctype>::coordinate_difference Unit;
Chris@16 435 low(interval, static_cast<ctype>(
Chris@16 436 static_cast<Unit>(low(interval)) + displacement));
Chris@16 437 high(interval, static_cast<ctype>(
Chris@16 438 static_cast<Unit>(high(interval)) + displacement));
Chris@16 439 return interval;
Chris@16 440 }
Chris@16 441
Chris@16 442 struct y_i_convolve : gtl_yes {};
Chris@16 443
Chris@16 444 template <typename IntervalType>
Chris@16 445 typename enable_if<
Chris@16 446 typename gtl_and<
Chris@16 447 y_i_convolve,
Chris@16 448 typename is_mutable_interval_concept<
Chris@16 449 typename geometry_concept<IntervalType>::type
Chris@16 450 >::type
Chris@16 451 >::type,
Chris@16 452 IntervalType
Chris@16 453 >::type& convolve(
Chris@16 454 IntervalType& interval,
Chris@16 455 typename interval_coordinate_type<IntervalType>::type value) {
Chris@16 456 typedef typename interval_coordinate_type<IntervalType>::type Unit;
Chris@16 457 Unit newLow = low(interval) + value;
Chris@16 458 Unit newHigh = high(interval) + value;
Chris@16 459 low(interval, newLow);
Chris@16 460 high(interval, newHigh);
Chris@16 461 return interval;
Chris@16 462 }
Chris@16 463
Chris@16 464 struct y_i_deconvolve : gtl_yes {};
Chris@16 465
Chris@16 466 template <typename IntervalType>
Chris@16 467 typename enable_if<
Chris@16 468 typename gtl_and<
Chris@16 469 y_i_deconvolve,
Chris@16 470 typename is_mutable_interval_concept<
Chris@16 471 typename geometry_concept<IntervalType>::type
Chris@16 472 >::type
Chris@16 473 >::type,
Chris@16 474 IntervalType
Chris@16 475 >::type& deconvolve(
Chris@16 476 IntervalType& interval,
Chris@16 477 typename interval_coordinate_type<IntervalType>::type value) {
Chris@16 478 typedef typename interval_coordinate_type<IntervalType>::type Unit;
Chris@16 479 Unit newLow = low(interval) - value;
Chris@16 480 Unit newHigh = high(interval) - value;
Chris@16 481 low(interval, newLow);
Chris@16 482 high(interval, newHigh);
Chris@16 483 return interval;
Chris@16 484 }
Chris@16 485
Chris@16 486 struct y_i_convolve2 : gtl_yes {};
Chris@16 487
Chris@16 488 template <typename IntervalType1, typename IntervalType2>
Chris@16 489 typename enable_if<
Chris@16 490 typename gtl_and_3<
Chris@16 491 y_i_convolve2,
Chris@16 492 typename is_mutable_interval_concept<
Chris@16 493 typename geometry_concept<IntervalType1>::type
Chris@16 494 >::type,
Chris@16 495 typename is_interval_concept<
Chris@16 496 typename geometry_concept<IntervalType2>::type
Chris@16 497 >::type
Chris@16 498 >::type,
Chris@16 499 IntervalType1
Chris@16 500 >::type& convolve(IntervalType1& lvalue, const IntervalType2& rvalue) {
Chris@16 501 typedef typename interval_coordinate_type<IntervalType1>::type Unit;
Chris@16 502 Unit newLow = low(lvalue) + low(rvalue);
Chris@16 503 Unit newHigh = high(lvalue) + high(rvalue);
Chris@16 504 low(lvalue, newLow);
Chris@16 505 high(lvalue, newHigh);
Chris@16 506 return lvalue;
Chris@16 507 }
Chris@16 508
Chris@16 509 struct y_i_deconvolve2 : gtl_yes {};
Chris@16 510
Chris@16 511 template <typename IntervalType1, typename IntervalType2>
Chris@16 512 typename enable_if<
Chris@16 513 typename gtl_and_3<
Chris@16 514 y_i_deconvolve2,
Chris@16 515 typename is_mutable_interval_concept<
Chris@16 516 typename geometry_concept<IntervalType1>::type
Chris@16 517 >::type,
Chris@16 518 typename is_interval_concept<
Chris@16 519 typename geometry_concept<IntervalType2>::type
Chris@16 520 >::type
Chris@16 521 >::type,
Chris@16 522 IntervalType1
Chris@16 523 >::type& deconvolve(IntervalType1& lvalue, const IntervalType2& rvalue) {
Chris@16 524 typedef typename interval_coordinate_type<IntervalType1>::type Unit;
Chris@16 525 Unit newLow = low(lvalue) - low(rvalue);
Chris@16 526 Unit newHigh = high(lvalue) - high(rvalue);
Chris@16 527 low(lvalue, newLow);
Chris@16 528 high(lvalue, newHigh);
Chris@16 529 return lvalue;
Chris@16 530 }
Chris@16 531
Chris@16 532 struct y_i_reconvolve : gtl_yes {};
Chris@16 533
Chris@16 534 template <typename IntervalType1, typename IntervalType2>
Chris@16 535 typename enable_if<
Chris@16 536 typename gtl_and_3<
Chris@16 537 y_i_reconvolve,
Chris@16 538 typename is_mutable_interval_concept<
Chris@16 539 typename geometry_concept<IntervalType1>::type
Chris@16 540 >::type,
Chris@16 541 typename is_interval_concept<
Chris@16 542 typename geometry_concept<IntervalType2>::type
Chris@16 543 >::type
Chris@16 544 >::type,
Chris@16 545 IntervalType1
Chris@16 546 >::type& reflected_convolve(
Chris@16 547 IntervalType1& lvalue,
Chris@16 548 const IntervalType2& rvalue) {
Chris@16 549 typedef typename interval_coordinate_type<IntervalType1>::type Unit;
Chris@16 550 Unit newLow = low(lvalue) - high(rvalue);
Chris@16 551 Unit newHigh = high(lvalue) - low(rvalue);
Chris@16 552 low(lvalue, newLow);
Chris@16 553 high(lvalue, newHigh);
Chris@16 554 return lvalue;
Chris@16 555 }
Chris@16 556
Chris@16 557 struct y_i_redeconvolve : gtl_yes {};
Chris@16 558
Chris@16 559 template <typename IntervalType1, typename IntervalType2>
Chris@16 560 typename enable_if<
Chris@16 561 typename gtl_and_3<
Chris@16 562 y_i_redeconvolve,
Chris@16 563 typename is_mutable_interval_concept<
Chris@16 564 typename geometry_concept<IntervalType1>::type
Chris@16 565 >::type,
Chris@16 566 typename is_interval_concept<
Chris@16 567 typename geometry_concept<IntervalType2>::type
Chris@16 568 >::type
Chris@16 569 >::type,
Chris@16 570 IntervalType1
Chris@16 571 >::type& reflected_deconvolve(
Chris@16 572 IntervalType1& lvalue,
Chris@16 573 const IntervalType2& rvalue) {
Chris@16 574 typedef typename interval_coordinate_type<IntervalType1>::type Unit;
Chris@16 575 Unit newLow = low(lvalue) + high(rvalue);
Chris@16 576 Unit newHigh = high(lvalue) + low(rvalue);
Chris@16 577 low(lvalue, newLow);
Chris@16 578 high(lvalue, newHigh);
Chris@16 579 return lvalue;
Chris@16 580 }
Chris@16 581
Chris@16 582 struct y_i_e_dist1 : gtl_yes {};
Chris@16 583
Chris@16 584 template <typename IntervalType>
Chris@16 585 typename enable_if<
Chris@16 586 typename gtl_and<y_i_e_dist1,
Chris@16 587 typename is_interval_concept<
Chris@16 588 typename geometry_concept<IntervalType>::type
Chris@16 589 >::type
Chris@16 590 >::type,
Chris@16 591 typename interval_difference_type<IntervalType>::type
Chris@16 592 >::type euclidean_distance(
Chris@16 593 const IntervalType& interval,
Chris@16 594 typename interval_coordinate_type<IntervalType>::type position) {
Chris@16 595 typedef typename interval_difference_type<IntervalType>::type Unit;
Chris@16 596 Unit dist[3] = {
Chris@16 597 0,
Chris@16 598 (Unit)low(interval) - (Unit)position,
Chris@16 599 (Unit)position - (Unit)high(interval)
Chris@16 600 };
Chris@16 601 return dist[(dist[1] > 0) + ((dist[2] > 0) << 1)];
Chris@16 602 }
Chris@16 603
Chris@16 604 struct y_i_e_dist2 : gtl_yes {};
Chris@16 605
Chris@16 606 template <typename IntervalType1, typename IntervalType2>
Chris@16 607 typename enable_if<
Chris@16 608 typename gtl_and_3<
Chris@16 609 y_i_e_dist2,
Chris@16 610 typename is_interval_concept<
Chris@16 611 typename geometry_concept<IntervalType1>::type
Chris@16 612 >::type,
Chris@16 613 typename is_interval_concept<
Chris@16 614 typename geometry_concept<IntervalType2>::type
Chris@16 615 >::type
Chris@16 616 >::type,
Chris@16 617 typename interval_difference_type<IntervalType1>::type
Chris@16 618 >::type euclidean_distance(
Chris@16 619 const IntervalType1& interval1,
Chris@16 620 const IntervalType2& interval2) {
Chris@16 621 typedef typename interval_difference_type<IntervalType1>::type Unit;
Chris@16 622 Unit dist[3] = {
Chris@16 623 0,
Chris@16 624 (Unit)low(interval1) - (Unit)high(interval2),
Chris@16 625 (Unit)low(interval2) - (Unit)high(interval1)
Chris@16 626 };
Chris@16 627 return dist[(dist[1] > 0) + ((dist[2] > 0) << 1)];
Chris@16 628 }
Chris@16 629
Chris@16 630 struct y_i_e_intersects : gtl_yes {};
Chris@16 631
Chris@16 632 template <typename IntervalType1, typename IntervalType2>
Chris@16 633 typename enable_if<
Chris@16 634 typename gtl_and_3<
Chris@16 635 y_i_e_intersects,
Chris@16 636 typename is_interval_concept<
Chris@16 637 typename geometry_concept<IntervalType1>::type
Chris@16 638 >::type,
Chris@16 639 typename is_interval_concept<
Chris@16 640 typename geometry_concept<IntervalType2>::type
Chris@16 641 >::type
Chris@16 642 >::type,
Chris@16 643 bool
Chris@16 644 >::type intersects(
Chris@16 645 const IntervalType1& interval1,
Chris@16 646 const IntervalType2& interval2,
Chris@16 647 bool consider_touch = true) {
Chris@16 648 return consider_touch ?
Chris@16 649 (low(interval1) <= high(interval2)) &&
Chris@16 650 (high(interval1) >= low(interval2)) :
Chris@16 651 (low(interval1) < high(interval2)) &&
Chris@16 652 (high(interval1) > low(interval2));
Chris@16 653 }
Chris@16 654
Chris@16 655 struct y_i_e_bintersect : gtl_yes {};
Chris@16 656
Chris@16 657 template <typename IntervalType1, typename IntervalType2>
Chris@16 658 typename enable_if<
Chris@16 659 typename gtl_and_3<
Chris@16 660 y_i_e_bintersect,
Chris@16 661 typename is_interval_concept<
Chris@16 662 typename geometry_concept<IntervalType1>::type
Chris@16 663 >::type,
Chris@16 664 typename is_interval_concept<
Chris@16 665 typename geometry_concept<IntervalType2>::type
Chris@16 666 >::type
Chris@16 667 >::type,
Chris@16 668 bool
Chris@16 669 >::type boundaries_intersect(
Chris@16 670 const IntervalType1& interval1,
Chris@16 671 const IntervalType2& interval2,
Chris@16 672 bool consider_touch = true) {
Chris@16 673 return (contains(interval1, low(interval2), consider_touch) ||
Chris@16 674 contains(interval1, high(interval2), consider_touch)) &&
Chris@16 675 (contains(interval2, low(interval1), consider_touch) ||
Chris@16 676 contains(interval2, high(interval1), consider_touch));
Chris@16 677 }
Chris@16 678
Chris@16 679 struct y_i_intersect : gtl_yes {};
Chris@16 680
Chris@16 681 template <typename IntervalType1, typename IntervalType2>
Chris@16 682 typename enable_if<
Chris@16 683 typename gtl_and_3<
Chris@16 684 y_i_intersect,
Chris@16 685 typename is_mutable_interval_concept<
Chris@16 686 typename geometry_concept<IntervalType1>::type
Chris@16 687 >::type,
Chris@16 688 typename is_interval_concept<
Chris@16 689 typename geometry_concept<IntervalType2>::type
Chris@16 690 >::type
Chris@16 691 >::type,
Chris@16 692 bool
Chris@16 693 >::type intersect(
Chris@16 694 IntervalType1& lvalue,
Chris@16 695 const IntervalType2& rvalue,
Chris@16 696 bool consider_touch = true) {
Chris@16 697 typedef typename interval_coordinate_type<IntervalType1>::type Unit;
Chris@16 698 Unit lowVal = (std::max)(low(lvalue), low(rvalue));
Chris@16 699 Unit highVal = (std::min)(high(lvalue), high(rvalue));
Chris@16 700 bool valid = consider_touch ? lowVal <= highVal : lowVal < highVal;
Chris@16 701 if (valid) {
Chris@16 702 low(lvalue, lowVal);
Chris@16 703 high(lvalue, highVal);
Chris@16 704 }
Chris@16 705 return valid;
Chris@16 706 }
Chris@16 707
Chris@16 708 struct y_i_g_intersect : gtl_yes {};
Chris@16 709
Chris@16 710 // TODO(asydorchuk): Deprecated.
Chris@16 711 template <typename IntervalType1, typename IntervalType2>
Chris@16 712 typename enable_if<
Chris@16 713 typename gtl_and_3<
Chris@16 714 y_i_g_intersect,
Chris@16 715 typename is_mutable_interval_concept<
Chris@16 716 typename geometry_concept<IntervalType1>::type
Chris@16 717 >::type,
Chris@16 718 typename is_interval_concept<
Chris@16 719 typename geometry_concept<IntervalType2>::type
Chris@16 720 >::type
Chris@16 721 >::type,
Chris@16 722 IntervalType1
Chris@16 723 >::type& generalized_intersect(
Chris@16 724 IntervalType1& lvalue,
Chris@16 725 const IntervalType2& rvalue) {
Chris@16 726 typedef typename interval_coordinate_type<IntervalType1>::type Unit;
Chris@16 727 Unit coords[4] = {low(lvalue), high(lvalue), low(rvalue), high(rvalue)};
Chris@16 728 // TODO(asydorchuk): consider implementing faster sorting of small
Chris@16 729 // fixed length range.
Chris@16 730 polygon_sort(coords, coords+4);
Chris@16 731 low(lvalue, coords[1]);
Chris@16 732 high(lvalue, coords[2]);
Chris@16 733 return lvalue;
Chris@16 734 }
Chris@16 735
Chris@16 736 struct y_i_abuts1 : gtl_yes {};
Chris@16 737
Chris@16 738 template <typename IntervalType1, typename IntervalType2>
Chris@16 739 typename enable_if<
Chris@16 740 typename gtl_and_3<
Chris@16 741 y_i_abuts1,
Chris@16 742 typename is_interval_concept<
Chris@16 743 typename geometry_concept<IntervalType1>::type
Chris@16 744 >::type,
Chris@16 745 typename is_interval_concept<
Chris@16 746 typename geometry_concept<IntervalType2>::type
Chris@16 747 >::type
Chris@16 748 >::type,
Chris@16 749 bool
Chris@16 750 >::type abuts(
Chris@16 751 const IntervalType1& interval1,
Chris@16 752 const IntervalType2& interval2,
Chris@16 753 direction_1d dir) {
Chris@16 754 return dir.to_int() ? low(interval2) == high(interval1) :
Chris@16 755 low(interval1) == high(interval2);
Chris@16 756 }
Chris@16 757
Chris@16 758 struct y_i_abuts2 : gtl_yes {};
Chris@16 759
Chris@16 760 template <typename IntervalType1, typename IntervalType2>
Chris@16 761 typename enable_if<
Chris@16 762 typename gtl_and_3<
Chris@16 763 y_i_abuts2,
Chris@16 764 typename is_interval_concept<
Chris@16 765 typename geometry_concept<IntervalType1>::type
Chris@16 766 >::type,
Chris@16 767 typename is_interval_concept<
Chris@16 768 typename geometry_concept<IntervalType2>::type
Chris@16 769 >::type
Chris@16 770 >::type,
Chris@16 771 bool
Chris@16 772 >::type abuts(
Chris@16 773 const IntervalType1& interval1,
Chris@16 774 const IntervalType2& interval2) {
Chris@16 775 return abuts(interval1, interval2, HIGH) ||
Chris@16 776 abuts(interval1, interval2, LOW);
Chris@16 777 }
Chris@16 778
Chris@16 779 struct y_i_bloat : gtl_yes {};
Chris@16 780
Chris@16 781 template <typename IntervalType>
Chris@16 782 typename enable_if<
Chris@16 783 typename gtl_and<
Chris@16 784 y_i_bloat,
Chris@16 785 typename is_mutable_interval_concept<
Chris@16 786 typename geometry_concept<IntervalType>::type
Chris@16 787 >::type
Chris@16 788 >::type,
Chris@16 789 IntervalType
Chris@16 790 >::type& bloat(
Chris@16 791 IntervalType& interval,
Chris@16 792 typename interval_coordinate_type<IntervalType>::type bloating) {
Chris@16 793 low(interval, low(interval) - bloating);
Chris@16 794 high(interval, high(interval) + bloating);
Chris@16 795 return interval;
Chris@16 796 }
Chris@16 797
Chris@16 798 struct y_i_bloat2 : gtl_yes {};
Chris@16 799
Chris@16 800 template <typename IntervalType>
Chris@16 801 typename enable_if<
Chris@16 802 typename gtl_and<
Chris@16 803 y_i_bloat2,
Chris@16 804 typename is_mutable_interval_concept<
Chris@16 805 typename geometry_concept<IntervalType>::type
Chris@16 806 >::type
Chris@16 807 >::type,
Chris@16 808 IntervalType
Chris@16 809 >::type& bloat(
Chris@16 810 IntervalType& interval,
Chris@16 811 direction_1d dir,
Chris@16 812 typename interval_coordinate_type<IntervalType>::type bloating) {
Chris@16 813 set(interval, dir, get(interval, dir) + dir.get_sign() * bloating);
Chris@16 814 return interval;
Chris@16 815 }
Chris@16 816
Chris@16 817 struct y_i_shrink : gtl_yes {};
Chris@16 818
Chris@16 819 template <typename IntervalType>
Chris@16 820 typename enable_if<
Chris@16 821 typename gtl_and<
Chris@16 822 y_i_shrink,
Chris@16 823 typename is_mutable_interval_concept<
Chris@16 824 typename geometry_concept<IntervalType>::type
Chris@16 825 >::type
Chris@16 826 >::type,
Chris@16 827 IntervalType
Chris@16 828 >::type& shrink(
Chris@16 829 IntervalType& interval,
Chris@16 830 typename interval_coordinate_type<IntervalType>::type shrinking) {
Chris@16 831 return bloat(interval, -shrinking);
Chris@16 832 }
Chris@16 833
Chris@16 834 struct y_i_shrink2 : gtl_yes {};
Chris@16 835
Chris@16 836 template <typename IntervalType>
Chris@16 837 typename enable_if<
Chris@16 838 typename gtl_and<
Chris@16 839 y_i_shrink2,
Chris@16 840 typename is_mutable_interval_concept<
Chris@16 841 typename geometry_concept<IntervalType>::type
Chris@16 842 >::type
Chris@16 843 >::type,
Chris@16 844 IntervalType
Chris@16 845 >::type& shrink(
Chris@16 846 IntervalType& interval,
Chris@16 847 direction_1d dir,
Chris@16 848 typename interval_coordinate_type<IntervalType>::type shrinking) {
Chris@16 849 return bloat(interval, dir, -shrinking);
Chris@16 850 }
Chris@16 851
Chris@16 852 struct y_i_encompass : gtl_yes {};
Chris@16 853
Chris@16 854 template <typename IntervalType1, typename IntervalType2>
Chris@16 855 typename enable_if<
Chris@16 856 typename gtl_and_3<
Chris@16 857 y_i_encompass,
Chris@16 858 typename is_mutable_interval_concept<
Chris@16 859 typename geometry_concept<IntervalType1>::type
Chris@16 860 >::type,
Chris@16 861 typename is_interval_concept<
Chris@16 862 typename geometry_concept<IntervalType2>::type
Chris@16 863 >::type
Chris@16 864 >::type,
Chris@16 865 bool
Chris@16 866 >::type encompass(IntervalType1& interval1, const IntervalType2& interval2) {
Chris@16 867 bool retval = !contains(interval1, interval2, true);
Chris@16 868 low(interval1, (std::min)(low(interval1), low(interval2)));
Chris@16 869 high(interval1, (std::max)(high(interval1), high(interval2)));
Chris@16 870 return retval;
Chris@16 871 }
Chris@16 872
Chris@16 873 struct y_i_encompass2 : gtl_yes {};
Chris@16 874
Chris@16 875 template <typename IntervalType>
Chris@16 876 typename enable_if<
Chris@16 877 typename gtl_and<
Chris@16 878 y_i_encompass2,
Chris@16 879 typename is_mutable_interval_concept<
Chris@16 880 typename geometry_concept<IntervalType>::type
Chris@16 881 >::type
Chris@16 882 >::type,
Chris@16 883 bool
Chris@16 884 >::type encompass(
Chris@16 885 IntervalType& interval,
Chris@16 886 typename interval_coordinate_type<IntervalType>::type value) {
Chris@16 887 bool retval = !contains(interval, value, true);
Chris@16 888 low(interval, (std::min)(low(interval), value));
Chris@16 889 high(interval, (std::max)(high(interval), value));
Chris@16 890 return retval;
Chris@16 891 }
Chris@16 892
Chris@16 893 struct y_i_get_half : gtl_yes {};
Chris@16 894
Chris@16 895 template <typename IntervalType>
Chris@16 896 typename enable_if<
Chris@16 897 typename gtl_and<
Chris@16 898 y_i_get_half,
Chris@16 899 typename is_mutable_interval_concept<
Chris@16 900 typename geometry_concept<IntervalType>::type
Chris@16 901 >::type
Chris@16 902 >::type,
Chris@16 903 IntervalType
Chris@16 904 >::type get_half(const IntervalType& interval, direction_1d dir) {
Chris@16 905 typedef typename interval_coordinate_type<IntervalType>::type Unit;
Chris@16 906 Unit c = (get(interval, LOW) + get(interval, HIGH)) / 2;
Chris@16 907 return construct<IntervalType>(
Chris@16 908 (dir == LOW) ? get(interval, LOW) : c,
Chris@16 909 (dir == LOW) ? c : get(interval, HIGH));
Chris@16 910 }
Chris@16 911
Chris@16 912 struct y_i_join_with : gtl_yes {};
Chris@16 913
Chris@16 914 template <typename IntervalType1, typename IntervalType2>
Chris@16 915 typename enable_if<
Chris@16 916 typename gtl_and_3<
Chris@16 917 y_i_join_with,
Chris@16 918 typename is_mutable_interval_concept<
Chris@16 919 typename geometry_concept<IntervalType1>::type
Chris@16 920 >::type,
Chris@16 921 typename is_interval_concept<
Chris@16 922 typename geometry_concept<IntervalType2>::type
Chris@16 923 >::type>::type,
Chris@16 924 bool
Chris@16 925 >::type join_with(IntervalType1& interval1, const IntervalType2& interval2) {
Chris@16 926 if (abuts(interval1, interval2)) {
Chris@16 927 encompass(interval1, interval2);
Chris@16 928 return true;
Chris@16 929 }
Chris@16 930 return false;
Chris@16 931 }
Chris@16 932 } // polygon
Chris@16 933 } // boost
Chris@16 934
Chris@16 935 #endif // BOOST_POLYGON_INTERVAL_CONCEPT_HPP