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