linear_to_linear.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_LINEAR_TO_LINEAR_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_LINEAR_HPP
  8. #include <boost/geometry/core/point_type.hpp>
  9. #include <boost/geometry/strategies/distance.hpp>
  10. #include <boost/geometry/iterators/point_iterator.hpp>
  11. #include <boost/geometry/iterators/segment_iterator.hpp>
  12. #include <boost/geometry/algorithms/num_points.hpp>
  13. #include <boost/geometry/algorithms/num_segments.hpp>
  14. #include <boost/geometry/algorithms/dispatch/distance.hpp>
  15. #include <boost/geometry/algorithms/detail/distance/range_to_geometry_rtree.hpp>
  16. namespace boost { namespace geometry
  17. {
  18. #ifndef DOXYGEN_NO_DETAIL
  19. namespace detail { namespace distance
  20. {
  21. template <typename Linear1, typename Linear2, typename Strategy>
  22. struct linear_to_linear
  23. {
  24. typedef typename strategy::distance::services::return_type
  25. <
  26. Strategy,
  27. typename point_type<Linear1>::type,
  28. typename point_type<Linear2>::type
  29. >::type return_type;
  30. static inline return_type apply(Linear1 const& linear1,
  31. Linear2 const& linear2,
  32. Strategy const& strategy,
  33. bool = false)
  34. {
  35. if (geometry::num_points(linear1) == 1)
  36. {
  37. return dispatch::distance
  38. <
  39. typename point_type<Linear1>::type,
  40. Linear2,
  41. Strategy
  42. >::apply(*points_begin(linear1), linear2, strategy);
  43. }
  44. if (geometry::num_points(linear2) == 1)
  45. {
  46. return dispatch::distance
  47. <
  48. typename point_type<Linear2>::type,
  49. Linear1,
  50. Strategy
  51. >::apply(*points_begin(linear2), linear1, strategy);
  52. }
  53. if (geometry::num_segments(linear2) < geometry::num_segments(linear1))
  54. {
  55. return point_or_segment_range_to_geometry_rtree
  56. <
  57. geometry::segment_iterator<Linear2 const>,
  58. Linear1,
  59. Strategy
  60. >::apply(geometry::segments_begin(linear2),
  61. geometry::segments_end(linear2),
  62. linear1,
  63. strategy);
  64. }
  65. return point_or_segment_range_to_geometry_rtree
  66. <
  67. geometry::segment_iterator<Linear1 const>,
  68. Linear2,
  69. Strategy
  70. >::apply(geometry::segments_begin(linear1),
  71. geometry::segments_end(linear1),
  72. linear2,
  73. strategy);
  74. }
  75. };
  76. }} // namespace detail::distance
  77. #endif // DOXYGEN_NO_DETAIL
  78. #ifndef DOXYGEN_NO_DISPATCH
  79. namespace dispatch
  80. {
  81. template <typename Linear1, typename Linear2, typename Strategy>
  82. struct distance
  83. <
  84. Linear1, Linear2, Strategy,
  85. linear_tag, linear_tag,
  86. strategy_tag_distance_point_segment, false
  87. > : detail::distance::linear_to_linear
  88. <
  89. Linear1, Linear2, Strategy
  90. >
  91. {};
  92. } // namespace dispatch
  93. #endif // DOXYGEN_NO_DISPATCH
  94. }} // namespace boost::geometry
  95. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_LINEAR_HPP