Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / geometry / algorithms / detail / is_valid / has_valid_self_turns.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2014, 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 <boost/geometry/core/point_type.hpp>
14
15 #include <boost/geometry/policies/predicate_based_interrupt_policy.hpp>
16 #include <boost/geometry/policies/robustness/segment_ratio_type.hpp>
17 #include <boost/geometry/policies/robustness/get_rescale_policy.hpp>
18
19 #include <boost/geometry/algorithms/detail/overlay/get_turn_info.hpp>
20 #include <boost/geometry/algorithms/detail/overlay/turn_info.hpp>
21 #include <boost/geometry/algorithms/detail/overlay/self_turn_points.hpp>
22
23 #include <boost/geometry/algorithms/detail/is_valid/is_acceptable_turn.hpp>
24
25
26 namespace boost { namespace geometry
27 {
28
29
30 #ifndef DOXYGEN_NO_DETAIL
31 namespace detail { namespace is_valid
32 {
33
34
35 template
36 <
37     typename Geometry,
38     typename IsAcceptableTurn = is_acceptable_turn<Geometry>
39 >
40 class has_valid_self_turns
41 {
42 private:
43     typedef typename point_type<Geometry>::type point_type;
44
45     typedef typename geometry::rescale_policy_type
46         <
47             point_type
48         >::type rescale_policy_type;
49
50     typedef detail::overlay::get_turn_info
51         <
52             detail::overlay::assign_null_policy
53         > turn_policy;
54
55 public:
56     typedef detail::overlay::turn_info
57         <
58             point_type,
59             typename geometry::segment_ratio_type
60                 <
61                     point_type,
62                     rescale_policy_type
63                 >::type
64         > turn_type;
65
66     // returns true if all turns are valid
67     template <typename Turns>
68     static inline bool apply(Geometry const& geometry, Turns& turns)
69     {
70         rescale_policy_type robust_policy
71             = geometry::get_rescale_policy<rescale_policy_type>(geometry);
72
73         detail::overlay::stateless_predicate_based_interrupt_policy
74             <
75                 IsAcceptableTurn
76             > interrupt_policy;
77
78         geometry::self_turns<turn_policy>(geometry,
79                                           robust_policy,
80                                           turns,
81                                           interrupt_policy);
82
83         return !interrupt_policy.has_intersections;
84     }
85 };
86
87
88 }} // namespace detail::is_valid
89 #endif // DOXYGEN_NO_DETAIL
90
91 }} // namespace boost::geometry
92
93 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_HAS_VALID_SELF_TURNS_HPP