range_to_geometry_rtree.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_RANGE_TO_GEOMETRY_RTREE_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_RANGE_TO_GEOMETRY_RTREE_HPP
  8. #include <iterator>
  9. #include <utility>
  10. #include <boost/geometry/core/assert.hpp>
  11. #include <boost/geometry/core/point_type.hpp>
  12. #include <boost/geometry/iterators/has_one_element.hpp>
  13. #include <boost/geometry/strategies/distance.hpp>
  14. #include <boost/geometry/algorithms/dispatch/distance.hpp>
  15. #include <boost/geometry/algorithms/detail/closest_feature/range_to_range.hpp>
  16. #include <boost/geometry/algorithms/detail/distance/is_comparable.hpp>
  17. #include <boost/geometry/algorithms/detail/distance/iterator_selector.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. #ifndef DOXYGEN_NO_DETAIL
  21. namespace detail { namespace distance
  22. {
  23. template
  24. <
  25. typename PointOrSegmentIterator,
  26. typename Geometry,
  27. typename Strategy
  28. >
  29. class point_or_segment_range_to_geometry_rtree
  30. {
  31. private:
  32. typedef typename std::iterator_traits
  33. <
  34. PointOrSegmentIterator
  35. >::value_type point_or_segment_type;
  36. typedef iterator_selector<Geometry const> selector_type;
  37. typedef detail::closest_feature::range_to_range_rtree range_to_range;
  38. public:
  39. typedef typename strategy::distance::services::return_type
  40. <
  41. Strategy,
  42. typename point_type<point_or_segment_type>::type,
  43. typename point_type<Geometry>::type
  44. >::type return_type;
  45. static inline return_type apply(PointOrSegmentIterator first,
  46. PointOrSegmentIterator last,
  47. Geometry const& geometry,
  48. Strategy const& strategy)
  49. {
  50. namespace sds = strategy::distance::services;
  51. BOOST_GEOMETRY_ASSERT( first != last );
  52. if ( geometry::has_one_element(first, last) )
  53. {
  54. return dispatch::distance
  55. <
  56. point_or_segment_type, Geometry, Strategy
  57. >::apply(*first, geometry, strategy);
  58. }
  59. typename sds::return_type
  60. <
  61. typename sds::comparable_type<Strategy>::type,
  62. typename point_type<point_or_segment_type>::type,
  63. typename point_type<Geometry>::type
  64. >::type cd_min;
  65. std::pair
  66. <
  67. point_or_segment_type,
  68. typename selector_type::iterator_type
  69. > closest_features
  70. = range_to_range::apply(first,
  71. last,
  72. selector_type::begin(geometry),
  73. selector_type::end(geometry),
  74. sds::get_comparable
  75. <
  76. Strategy
  77. >::apply(strategy),
  78. cd_min);
  79. return
  80. is_comparable<Strategy>::value
  81. ?
  82. cd_min
  83. :
  84. dispatch::distance
  85. <
  86. point_or_segment_type,
  87. typename std::iterator_traits
  88. <
  89. typename selector_type::iterator_type
  90. >::value_type,
  91. Strategy
  92. >::apply(closest_features.first,
  93. *closest_features.second,
  94. strategy);
  95. }
  96. };
  97. }} // namespace detail::distance
  98. #endif // DOXYGEN_NO_DETAIL
  99. }} // namespace boost::geometry
  100. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_RANGE_TO_GEOMETRY_RTREE_HPP