File indexing completed on 2025-01-18 09:35:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_NUM_DISTINCT_CONSECUTIVE_POINTS_HPP
0013 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_NUM_DISTINCT_CONSECUTIVE_POINTS_HPP
0014
0015
0016 #include <algorithm>
0017 #include <cstddef>
0018
0019 #include <boost/range/begin.hpp>
0020 #include <boost/range/end.hpp>
0021 #include <boost/range/size.hpp>
0022
0023 #include <boost/geometry/algorithms/detail/equals/point_point.hpp>
0024
0025
0026 namespace boost { namespace geometry
0027 {
0028
0029
0030 #ifndef DOXYGEN_NO_DETAIL
0031 namespace detail
0032 {
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 template
0044 <
0045 typename Range,
0046 std::size_t MaximumNumber,
0047 bool AllowDuplicates
0048 >
0049 struct num_distinct_consecutive_points
0050 {
0051 template <typename Strategy>
0052 static inline std::size_t apply(Range const& range, Strategy const& strategy)
0053 {
0054 std::size_t const size = boost::size(range);
0055
0056 if ( size < 2u )
0057 {
0058 return (size < MaximumNumber) ? size : MaximumNumber;
0059 }
0060
0061 auto current = boost::begin(range);
0062 auto const end = boost::end(range);
0063 std::size_t counter(0);
0064 do
0065 {
0066 ++counter;
0067 auto next = std::find_if(current, end, [&](auto const& pt) {
0068 return ! equals::equals_point_point(pt, *current, strategy);
0069 });
0070 current = next;
0071 }
0072 while ( current != end && counter <= MaximumNumber );
0073
0074 return counter;
0075 }
0076 };
0077
0078
0079 template <typename Range, std::size_t MaximumNumber>
0080 struct num_distinct_consecutive_points<Range, MaximumNumber, false>
0081 {
0082 template <typename Strategy>
0083 static inline std::size_t apply(Range const& range, Strategy const&)
0084 {
0085 std::size_t const size = boost::size(range);
0086 return (size < MaximumNumber) ? size : MaximumNumber;
0087 }
0088 };
0089
0090
0091 }
0092 #endif
0093
0094
0095 }}
0096
0097
0098 #endif