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_CLOSEST_FEATURE_GEOMETRY_TO_RANGE_HPP
11 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_FEATURE_GEOMETRY_TO_RANGE_HPP
15 #include <boost/geometry/core/assert.hpp>
16 #include <boost/geometry/core/point_type.hpp>
17 #include <boost/geometry/strategies/distance.hpp>
18 #include <boost/geometry/util/math.hpp>
20 #include <boost/geometry/algorithms/dispatch/distance.hpp>
23 namespace boost { namespace geometry
26 #ifndef DOXYGEN_NO_DETAIL
27 namespace detail { namespace closest_feature
32 // returns the range iterator the realizes the closest
33 // distance between the geometry and the element of the range
34 class geometry_to_range
40 typename RangeIterator,
44 static inline void apply(Geometry const& geometry,
47 Strategy const& strategy,
48 RangeIterator& it_min,
51 BOOST_GEOMETRY_ASSERT( first != last );
53 Distance const zero = Distance(0);
55 // start with first distance
57 dist_min = dispatch::distance
60 typename std::iterator_traits<RangeIterator>::value_type,
62 >::apply(geometry, *it_min, strategy);
64 // check if other elements in the range are closer
65 for (RangeIterator it = ++first; it != last; ++it)
67 Distance dist = dispatch::distance
70 typename std::iterator_traits<RangeIterator>::value_type,
72 >::apply(geometry, *it, strategy);
74 if (geometry::math::equals(dist, zero))
80 else if (dist < dist_min)
92 typename RangeIterator,
96 static inline RangeIterator apply(Geometry const& geometry,
99 Strategy const& strategy,
102 RangeIterator it_min;
103 apply(geometry, first, last, strategy, it_min, dist_min);
112 typename RangeIterator,
115 static inline RangeIterator apply(Geometry const& geometry,
118 Strategy const& strategy)
120 typename strategy::distance::services::return_type
123 typename point_type<Geometry>::type,
126 typename std::iterator_traits
133 return apply(geometry, first, last, strategy, dist_min);
139 }} // namespace detail::closest_feature
140 #endif // DOXYGEN_NO_DETAIL
142 }} // namespace boost::geometry
145 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_FEATURE_GEOMETRY_TO_RANGE_HPP