1 // Boost.Geometry (aka GGL, Generic Geometry Library) 2 3 // Copyright (c) 2014, Oracle and/or its affiliates. 4 5 // Contributed and/or modified by Menelaos Karavelas, 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_LINEAR_HPP 11 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_LINEAR_TO_LINEAR_HPP 12 13 #include <boost/geometry/core/point_type.hpp> 14 15 #include <boost/geometry/strategies/distance.hpp> 16 17 #include <boost/geometry/iterators/point_iterator.hpp> 18 #include <boost/geometry/iterators/segment_iterator.hpp> 19 20 #include <boost/geometry/algorithms/num_points.hpp> 21 #include <boost/geometry/algorithms/num_segments.hpp> 22 23 #include <boost/geometry/algorithms/dispatch/distance.hpp> 24 25 #include <boost/geometry/algorithms/detail/distance/range_to_geometry_rtree.hpp> 26 27 28 namespace boost { namespace geometry 29 { 30 31 #ifndef DOXYGEN_NO_DETAIL 32 namespace detail { namespace distance 33 { 34 35 36 template <typename Linear1, typename Linear2, typename Strategy> 37 struct linear_to_linear 38 { 39 typedef typename strategy::distance::services::return_type 40 < 41 Strategy, 42 typename point_type<Linear1>::type, 43 typename point_type<Linear2>::type 44 >::type return_type; 45 applyboost::geometry::detail::distance::linear_to_linear46 static inline return_type apply(Linear1 const& linear1, 47 Linear2 const& linear2, 48 Strategy const& strategy, 49 bool = false) 50 { 51 if (geometry::num_points(linear1) == 1) 52 { 53 return dispatch::distance 54 < 55 typename point_type<Linear1>::type, 56 Linear2, 57 Strategy 58 >::apply(*points_begin(linear1), linear2, strategy); 59 } 60 61 if (geometry::num_points(linear2) == 1) 62 { 63 return dispatch::distance 64 < 65 typename point_type<Linear2>::type, 66 Linear1, 67 Strategy 68 >::apply(*points_begin(linear2), linear1, strategy); 69 } 70 71 if (geometry::num_segments(linear2) < geometry::num_segments(linear1)) 72 { 73 return point_or_segment_range_to_geometry_rtree 74 < 75 geometry::segment_iterator<Linear2 const>, 76 Linear1, 77 Strategy 78 >::apply(geometry::segments_begin(linear2), 79 geometry::segments_end(linear2), 80 linear1, 81 strategy); 82 83 } 84 85 return point_or_segment_range_to_geometry_rtree 86 < 87 geometry::segment_iterator<Linear1 const>, 88 Linear2, 89 Strategy 90 >::apply(geometry::segments_begin(linear1), 91 geometry::segments_end(linear1), 92 linear2, 93 strategy); 94 } 95 }; 96 97 98 }} // namespace detail::distance 99 #endif // DOXYGEN_NO_DETAIL 100 101 102 #ifndef DOXYGEN_NO_DISPATCH 103 namespace dispatch 104 { 105 106 template <typename Linear1, typename Linear2, typename Strategy> 107 struct distance 108 < 109 Linear1, Linear2, Strategy, 110 linear_tag, linear_tag, 111 strategy_tag_distance_point_segment, false 112 > : detail::distance::linear_to_linear 113 < 114 Linear1, Linear2, Strategy 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_LINEAR_HPP 124