]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 2020, Oracle and/or its affiliates. | |
4 | ||
5 | // Contributed and/or modified by Adam Wulkiewicz, 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 | #include <geometry_test_common.hpp> | |
11 | ||
12 | #include <boost/geometry/algorithms/correct.hpp> | |
13 | #include <boost/geometry/algorithms/equals.hpp> | |
14 | #include <boost/geometry/algorithms/intersection.hpp> | |
15 | #include <boost/geometry/geometries/geometries.hpp> | |
16 | #include <boost/geometry/io/wkt/wkt.hpp> | |
17 | #include <boost/geometry/strategies/cartesian/area.hpp> | |
18 | #include <boost/geometry/strategies/cartesian/intersection.hpp> | |
19 | #include <boost/geometry/strategies/cartesian/point_in_poly_winding.hpp> | |
20 | #include <boost/geometry/strategies/cartesian/point_in_point.hpp> | |
21 | ||
22 | #include <boost/tuple/tuple.hpp> | |
23 | ||
20effc67 TL |
24 | // TEMP |
25 | #include <boost/geometry/strategies/cartesian.hpp> | |
26 | #include <boost/geometry/strategies/geographic.hpp> | |
27 | #include <boost/geometry/strategies/spherical.hpp> | |
28 | ||
29 | ||
f67539c2 TL |
30 | typedef bg::model::point<double, 2, bg::cs::cartesian> Pt; |
31 | typedef bg::model::linestring<Pt> Ls; | |
32 | typedef bg::model::polygon<Pt> Po; | |
33 | typedef bg::model::ring<Pt> R; | |
34 | typedef bg::model::multi_point<Pt> MPt; | |
35 | typedef bg::model::multi_linestring<Ls> MLs; | |
36 | typedef bg::model::multi_polygon<Po> MPo; | |
37 | ||
38 | #ifdef BOOST_GEOMETRY_CXX11_TUPLE | |
39 | ||
40 | #include <tuple> | |
41 | ||
42 | #endif | |
43 | ||
44 | template <typename G> | |
45 | inline void check(std::string const& wkt1, | |
46 | std::string const& wkt2, | |
47 | G const& g, | |
48 | std::string const& expected) | |
49 | { | |
50 | G expect; | |
51 | bg::read_wkt(expected, expect); | |
52 | bg::correct(expect); | |
53 | if (! boost::empty(g) || ! boost::empty(expect)) | |
54 | { | |
55 | BOOST_CHECK_MESSAGE( | |
56 | // Commented out becasue the output in reversed case may be slightly different | |
57 | // e.g. different number of duplicated points in MultiPoint | |
58 | //boost::size(g) == boost::size(expect) && | |
59 | bg::equals(g, expect), | |
60 | wkt1 << " x " << wkt2 << " -> " << bg::wkt(g) | |
61 | << " different than expected: " << expected | |
62 | ); | |
63 | } | |
64 | } | |
65 | ||
66 | inline void check(std::string const& wkt1, | |
67 | std::string const& wkt2, | |
68 | boost::tuple<MPt, MLs, MPo> const& tup, | |
69 | std::string const& out_p_str, | |
70 | std::string const& out_l_str, | |
71 | std::string const& out_a_str) | |
72 | { | |
73 | check(wkt1, wkt2, boost::get<0>(tup), out_p_str); | |
74 | check(wkt1, wkt2, boost::get<1>(tup), out_l_str); | |
75 | check(wkt1, wkt2, boost::get<2>(tup), out_a_str); | |
76 | } | |
77 | ||
78 | inline void check(std::string const& wkt1, | |
79 | std::string const& wkt2, | |
80 | std::pair<MPt, MLs> const& pair, | |
81 | std::string const& out_p_str, | |
82 | std::string const& out_l_str, | |
83 | std::string const& ) | |
84 | { | |
85 | check(wkt1, wkt2, pair.first, out_p_str); | |
86 | check(wkt1, wkt2, pair.second, out_l_str); | |
87 | } | |
88 | ||
89 | #ifdef BOOST_GEOMETRY_CXX11_TUPLE | |
90 | ||
91 | inline void check(std::string const& wkt1, | |
92 | std::string const& wkt2, | |
93 | std::tuple<MPt, MLs, MPo> const& tup, | |
94 | std::string const& out_p_str, | |
95 | std::string const& out_l_str, | |
96 | std::string const& out_a_str) | |
97 | { | |
98 | check(wkt1, wkt2, std::get<0>(tup), out_p_str); | |
99 | check(wkt1, wkt2, std::get<1>(tup), out_l_str); | |
100 | check(wkt1, wkt2, std::get<2>(tup), out_a_str); | |
101 | } | |
102 | ||
103 | #endif | |
104 | ||
105 | template <typename In1, typename In2, typename Tup> | |
106 | inline void test_one(std::string const& in1_str, | |
107 | std::string const& in2_str, | |
108 | std::string const& out_p_str = "MULTIPOINT()", | |
109 | std::string const& out_l_str = "MULTILINESTRING()", | |
110 | std::string const& out_a_str = "MULTIPOLYGON()") | |
111 | { | |
112 | In1 in1; | |
113 | bg::read_wkt(in1_str, in1); | |
114 | bg::correct(in1); | |
115 | ||
116 | In2 in2; | |
117 | bg::read_wkt(in2_str, in2); | |
118 | bg::correct(in2); | |
119 | ||
120 | { | |
121 | Tup result; | |
122 | bg::intersection(in1, in2, result); | |
123 | check(in1_str, in2_str, result, out_p_str, out_l_str, out_a_str); | |
124 | } | |
125 | { | |
126 | Tup result; | |
127 | bg::intersection(in2, in1, result); | |
128 | check(in1_str, in2_str, result, out_p_str, out_l_str, out_a_str); | |
129 | } | |
130 | } | |
131 | ||
132 | template <typename Tup> | |
133 | inline void test_pp() | |
134 | { | |
135 | test_one<Pt, Pt, Tup>( | |
136 | "POINT(0 0)", | |
137 | "POINT(0 0)", | |
138 | "MULTIPOINT(0 0)"); | |
139 | ||
140 | test_one<Pt, MPt, Tup>( | |
141 | "POINT(0 0)", | |
142 | "MULTIPOINT(0 0, 1 1)", | |
143 | "MULTIPOINT(0 0)"); | |
144 | ||
145 | test_one<MPt, MPt, Tup>( | |
146 | "MULTIPOINT(0 0, 1 1, 2 2)", | |
147 | "MULTIPOINT(1 1, 2 2, 3 3)", | |
148 | "MULTIPOINT(1 1, 2 2)"); | |
149 | } | |
150 | ||
151 | template <typename Tup> | |
152 | inline void test_pl() | |
153 | { | |
154 | test_one<Pt, Ls, Tup>( | |
155 | "POINT(0 0)", | |
156 | "LINESTRING(0 0, 1 1)", | |
157 | "MULTIPOINT(0 0)"); | |
158 | ||
159 | test_one<Pt, MLs, Tup>( | |
160 | "POINT(1 1)", | |
161 | "MULTILINESTRING((0 0, 1 1),(1 1, 2 2),(4 4, 5 5))", | |
162 | "MULTIPOINT(1 1)"); | |
163 | ||
164 | test_one<MPt, Ls, Tup>( | |
165 | "MULTIPOINT(0 0, 1 1, 2 2, 3 3)", | |
166 | "LINESTRING(0 0, 1 1)", | |
167 | "MULTIPOINT(0 0, 1 1)"); | |
168 | ||
169 | test_one<MPt, MLs, Tup>( | |
170 | "MULTIPOINT(0 0, 1 1, 2 2, 3 3)", | |
171 | "MULTILINESTRING((0 0, 1 1),(1 1, 2 2),(4 4, 5 5))", | |
172 | "MULTIPOINT(0 0, 1 1, 2 2)"); | |
173 | } | |
174 | ||
175 | template <typename Tup> | |
176 | inline void test_pa() | |
177 | { | |
178 | test_one<Pt, R, Tup>( | |
179 | "POINT(0 0)", | |
180 | "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))", | |
181 | "MULTIPOINT(0 0)"); | |
182 | ||
183 | test_one<Pt, Po, Tup>( | |
184 | "POINT(0 0)", | |
185 | "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))", | |
186 | "MULTIPOINT(0 0)"); | |
187 | ||
188 | test_one<Pt, MPo, Tup>( | |
189 | "POINT(0 0)", | |
190 | "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),((0 0, 1 2, 2 2, 2 1, 0 0)))", | |
191 | "MULTIPOINT(0 0)"); | |
192 | ||
193 | test_one<MPt, R, Tup>( | |
194 | "MULTIPOINT(0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6)", | |
195 | "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))", | |
196 | "MULTIPOINT(0 0, 1 1, 2 2, 3 3, 4 4, 5 5)"); | |
197 | ||
198 | test_one<MPt, Po, Tup>( | |
199 | "MULTIPOINT(0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6)", | |
200 | "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))", | |
201 | "MULTIPOINT(0 0, 4 4, 5 5)"); | |
202 | ||
203 | test_one<MPt, MPo, Tup>( | |
204 | "MULTIPOINT(0 0, 0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6)", | |
205 | "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),((0 0, 1 2, 2 2, 2 1, 0 0)))", | |
206 | "MULTIPOINT(0 0, 0 0, 1 1, 2 2, 4 4, 5 5)"); // one (0 0) could be filtered out | |
207 | } | |
208 | ||
209 | template <typename Tup> | |
210 | inline void test_ll() | |
211 | { | |
212 | test_one<Ls, Ls, Tup>( | |
213 | "LINESTRING(0 0, 1 0, 2 1, 3 0)", | |
214 | "LINESTRING(0 0, 1 0, 3 0, 4 0)", | |
215 | "MULTIPOINT(3 0)", | |
216 | "MULTILINESTRING((0 0, 1 0))"); | |
217 | ||
218 | test_one<Ls, MLs, Tup>( | |
219 | "LINESTRING(0 0, 1 0, 2 1, 3 0)", | |
220 | "MULTILINESTRING((0 0, 1 0, 3 0),(2 1, 2 2))", | |
221 | "MULTIPOINT(3 0, 2 1)", | |
222 | "MULTILINESTRING((0 0, 1 0))"); | |
223 | ||
224 | test_one<MLs, MLs, Tup>( | |
225 | "MULTILINESTRING((0 0, 1 0, 2 1),(2 1, 3 0))", | |
226 | "MULTILINESTRING((0 0, 1 0, 3 0),(2 1, 2 2))", | |
227 | "MULTIPOINT(3 0, 2 1, 2 1)", // (2 1) could be filtered out | |
228 | "MULTILINESTRING((0 0, 1 0))"); | |
229 | ||
230 | ||
231 | test_one<Ls, Ls, Tup>( | |
232 | "LINESTRING(0 0, 0 5, 5 5, 5 0, 0 0)", | |
233 | "LINESTRING(0 0, 0 1, 6 1, 5 2, 5 5, 5 6, 4 5, 4 7, 7 7, 7 0, 0 0)", | |
234 | "MULTIPOINT(4 5, 5 1, 0 0)", // (0 0) could be filtered out | |
235 | "MULTILINESTRING((0 0, 0 1), (5 5, 5 2), (5 0, 0 0))"); | |
236 | ||
237 | test_one<MLs, MLs, Tup>( | |
238 | "MULTILINESTRING((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))", | |
239 | "MULTILINESTRING((0 0, 1 4, 5 4, 5 1, 4 1, 0 0),(0 0, 2 1, 2 2, 1 2, 0 0))", | |
240 | // all (0 0) could be filtered out | |
241 | "MULTIPOINT(0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0)", | |
242 | "MULTILINESTRING((5 4,5 1),(0 0,4 1),(4 4,1 4,0 0))"); | |
243 | } | |
244 | ||
245 | template <typename Tup> | |
246 | inline void test_la() | |
247 | { | |
248 | test_one<Ls, R, Tup>( | |
249 | "LINESTRING(0 2, -4 1, 0 0, 5 0, 9 1, 5 2, 9 3, 5 5, 4 9, 4 5, 3 3, 2 5, 2 9, 0 5)", | |
250 | "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))", | |
251 | "MULTIPOINT(0 2, 5 2, 5 5, 0 5)", | |
252 | "MULTILINESTRING((0 0, 5 0),(4 5, 3 3, 2 5))"); | |
253 | ||
254 | test_one<Ls, Po, Tup>( | |
255 | "LINESTRING(1 4, -4 1, 0 0, 5 0, 9 1, 5 2, 9 3, 5 5, 4 9, 4 5, 3 3, 2 5, 2 9, 0 5)", | |
256 | "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))", | |
257 | "MULTIPOINT(5 2, 5 5, 0 5)", | |
258 | "MULTILINESTRING((1 4, 0 3.4)(0 0, 5 0),(4 5, 3.5 4),(2.5 4, 2 5))"); | |
259 | ||
260 | test_one<MLs, R, Tup>( | |
261 | "MULTILINESTRING((0 2, -4 1, 0 0, 5 0, 9 1, 5 2, 9 3, 5 5, 4 9), (4 9, 4 5, 3 3, 2 5, 2 9, 0 5))", | |
262 | "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))", | |
263 | "MULTIPOINT(0 2, 5 2, 5 5, 0 5)", | |
264 | "MULTILINESTRING((0 0, 5 0),(4 5, 3 3, 2 5))"); | |
265 | ||
266 | test_one<MLs, Po, Tup>( | |
267 | "MULTILINESTRING((1 4, -4 1, 0 0, 5 0, 9 1, 5 2, 9 3, 5 5, 4 9), (4 9, 4 5, 3 3, 2 5, 2 9, 0 5))", | |
268 | "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))", | |
269 | "MULTIPOINT(5 2, 5 5, 0 5)", | |
270 | "MULTILINESTRING((1 4, 0 3.4)(0 0, 5 0),(4 5, 3.5 4),(2.5 4, 2 5))"); | |
271 | ||
272 | test_one<MLs, MPo, Tup>( | |
273 | "MULTILINESTRING((1 4, -4 1, 0 0, 5 0, 9 1, 5 2, 9 3, 5 5, 4 9), (4 9, 4 5, 4 4, 2 2, 2 5, 1 9, 0 5))", | |
274 | "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),((0 0, 1 2, 2 2, 2 1, 0 0)))", | |
275 | "MULTIPOINT(5 2, 5 5, 2 2, 0 5)", | |
276 | "MULTILINESTRING((1 4, 0 3.4)(0 0, 5 0),(4 5, 4 4),(2 4, 2 5))"); | |
277 | ||
278 | ||
279 | test_one<Ls, R, Tup>( | |
280 | "LINESTRING(0 0, 0 5, 5 5, 5 0, 0 0)", | |
281 | "POLYGON((0 0, 0 1, 6 1, 5 2, 5 5, 5 6, 4 5, 4 7, 7 7, 7 0, 0 0))", | |
282 | "MULTIPOINT(4 5)", | |
283 | "MULTILINESTRING((0 0, 0 1), (5 5, 5 2), (5 1, 5 0, 0 0))"); | |
284 | ||
285 | test_one<MLs, Po, Tup>( | |
286 | "MULTILINESTRING((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))", | |
287 | "POLYGON((0 0, 1 4, 5 4, 5 1, 4 1, 0 0),(0 0, 2 1, 2 2, 1 2, 0 0))", | |
288 | "MULTIPOINT(0 0)", // (0 0) could be filtered out | |
289 | "MULTILINESTRING((5 4, 5 1),(0 0, 4 1, 4 4, 1 4, 0 0))"); | |
290 | } | |
291 | ||
292 | template <typename Tup> | |
293 | inline void test_aa() | |
294 | { | |
295 | test_one<R, R, Tup>( | |
296 | "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))", | |
297 | "POLYGON((0 0, 0 1, 6 1, 5 2, 5 5, 5 6, 4 5, 4 7, 7 7, 7 0, 0 0))", | |
298 | "MULTIPOINT(4 5)", | |
299 | "MULTILINESTRING((5 2, 5 5))", | |
300 | "MULTIPOLYGON(((0 0, 0 1, 5 1, 5 0, 0 0)))"); | |
301 | ||
302 | test_one<R, MPo, Tup>( | |
303 | "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))", | |
304 | "MULTIPOLYGON(((0 0, 0 1, 6 1, 6 0, 0 0))," | |
305 | "((6 1, 5 2, 5 5, 5 6, 4 5, 4 7, 7 7, 7 1, 6 1)))", | |
306 | "MULTIPOINT(4 5)", | |
307 | "MULTILINESTRING((5 2, 5 5))", | |
308 | "MULTIPOLYGON(((0 0, 0 1, 5 1, 5 0, 0 0)))"); | |
309 | ||
310 | test_one<Po, Po, Tup>( | |
311 | "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))", | |
312 | "POLYGON((0 0, 1 4, 5 4, 5 1, 4 1, 0 0),(0 0, 2 1, 2 2, 1 2, 0 0))", | |
313 | // all (0 0) could be filtered out | |
314 | "MULTIPOINT(0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0)", | |
315 | "MULTILINESTRING((0 0, 1 4, 4 4),(0 0, 4 1))", | |
316 | "MULTIPOLYGON(((4 1, 4 4, 5 4, 5 1, 4 1)))"); | |
317 | ||
318 | test_one<Po, MPo, Tup>( | |
319 | "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))", | |
320 | "MULTIPOLYGON(((0 0, 1 4, 5 4, 5 1, 4 1, 0 0),(0 0, 2 1, 2 2, 1 2, 0 0))," | |
321 | "((5 0, 5 1, 6 1, 6 4, 5 4, 3 6, 2 5, 2 7, 7 7, 7 0 5 0)))", | |
322 | // all (0 0) and (5 0) could be filtered out | |
323 | "MULTIPOINT(2 5, 5 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0)", | |
324 | "MULTILINESTRING((0 0, 1 4, 4 4),(0 0, 4 1),(5 1, 5 0))", | |
325 | "MULTIPOLYGON(((4 1, 4 4, 5 4, 5 1, 4 1)),((5 4, 4 5, 5 5, 5 4)))"); | |
326 | ||
327 | test_one<MPo, MPo, Tup>( | |
328 | "MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))," | |
329 | "((2 6, 2 8, 8 8, 8 5, 7 5, 7 6, 2 6)))", | |
330 | "MULTIPOLYGON(((0 0, 1 4, 5 4, 5 1, 4 1, 0 0),(0 0, 2 1, 2 2, 1 2, 0 0))," | |
331 | "((5 0, 5 1, 6 1, 6 4, 5 4, 3 6, 2 5, 2 7, 7 7, 7 0 5 0)))", | |
332 | // all (0 0) and (5 0) could be filtered out | |
333 | "MULTIPOINT(2 5, 5 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0)", | |
334 | "MULTILINESTRING((0 0, 1 4, 4 4),(0 0, 4 1),(5 1, 5 0),(7 5, 7 6))", | |
335 | "MULTIPOLYGON(((4 1, 4 4, 5 4, 5 1, 4 1))," | |
336 | "((5 4, 4 5, 5 5, 5 4))," | |
337 | "((2 6, 2 7, 7 7, 7 6, 2 6)))"); | |
338 | } | |
339 | ||
340 | template <typename Tup> | |
341 | inline void test_pair() | |
342 | { | |
343 | test_pp<Tup>(); | |
344 | test_pl<Tup>(); | |
345 | test_pa<Tup>(); | |
346 | test_ll<Tup>(); | |
347 | test_la<Tup>(); | |
348 | } | |
349 | ||
350 | template <typename Tup> | |
351 | inline void test_tuple() | |
352 | { | |
353 | test_pp<Tup>(); | |
354 | test_pl<Tup>(); | |
355 | test_pa<Tup>(); | |
356 | test_ll<Tup>(); | |
357 | test_la<Tup>(); | |
358 | test_aa<Tup>(); | |
359 | } | |
360 | ||
361 | int test_main(int, char* []) | |
362 | { | |
363 | test_pair<std::pair<MPt, MLs> >(); | |
364 | test_tuple<boost::tuple<MPt, MLs, MPo> >(); | |
365 | ||
366 | #ifdef BOOST_GEOMETRY_CXX11_TUPLE | |
367 | test_tuple<std::tuple<MPt, MLs, MPo> >(); | |
368 | #endif | |
369 | ||
370 | return 0; | |
371 | } |