]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
1e59de90 | 3 | // Copyright (c) 2014-2021, Oracle and/or its affiliates. |
7c673cae FG |
4 | |
5 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle | |
b32b8144 | 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_IS_VALID_HAS_VALID_SELF_TURNS_HPP | |
12 | #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_HAS_VALID_SELF_TURNS_HPP | |
13 | ||
14 | #include <vector> | |
15 | ||
16 | #include <boost/core/ignore_unused.hpp> | |
20effc67 | 17 | #include <boost/range/empty.hpp> |
7c673cae | 18 | |
92f5a8d4 TL |
19 | #include <boost/geometry/algorithms/detail/is_valid/is_acceptable_turn.hpp> |
20 | #include <boost/geometry/algorithms/detail/overlay/get_turn_info.hpp> | |
21 | #include <boost/geometry/algorithms/detail/overlay/turn_info.hpp> | |
22 | #include <boost/geometry/algorithms/detail/overlay/self_turn_points.hpp> | |
23 | #include <boost/geometry/algorithms/validity_failure_type.hpp> | |
24 | ||
7c673cae FG |
25 | #include <boost/geometry/core/assert.hpp> |
26 | #include <boost/geometry/core/point_type.hpp> | |
27 | ||
28 | #include <boost/geometry/policies/predicate_based_interrupt_policy.hpp> | |
29 | #include <boost/geometry/policies/robustness/segment_ratio_type.hpp> | |
30 | #include <boost/geometry/policies/robustness/get_rescale_policy.hpp> | |
31 | ||
7c673cae FG |
32 | namespace boost { namespace geometry |
33 | { | |
34 | ||
35 | ||
36 | #ifndef DOXYGEN_NO_DETAIL | |
37 | namespace detail { namespace is_valid | |
38 | { | |
39 | ||
40 | ||
41 | template | |
42 | < | |
43 | typename Geometry, | |
1e59de90 | 44 | typename CSTag // TODO: remove |
7c673cae FG |
45 | > |
46 | class has_valid_self_turns | |
47 | { | |
48 | private: | |
49 | typedef typename point_type<Geometry>::type point_type; | |
50 | ||
51 | typedef typename geometry::rescale_policy_type | |
52 | < | |
92f5a8d4 TL |
53 | point_type, |
54 | CSTag | |
7c673cae FG |
55 | >::type rescale_policy_type; |
56 | ||
7c673cae FG |
57 | public: |
58 | typedef detail::overlay::turn_info | |
59 | < | |
60 | point_type, | |
92f5a8d4 | 61 | typename segment_ratio_type |
7c673cae FG |
62 | < |
63 | point_type, | |
64 | rescale_policy_type | |
65 | >::type | |
66 | > turn_type; | |
67 | ||
68 | // returns true if all turns are valid | |
b32b8144 | 69 | template <typename Turns, typename VisitPolicy, typename Strategy> |
7c673cae FG |
70 | static inline bool apply(Geometry const& geometry, |
71 | Turns& turns, | |
b32b8144 FG |
72 | VisitPolicy& visitor, |
73 | Strategy const& strategy) | |
7c673cae FG |
74 | { |
75 | boost::ignore_unused(visitor); | |
76 | ||
77 | rescale_policy_type robust_policy | |
92f5a8d4 | 78 | = geometry::get_rescale_policy<rescale_policy_type>(geometry, strategy); |
7c673cae FG |
79 | |
80 | detail::overlay::stateless_predicate_based_interrupt_policy | |
81 | < | |
92f5a8d4 | 82 | is_acceptable_turn<Geometry> |
7c673cae FG |
83 | > interrupt_policy; |
84 | ||
92f5a8d4 | 85 | // Calculate self-turns, skipping adjacent segments |
1e59de90 TL |
86 | detail::self_get_turn_points::self_turns |
87 | < | |
88 | false, detail::overlay::assign_null_policy | |
89 | >(geometry, strategy, robust_policy, turns, interrupt_policy, | |
90 | 0, true); | |
7c673cae FG |
91 | |
92 | if (interrupt_policy.has_intersections) | |
93 | { | |
94 | BOOST_GEOMETRY_ASSERT(! boost::empty(turns)); | |
95 | return visitor.template apply<failure_self_intersections>(turns); | |
96 | } | |
97 | else | |
98 | { | |
99 | return visitor.template apply<no_failure>(); | |
100 | } | |
101 | } | |
102 | ||
103 | // returns true if all turns are valid | |
b32b8144 FG |
104 | template <typename VisitPolicy, typename Strategy> |
105 | static inline bool apply(Geometry const& geometry, VisitPolicy& visitor, Strategy const& strategy) | |
7c673cae FG |
106 | { |
107 | std::vector<turn_type> turns; | |
b32b8144 | 108 | return apply(geometry, turns, visitor, strategy); |
7c673cae FG |
109 | } |
110 | }; | |
111 | ||
112 | ||
113 | }} // namespace detail::is_valid | |
114 | #endif // DOXYGEN_NO_DETAIL | |
115 | ||
116 | }} // namespace boost::geometry | |
117 | ||
118 | #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_HAS_VALID_SELF_TURNS_HPP |