]>
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. |
92f5a8d4 TL |
4 | |
5 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle | |
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 | ||
7c673cae FG |
11 | #ifndef BOOST_GEOMETRY_TEST_GET_TURNS_LL_INVARIANCE_HPP |
12 | #define BOOST_GEOMETRY_TEST_GET_TURNS_LL_INVARIANCE_HPP | |
13 | ||
14 | #include <vector> | |
15 | ||
1e59de90 TL |
16 | #include <boost/range/begin.hpp> |
17 | #include <boost/range/end.hpp> | |
18 | #include <boost/range/size.hpp> | |
19 | ||
7c673cae FG |
20 | #include <boost/geometry/algorithms/reverse.hpp> |
21 | ||
22 | #include <boost/geometry/algorithms/detail/signed_size_type.hpp> | |
23 | ||
24 | #include <boost/geometry/algorithms/detail/relate/turns.hpp> | |
25 | ||
26 | #include <boost/geometry/algorithms/detail/turns/compare_turns.hpp> | |
27 | #include <boost/geometry/algorithms/detail/turns/print_turns.hpp> | |
28 | #include <boost/geometry/algorithms/detail/turns/filter_continue_turns.hpp> | |
29 | #include <boost/geometry/algorithms/detail/turns/remove_duplicate_turns.hpp> | |
30 | ||
31 | #include <boost/geometry/io/wkt/write.hpp> | |
32 | ||
33 | ||
34 | namespace bg = ::boost::geometry; | |
35 | namespace bg_detail = ::boost::geometry::detail; | |
36 | namespace bg_turns = bg_detail::turns; | |
37 | ||
38 | template | |
39 | < | |
40 | bool Enable = true, | |
41 | bool EnableRemoveDuplicateTurns = true, | |
42 | bool EnableDegenerateTurns = true | |
43 | > | |
44 | class test_get_turns_ll_invariance | |
45 | { | |
46 | private: | |
47 | struct assign_policy | |
48 | { | |
49 | static bool const include_no_turn = false; | |
50 | static bool const include_degenerate = EnableDegenerateTurns; | |
51 | static bool const include_opposite = false; | |
20effc67 | 52 | static bool const include_start_turn = false; |
7c673cae FG |
53 | |
54 | template | |
55 | < | |
56 | typename Info, | |
57 | typename Point1, | |
58 | typename Point2, | |
59 | typename IntersectionInfo | |
60 | > | |
61 | static inline void apply(Info& , Point1 const& , Point2 const& , | |
62 | IntersectionInfo const&) | |
63 | { | |
64 | } | |
65 | }; | |
66 | ||
67 | ||
68 | ||
69 | template | |
70 | < | |
71 | typename Turns, | |
72 | typename LinearGeometry1, | |
1e59de90 TL |
73 | typename LinearGeometry2, |
74 | typename Strategy | |
7c673cae FG |
75 | > |
76 | static inline void compute_turns(Turns& turns, | |
77 | LinearGeometry1 const& linear1, | |
1e59de90 TL |
78 | LinearGeometry2 const& linear2, |
79 | Strategy const& strategy) | |
7c673cae FG |
80 | { |
81 | turns.clear(); | |
1e59de90 | 82 | bg_detail::get_turns::no_interrupt_policy interrupt_policy; |
7c673cae FG |
83 | bg_detail::relate::turns::get_turns |
84 | < | |
85 | LinearGeometry1, | |
86 | LinearGeometry2, | |
87 | bg_detail::get_turns::get_turn_info_type | |
1e59de90 TL |
88 | < |
89 | LinearGeometry1, | |
90 | LinearGeometry2, | |
91 | assign_policy | |
92 | > | |
93 | >::apply(turns, linear1, linear2, | |
94 | interrupt_policy, | |
95 | strategy); | |
7c673cae FG |
96 | } |
97 | ||
98 | ||
99 | ||
100 | public: | |
101 | template <typename Linear1, typename Linear2> | |
102 | static inline void apply(Linear1 const& lineargeometry1, | |
103 | Linear2 const& lineargeometry2) | |
104 | { | |
1e59de90 | 105 | typedef typename bg::strategies::relate::services::default_strategy |
92f5a8d4 TL |
106 | < |
107 | Linear1, Linear2 | |
108 | >::type strategy_type; | |
109 | ||
7c673cae FG |
110 | typedef typename bg_detail::relate::turns::get_turns |
111 | < | |
112 | Linear1, Linear2 | |
92f5a8d4 | 113 | >::template turn_info_type<strategy_type>::type turn_info; |
7c673cae FG |
114 | |
115 | typedef std::vector<turn_info> turns_container; | |
116 | ||
117 | typedef bg_turns::filter_continue_turns | |
118 | < | |
119 | turns_container, true | |
120 | > filter_continue_turns; | |
121 | ||
122 | typedef bg_turns::remove_duplicate_turns | |
123 | < | |
124 | turns_container, EnableRemoveDuplicateTurns | |
125 | > remove_duplicate_turns; | |
126 | ||
127 | turns_container turns; | |
128 | ||
129 | Linear1 linear1(lineargeometry1); | |
130 | Linear2 linear2(lineargeometry2); | |
131 | ||
132 | Linear2 linear2_reverse(linear2); | |
133 | boost::geometry::reverse(linear2_reverse); | |
134 | ||
135 | turns_container turns_all, rturns_all; | |
1e59de90 TL |
136 | strategy_type strategy; |
137 | compute_turns(turns_all, linear1, linear2, strategy); | |
138 | compute_turns(rturns_all, linear1, linear2_reverse, strategy); | |
7c673cae FG |
139 | |
140 | turns_container turns_wo_cont(turns_all); | |
141 | turns_container rturns_wo_cont(rturns_all); | |
142 | ||
143 | filter_continue_turns::apply(turns_wo_cont); | |
144 | filter_continue_turns::apply(rturns_wo_cont); | |
145 | ||
146 | std::sort(boost::begin(turns_all), boost::end(turns_all), | |
147 | bg_turns::less_seg_fraction_other_op<>()); | |
148 | ||
149 | std::sort(boost::begin(turns_wo_cont), boost::end(turns_wo_cont), | |
150 | bg_turns::less_seg_fraction_other_op<>()); | |
151 | ||
152 | std::sort(boost::begin(rturns_all), boost::end(rturns_all), | |
153 | bg_turns::less_seg_fraction_other_op<std::greater<boost::geometry::signed_size_type> >()); | |
154 | ||
155 | std::sort(boost::begin(rturns_wo_cont), boost::end(rturns_wo_cont), | |
156 | bg_turns::less_seg_fraction_other_op<std::greater<boost::geometry::signed_size_type> >()); | |
157 | ||
158 | remove_duplicate_turns::apply(turns_all); | |
159 | remove_duplicate_turns::apply(turns_wo_cont); | |
160 | remove_duplicate_turns::apply(rturns_all); | |
161 | remove_duplicate_turns::apply(rturns_wo_cont); | |
162 | ||
163 | #ifdef BOOST_GEOMETRY_TEST_DEBUG | |
164 | std::cout << std::endl << std::endl; | |
165 | std::cout << "### ORIGINAL TURNS ###" << std::endl; | |
166 | bg_turns::print_turns(linear1, linear2, turns_all); | |
167 | std::cout << std::endl << std::endl; | |
168 | std::cout << "### ORIGINAL REVERSE TURNS ###" << std::endl; | |
169 | bg_turns::print_turns(linear1, linear2_reverse, rturns_all); | |
170 | std::cout << std::endl << std::endl; | |
171 | std::cout << "### TURNS W/O CONTINUE TURNS ###" << std::endl; | |
172 | bg_turns::print_turns(linear1, linear2, turns_wo_cont); | |
173 | std::cout << std::endl << std::endl; | |
174 | std::cout << "### REVERSE TURNS W/O CONTINUE TURNS ###" << std::endl; | |
175 | bg_turns::print_turns(linear1, linear2_reverse, rturns_wo_cont); | |
176 | std::cout << std::endl << std::endl; | |
177 | #endif | |
178 | ||
179 | BOOST_CHECK_MESSAGE(boost::size(turns_wo_cont) == boost::size(rturns_wo_cont), | |
180 | "Incompatible turns count: " << boost::size(turns_wo_cont) << | |
181 | " and " << boost::size(rturns_wo_cont) << | |
182 | " for L1: " << bg::wkt(lineargeometry1) << | |
183 | ", L2: " << bg::wkt(lineargeometry2)); | |
184 | } | |
185 | }; | |
186 | ||
187 | template <bool EnableRemoveDuplicateTurns, bool EnableDegenerateTurns> | |
188 | class test_get_turns_ll_invariance | |
189 | < | |
190 | false, EnableRemoveDuplicateTurns, EnableDegenerateTurns | |
191 | > | |
192 | { | |
193 | public: | |
194 | template <typename Linear1, typename Linear2> | |
195 | static inline void apply(Linear1 const&, Linear2 const&) | |
196 | { | |
197 | } | |
198 | }; | |
199 | ||
200 | #endif // BOOST_GEOMETRY_TEST_GET_TURNS_LL_INVARIANCE_HPP |