Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:02

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2014, Oracle and/or its affiliates.
0004 
0005 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
0006 
0007 // Licensed under the Boost Software License version 1.0.
0008 // http://www.boost.org/users/license.html
0009 
0010 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_FEATURE_GEOMETRY_TO_RANGE_HPP
0011 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_FEATURE_GEOMETRY_TO_RANGE_HPP
0012 
0013 #include <iterator>
0014 
0015 #include <boost/geometry/core/assert.hpp>
0016 #include <boost/geometry/core/point_type.hpp>
0017 #include <boost/geometry/strategies/distance.hpp>
0018 #include <boost/geometry/util/math.hpp>
0019 
0020 #include <boost/geometry/algorithms/dispatch/distance.hpp>
0021 
0022 
0023 namespace boost { namespace geometry
0024 {
0025 
0026 #ifndef DOXYGEN_NO_DETAIL
0027 namespace detail { namespace closest_feature
0028 {
0029 
0030 
0031 
0032 // returns the range iterator the realizes the closest
0033 // distance between the geometry and the element of the range
0034 class geometry_to_range
0035 {
0036 private:
0037     template
0038     <
0039         typename Geometry,
0040         typename RangeIterator,
0041         typename Strategy,
0042         typename Distance
0043     >
0044     static inline void apply(Geometry const& geometry,
0045                              RangeIterator first,
0046                              RangeIterator last,
0047                              Strategy const& strategy,
0048                              RangeIterator& it_min,
0049                              Distance& dist_min)
0050     {
0051         BOOST_GEOMETRY_ASSERT( first != last );
0052 
0053         Distance const zero = Distance(0);
0054 
0055         // start with first distance
0056         it_min = first;
0057         dist_min = dispatch::distance
0058             <
0059                 Geometry,
0060                 typename std::iterator_traits<RangeIterator>::value_type,
0061                 Strategy
0062             >::apply(geometry, *it_min, strategy);
0063 
0064         // check if other elements in the range are closer
0065         for (RangeIterator it = ++first; it != last; ++it)
0066         {
0067             Distance dist = dispatch::distance
0068                 <
0069                     Geometry,
0070                     typename std::iterator_traits<RangeIterator>::value_type,
0071                     Strategy
0072                 >::apply(geometry, *it, strategy);
0073 
0074             if (geometry::math::equals(dist, zero))
0075             {
0076                 dist_min = dist;
0077                 it_min = it;
0078                 return;
0079             }
0080             else if (dist < dist_min)
0081             {
0082                 dist_min = dist;
0083                 it_min = it;
0084             }
0085         }
0086     }
0087 
0088 public:
0089     template
0090     <
0091         typename Geometry,
0092         typename RangeIterator,
0093         typename Strategy,
0094         typename Distance
0095     >
0096     static inline RangeIterator apply(Geometry const& geometry,
0097                                       RangeIterator first,
0098                                       RangeIterator last,
0099                                       Strategy const& strategy,
0100                                       Distance& dist_min)
0101     {
0102         RangeIterator it_min;
0103         apply(geometry, first, last, strategy, it_min, dist_min);
0104 
0105         return it_min;
0106     }
0107 
0108 
0109     template
0110     <
0111         typename Geometry,
0112         typename RangeIterator,
0113         typename Strategy
0114     >
0115     static inline RangeIterator apply(Geometry const& geometry,
0116                                       RangeIterator first,
0117                                       RangeIterator last,
0118                                       Strategy const& strategy)
0119     {
0120         typename strategy::distance::services::return_type
0121             <
0122                 Strategy,
0123                 typename point_type<Geometry>::type,
0124                 typename point_type
0125                     <
0126                         typename std::iterator_traits
0127                             <
0128                                 RangeIterator
0129                             >::value_type
0130                     >::type
0131             >::type dist_min;
0132 
0133         return apply(geometry, first, last, strategy, dist_min);
0134     }
0135 };
0136 
0137 
0138 
0139 }} // namespace detail::closest_feature
0140 #endif // DOXYGEN_NO_DETAIL
0141 
0142 }} // namespace boost::geometry
0143 
0144 
0145 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_FEATURE_GEOMETRY_TO_RANGE_HPP