Back to home page

EIC code displayed by LXR

 
 

    


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

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_POLICIES_PREDICATE_BASED_INTERRUPT_POLICY_HPP
0013 #define BOOST_GEOMETRY_ALGORITHMS_POLICIES_PREDICATE_BASED_INTERRUPT_POLICY_HPP
0014 
0015 #include <algorithm>
0016 
0017 #include <boost/range/begin.hpp>
0018 #include <boost/range/empty.hpp>
0019 #include <boost/range/end.hpp>
0020 
0021 
0022 namespace boost { namespace geometry
0023 {
0024 
0025 
0026 #ifndef DOXYGEN_NO_DETAIL
0027 namespace detail { namespace overlay
0028 {
0029 
0030 
0031 template
0032 <
0033     typename IsAcceptableTurnPredicate,
0034     bool AllowEmptyTurnRange = true // by default, allow an empty turn range
0035 >
0036 struct stateless_predicate_based_interrupt_policy
0037 {
0038     static bool const enabled = true;
0039     bool has_intersections; // set to true if there is at least one
0040                             // unacceptable turn
0041 
0042     inline stateless_predicate_based_interrupt_policy()
0043         : has_intersections(false)
0044     {}
0045 
0046     template <typename Range>
0047     inline bool apply(Range const& range)
0048     {
0049         // if there is at least one unacceptable turn in the range, return true
0050         bool const has_unacceptable_turn = std::any_of(boost::begin(range), boost::end(range),
0051             [](auto const& turn) {
0052                 return ! IsAcceptableTurnPredicate::apply(turn);
0053             });
0054 
0055         has_intersections = has_unacceptable_turn
0056                 && !(AllowEmptyTurnRange && boost::empty(range));
0057 
0058         return has_intersections;
0059     }
0060 };
0061 
0062 
0063 
0064 
0065 template
0066 <
0067     typename IsAcceptableTurnPredicate,
0068     bool AllowEmptyTurnRange = true // by default, allow an empty turn range
0069 >
0070 struct predicate_based_interrupt_policy
0071 {
0072     static bool const enabled = true;
0073     bool has_intersections; // set to true if there is at least one
0074                             // unacceptable turn
0075     IsAcceptableTurnPredicate const& m_predicate;
0076 
0077     inline
0078     predicate_based_interrupt_policy(IsAcceptableTurnPredicate const& predicate)
0079         : has_intersections(false)
0080         , m_predicate(predicate)
0081     {}
0082 
0083     template <typename Range>
0084     inline bool apply(Range const& range)
0085     {
0086         // if there is at least one unacceptable turn in the range, return true
0087         bool const has_unacceptable_turn = std::any_of(boost::begin(range),
0088                                                        boost::end(range),
0089                                                        [&]( auto const& turn ) {
0090                                                            return ! m_predicate.apply(turn);
0091                                                        });
0092 
0093         has_intersections = has_unacceptable_turn
0094             && !(AllowEmptyTurnRange && boost::empty(range));
0095 
0096         return has_intersections;
0097     }
0098 };
0099 
0100 
0101 
0102 
0103 }} // namespace detail::overlay
0104 #endif // DOXYGEN_NO_DETAIL
0105 
0106 
0107 }} // namespace boost::geometry
0108 
0109 
0110 #endif // BOOST_GEOMETRY_ALGORITHMS_POLICIES_PREDICATE_BASED_INTERRUPT_POLICY_HPP