]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/set_operations/intersection/intersection_tupled.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2020, Oracle and/or its affiliates.
5 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7 // Licensed under the Boost Software License version 1.0.
8 // http://www.boost.org/users/license.html
10 #include <geometry_test_common.hpp>
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/intersection.hpp>
18 #include <boost/geometry/strategies/cartesian/point_in_poly_winding.hpp>
19 #include <boost/geometry/strategies/cartesian/point_in_point.hpp>
21 #include <boost/tuple/tuple.hpp>
24 #include <boost/geometry/strategies/cartesian.hpp>
25 #include <boost/geometry/strategies/geographic.hpp>
26 #include <boost/geometry/strategies/spherical.hpp>
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
;
37 #ifdef BOOST_GEOMETRY_CXX11_TUPLE
44 inline void check(std::string
const& wkt1
,
45 std::string
const& wkt2
,
47 std::string
const& expected
)
50 bg::read_wkt(expected
, expect
);
52 if (! boost::empty(g
) || ! boost::empty(expect
))
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
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
)
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
);
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
,
84 check(wkt1
, wkt2
, pair
.first
, out_p_str
);
85 check(wkt1
, wkt2
, pair
.second
, out_l_str
);
88 #ifdef BOOST_GEOMETRY_CXX11_TUPLE
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
)
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
);
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()")
112 bg::read_wkt(in1_str
, in1
);
116 bg::read_wkt(in2_str
, in2
);
121 bg::intersection(in1
, in2
, result
);
122 check(in1_str
, in2_str
, result
, out_p_str
, out_l_str
, out_a_str
);
126 bg::intersection(in2
, in1
, result
);
127 check(in1_str
, in2_str
, result
, out_p_str
, out_l_str
, out_a_str
);
131 template <typename Tup
>
132 inline void test_pp()
134 test_one
<Pt
, Pt
, Tup
>(
139 test_one
<Pt
, MPt
, Tup
>(
141 "MULTIPOINT(0 0, 1 1)",
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)");
150 template <typename Tup
>
151 inline void test_pl()
153 test_one
<Pt
, Ls
, Tup
>(
155 "LINESTRING(0 0, 1 1)",
158 test_one
<Pt
, MLs
, Tup
>(
160 "MULTILINESTRING((0 0, 1 1),(1 1, 2 2),(4 4, 5 5))",
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)");
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)");
174 template <typename Tup
>
175 inline void test_pa()
177 test_one
<Pt
, R
, Tup
>(
179 "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))",
182 test_one
<Pt
, Po
, Tup
>(
184 "POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))",
187 test_one
<Pt
, MPo
, Tup
>(
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)))",
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)");
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)");
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
208 template <typename Tup
>
209 inline void test_ll()
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)",
215 "MULTILINESTRING((0 0, 1 0))");
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))");
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))");
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))");
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))");
244 template <typename Tup
>
245 inline void test_la()
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))");
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))");
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))");
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))");
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))");
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))",
282 "MULTILINESTRING((0 0, 0 1), (5 5, 5 2), (5 1, 5 0, 0 0))");
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))");
291 template <typename Tup
>
292 inline void test_aa()
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))",
298 "MULTILINESTRING((5 2, 5 5))",
299 "MULTIPOLYGON(((0 0, 0 1, 5 1, 5 0, 0 0)))");
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)))",
306 "MULTILINESTRING((5 2, 5 5))",
307 "MULTIPOLYGON(((0 0, 0 1, 5 1, 5 0, 0 0)))");
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)))");
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)))");
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)))");
339 template <typename Tup
>
340 inline void test_pair()
349 template <typename Tup
>
350 inline void test_tuple()
360 int test_main(int, char* [])
362 test_pair
<std::pair
<MPt
, MLs
> >();
363 test_tuple
<boost::tuple
<MPt
, MLs
, MPo
> >();
365 #ifdef BOOST_GEOMETRY_CXX11_TUPLE
366 test_tuple
<std::tuple
<MPt
, MLs
, MPo
> >();