annotate DEPENDENCIES/generic/include/boost/geometry/index/detail/predicates.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // Boost.Geometry Index
Chris@16 2 //
Chris@16 3 // Spatial query predicates definition and checks.
Chris@16 4 //
Chris@101 5 // Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland.
Chris@16 6 //
Chris@16 7 // Use, modification and distribution is subject to the Boost Software License,
Chris@16 8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 9 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 10
Chris@16 11 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_PREDICATES_HPP
Chris@16 12 #define BOOST_GEOMETRY_INDEX_DETAIL_PREDICATES_HPP
Chris@16 13
Chris@16 14 #include <boost/geometry/index/predicates.hpp>
Chris@16 15 #include <boost/geometry/index/detail/tags.hpp>
Chris@16 16
Chris@16 17 namespace boost { namespace geometry { namespace index { namespace detail {
Chris@16 18
Chris@101 19 namespace predicates {
Chris@101 20
Chris@16 21 // ------------------------------------------------------------------ //
Chris@16 22 // predicates
Chris@16 23 // ------------------------------------------------------------------ //
Chris@16 24
Chris@16 25 template <typename Fun, bool IsFunction>
Chris@16 26 struct satisfies_impl
Chris@16 27 {
Chris@16 28 satisfies_impl(Fun f) : fun(f) {}
Chris@16 29 Fun * fun;
Chris@16 30 };
Chris@16 31
Chris@16 32 template <typename Fun>
Chris@16 33 struct satisfies_impl<Fun, false>
Chris@16 34 {
Chris@16 35 satisfies_impl(Fun const& f) : fun(f) {}
Chris@16 36 Fun fun;
Chris@16 37 };
Chris@16 38
Chris@16 39 template <typename Fun, bool Negated>
Chris@16 40 struct satisfies
Chris@16 41 : satisfies_impl<Fun, ::boost::is_function<Fun>::value>
Chris@16 42 {
Chris@16 43 typedef satisfies_impl<Fun, ::boost::is_function<Fun>::value> base;
Chris@16 44
Chris@16 45 satisfies(Fun const& f) : base(f) {}
Chris@16 46 satisfies(base const& b) : base(b) {}
Chris@16 47 };
Chris@16 48
Chris@16 49 // ------------------------------------------------------------------ //
Chris@16 50
Chris@16 51 struct contains_tag {};
Chris@16 52 struct covered_by_tag {};
Chris@16 53 struct covers_tag {};
Chris@16 54 struct disjoint_tag {};
Chris@16 55 struct intersects_tag {};
Chris@16 56 struct overlaps_tag {};
Chris@16 57 struct touches_tag {};
Chris@16 58 struct within_tag {};
Chris@16 59
Chris@16 60 template <typename Geometry, typename Tag, bool Negated>
Chris@16 61 struct spatial_predicate
Chris@16 62 {
Chris@16 63 spatial_predicate(Geometry const& g) : geometry(g) {}
Chris@16 64 Geometry geometry;
Chris@16 65 };
Chris@16 66
Chris@16 67 // ------------------------------------------------------------------ //
Chris@16 68
Chris@101 69 // CONSIDER: separated nearest<> and path<> may be replaced by
Chris@101 70 // nearest_predicate<Geometry, Tag>
Chris@101 71 // where Tag = point_tag | path_tag
Chris@101 72 // IMPROVEMENT: user-defined nearest predicate allowing to define
Chris@101 73 // all or only geometrical aspects of the search
Chris@16 74
Chris@16 75 template <typename PointOrRelation>
Chris@16 76 struct nearest
Chris@16 77 {
Chris@16 78 nearest(PointOrRelation const& por, unsigned k)
Chris@16 79 : point_or_relation(por)
Chris@16 80 , count(k)
Chris@16 81 {}
Chris@16 82 PointOrRelation point_or_relation;
Chris@16 83 unsigned count;
Chris@16 84 };
Chris@16 85
Chris@16 86 template <typename SegmentOrLinestring>
Chris@16 87 struct path
Chris@16 88 {
Chris@16 89 path(SegmentOrLinestring const& g, unsigned k)
Chris@16 90 : geometry(g)
Chris@16 91 , count(k)
Chris@16 92 {}
Chris@16 93 SegmentOrLinestring geometry;
Chris@16 94 unsigned count;
Chris@16 95 };
Chris@16 96
Chris@101 97 } // namespace predicates
Chris@101 98
Chris@16 99 // ------------------------------------------------------------------ //
Chris@16 100 // predicate_check
Chris@16 101 // ------------------------------------------------------------------ //
Chris@16 102
Chris@16 103 template <typename Predicate, typename Tag>
Chris@16 104 struct predicate_check
Chris@16 105 {
Chris@16 106 BOOST_MPL_ASSERT_MSG(
Chris@16 107 (false),
Chris@16 108 NOT_IMPLEMENTED_FOR_THIS_PREDICATE_OR_TAG,
Chris@16 109 (predicate_check));
Chris@16 110 };
Chris@16 111
Chris@16 112 // ------------------------------------------------------------------ //
Chris@16 113
Chris@16 114 template <typename Fun>
Chris@101 115 struct predicate_check<predicates::satisfies<Fun, false>, value_tag>
Chris@16 116 {
Chris@16 117 template <typename Value, typename Indexable>
Chris@101 118 static inline bool apply(predicates::satisfies<Fun, false> const& p, Value const& v, Indexable const&)
Chris@16 119 {
Chris@16 120 return p.fun(v);
Chris@16 121 }
Chris@16 122 };
Chris@16 123
Chris@16 124 template <typename Fun>
Chris@101 125 struct predicate_check<predicates::satisfies<Fun, true>, value_tag>
Chris@16 126 {
Chris@16 127 template <typename Value, typename Indexable>
Chris@101 128 static inline bool apply(predicates::satisfies<Fun, true> const& p, Value const& v, Indexable const&)
Chris@16 129 {
Chris@16 130 return !p.fun(v);
Chris@16 131 }
Chris@16 132 };
Chris@16 133
Chris@16 134 // ------------------------------------------------------------------ //
Chris@16 135
Chris@16 136 template <typename Tag>
Chris@16 137 struct spatial_predicate_call
Chris@16 138 {
Chris@16 139 BOOST_MPL_ASSERT_MSG(false, NOT_IMPLEMENTED_FOR_THIS_TAG, (Tag));
Chris@16 140 };
Chris@16 141
Chris@16 142 template <>
Chris@101 143 struct spatial_predicate_call<predicates::contains_tag>
Chris@16 144 {
Chris@16 145 template <typename G1, typename G2>
Chris@16 146 static inline bool apply(G1 const& g1, G2 const& g2)
Chris@16 147 {
Chris@16 148 return geometry::within(g2, g1);
Chris@16 149 }
Chris@16 150 };
Chris@16 151
Chris@16 152 template <>
Chris@101 153 struct spatial_predicate_call<predicates::covered_by_tag>
Chris@16 154 {
Chris@16 155 template <typename G1, typename G2>
Chris@16 156 static inline bool apply(G1 const& g1, G2 const& g2)
Chris@16 157 {
Chris@16 158 return geometry::covered_by(g1, g2);
Chris@16 159 }
Chris@16 160 };
Chris@16 161
Chris@16 162 template <>
Chris@101 163 struct spatial_predicate_call<predicates::covers_tag>
Chris@16 164 {
Chris@16 165 template <typename G1, typename G2>
Chris@16 166 static inline bool apply(G1 const& g1, G2 const& g2)
Chris@16 167 {
Chris@16 168 return geometry::covered_by(g2, g1);
Chris@16 169 }
Chris@16 170 };
Chris@16 171
Chris@16 172 template <>
Chris@101 173 struct spatial_predicate_call<predicates::disjoint_tag>
Chris@16 174 {
Chris@16 175 template <typename G1, typename G2>
Chris@16 176 static inline bool apply(G1 const& g1, G2 const& g2)
Chris@16 177 {
Chris@16 178 return geometry::disjoint(g1, g2);
Chris@16 179 }
Chris@16 180 };
Chris@16 181
Chris@16 182 template <>
Chris@101 183 struct spatial_predicate_call<predicates::intersects_tag>
Chris@16 184 {
Chris@16 185 template <typename G1, typename G2>
Chris@16 186 static inline bool apply(G1 const& g1, G2 const& g2)
Chris@16 187 {
Chris@16 188 return geometry::intersects(g1, g2);
Chris@16 189 }
Chris@16 190 };
Chris@16 191
Chris@16 192 template <>
Chris@101 193 struct spatial_predicate_call<predicates::overlaps_tag>
Chris@16 194 {
Chris@16 195 template <typename G1, typename G2>
Chris@16 196 static inline bool apply(G1 const& g1, G2 const& g2)
Chris@16 197 {
Chris@16 198 return geometry::overlaps(g1, g2);
Chris@16 199 }
Chris@16 200 };
Chris@16 201
Chris@16 202 template <>
Chris@101 203 struct spatial_predicate_call<predicates::touches_tag>
Chris@16 204 {
Chris@16 205 template <typename G1, typename G2>
Chris@16 206 static inline bool apply(G1 const& g1, G2 const& g2)
Chris@16 207 {
Chris@16 208 return geometry::touches(g1, g2);
Chris@16 209 }
Chris@16 210 };
Chris@16 211
Chris@16 212 template <>
Chris@101 213 struct spatial_predicate_call<predicates::within_tag>
Chris@16 214 {
Chris@16 215 template <typename G1, typename G2>
Chris@16 216 static inline bool apply(G1 const& g1, G2 const& g2)
Chris@16 217 {
Chris@16 218 return geometry::within(g1, g2);
Chris@16 219 }
Chris@16 220 };
Chris@16 221
Chris@16 222 // ------------------------------------------------------------------ //
Chris@16 223
Chris@16 224 // spatial predicate
Chris@16 225 template <typename Geometry, typename Tag>
Chris@101 226 struct predicate_check<predicates::spatial_predicate<Geometry, Tag, false>, value_tag>
Chris@16 227 {
Chris@101 228 typedef predicates::spatial_predicate<Geometry, Tag, false> Pred;
Chris@16 229
Chris@16 230 template <typename Value, typename Indexable>
Chris@16 231 static inline bool apply(Pred const& p, Value const&, Indexable const& i)
Chris@16 232 {
Chris@16 233 return spatial_predicate_call<Tag>::apply(i, p.geometry);
Chris@16 234 }
Chris@16 235 };
Chris@16 236
Chris@16 237 // negated spatial predicate
Chris@16 238 template <typename Geometry, typename Tag>
Chris@101 239 struct predicate_check<predicates::spatial_predicate<Geometry, Tag, true>, value_tag>
Chris@16 240 {
Chris@101 241 typedef predicates::spatial_predicate<Geometry, Tag, true> Pred;
Chris@16 242
Chris@16 243 template <typename Value, typename Indexable>
Chris@16 244 static inline bool apply(Pred const& p, Value const&, Indexable const& i)
Chris@16 245 {
Chris@16 246 return !spatial_predicate_call<Tag>::apply(i, p.geometry);
Chris@16 247 }
Chris@16 248 };
Chris@16 249
Chris@16 250 // ------------------------------------------------------------------ //
Chris@16 251
Chris@16 252 template <typename DistancePredicates>
Chris@101 253 struct predicate_check<predicates::nearest<DistancePredicates>, value_tag>
Chris@16 254 {
Chris@16 255 template <typename Value, typename Box>
Chris@101 256 static inline bool apply(predicates::nearest<DistancePredicates> const&, Value const&, Box const&)
Chris@16 257 {
Chris@16 258 return true;
Chris@16 259 }
Chris@16 260 };
Chris@16 261
Chris@16 262 template <typename Linestring>
Chris@101 263 struct predicate_check<predicates::path<Linestring>, value_tag>
Chris@16 264 {
Chris@16 265 template <typename Value, typename Box>
Chris@101 266 static inline bool apply(predicates::path<Linestring> const&, Value const&, Box const&)
Chris@16 267 {
Chris@16 268 return true;
Chris@16 269 }
Chris@16 270 };
Chris@16 271
Chris@16 272 // ------------------------------------------------------------------ //
Chris@16 273 // predicates_check for bounds
Chris@16 274 // ------------------------------------------------------------------ //
Chris@16 275
Chris@16 276 template <typename Fun, bool Negated>
Chris@101 277 struct predicate_check<predicates::satisfies<Fun, Negated>, bounds_tag>
Chris@16 278 {
Chris@16 279 template <typename Value, typename Box>
Chris@101 280 static bool apply(predicates::satisfies<Fun, Negated> const&, Value const&, Box const&)
Chris@16 281 {
Chris@16 282 return true;
Chris@16 283 }
Chris@16 284 };
Chris@16 285
Chris@16 286 // ------------------------------------------------------------------ //
Chris@16 287
Chris@16 288 // NOT NEGATED
Chris@16 289 // value_tag bounds_tag
Chris@16 290 // ---------------------------
Chris@16 291 // contains(I,G) contains(I,G)
Chris@16 292 // covered_by(I,G) intersects(I,G)
Chris@16 293 // covers(I,G) covers(I,G)
Chris@16 294 // disjoint(I,G) !covered_by(I,G)
Chris@16 295 // intersects(I,G) intersects(I,G)
Chris@16 296 // overlaps(I,G) intersects(I,G) - possibly change to the version without border case, e.g. intersects_without_border(0,0x1,1, 1,1x2,2) should give false
Chris@16 297 // touches(I,G) intersects(I,G)
Chris@16 298 // within(I,G) intersects(I,G) - possibly change to the version without border case, e.g. intersects_without_border(0,0x1,1, 1,1x2,2) should give false
Chris@16 299
Chris@16 300 // spatial predicate - default
Chris@16 301 template <typename Geometry, typename Tag>
Chris@101 302 struct predicate_check<predicates::spatial_predicate<Geometry, Tag, false>, bounds_tag>
Chris@16 303 {
Chris@101 304 typedef predicates::spatial_predicate<Geometry, Tag, false> Pred;
Chris@16 305
Chris@16 306 template <typename Value, typename Indexable>
Chris@16 307 static inline bool apply(Pred const& p, Value const&, Indexable const& i)
Chris@16 308 {
Chris@101 309 return spatial_predicate_call<predicates::intersects_tag>::apply(i, p.geometry);
Chris@16 310 }
Chris@16 311 };
Chris@16 312
Chris@16 313 // spatial predicate - contains
Chris@16 314 template <typename Geometry>
Chris@101 315 struct predicate_check<predicates::spatial_predicate<Geometry, predicates::contains_tag, false>, bounds_tag>
Chris@16 316 {
Chris@101 317 typedef predicates::spatial_predicate<Geometry, predicates::contains_tag, false> Pred;
Chris@16 318
Chris@16 319 template <typename Value, typename Indexable>
Chris@16 320 static inline bool apply(Pred const& p, Value const&, Indexable const& i)
Chris@16 321 {
Chris@101 322 return spatial_predicate_call<predicates::contains_tag>::apply(i, p.geometry);
Chris@16 323 }
Chris@16 324 };
Chris@16 325
Chris@16 326 // spatial predicate - covers
Chris@16 327 template <typename Geometry>
Chris@101 328 struct predicate_check<predicates::spatial_predicate<Geometry, predicates::covers_tag, false>, bounds_tag>
Chris@16 329 {
Chris@101 330 typedef predicates::spatial_predicate<Geometry, predicates::covers_tag, false> Pred;
Chris@16 331
Chris@16 332 template <typename Value, typename Indexable>
Chris@16 333 static inline bool apply(Pred const& p, Value const&, Indexable const& i)
Chris@16 334 {
Chris@101 335 return spatial_predicate_call<predicates::covers_tag>::apply(i, p.geometry);
Chris@16 336 }
Chris@16 337 };
Chris@16 338
Chris@16 339 // spatial predicate - disjoint
Chris@16 340 template <typename Geometry>
Chris@101 341 struct predicate_check<predicates::spatial_predicate<Geometry, predicates::disjoint_tag, false>, bounds_tag>
Chris@16 342 {
Chris@101 343 typedef predicates::spatial_predicate<Geometry, predicates::disjoint_tag, false> Pred;
Chris@16 344
Chris@16 345 template <typename Value, typename Indexable>
Chris@16 346 static inline bool apply(Pred const& p, Value const&, Indexable const& i)
Chris@16 347 {
Chris@101 348 return !spatial_predicate_call<predicates::covered_by_tag>::apply(i, p.geometry);
Chris@16 349 }
Chris@16 350 };
Chris@16 351
Chris@16 352 // NEGATED
Chris@16 353 // value_tag bounds_tag
Chris@16 354 // ---------------------------
Chris@16 355 // !contains(I,G) TRUE
Chris@16 356 // !covered_by(I,G) !covered_by(I,G)
Chris@16 357 // !covers(I,G) TRUE
Chris@16 358 // !disjoint(I,G) !disjoint(I,G)
Chris@16 359 // !intersects(I,G) !covered_by(I,G)
Chris@16 360 // !overlaps(I,G) TRUE
Chris@16 361 // !touches(I,G) !intersects(I,G)
Chris@16 362 // !within(I,G) !within(I,G)
Chris@16 363
Chris@16 364 // negated spatial predicate - default
Chris@16 365 template <typename Geometry, typename Tag>
Chris@101 366 struct predicate_check<predicates::spatial_predicate<Geometry, Tag, true>, bounds_tag>
Chris@16 367 {
Chris@101 368 typedef predicates::spatial_predicate<Geometry, Tag, true> Pred;
Chris@16 369
Chris@16 370 template <typename Value, typename Indexable>
Chris@16 371 static inline bool apply(Pred const& p, Value const&, Indexable const& i)
Chris@16 372 {
Chris@16 373 return !spatial_predicate_call<Tag>::apply(i, p.geometry);
Chris@16 374 }
Chris@16 375 };
Chris@16 376
Chris@16 377 // negated spatial predicate - contains
Chris@16 378 template <typename Geometry>
Chris@101 379 struct predicate_check<predicates::spatial_predicate<Geometry, predicates::contains_tag, true>, bounds_tag>
Chris@16 380 {
Chris@101 381 typedef predicates::spatial_predicate<Geometry, predicates::contains_tag, true> Pred;
Chris@16 382
Chris@16 383 template <typename Value, typename Indexable>
Chris@16 384 static inline bool apply(Pred const& , Value const&, Indexable const& )
Chris@16 385 {
Chris@16 386 return true;
Chris@16 387 }
Chris@16 388 };
Chris@16 389
Chris@16 390 // negated spatial predicate - covers
Chris@16 391 template <typename Geometry>
Chris@101 392 struct predicate_check<predicates::spatial_predicate<Geometry, predicates::covers_tag, true>, bounds_tag>
Chris@16 393 {
Chris@101 394 typedef predicates::spatial_predicate<Geometry, predicates::covers_tag, true> Pred;
Chris@16 395
Chris@16 396 template <typename Value, typename Indexable>
Chris@16 397 static inline bool apply(Pred const& , Value const&, Indexable const& )
Chris@16 398 {
Chris@16 399 return true;
Chris@16 400 }
Chris@16 401 };
Chris@16 402
Chris@16 403 // negated spatial predicate - intersects
Chris@16 404 template <typename Geometry>
Chris@101 405 struct predicate_check<predicates::spatial_predicate<Geometry, predicates::intersects_tag, true>, bounds_tag>
Chris@16 406 {
Chris@101 407 typedef predicates::spatial_predicate<Geometry, predicates::intersects_tag, true> Pred;
Chris@16 408
Chris@16 409 template <typename Value, typename Indexable>
Chris@16 410 static inline bool apply(Pred const& p, Value const&, Indexable const& i)
Chris@16 411 {
Chris@101 412 return !spatial_predicate_call<predicates::covered_by_tag>::apply(i, p.geometry);
Chris@16 413 }
Chris@16 414 };
Chris@16 415
Chris@16 416 // negated spatial predicate - overlaps
Chris@16 417 template <typename Geometry>
Chris@101 418 struct predicate_check<predicates::spatial_predicate<Geometry, predicates::overlaps_tag, true>, bounds_tag>
Chris@16 419 {
Chris@101 420 typedef predicates::spatial_predicate<Geometry, predicates::overlaps_tag, true> Pred;
Chris@16 421
Chris@16 422 template <typename Value, typename Indexable>
Chris@16 423 static inline bool apply(Pred const& , Value const&, Indexable const& )
Chris@16 424 {
Chris@16 425 return true;
Chris@16 426 }
Chris@16 427 };
Chris@16 428
Chris@16 429 // negated spatial predicate - touches
Chris@16 430 template <typename Geometry>
Chris@101 431 struct predicate_check<predicates::spatial_predicate<Geometry, predicates::touches_tag, true>, bounds_tag>
Chris@16 432 {
Chris@101 433 typedef predicates::spatial_predicate<Geometry, predicates::touches_tag, true> Pred;
Chris@16 434
Chris@16 435 template <typename Value, typename Indexable>
Chris@16 436 static inline bool apply(Pred const& p, Value const&, Indexable const& i)
Chris@16 437 {
Chris@101 438 return !spatial_predicate_call<predicates::intersects_tag>::apply(i, p.geometry);
Chris@16 439 }
Chris@16 440 };
Chris@16 441
Chris@16 442 // ------------------------------------------------------------------ //
Chris@16 443
Chris@16 444 template <typename DistancePredicates>
Chris@101 445 struct predicate_check<predicates::nearest<DistancePredicates>, bounds_tag>
Chris@16 446 {
Chris@16 447 template <typename Value, typename Box>
Chris@101 448 static inline bool apply(predicates::nearest<DistancePredicates> const&, Value const&, Box const&)
Chris@16 449 {
Chris@16 450 return true;
Chris@16 451 }
Chris@16 452 };
Chris@16 453
Chris@16 454 template <typename Linestring>
Chris@101 455 struct predicate_check<predicates::path<Linestring>, bounds_tag>
Chris@16 456 {
Chris@16 457 template <typename Value, typename Box>
Chris@101 458 static inline bool apply(predicates::path<Linestring> const&, Value const&, Box const&)
Chris@16 459 {
Chris@16 460 return true;
Chris@16 461 }
Chris@16 462 };
Chris@16 463
Chris@16 464 // ------------------------------------------------------------------ //
Chris@16 465 // predicates_length
Chris@16 466 // ------------------------------------------------------------------ //
Chris@16 467
Chris@16 468 template <typename T>
Chris@16 469 struct predicates_length
Chris@16 470 {
Chris@16 471 static const unsigned value = 1;
Chris@16 472 };
Chris@16 473
Chris@16 474 //template <typename F, typename S>
Chris@16 475 //struct predicates_length< std::pair<F, S> >
Chris@16 476 //{
Chris@16 477 // static const unsigned value = 2;
Chris@16 478 //};
Chris@16 479
Chris@16 480 //template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
Chris@16 481 //struct predicates_length< boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
Chris@16 482 //{
Chris@16 483 // static const unsigned value = boost::tuples::length< boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >::value;
Chris@16 484 //};
Chris@16 485
Chris@16 486 template <typename Head, typename Tail>
Chris@16 487 struct predicates_length< boost::tuples::cons<Head, Tail> >
Chris@16 488 {
Chris@16 489 static const unsigned value = boost::tuples::length< boost::tuples::cons<Head, Tail> >::value;
Chris@16 490 };
Chris@16 491
Chris@16 492 // ------------------------------------------------------------------ //
Chris@16 493 // predicates_element
Chris@16 494 // ------------------------------------------------------------------ //
Chris@16 495
Chris@16 496 template <unsigned I, typename T>
Chris@16 497 struct predicates_element
Chris@16 498 {
Chris@16 499 BOOST_MPL_ASSERT_MSG((I < 1), INVALID_INDEX, (predicates_element));
Chris@16 500 typedef T type;
Chris@16 501 static type const& get(T const& p) { return p; }
Chris@16 502 };
Chris@16 503
Chris@16 504 //template <unsigned I, typename F, typename S>
Chris@16 505 //struct predicates_element< I, std::pair<F, S> >
Chris@16 506 //{
Chris@16 507 // BOOST_MPL_ASSERT_MSG((I < 2), INVALID_INDEX, (predicates_element));
Chris@16 508 //
Chris@16 509 // typedef F type;
Chris@16 510 // static type const& get(std::pair<F, S> const& p) { return p.first; }
Chris@16 511 //};
Chris@16 512 //
Chris@16 513 //template <typename F, typename S>
Chris@16 514 //struct predicates_element< 1, std::pair<F, S> >
Chris@16 515 //{
Chris@16 516 // typedef S type;
Chris@16 517 // static type const& get(std::pair<F, S> const& p) { return p.second; }
Chris@16 518 //};
Chris@16 519 //
Chris@16 520 //template <unsigned I, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
Chris@16 521 //struct predicates_element< I, boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
Chris@16 522 //{
Chris@16 523 // typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> predicate_type;
Chris@16 524 //
Chris@16 525 // typedef typename boost::tuples::element<I, predicate_type>::type type;
Chris@16 526 // static type const& get(predicate_type const& p) { return boost::get<I>(p); }
Chris@16 527 //};
Chris@16 528
Chris@16 529 template <unsigned I, typename Head, typename Tail>
Chris@16 530 struct predicates_element< I, boost::tuples::cons<Head, Tail> >
Chris@16 531 {
Chris@16 532 typedef boost::tuples::cons<Head, Tail> predicate_type;
Chris@16 533
Chris@16 534 typedef typename boost::tuples::element<I, predicate_type>::type type;
Chris@16 535 static type const& get(predicate_type const& p) { return boost::get<I>(p); }
Chris@16 536 };
Chris@16 537
Chris@16 538 // ------------------------------------------------------------------ //
Chris@16 539 // predicates_check
Chris@16 540 // ------------------------------------------------------------------ //
Chris@16 541
Chris@16 542 //template <typename PairPredicates, typename Tag, unsigned First, unsigned Last>
Chris@16 543 //struct predicates_check_pair {};
Chris@16 544 //
Chris@16 545 //template <typename PairPredicates, typename Tag, unsigned I>
Chris@16 546 //struct predicates_check_pair<PairPredicates, Tag, I, I>
Chris@16 547 //{
Chris@16 548 // template <typename Value, typename Indexable>
Chris@16 549 // static inline bool apply(PairPredicates const& , Value const& , Indexable const& )
Chris@16 550 // {
Chris@16 551 // return true;
Chris@16 552 // }
Chris@16 553 //};
Chris@16 554 //
Chris@16 555 //template <typename PairPredicates, typename Tag>
Chris@16 556 //struct predicates_check_pair<PairPredicates, Tag, 0, 1>
Chris@16 557 //{
Chris@16 558 // template <typename Value, typename Indexable>
Chris@16 559 // static inline bool apply(PairPredicates const& p, Value const& v, Indexable const& i)
Chris@16 560 // {
Chris@16 561 // return predicate_check<typename PairPredicates::first_type, Tag>::apply(p.first, v, i);
Chris@16 562 // }
Chris@16 563 //};
Chris@16 564 //
Chris@16 565 //template <typename PairPredicates, typename Tag>
Chris@16 566 //struct predicates_check_pair<PairPredicates, Tag, 1, 2>
Chris@16 567 //{
Chris@16 568 // template <typename Value, typename Indexable>
Chris@16 569 // static inline bool apply(PairPredicates const& p, Value const& v, Indexable const& i)
Chris@16 570 // {
Chris@16 571 // return predicate_check<typename PairPredicates::second_type, Tag>::apply(p.second, v, i);
Chris@16 572 // }
Chris@16 573 //};
Chris@16 574 //
Chris@16 575 //template <typename PairPredicates, typename Tag>
Chris@16 576 //struct predicates_check_pair<PairPredicates, Tag, 0, 2>
Chris@16 577 //{
Chris@16 578 // template <typename Value, typename Indexable>
Chris@16 579 // static inline bool apply(PairPredicates const& p, Value const& v, Indexable const& i)
Chris@16 580 // {
Chris@16 581 // return predicate_check<typename PairPredicates::first_type, Tag>::apply(p.first, v, i)
Chris@16 582 // && predicate_check<typename PairPredicates::second_type, Tag>::apply(p.second, v, i);
Chris@16 583 // }
Chris@16 584 //};
Chris@16 585
Chris@16 586 template <typename TuplePredicates, typename Tag, unsigned First, unsigned Last>
Chris@16 587 struct predicates_check_tuple
Chris@16 588 {
Chris@16 589 template <typename Value, typename Indexable>
Chris@16 590 static inline bool apply(TuplePredicates const& p, Value const& v, Indexable const& i)
Chris@16 591 {
Chris@16 592 return
Chris@16 593 predicate_check<
Chris@16 594 typename boost::tuples::element<First, TuplePredicates>::type,
Chris@16 595 Tag
Chris@16 596 >::apply(boost::get<First>(p), v, i) &&
Chris@16 597 predicates_check_tuple<TuplePredicates, Tag, First+1, Last>::apply(p, v, i);
Chris@16 598 }
Chris@16 599 };
Chris@16 600
Chris@16 601 template <typename TuplePredicates, typename Tag, unsigned First>
Chris@16 602 struct predicates_check_tuple<TuplePredicates, Tag, First, First>
Chris@16 603 {
Chris@16 604 template <typename Value, typename Indexable>
Chris@16 605 static inline bool apply(TuplePredicates const& , Value const& , Indexable const& )
Chris@16 606 {
Chris@16 607 return true;
Chris@16 608 }
Chris@16 609 };
Chris@16 610
Chris@16 611 template <typename Predicate, typename Tag, unsigned First, unsigned Last>
Chris@16 612 struct predicates_check_impl
Chris@16 613 {
Chris@16 614 static const bool check = First < 1 && Last <= 1 && First <= Last;
Chris@16 615 BOOST_MPL_ASSERT_MSG((check), INVALID_INDEXES, (predicates_check_impl));
Chris@16 616
Chris@16 617 template <typename Value, typename Indexable>
Chris@16 618 static inline bool apply(Predicate const& p, Value const& v, Indexable const& i)
Chris@16 619 {
Chris@16 620 return predicate_check<Predicate, Tag>::apply(p, v, i);
Chris@16 621 }
Chris@16 622 };
Chris@16 623
Chris@16 624 //template <typename Predicate1, typename Predicate2, typename Tag, size_t First, size_t Last>
Chris@16 625 //struct predicates_check_impl<std::pair<Predicate1, Predicate2>, Tag, First, Last>
Chris@16 626 //{
Chris@16 627 // BOOST_MPL_ASSERT_MSG((First < 2 && Last <= 2 && First <= Last), INVALID_INDEXES, (predicates_check_impl));
Chris@16 628 //
Chris@16 629 // template <typename Value, typename Indexable>
Chris@16 630 // static inline bool apply(std::pair<Predicate1, Predicate2> const& p, Value const& v, Indexable const& i)
Chris@16 631 // {
Chris@16 632 // return predicate_check<Predicate1, Tag>::apply(p.first, v, i)
Chris@16 633 // && predicate_check<Predicate2, Tag>::apply(p.second, v, i);
Chris@16 634 // }
Chris@16 635 //};
Chris@16 636 //
Chris@16 637 //template <
Chris@16 638 // typename T0, typename T1, typename T2, typename T3, typename T4,
Chris@16 639 // typename T5, typename T6, typename T7, typename T8, typename T9,
Chris@16 640 // typename Tag, unsigned First, unsigned Last
Chris@16 641 //>
Chris@16 642 //struct predicates_check_impl<
Chris@16 643 // boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>,
Chris@16 644 // Tag, First, Last
Chris@16 645 //>
Chris@16 646 //{
Chris@16 647 // typedef boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> predicates_type;
Chris@16 648 //
Chris@16 649 // static const unsigned pred_len = boost::tuples::length<predicates_type>::value;
Chris@16 650 // BOOST_MPL_ASSERT_MSG((First < pred_len && Last <= pred_len && First <= Last), INVALID_INDEXES, (predicates_check_impl));
Chris@16 651 //
Chris@16 652 // template <typename Value, typename Indexable>
Chris@16 653 // static inline bool apply(predicates_type const& p, Value const& v, Indexable const& i)
Chris@16 654 // {
Chris@16 655 // return predicates_check_tuple<
Chris@16 656 // predicates_type,
Chris@16 657 // Tag, First, Last
Chris@16 658 // >::apply(p, v, i);
Chris@16 659 // }
Chris@16 660 //};
Chris@16 661
Chris@16 662 template <typename Head, typename Tail, typename Tag, unsigned First, unsigned Last>
Chris@16 663 struct predicates_check_impl<
Chris@16 664 boost::tuples::cons<Head, Tail>,
Chris@16 665 Tag, First, Last
Chris@16 666 >
Chris@16 667 {
Chris@16 668 typedef boost::tuples::cons<Head, Tail> predicates_type;
Chris@16 669
Chris@16 670 static const unsigned pred_len = boost::tuples::length<predicates_type>::value;
Chris@16 671 static const bool check = First < pred_len && Last <= pred_len && First <= Last;
Chris@16 672 BOOST_MPL_ASSERT_MSG((check), INVALID_INDEXES, (predicates_check_impl));
Chris@16 673
Chris@16 674 template <typename Value, typename Indexable>
Chris@16 675 static inline bool apply(predicates_type const& p, Value const& v, Indexable const& i)
Chris@16 676 {
Chris@16 677 return predicates_check_tuple<
Chris@16 678 predicates_type,
Chris@16 679 Tag, First, Last
Chris@16 680 >::apply(p, v, i);
Chris@16 681 }
Chris@16 682 };
Chris@16 683
Chris@16 684 template <typename Tag, unsigned First, unsigned Last, typename Predicates, typename Value, typename Indexable>
Chris@16 685 inline bool predicates_check(Predicates const& p, Value const& v, Indexable const& i)
Chris@16 686 {
Chris@16 687 return detail::predicates_check_impl<Predicates, Tag, First, Last>
Chris@16 688 ::apply(p, v, i);
Chris@16 689 }
Chris@16 690
Chris@16 691 // ------------------------------------------------------------------ //
Chris@16 692 // nearest predicate helpers
Chris@16 693 // ------------------------------------------------------------------ //
Chris@16 694
Chris@16 695 // predicates_is_nearest
Chris@16 696
Chris@16 697 template <typename P>
Chris@16 698 struct predicates_is_distance
Chris@16 699 {
Chris@16 700 static const unsigned value = 0;
Chris@16 701 };
Chris@16 702
Chris@16 703 template <typename DistancePredicates>
Chris@101 704 struct predicates_is_distance< predicates::nearest<DistancePredicates> >
Chris@16 705 {
Chris@16 706 static const unsigned value = 1;
Chris@16 707 };
Chris@16 708
Chris@16 709 template <typename Linestring>
Chris@101 710 struct predicates_is_distance< predicates::path<Linestring> >
Chris@16 711 {
Chris@16 712 static const unsigned value = 1;
Chris@16 713 };
Chris@16 714
Chris@16 715 // predicates_count_nearest
Chris@16 716
Chris@16 717 template <typename T>
Chris@16 718 struct predicates_count_distance
Chris@16 719 {
Chris@16 720 static const unsigned value = predicates_is_distance<T>::value;
Chris@16 721 };
Chris@16 722
Chris@16 723 //template <typename F, typename S>
Chris@16 724 //struct predicates_count_distance< std::pair<F, S> >
Chris@16 725 //{
Chris@16 726 // static const unsigned value = predicates_is_distance<F>::value
Chris@16 727 // + predicates_is_distance<S>::value;
Chris@16 728 //};
Chris@16 729
Chris@16 730 template <typename Tuple, unsigned N>
Chris@16 731 struct predicates_count_distance_tuple
Chris@16 732 {
Chris@16 733 static const unsigned value =
Chris@16 734 predicates_is_distance<typename boost::tuples::element<N-1, Tuple>::type>::value
Chris@16 735 + predicates_count_distance_tuple<Tuple, N-1>::value;
Chris@16 736 };
Chris@16 737
Chris@16 738 template <typename Tuple>
Chris@16 739 struct predicates_count_distance_tuple<Tuple, 1>
Chris@16 740 {
Chris@16 741 static const unsigned value =
Chris@16 742 predicates_is_distance<typename boost::tuples::element<0, Tuple>::type>::value;
Chris@16 743 };
Chris@16 744
Chris@16 745 //template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
Chris@16 746 //struct predicates_count_distance< boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
Chris@16 747 //{
Chris@16 748 // static const unsigned value = predicates_count_distance_tuple<
Chris@16 749 // boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>,
Chris@16 750 // boost::tuples::length< boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >::value
Chris@16 751 // >::value;
Chris@16 752 //};
Chris@16 753
Chris@16 754 template <typename Head, typename Tail>
Chris@16 755 struct predicates_count_distance< boost::tuples::cons<Head, Tail> >
Chris@16 756 {
Chris@16 757 static const unsigned value = predicates_count_distance_tuple<
Chris@16 758 boost::tuples::cons<Head, Tail>,
Chris@16 759 boost::tuples::length< boost::tuples::cons<Head, Tail> >::value
Chris@16 760 >::value;
Chris@16 761 };
Chris@16 762
Chris@16 763 // predicates_find_nearest
Chris@16 764
Chris@16 765 template <typename T>
Chris@16 766 struct predicates_find_distance
Chris@16 767 {
Chris@16 768 static const unsigned value = predicates_is_distance<T>::value ? 0 : 1;
Chris@16 769 };
Chris@16 770
Chris@16 771 //template <typename F, typename S>
Chris@16 772 //struct predicates_find_distance< std::pair<F, S> >
Chris@16 773 //{
Chris@16 774 // static const unsigned value = predicates_is_distance<F>::value ? 0 :
Chris@16 775 // (predicates_is_distance<S>::value ? 1 : 2);
Chris@16 776 //};
Chris@16 777
Chris@16 778 template <typename Tuple, unsigned N>
Chris@16 779 struct predicates_find_distance_tuple
Chris@16 780 {
Chris@16 781 static const bool is_found = predicates_find_distance_tuple<Tuple, N-1>::is_found
Chris@16 782 || predicates_is_distance<typename boost::tuples::element<N-1, Tuple>::type>::value;
Chris@16 783
Chris@16 784 static const unsigned value = predicates_find_distance_tuple<Tuple, N-1>::is_found ?
Chris@16 785 predicates_find_distance_tuple<Tuple, N-1>::value :
Chris@16 786 (predicates_is_distance<typename boost::tuples::element<N-1, Tuple>::type>::value ?
Chris@16 787 N-1 : boost::tuples::length<Tuple>::value);
Chris@16 788 };
Chris@16 789
Chris@16 790 template <typename Tuple>
Chris@16 791 struct predicates_find_distance_tuple<Tuple, 1>
Chris@16 792 {
Chris@16 793 static const bool is_found = predicates_is_distance<typename boost::tuples::element<0, Tuple>::type>::value;
Chris@16 794 static const unsigned value = is_found ? 0 : boost::tuples::length<Tuple>::value;
Chris@16 795 };
Chris@16 796
Chris@16 797 //template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
Chris@16 798 //struct predicates_find_distance< boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
Chris@16 799 //{
Chris@16 800 // static const unsigned value = predicates_find_distance_tuple<
Chris@16 801 // boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>,
Chris@16 802 // boost::tuples::length< boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >::value
Chris@16 803 // >::value;
Chris@16 804 //};
Chris@16 805
Chris@16 806 template <typename Head, typename Tail>
Chris@16 807 struct predicates_find_distance< boost::tuples::cons<Head, Tail> >
Chris@16 808 {
Chris@16 809 static const unsigned value = predicates_find_distance_tuple<
Chris@16 810 boost::tuples::cons<Head, Tail>,
Chris@16 811 boost::tuples::length< boost::tuples::cons<Head, Tail> >::value
Chris@16 812 >::value;
Chris@16 813 };
Chris@16 814
Chris@16 815 }}}} // namespace boost::geometry::index::detail
Chris@16 816
Chris@16 817 #endif // BOOST_GEOMETRY_INDEX_DETAIL_PREDICATES_HPP