]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
20effc67 | 3 | // Copyright (c) 2014-2020, Oracle and/or its affiliates. |
7c673cae FG |
4 | |
5 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle | |
20effc67 | 6 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle |
7c673cae FG |
7 | |
8 | // Licensed under the Boost Software License version 1.0. | |
9 | // http://www.boost.org/users/license.html | |
10 | ||
11 | #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_NUM_DISTINCT_CONSECUTIVE_POINTS_HPP | |
12 | #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_NUM_DISTINCT_CONSECUTIVE_POINTS_HPP | |
13 | ||
7c673cae FG |
14 | |
15 | #include <algorithm> | |
20effc67 | 16 | #include <cstddef> |
7c673cae | 17 | |
20effc67 TL |
18 | #include <boost/range/begin.hpp> |
19 | #include <boost/range/end.hpp> | |
20 | #include <boost/range/size.hpp> | |
7c673cae FG |
21 | |
22 | ||
23 | namespace boost { namespace geometry | |
24 | { | |
25 | ||
26 | ||
27 | #ifndef DOXYGEN_NO_DETAIL | |
28 | namespace detail | |
29 | { | |
30 | ||
31 | ||
32 | // returns the number of distinct values in the range; | |
33 | // return values are 0u through MaximumNumber, where MaximumNumber | |
34 | // corresponds to MaximumNumber or more distinct values | |
35 | // | |
36 | // FUTURE: take into account topologically closed ranges; | |
37 | // add appropriate template parameter(s) to control whether | |
38 | // the closing point for topologically closed ranges is to be | |
39 | // accounted for separately or not | |
40 | template | |
41 | < | |
42 | typename Range, | |
43 | std::size_t MaximumNumber, | |
1e59de90 | 44 | bool AllowDuplicates /* true */ |
7c673cae FG |
45 | > |
46 | struct num_distinct_consecutive_points | |
47 | { | |
1e59de90 TL |
48 | template <typename Strategy> |
49 | static inline std::size_t apply(Range const& range, Strategy const& strategy) | |
7c673cae FG |
50 | { |
51 | typedef typename boost::range_iterator<Range const>::type iterator; | |
52 | ||
53 | std::size_t const size = boost::size(range); | |
54 | ||
55 | if ( size < 2u ) | |
56 | { | |
57 | return (size < MaximumNumber) ? size : MaximumNumber; | |
58 | } | |
59 | ||
60 | iterator current = boost::begin(range); | |
1e59de90 | 61 | iterator const end = boost::end(range); |
7c673cae FG |
62 | std::size_t counter(0); |
63 | do | |
64 | { | |
65 | ++counter; | |
1e59de90 TL |
66 | iterator next = std::find_if(current, end, [&](auto const& pt) { |
67 | return ! equals::equals_point_point(pt, *current, strategy); | |
68 | }); | |
7c673cae FG |
69 | current = next; |
70 | } | |
1e59de90 | 71 | while ( current != end && counter <= MaximumNumber ); |
7c673cae FG |
72 | |
73 | return counter; | |
74 | } | |
75 | }; | |
76 | ||
77 | ||
1e59de90 TL |
78 | template <typename Range, std::size_t MaximumNumber> |
79 | struct num_distinct_consecutive_points<Range, MaximumNumber, false> | |
7c673cae | 80 | { |
1e59de90 TL |
81 | template <typename Strategy> |
82 | static inline std::size_t apply(Range const& range, Strategy const&) | |
7c673cae FG |
83 | { |
84 | std::size_t const size = boost::size(range); | |
85 | return (size < MaximumNumber) ? size : MaximumNumber; | |
86 | } | |
87 | }; | |
88 | ||
89 | ||
90 | } // namespace detail | |
91 | #endif // DOXYGEN_NO_DETAIL | |
92 | ||
93 | ||
94 | }} // namespace boost::geometry | |
95 | ||
96 | ||
97 | #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_NUM_DISTINCT_CONSECUTIVE_POINTS_HPP |