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_NUM_DISTINCT_CONSECUTIVE_POINTS_HPP
11 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_NUM_DISTINCT_CONSECUTIVE_POINTS_HPP
17 #include <boost/range.hpp>
21 namespace boost { namespace geometry
25 #ifndef DOXYGEN_NO_DETAIL
30 // returns the number of distinct values in the range;
31 // return values are 0u through MaximumNumber, where MaximumNumber
32 // corresponds to MaximumNumber or more distinct values
34 // FUTURE: take into account topologically closed ranges;
35 // add appropriate template parameter(s) to control whether
36 // the closing point for topologically closed ranges is to be
37 // accounted for separately or not
41 std::size_t MaximumNumber,
42 bool AllowDuplicates /* true */,
45 struct num_distinct_consecutive_points
47 static inline std::size_t apply(Range const& range)
49 typedef typename boost::range_iterator<Range const>::type iterator;
51 std::size_t const size = boost::size(range);
55 return (size < MaximumNumber) ? size : MaximumNumber;
58 iterator current = boost::begin(range);
59 std::size_t counter(0);
63 iterator next = std::find_if(current,
65 NotEqualTo(*current));
68 while ( current != boost::end(range) && counter <= MaximumNumber );
75 template <typename Range, std::size_t MaximumNumber, typename NotEqualTo>
76 struct num_distinct_consecutive_points<Range, MaximumNumber, false, NotEqualTo>
78 static inline std::size_t apply(Range const& range)
80 std::size_t const size = boost::size(range);
81 return (size < MaximumNumber) ? size : MaximumNumber;
87 #endif // DOXYGEN_NO_DETAIL
90 }} // namespace boost::geometry
93 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_NUM_DISTINCT_CONSECUTIVE_POINTS_HPP