]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 2014-2015, Oracle and/or its affiliates. | |
4 | ||
5 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle | |
6 | ||
7 | // Licensed under the Boost Software License version 1.0. | |
8 | // http://www.boost.org/users/license.html | |
9 | ||
10 | #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_HAS_VALID_SELF_TURNS_HPP | |
11 | #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_HAS_VALID_SELF_TURNS_HPP | |
12 | ||
13 | #include <vector> | |
14 | ||
15 | #include <boost/core/ignore_unused.hpp> | |
16 | #include <boost/range.hpp> | |
17 | ||
18 | #include <boost/geometry/core/assert.hpp> | |
19 | #include <boost/geometry/core/point_type.hpp> | |
20 | ||
21 | #include <boost/geometry/policies/predicate_based_interrupt_policy.hpp> | |
22 | #include <boost/geometry/policies/robustness/segment_ratio_type.hpp> | |
23 | #include <boost/geometry/policies/robustness/get_rescale_policy.hpp> | |
24 | ||
25 | #include <boost/geometry/algorithms/detail/overlay/get_turn_info.hpp> | |
26 | #include <boost/geometry/algorithms/detail/overlay/turn_info.hpp> | |
27 | #include <boost/geometry/algorithms/detail/overlay/self_turn_points.hpp> | |
28 | ||
29 | #include <boost/geometry/algorithms/detail/is_valid/is_acceptable_turn.hpp> | |
30 | ||
31 | namespace boost { namespace geometry | |
32 | { | |
33 | ||
34 | ||
35 | #ifndef DOXYGEN_NO_DETAIL | |
36 | namespace detail { namespace is_valid | |
37 | { | |
38 | ||
39 | ||
40 | template | |
41 | < | |
42 | typename Geometry, | |
43 | typename IsAcceptableTurn = is_acceptable_turn<Geometry> | |
44 | > | |
45 | class has_valid_self_turns | |
46 | { | |
47 | private: | |
48 | typedef typename point_type<Geometry>::type point_type; | |
49 | ||
50 | typedef typename geometry::rescale_policy_type | |
51 | < | |
52 | point_type | |
53 | >::type rescale_policy_type; | |
54 | ||
55 | typedef detail::overlay::get_turn_info | |
56 | < | |
57 | detail::overlay::assign_null_policy | |
58 | > turn_policy; | |
59 | ||
60 | public: | |
61 | typedef detail::overlay::turn_info | |
62 | < | |
63 | point_type, | |
64 | typename geometry::segment_ratio_type | |
65 | < | |
66 | point_type, | |
67 | rescale_policy_type | |
68 | >::type | |
69 | > turn_type; | |
70 | ||
71 | // returns true if all turns are valid | |
72 | template <typename Turns, typename VisitPolicy> | |
73 | static inline bool apply(Geometry const& geometry, | |
74 | Turns& turns, | |
75 | VisitPolicy& visitor) | |
76 | { | |
77 | boost::ignore_unused(visitor); | |
78 | ||
79 | rescale_policy_type robust_policy | |
80 | = geometry::get_rescale_policy<rescale_policy_type>(geometry); | |
81 | ||
82 | detail::overlay::stateless_predicate_based_interrupt_policy | |
83 | < | |
84 | IsAcceptableTurn | |
85 | > interrupt_policy; | |
86 | ||
87 | geometry::self_turns<turn_policy>(geometry, | |
88 | robust_policy, | |
89 | turns, | |
90 | interrupt_policy); | |
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 | |
104 | template <typename VisitPolicy> | |
105 | static inline bool apply(Geometry const& geometry, VisitPolicy& visitor) | |
106 | { | |
107 | std::vector<turn_type> turns; | |
108 | return apply(geometry, turns, visitor); | |
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 |