linear_to_box.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2018, 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_DISTANCE_LINEAR_TO_BOX_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_BOX_HPP
  8. #include <boost/geometry/core/point_type.hpp>
  9. #include <boost/geometry/algorithms/intersects.hpp>
  10. namespace boost { namespace geometry
  11. {
  12. #ifndef DOXYGEN_NO_DETAIL
  13. namespace detail { namespace distance
  14. {
  15. template <typename Linear, typename Box, typename Strategy>
  16. struct linear_to_box
  17. {
  18. typedef typename strategy::distance::services::return_type
  19. <
  20. Strategy,
  21. typename point_type<Linear>::type,
  22. typename point_type<Box>::type
  23. >::type return_type;
  24. template <typename Iterator>
  25. static inline return_type apply(Box const& box,
  26. Iterator begin,
  27. Iterator end,
  28. Strategy const& strategy)
  29. {
  30. bool first = true;
  31. return_type d_min(0);
  32. for (Iterator it = begin; it != end; ++it, first = false)
  33. {
  34. typedef typename std::iterator_traits<Iterator>::value_type
  35. Segment;
  36. return_type d = dispatch::distance<Segment, Box, Strategy>
  37. ::apply(*it, box, strategy);
  38. if ( first || d < d_min )
  39. {
  40. d_min = d;
  41. }
  42. }
  43. return d_min;
  44. }
  45. static inline return_type apply(Linear const& linear,
  46. Box const& box,
  47. Strategy const& strategy)
  48. {
  49. if ( geometry::intersects(linear, box) )
  50. {
  51. return 0;
  52. }
  53. return apply(box,
  54. geometry::segments_begin(linear),
  55. geometry::segments_end(linear),
  56. strategy);
  57. }
  58. static inline return_type apply(Box const& box,
  59. Linear const& linear,
  60. Strategy const& strategy)
  61. {
  62. return apply(linear, box, strategy);
  63. }
  64. };
  65. }} // namespace detail::distance
  66. #endif // DOXYGEN_NO_DETAIL
  67. #ifndef DOXYGEN_NO_DISPATCH
  68. namespace dispatch
  69. {
  70. template <typename Linear, typename Box, typename Strategy>
  71. struct distance
  72. <
  73. Linear, Box, Strategy,
  74. linear_tag, box_tag,
  75. strategy_tag_distance_segment_box, false
  76. >
  77. : detail::distance::linear_to_box
  78. <
  79. Linear, Box, Strategy
  80. >
  81. {};
  82. template <typename Areal, typename Box, typename Strategy>
  83. struct distance
  84. <
  85. Areal, Box, Strategy,
  86. areal_tag, box_tag,
  87. strategy_tag_distance_segment_box, false
  88. >
  89. : detail::distance::linear_to_box
  90. <
  91. Areal, Box, Strategy
  92. >
  93. {};
  94. } // namespace dispatch
  95. #endif // DOXYGEN_NO_DISPATCH
  96. }} // namespace boost::geometry
  97. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_BOX_HPP