1 // Boost.Geometry (aka GGL, Generic Geometry Library) 2 3 // Copyright (c) 2018, Oracle and/or its affiliates. 4 5 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle 6 7 // Licensed under the Boost Software License version 1.0. 8 // http://www.boost.org/users/license.html 9 10 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_BOX_HPP 11 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_BOX_HPP 12 13 #include <boost/geometry/core/point_type.hpp> 14 15 #include <boost/geometry/algorithms/intersects.hpp> 16 17 namespace boost { namespace geometry 18 { 19 20 #ifndef DOXYGEN_NO_DETAIL 21 namespace detail { namespace distance 22 { 23 24 template <typename Linear, typename Box, typename Strategy> 25 struct linear_to_box 26 { 27 typedef typename strategy::distance::services::return_type 28 < 29 Strategy, 30 typename point_type<Linear>::type, 31 typename point_type<Box>::type 32 >::type return_type; 33 34 template <typename Iterator> applyboost::geometry::detail::distance::linear_to_box35 static inline return_type apply(Box const& box, 36 Iterator begin, 37 Iterator end, 38 Strategy const& strategy) 39 { 40 bool first = true; 41 return_type d_min(0); 42 for (Iterator it = begin; it != end; ++it, first = false) 43 { 44 typedef typename std::iterator_traits<Iterator>::value_type 45 Segment; 46 47 return_type d = dispatch::distance<Segment, Box, Strategy> 48 ::apply(*it, box, strategy); 49 50 if ( first || d < d_min ) 51 { 52 d_min = d; 53 } 54 } 55 return d_min; 56 } 57 applyboost::geometry::detail::distance::linear_to_box58 static inline return_type apply(Linear const& linear, 59 Box const& box, 60 Strategy const& strategy) 61 { 62 if ( geometry::intersects(linear, box) ) 63 { 64 return 0; 65 } 66 67 return apply(box, 68 geometry::segments_begin(linear), 69 geometry::segments_end(linear), 70 strategy); 71 } 72 73 applyboost::geometry::detail::distance::linear_to_box74 static inline return_type apply(Box const& box, 75 Linear const& linear, 76 Strategy const& strategy) 77 { 78 return apply(linear, box, strategy); 79 } 80 }; 81 82 }} // namespace detail::distance 83 #endif // DOXYGEN_NO_DETAIL 84 85 86 #ifndef DOXYGEN_NO_DISPATCH 87 namespace dispatch 88 { 89 90 template <typename Linear, typename Box, typename Strategy> 91 struct distance 92 < 93 Linear, Box, Strategy, 94 linear_tag, box_tag, 95 strategy_tag_distance_segment_box, false 96 > 97 : detail::distance::linear_to_box 98 < 99 Linear, Box, Strategy 100 > 101 {}; 102 103 104 template <typename Areal, typename Box, typename Strategy> 105 struct distance 106 < 107 Areal, Box, Strategy, 108 areal_tag, box_tag, 109 strategy_tag_distance_segment_box, false 110 > 111 : detail::distance::linear_to_box 112 < 113 Areal, Box, Strategy 114 > 115 {}; 116 117 118 } // namespace dispatch 119 #endif // DOXYGEN_NO_DISPATCH 120 121 }} // namespace boost::geometry 122 123 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_BOX_HPP 124