linear_to_linear.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2021, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_LINEAR_HPP
  8. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_LINEAR_HPP
  9. #include <boost/geometry/algorithms/detail/distance/range_to_geometry_rtree.hpp>
  10. #include <boost/geometry/algorithms/detail/distance/strategy_utils.hpp>
  11. #include <boost/geometry/algorithms/dispatch/distance.hpp>
  12. #include <boost/geometry/algorithms/num_points.hpp>
  13. #include <boost/geometry/algorithms/num_segments.hpp>
  14. #include <boost/geometry/core/point_type.hpp>
  15. #include <boost/geometry/iterators/point_iterator.hpp>
  16. #include <boost/geometry/iterators/segment_iterator.hpp>
  17. #include <boost/geometry/strategies/distance.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. #ifndef DOXYGEN_NO_DETAIL
  21. namespace detail { namespace distance
  22. {
  23. template <typename Linear1, typename Linear2, typename Strategies>
  24. struct linear_to_linear
  25. {
  26. typedef distance::return_t<Linear1, Linear2, Strategies> return_type;
  27. static inline return_type apply(Linear1 const& linear1,
  28. Linear2 const& linear2,
  29. Strategies const& strategies,
  30. bool = false)
  31. {
  32. if (geometry::num_points(linear1) == 1)
  33. {
  34. return dispatch::distance
  35. <
  36. typename point_type<Linear1>::type,
  37. Linear2,
  38. Strategies
  39. >::apply(*points_begin(linear1), linear2, strategies);
  40. }
  41. if (geometry::num_points(linear2) == 1)
  42. {
  43. return dispatch::distance
  44. <
  45. typename point_type<Linear2>::type,
  46. Linear1,
  47. Strategies
  48. >::apply(*points_begin(linear2), linear1, strategies);
  49. }
  50. if (geometry::num_segments(linear2) < geometry::num_segments(linear1))
  51. {
  52. return point_or_segment_range_to_geometry_rtree
  53. <
  54. geometry::segment_iterator<Linear2 const>,
  55. Linear1,
  56. Strategies
  57. >::apply(geometry::segments_begin(linear2),
  58. geometry::segments_end(linear2),
  59. linear1,
  60. strategies);
  61. }
  62. return point_or_segment_range_to_geometry_rtree
  63. <
  64. geometry::segment_iterator<Linear1 const>,
  65. Linear2,
  66. Strategies
  67. >::apply(geometry::segments_begin(linear1),
  68. geometry::segments_end(linear1),
  69. linear2,
  70. strategies);
  71. }
  72. };
  73. }} // namespace detail::distance
  74. #endif // DOXYGEN_NO_DETAIL
  75. #ifndef DOXYGEN_NO_DISPATCH
  76. namespace dispatch
  77. {
  78. template <typename Linear1, typename Linear2, typename Strategy, typename StrategyTag>
  79. struct distance
  80. <
  81. Linear1, Linear2, Strategy,
  82. linear_tag, linear_tag,
  83. StrategyTag, false
  84. > : detail::distance::linear_to_linear
  85. <
  86. Linear1, Linear2, Strategy
  87. >
  88. {};
  89. } // namespace dispatch
  90. #endif // DOXYGEN_NO_DISPATCH
  91. }} // namespace boost::geometry
  92. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_LINEAR_HPP