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