1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2014, Oracle and/or its affiliates.
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
7 // Licensed under the Boost Software License version 1.0.
8 // http://www.boost.org/users/license.html
10 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_MULTIPOINT_TO_GEOMETRY_HPP
11 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_MULTIPOINT_TO_GEOMETRY_HPP
13 #include <boost/range.hpp>
15 #include <boost/geometry/core/point_type.hpp>
16 #include <boost/geometry/core/tags.hpp>
18 #include <boost/geometry/strategies/distance.hpp>
19 #include <boost/geometry/strategies/tags.hpp>
21 #include <boost/geometry/algorithms/covered_by.hpp>
23 #include <boost/geometry/algorithms/dispatch/distance.hpp>
25 #include <boost/geometry/algorithms/detail/check_iterator_range.hpp>
26 #include <boost/geometry/algorithms/detail/distance/range_to_geometry_rtree.hpp>
29 namespace boost { namespace geometry
32 #ifndef DOXYGEN_NO_DETAIL
33 namespace detail { namespace distance
37 template <typename MultiPoint1, typename MultiPoint2, typename Strategy>
38 struct multipoint_to_multipoint
40 typedef typename strategy::distance::services::return_type
43 typename point_type<MultiPoint1>::type,
44 typename point_type<MultiPoint2>::type
47 static inline return_type apply(MultiPoint1 const& multipoint1,
48 MultiPoint2 const& multipoint2,
49 Strategy const& strategy)
51 if (boost::size(multipoint2) < boost::size(multipoint1))
54 return point_or_segment_range_to_geometry_rtree
56 typename boost::range_iterator<MultiPoint2 const>::type,
59 >::apply(boost::begin(multipoint2),
60 boost::end(multipoint2),
65 return point_or_segment_range_to_geometry_rtree
67 typename boost::range_iterator<MultiPoint1 const>::type,
70 >::apply(boost::begin(multipoint1),
71 boost::end(multipoint1),
78 template <typename MultiPoint, typename Linear, typename Strategy>
79 struct multipoint_to_linear
81 typedef typename strategy::distance::services::return_type
84 typename point_type<MultiPoint>::type,
85 typename point_type<Linear>::type
88 static inline return_type apply(MultiPoint const& multipoint,
90 Strategy const& strategy)
92 return detail::distance::point_or_segment_range_to_geometry_rtree
94 typename boost::range_iterator<MultiPoint const>::type,
97 >::apply(boost::begin(multipoint),
98 boost::end(multipoint),
103 static inline return_type apply(Linear const& linear,
104 MultiPoint const& multipoint,
105 Strategy const& strategy)
107 return apply(multipoint, linear, strategy);
112 template <typename MultiPoint, typename Areal, typename Strategy>
113 class multipoint_to_areal
116 struct not_covered_by_areal
118 not_covered_by_areal(Areal const& areal)
122 template <typename Point>
123 inline bool apply(Point const& point) const
125 return !geometry::covered_by(point, m_areal);
128 Areal const& m_areal;
132 typedef typename strategy::distance::services::return_type
135 typename point_type<MultiPoint>::type,
136 typename point_type<Areal>::type
139 static inline return_type apply(MultiPoint const& multipoint,
141 Strategy const& strategy)
143 not_covered_by_areal predicate(areal);
145 if (check_iterator_range
147 not_covered_by_areal, false
148 >::apply(boost::begin(multipoint),
149 boost::end(multipoint),
152 return detail::distance::point_or_segment_range_to_geometry_rtree
154 typename boost::range_iterator<MultiPoint const>::type,
157 >::apply(boost::begin(multipoint),
158 boost::end(multipoint),
165 static inline return_type apply(Areal const& areal,
166 MultiPoint const& multipoint,
167 Strategy const& strategy)
169 return apply(multipoint, areal, strategy);
174 }} // namespace detail::distance
175 #endif // DOXYGEN_NO_DETAIL
179 #ifndef DOXYGEN_NO_DISPATCH
184 template <typename MultiPoint1, typename MultiPoint2, typename Strategy>
187 MultiPoint1, MultiPoint2, Strategy,
188 multi_point_tag, multi_point_tag,
189 strategy_tag_distance_point_point, false
190 > : detail::distance::multipoint_to_multipoint
192 MultiPoint1, MultiPoint2, Strategy
196 template <typename MultiPoint, typename Linear, typename Strategy>
199 MultiPoint, Linear, Strategy, multi_point_tag, linear_tag,
200 strategy_tag_distance_point_segment, false
201 > : detail::distance::multipoint_to_linear<MultiPoint, Linear, Strategy>
205 template <typename Linear, typename MultiPoint, typename Strategy>
208 Linear, MultiPoint, Strategy, linear_tag, multi_point_tag,
209 strategy_tag_distance_point_segment, false
210 > : detail::distance::multipoint_to_linear<MultiPoint, Linear, Strategy>
214 template <typename MultiPoint, typename Areal, typename Strategy>
217 MultiPoint, Areal, Strategy, multi_point_tag, areal_tag,
218 strategy_tag_distance_point_segment, false
219 > : detail::distance::multipoint_to_areal<MultiPoint, Areal, Strategy>
223 template <typename Areal, typename MultiPoint, typename Strategy>
226 Areal, MultiPoint, Strategy, areal_tag, multi_point_tag,
227 strategy_tag_distance_point_segment, false
228 > : detail::distance::multipoint_to_areal<MultiPoint, Areal, Strategy>
232 } // namespace dispatch
233 #endif // DOXYGEN_NO_DISPATCH
236 }} // namespace boost::geometry
239 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISTANCE_MULTIPOINT_TO_GEOMETRY_HPP