]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // Boost.Geometry |
2 | // Unit Test | |
3 | ||
4 | // Copyright (c) 2021, Oracle and/or its affiliates. | |
5 | ||
6 | // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle | |
7 | ||
8 | // Licensed under the Boost Software License version 1.0. | |
9 | // http://www.boost.org/users/license.html | |
10 | ||
11 | #ifndef BOOST_TEST_MODULE | |
12 | #define BOOST_TEST_MODULE test_closest_points_linear_linear | |
13 | #endif | |
14 | ||
15 | #include "common.hpp" | |
16 | #include "empty_geometry.hpp" | |
17 | ||
18 | namespace bg = boost::geometry; | |
19 | ||
20 | //=========================================================================== | |
21 | ||
22 | template <typename Point, typename Strategies> | |
23 | void test_closest_points_segment_segment(Strategies const& strategies) | |
24 | { | |
25 | ||
26 | #ifdef BOOST_GEOMETRY_TEST_DEBUG | |
27 | std::cout << std::endl; | |
28 | std::cout << "point/segment closest_points tests" << std::endl; | |
29 | #endif | |
30 | ||
31 | typedef bg::model::segment<Point> Segment; | |
32 | typedef test_geometry<Segment, Segment, Segment> tester; | |
33 | ||
34 | tester::apply("SEGMENT(0 2,2 0)", | |
35 | "SEGMENT(0 1,1 0)", | |
36 | "SEGMENT(0.5 1.5,0 1)", | |
37 | "SEGMENT(0.50019 1.50021,0 1)", | |
38 | "SEGMENT(1.496909 0.503379,1 0)", | |
39 | strategies); | |
40 | ||
41 | //default strategies | |
42 | tester::apply("SEGMENT(0 2,2 0)", | |
43 | "SEGMENT(0 1,1 0)", | |
44 | "SEGMENT(0.5 1.5,0 1)", | |
45 | "SEGMENT(0.50019 1.50021,0 1)", | |
46 | "SEGMENT(1.496909 0.503379,1 0)", | |
47 | strategies, true, true); | |
48 | ||
49 | //geometries intersect | |
50 | tester::apply("SEGMENT(0 0,1 1)", | |
51 | "SEGMENT(0 1,1 0)", | |
52 | "SEGMENT(0.5 0.5,0.5 0.5)", | |
53 | "SEGMENT(0.5 0.500057,0.5 0.500057)", | |
54 | strategies); | |
55 | } | |
56 | ||
57 | //=========================================================================== | |
58 | ||
59 | template <typename Point, typename Strategies> | |
60 | void test_closest_points_segment_linestring(Strategies const& strategies) | |
61 | { | |
62 | ||
63 | #ifdef BOOST_GEOMETRY_TEST_DEBUG | |
64 | std::cout << std::endl; | |
65 | std::cout << "segment/linestring closest_points tests" << std::endl; | |
66 | #endif | |
67 | ||
68 | typedef bg::model::linestring<Point> Linestring; | |
69 | typedef bg::model::segment<Point> Segment; | |
70 | typedef test_geometry<Segment, Linestring, Segment> tester; | |
71 | ||
72 | tester::apply("SEGMENT(0 2,2 0)", | |
73 | "LINESTRING(-1 0,0 1,1 0,-1 -2)", | |
74 | "SEGMENT(0.5 1.5,0 1)", | |
75 | "SEGMENT(0.50019 1.50021,0 1)", | |
76 | "SEGMENT(1.496909 0.503379,1 0)", | |
77 | strategies); | |
78 | ||
79 | //default strategies | |
80 | tester::apply("SEGMENT(0 2,2 0)", | |
81 | "LINESTRING(-1 0,0 1,1 0,-1 -2)", | |
82 | "SEGMENT(0.5 1.5,0 1)", | |
83 | "SEGMENT(0.50019 1.50021,0 1)", | |
84 | "SEGMENT(1.496909 0.503379,1 0)", | |
85 | strategies, true, true); | |
86 | ||
87 | //geometries intersect | |
88 | tester::apply("SEGMENT(0 0,1 1)", | |
89 | "LINESTRING(0 2,0 1,1 0,2 0)", | |
90 | "SEGMENT(0.5 0.5,0.5 0.5)", | |
91 | "SEGMENT(0.5 0.500057,0.5 0.500057)", | |
92 | strategies); | |
93 | } | |
94 | ||
95 | //=========================================================================== | |
96 | ||
97 | template <typename Point, typename Strategies> | |
98 | void test_closest_points_linestring_linestring(Strategies const& strategies) | |
99 | { | |
100 | ||
101 | #ifdef BOOST_GEOMETRY_TEST_DEBUG | |
102 | std::cout << std::endl; | |
103 | std::cout << "linestring/linestring closest_points tests" << std::endl; | |
104 | #endif | |
105 | ||
106 | typedef bg::model::linestring<Point> Linestring; | |
107 | typedef bg::model::segment<Point> Segment; | |
108 | typedef test_geometry<Linestring, Linestring, Segment> tester; | |
109 | ||
110 | tester::apply("LINESTRING(0 2,2 0,3 0,4 0,5 0)", | |
111 | "LINESTRING(-1 0,0 1,1 0,-1 -2)", | |
112 | "SEGMENT(0.5 1.5,0 1)", | |
113 | "SEGMENT(0.50019 1.50021,0 1)", | |
114 | "SEGMENT(1.496909 0.503379,1 0)", | |
115 | strategies); | |
116 | ||
117 | //default strategies | |
118 | tester::apply("LINESTRING(0 2,2 0,3 0,4 0,5 0)", | |
119 | "LINESTRING(-1 0,0 1,1 0,-1 -2)", | |
120 | "SEGMENT(0.5 1.5,0 1)", | |
121 | "SEGMENT(0.50019 1.50021,0 1)", | |
122 | "SEGMENT(1.496909 0.503379,1 0)", | |
123 | strategies, true, true); | |
124 | ||
125 | //geometries intersect | |
126 | tester::apply("LINESTRING(0 0,1 1,2 2)", | |
127 | "LINESTRING(0 2,0 1,1 0,2 0)", | |
128 | "SEGMENT(0.5 0.5,0.5 0.5)", | |
129 | "SEGMENT(0.5 0.500057,0.5 0.500057)", | |
130 | strategies); | |
131 | ||
132 | tester::apply("LINESTRING(0 0,1 1)", | |
133 | "LINESTRING(0 2,0 1,1 0,2 0)", | |
134 | "SEGMENT(0.5 0.5,0.5 0.5)", | |
135 | "SEGMENT(0.5 0.500057,0.5 0.500057)", | |
136 | strategies); | |
137 | } | |
138 | ||
139 | //=========================================================================== | |
140 | ||
141 | template <typename Point, typename Strategies> | |
142 | void test_closest_points_segment_multi_linestring(Strategies const& strategies) | |
143 | { | |
144 | ||
145 | #ifdef BOOST_GEOMETRY_TEST_DEBUG | |
146 | std::cout << std::endl; | |
147 | std::cout << "segment/multi-linestring closest_points tests" << std::endl; | |
148 | #endif | |
149 | ||
150 | typedef bg::model::linestring<Point> Linestring; | |
151 | typedef bg::model::multi_linestring<Linestring> MultiLinestring; | |
152 | typedef bg::model::segment<Point> Segment; | |
153 | typedef test_geometry<Segment, MultiLinestring, Segment> tester; | |
154 | ||
155 | tester::apply("SEGMENT(0 2,2 0)", | |
156 | "MULTILINESTRING((-1 0,0 1,1 0,-1 -2)(0 4,4 0,5 0))", | |
157 | "SEGMENT(0.5 1.5,0 1)", | |
158 | "SEGMENT(0.50019 1.50021,0 1)", | |
159 | "SEGMENT(1.496909 0.503379,1 0)", | |
160 | strategies); | |
161 | ||
162 | tester::apply("SEGMENT(0 2,2 0)", | |
163 | "MULTILINESTRING((-1 0,0 1,1 0,-1 -2)(0 4,4 0,5 0))", | |
164 | "SEGMENT(0.5 1.5,0 1)", | |
165 | "SEGMENT(0.50019 1.50021,0 1)", | |
166 | "SEGMENT(1.496909 0.503379,1 0)", | |
167 | strategies, true, true); | |
168 | ||
169 | //geometries intersect | |
170 | tester::apply("SEGMENT(0 0,1 1)", | |
171 | "MULTILINESTRING((0 2,0 1,1 0,2 0)(1 0,3 0))", | |
172 | "SEGMENT(0.5 0.5,0.5 0.5)", | |
173 | "SEGMENT(0.5 0.500057,0.5 0.500057)", | |
174 | strategies); | |
175 | } | |
176 | ||
177 | //=========================================================================== | |
178 | ||
179 | template <typename Point, typename Strategies> | |
180 | void test_closest_points_linestring_multi_linestring(Strategies const& strategies) | |
181 | { | |
182 | ||
183 | #ifdef BOOST_GEOMETRY_TEST_DEBUG | |
184 | std::cout << std::endl; | |
185 | std::cout << "linestring /multi-linestring closest_points tests" << std::endl; | |
186 | #endif | |
187 | ||
188 | typedef bg::model::linestring<Point> Linestring; | |
189 | typedef bg::model::multi_linestring<Linestring> MultiLinestring; | |
190 | typedef bg::model::segment<Point> Segment; | |
191 | typedef test_geometry<Linestring, MultiLinestring, Segment> tester; | |
192 | ||
193 | tester::apply("LINESTRING(0 2,2 0,2 -1)", | |
194 | "MULTILINESTRING((-1 0,0 1,1 0,-1 -2)(0 4,4 0,5 0))", | |
195 | "SEGMENT(0.5 1.5,0 1)", | |
196 | "SEGMENT(0.50019 1.50021,0 1)", | |
197 | "SEGMENT(1.496909 0.503379,1 0)", | |
198 | strategies); | |
199 | ||
200 | tester::apply("LINESTRING(0 2,2 0,2 -1)", | |
201 | "MULTILINESTRING((-1 0,0 1,1 0,-1 -2)(0 4,4 0,5 0))", | |
202 | "SEGMENT(0.5 1.5,0 1)", | |
203 | "SEGMENT(0.50019 1.50021,0 1)", | |
204 | "SEGMENT(1.496909 0.503379,1 0)", | |
205 | strategies, true, true); | |
206 | ||
207 | //geometries intersect | |
208 | tester::apply("LINESTRING(0 0,1 1)", | |
209 | "MULTILINESTRING((0 2,0 1,1 0,2 0)(1 0,3 0))", | |
210 | "SEGMENT(0.5 0.5,0.5 0.5)", | |
211 | "SEGMENT(0.5 0.500057,0.5 0.500057)", | |
212 | strategies); | |
213 | ||
214 | tester::apply("LINESTRING(0 0,1 1,2 2)", | |
215 | "MULTILINESTRING((0 2,0 1,1 0,2 0)(1 0,3 0))", | |
216 | "SEGMENT(0.5 0.5,0.5 0.5)", | |
217 | "SEGMENT(0.5 0.500057,0.5 0.500057)", | |
218 | strategies); | |
219 | } | |
220 | ||
221 | //=========================================================================== | |
222 | ||
223 | template <typename Point, typename Strategies> | |
224 | void test_closest_points_multi_linestring_multi_linestring(Strategies const& strategies) | |
225 | { | |
226 | ||
227 | #ifdef BOOST_GEOMETRY_TEST_DEBUG | |
228 | std::cout << std::endl; | |
229 | std::cout << "multi-linestring /multi-linestring closest_points tests" << std::endl; | |
230 | #endif | |
231 | ||
232 | typedef bg::model::linestring<Point> Linestring; | |
233 | typedef bg::model::multi_linestring<Linestring> MultiLinestring; | |
234 | typedef bg::model::segment<Point> Segment; | |
235 | typedef test_geometry<MultiLinestring, MultiLinestring, Segment> tester; | |
236 | ||
237 | tester::apply("MULTILINESTRING((0 2,2 0,2 -1)(0 2,-1 2))", | |
238 | "MULTILINESTRING((-1 0,0 1,1 0,-1 -2)(0 4,4 0,5 0))", | |
239 | "SEGMENT(0.5 1.5,0 1)", | |
240 | "SEGMENT(0.50019 1.50021,0 1)", | |
241 | "SEGMENT(1.496909 0.503379,1 0)", | |
242 | strategies); | |
243 | ||
244 | tester::apply("MULTILINESTRING((0 2,2 0,2 -1)(0 2,-1 2))", | |
245 | "MULTILINESTRING((-1 0,0 1,1 0,-1 -2)(0 4,4 0,5 0))", | |
246 | "SEGMENT(0.5 1.5,0 1)", | |
247 | "SEGMENT(0.50019 1.50021,0 1)", | |
248 | "SEGMENT(1.496909 0.503379,1 0)", | |
249 | strategies, true, true); | |
250 | ||
251 | //geometries intersect | |
252 | tester::apply("MULTILINESTRING((0 0,1 1,2 2)(1 2,1 3))", | |
253 | "MULTILINESTRING((0 2,0 1,1 0,2 0)(1 0,3 0))", | |
254 | "SEGMENT(0.5 0.5,0.5 0.5)", | |
255 | "SEGMENT(0.5 0.500057,0.5 0.500057)", | |
256 | strategies); | |
257 | ||
258 | //multiple intersections | |
259 | tester::apply("MULTILINESTRING((0 0,1 1,2 2)(2 0,3 0))", | |
260 | "MULTILINESTRING((0 2,0 1,1 0,2 0)(1 0,3 0))", | |
261 | "SEGMENT(0.5 0.5,0.5 0.5)", | |
262 | "SEGMENT(0.5 0.500057,0.5 0.500057)", | |
263 | strategies); | |
264 | } | |
265 | ||
266 | ||
267 | //=========================================================================== | |
268 | //=========================================================================== | |
269 | //=========================================================================== | |
270 | ||
271 | template <typename Point, typename Strategies> | |
272 | void test_all_l_l(Strategies strategies) | |
273 | { | |
274 | test_closest_points_segment_segment<Point>(strategies); | |
275 | test_closest_points_segment_linestring<Point>(strategies); | |
276 | test_closest_points_linestring_linestring<Point>(strategies); | |
277 | ||
278 | test_closest_points_segment_multi_linestring<Point>(strategies); | |
279 | test_closest_points_linestring_multi_linestring<Point>(strategies); | |
280 | test_closest_points_multi_linestring_multi_linestring<Point>(strategies); | |
281 | ||
282 | test_more_empty_input_linear_linear<Point>(strategies); | |
283 | } | |
284 | ||
285 | BOOST_AUTO_TEST_CASE( test_all_linear_linear ) | |
286 | { | |
287 | test_all_l_l<car_point>(cartesian()); | |
288 | ||
289 | test_all_l_l<sph_point>(spherical()); | |
290 | test_all_l_l<sph_point>(spherical( | |
291 | bg::formula::mean_radius<double>(bg::srs::spheroid<double>()))); | |
292 | ||
293 | test_all_l_l<geo_point>(andoyer()); | |
294 | test_all_l_l<geo_point>(thomas()); | |
295 | test_all_l_l<geo_point>(vincenty()); | |
296 | } |