]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. | |
4 | ||
5 | // Use, modification and distribution is subject to the Boost Software License, | |
6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
7 | // http://www.boost.org/LICENSE_1_0.txt) | |
8 | ||
9 | #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_TURN_INFO_HPP | |
10 | #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_TURN_INFO_HPP | |
11 | ||
12 | ||
13 | #include <boost/array.hpp> | |
14 | ||
15 | #include <boost/geometry/core/coordinate_type.hpp> | |
b32b8144 | 16 | #include <boost/geometry/algorithms/detail/signed_size_type.hpp> |
7c673cae FG |
17 | #include <boost/geometry/algorithms/detail/overlay/segment_identifier.hpp> |
18 | #include <boost/geometry/algorithms/detail/overlay/overlay_type.hpp> | |
92f5a8d4 | 19 | #include <boost/geometry/policies/robustness/segment_ratio.hpp> |
7c673cae FG |
20 | |
21 | namespace boost { namespace geometry | |
22 | { | |
23 | ||
24 | #ifndef DOXYGEN_NO_DETAIL | |
25 | namespace detail { namespace overlay | |
26 | { | |
27 | ||
28 | enum method_type | |
29 | { | |
30 | method_none, | |
31 | method_disjoint, | |
32 | method_crosses, | |
33 | method_touch, | |
34 | method_touch_interior, | |
35 | method_collinear, | |
36 | method_equal, | |
20effc67 | 37 | method_start, |
7c673cae FG |
38 | method_error |
39 | }; | |
40 | ||
41 | ||
42 | /*! | |
43 | \brief Turn operation: operation | |
44 | \details Information necessary for traversal phase (a phase | |
45 | of the overlay process). The information is gathered during the | |
46 | get_turns (segment intersection) phase. | |
47 | The class is to be included in the turn_info class, either direct | |
48 | or a derived or similar class with more (e.g. enrichment) information. | |
49 | */ | |
50 | template <typename Point, typename SegmentRatio> | |
51 | struct turn_operation | |
52 | { | |
53 | typedef SegmentRatio segment_ratio_type; | |
54 | ||
55 | operation_type operation; | |
56 | segment_identifier seg_id; | |
57 | SegmentRatio fraction; | |
58 | ||
59 | typedef typename coordinate_type<Point>::type comparable_distance_type; | |
60 | comparable_distance_type remaining_distance; | |
61 | ||
62 | inline turn_operation() | |
63 | : operation(operation_none) | |
64 | , remaining_distance(0) | |
65 | {} | |
66 | }; | |
67 | ||
68 | ||
69 | /*! | |
70 | \brief Turn information: intersection point, method, and turn information | |
71 | \details Information necessary for traversal phase (a phase | |
72 | of the overlay process). The information is gathered during the | |
73 | get_turns (segment intersection) phase. | |
74 | \tparam Point point type of intersection point | |
75 | \tparam Operation gives classes opportunity to add additional info | |
76 | \tparam Container gives classes opportunity to define how operations are stored | |
77 | */ | |
78 | template | |
79 | < | |
80 | typename Point, | |
92f5a8d4 | 81 | typename SegmentRatio = geometry::segment_ratio<typename coordinate_type<Point>::type>, |
7c673cae FG |
82 | typename Operation = turn_operation<Point, SegmentRatio>, |
83 | typename Container = boost::array<Operation, 2> | |
84 | > | |
85 | struct turn_info | |
86 | { | |
87 | typedef Point point_type; | |
88 | typedef SegmentRatio segment_ratio_type; | |
89 | typedef Operation turn_operation_type; | |
90 | typedef Container container_type; | |
91 | ||
92 | Point point; | |
93 | method_type method; | |
b32b8144 FG |
94 | bool touch_only; // True in case of method touch(interior) and lines do not cross |
95 | signed_size_type cluster_id; // For multiple turns on same location, > 0. Else -1. 0 is unused. | |
7c673cae | 96 | bool discarded; |
b32b8144 | 97 | bool has_colocated_both; // Colocated with a uu turn (for union) or ii (other) |
7c673cae FG |
98 | |
99 | Container operations; | |
100 | ||
101 | inline turn_info() | |
102 | : method(method_none) | |
b32b8144 | 103 | , touch_only(false) |
7c673cae FG |
104 | , cluster_id(-1) |
105 | , discarded(false) | |
b32b8144 | 106 | , has_colocated_both(false) |
7c673cae FG |
107 | {} |
108 | ||
109 | inline bool both(operation_type type) const | |
110 | { | |
111 | return has12(type, type); | |
112 | } | |
113 | ||
114 | inline bool has(operation_type type) const | |
115 | { | |
116 | return this->operations[0].operation == type | |
117 | || this->operations[1].operation == type; | |
118 | } | |
119 | ||
120 | inline bool combination(operation_type type1, operation_type type2) const | |
121 | { | |
122 | return has12(type1, type2) || has12(type2, type1); | |
123 | } | |
124 | ||
125 | inline bool blocked() const | |
126 | { | |
127 | return both(operation_blocked); | |
128 | } | |
129 | inline bool opposite() const | |
130 | { | |
131 | return both(operation_opposite); | |
132 | } | |
133 | inline bool any_blocked() const | |
134 | { | |
135 | return has(operation_blocked); | |
136 | } | |
b32b8144 FG |
137 | inline bool is_clustered() const |
138 | { | |
139 | return cluster_id > 0; | |
140 | } | |
1e59de90 TL |
141 | inline bool is_self() const |
142 | { | |
143 | return operations[0].seg_id.source_index | |
144 | == operations[1].seg_id.source_index; | |
145 | } | |
7c673cae FG |
146 | |
147 | private : | |
148 | inline bool has12(operation_type type1, operation_type type2) const | |
149 | { | |
150 | return this->operations[0].operation == type1 | |
151 | && this->operations[1].operation == type2 | |
152 | ; | |
153 | } | |
154 | ||
155 | }; | |
156 | ||
157 | ||
158 | }} // namespace detail::overlay | |
159 | #endif //DOXYGEN_NO_DETAIL | |
160 | ||
161 | ||
162 | }} // namespace boost::geometry | |
163 | ||
164 | ||
165 | #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_TURN_INFO_HPP |