Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2014-2023, Oracle and/or its affiliates.
0004 
0005 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
0006 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
0007 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0008 
0009 // Licensed under the Boost Software License version 1.0.
0010 // http://www.boost.org/users/license.html
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 // returns the number of distinct values in the range;
0036 // return values are 0u through MaximumNumber, where MaximumNumber
0037 // corresponds to MaximumNumber or more distinct values
0038 //
0039 // FUTURE: take into account topologically closed ranges;
0040 //         add appropriate template parameter(s) to control whether
0041 //         the closing point for topologically closed ranges is to be
0042 //         accounted for separately or not
0043 template
0044 <
0045     typename Range,
0046     std::size_t MaximumNumber,
0047     bool AllowDuplicates /* true */
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 } // namespace detail
0092 #endif // DOXYGEN_NO_DETAIL
0093 
0094 
0095 }} // namespace boost::geometry
0096 
0097 
0098 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_NUM_DISTINCT_CONSECUTIVE_POINTS_HPP