interface.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // Boost.Geometry
  2. // Copyright (c) 2021, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Vissarion Fysikopoulos, 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_CLOSEST_POINTS_INTERFACE_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_POINTS_INTERFACE_HPP
  8. #include <boost/concept_check.hpp>
  9. #include <boost/geometry/algorithms/detail/throw_on_empty_input.hpp>
  10. #include <boost/geometry/algorithms/detail/closest_points/utilities.hpp>
  11. #include <boost/geometry/algorithms/dispatch/closest_points.hpp>
  12. #include <boost/geometry/algorithms/detail/distance/interface.hpp>
  13. #include <boost/geometry/core/point_type.hpp>
  14. #include <boost/geometry/geometries/adapted/boost_variant.hpp> // For backward compatibility
  15. #include <boost/geometry/geometries/concepts/check.hpp>
  16. #include <boost/geometry/strategies/default_strategy.hpp>
  17. #include <boost/geometry/strategies/detail.hpp>
  18. #include <boost/geometry/strategies/closest_points/services.hpp>
  19. namespace boost { namespace geometry
  20. {
  21. #ifndef DOXYGEN_NO_DISPATCH
  22. namespace dispatch
  23. {
  24. // If reversal is needed, perform it
  25. template
  26. <
  27. typename Geometry1,
  28. typename Geometry2,
  29. typename Tag1,
  30. typename Tag2
  31. >
  32. struct closest_points
  33. <
  34. Geometry1, Geometry2,
  35. Tag1, Tag2, true
  36. >
  37. : closest_points<Geometry2, Geometry1, Tag2, Tag1, false>
  38. {
  39. template <typename Segment, typename Strategy>
  40. static inline void apply(Geometry1 const& g1, Geometry2 const& g2,
  41. Segment& shortest_seg, Strategy const& strategy)
  42. {
  43. closest_points
  44. <
  45. Geometry2, Geometry1, Tag2, Tag1, false
  46. >::apply(g2, g1, shortest_seg, strategy);
  47. detail::closest_points::swap_segment_points::apply(shortest_seg);
  48. }
  49. };
  50. } // namespace dispatch
  51. #endif // DOXYGEN_NO_DISPATCH
  52. namespace resolve_strategy
  53. {
  54. template<typename Strategy>
  55. struct closest_points
  56. {
  57. template <typename Geometry1, typename Geometry2, typename Segment>
  58. static inline void apply(Geometry1 const& geometry1,
  59. Geometry2 const& geometry2,
  60. Segment& shortest_seg,
  61. Strategy const& strategy)
  62. {
  63. dispatch::closest_points
  64. <
  65. Geometry1, Geometry2
  66. >::apply(geometry1, geometry2, shortest_seg, strategy);
  67. }
  68. };
  69. template <>
  70. struct closest_points<default_strategy>
  71. {
  72. template <typename Geometry1, typename Geometry2, typename Segment>
  73. static inline void
  74. apply(Geometry1 const& geometry1,
  75. Geometry2 const& geometry2,
  76. Segment& shortest_seg,
  77. default_strategy)
  78. {
  79. using strategy_type = typename strategies::closest_points::services::default_strategy
  80. <
  81. Geometry1, Geometry2
  82. >::type;
  83. dispatch::closest_points
  84. <
  85. Geometry1, Geometry2
  86. >::apply(geometry1, geometry2, shortest_seg, strategy_type());
  87. }
  88. };
  89. } // namespace resolve_strategy
  90. namespace resolve_variant
  91. {
  92. template <typename Geometry1, typename Geometry2>
  93. struct closest_points
  94. {
  95. template <typename Segment, typename Strategy>
  96. static inline void apply(Geometry1 const& geometry1,
  97. Geometry2 const& geometry2,
  98. Segment& shortest_seg,
  99. Strategy const& strategy)
  100. {
  101. resolve_strategy::closest_points
  102. <
  103. Strategy
  104. >::apply(geometry1, geometry2, shortest_seg, strategy);
  105. }
  106. };
  107. //TODO: Add support for DG/GC
  108. } // namespace resolve_variant
  109. /*!
  110. \brief Calculate the closest points between two geometries \brief_strategy
  111. \ingroup closest_points
  112. \details
  113. \details The free function closest_points calculates the distance between two geometries \brief_strategy. \details_strategy_reasons
  114. \tparam Geometry1 \tparam_geometry
  115. \tparam Geometry2 \tparam_geometry
  116. \tparam Segment Any type fulfilling a Segment Concept
  117. \tparam Strategy \tparam_strategy{Closest Points}
  118. \param geometry1 \param_geometry
  119. \param geometry2 \param_geometry
  120. \param shortest_seg Output segment containing the closest points
  121. \param strategy \param_strategy{closest_points}
  122. \note The strategy can be a point-point strategy. In case of distance point-line/point-polygon
  123. it may also be a point-segment strategy.
  124. \qbk{distinguish,with strategy}
  125. \qbk{
  126. [heading Example]
  127. [closest_points_strategy]
  128. [closest_points_strategy_output]
  129. [heading See also]
  130. \* [link geometry.reference.algorithms.distance distance]
  131. }
  132. */
  133. template <typename Geometry1, typename Geometry2, typename Segment, typename Strategy>
  134. inline void closest_points(Geometry1 const& geometry1,
  135. Geometry2 const& geometry2,
  136. Segment& shortest_seg,
  137. Strategy const& strategy)
  138. {
  139. concepts::check<Geometry1 const>();
  140. concepts::check<Geometry2 const>();
  141. detail::throw_on_empty_input(geometry1);
  142. detail::throw_on_empty_input(geometry2);
  143. resolve_variant::closest_points
  144. <
  145. Geometry1,
  146. Geometry2
  147. >::apply(geometry1, geometry2, shortest_seg, strategy);
  148. }
  149. /*!
  150. \brief Compute the closest points between two geometries.
  151. \ingroup closest_points
  152. \details The free function closest_points calculates the closest points between two geometries. \details_default_strategy
  153. \tparam Geometry1 \tparam_geometry
  154. \tparam Geometry2 \tparam_geometry
  155. \tparam Segment Any type fulfilling a Segment Concept
  156. \param geometry1 \param_geometry
  157. \param geometry2 \param_geometry
  158. \param shortest_seg Output segment containing the closest points
  159. \qbk{
  160. [heading Example]
  161. [closest_points]
  162. [closest_points_output]
  163. [heading See also]
  164. \* [link geometry.reference.algorithms.distance distance]
  165. }
  166. */
  167. template <typename Geometry1, typename Geometry2, typename Segment>
  168. inline void closest_points(Geometry1 const& geometry1,
  169. Geometry2 const& geometry2,
  170. Segment& shortest_seg)
  171. {
  172. closest_points(geometry1, geometry2, shortest_seg, default_strategy());
  173. }
  174. }} // namespace boost::geometry
  175. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_POINTS_INTERFACE_HPP