1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2015-2020, Oracle and/or its affiliates.
6 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9 // Licensed under the Boost Software License version 1.0.
10 // http://www.boost.org/users/license.html
12 #ifndef BOOST_TEST_MODULE
13 #define BOOST_TEST_MODULE test_intersection_linear_linear_areal
16 #ifdef BOOST_GEOMETRY_TEST_DEBUG
17 #define BOOST_GEOMETRY_DEBUG_TURNS
18 #define BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER
21 #include <boost/test/included/unit_test.hpp>
23 #include <boost/geometry/geometries/linestring.hpp>
24 #include <boost/geometry/geometries/multi_linestring.hpp>
25 #include <boost/geometry/geometries/ring.hpp>
26 #include <boost/geometry/geometries/polygon.hpp>
27 #include <boost/geometry/geometries/multi_polygon.hpp>
29 #include "test_intersection_linear_linear.hpp"
31 typedef bg::model::point
<double,2,bg::cs::cartesian
> point_type
;
32 typedef bg::model::multi_linestring
34 bg::model::linestring
<point_type
>
35 > multi_linestring_type
;
37 typedef bg::model::ring
<point_type
, true, false> open_ring_type
;
38 typedef bg::model::polygon
<point_type
, true, false> open_polygon_type
;
39 typedef bg::model::multi_polygon
<open_polygon_type
> open_multipolygon_type
;
41 typedef bg::model::ring
<point_type
> closed_ring_type
;
42 typedef bg::model::polygon
<point_type
> closed_polygon_type
;
43 typedef bg::model::multi_polygon
<closed_polygon_type
> closed_multipolygon_type
;
50 typename ClosedAreal1
,
51 typename ClosedAreal2
,
52 typename MultiLinestring
54 struct test_intersection_aal
56 static inline void apply(std::string
const& case_id
,
57 OpenAreal1
const& open_areal1
,
58 OpenAreal2
const& open_areal2
,
59 MultiLinestring
const& expected1
,
60 MultiLinestring
const& expected2
)
62 typedef test_intersection_of_geometries
64 OpenAreal1
, OpenAreal2
, MultiLinestring
67 tester::apply(open_areal1
, open_areal2
, expected1
, expected2
, case_id
);
69 ClosedAreal1 closed_areal1
;
70 ClosedAreal2 closed_areal2
;
71 bg::convert(open_areal1
, closed_areal1
);
72 bg::convert(open_areal2
, closed_areal2
);
74 typedef test_intersection_of_geometries
76 ClosedAreal1
, ClosedAreal2
, MultiLinestring
79 std::string case_id_closed
= case_id
+ "-closed";
81 #ifdef BOOST_GEOMETRY_TEST_DEBUG
82 std::cout
<< "testing closed areal geometries..." << std::endl
;
84 tester_of_closed::apply(closed_areal1
, closed_areal2
,
85 expected1
, expected2
, case_id_closed
);
88 static inline void apply(std::string
const& case_id
,
89 OpenAreal1
const& open_areal1
,
90 OpenAreal2
const& open_areal2
,
91 MultiLinestring
const& expected
)
93 apply(case_id
, open_areal1
, open_areal2
, expected
, expected
);
98 BOOST_AUTO_TEST_CASE( test_intersection_ring_ring_linestring
)
100 #ifdef BOOST_GEOMETRY_TEST_DEBUG
101 std::cout
<< std::endl
<< std::endl
<< std::endl
;
102 std::cout
<< "*** RING / RING / LINEAR INTERSECTION ***" << std::endl
;
103 std::cout
<< std::endl
;
105 typedef open_ring_type OG
;
106 typedef closed_ring_type CG
;
107 typedef multi_linestring_type ML
;
109 typedef test_intersection_aal
<OG
, OG
, CG
, CG
, ML
> tester
;
113 from_wkt
<OG
>("POLYGON((0 0,0 2,2 2,2 0))"),
114 from_wkt
<OG
>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
115 from_wkt
<ML
>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
116 from_wkt
<ML
>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
121 from_wkt
<OG
>("POLYGON(())"),
122 from_wkt
<OG
>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
123 from_wkt
<ML
>("MULTILINESTRING()")
128 from_wkt
<OG
>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
129 from_wkt
<OG
>("POLYGON(())"),
130 from_wkt
<ML
>("MULTILINESTRING()")
135 from_wkt
<OG
>("POLYGON(())"),
136 from_wkt
<OG
>("POLYGON(())"),
137 from_wkt
<ML
>("MULTILINESTRING()")
142 BOOST_AUTO_TEST_CASE( test_intersection_ring_polygon_linestring
)
144 #ifdef BOOST_GEOMETRY_TEST_DEBUG
145 std::cout
<< std::endl
<< std::endl
<< std::endl
;
146 std::cout
<< "*** RING / POLYGON / LINEAR INTERSECTION ***" << std::endl
;
147 std::cout
<< std::endl
;
149 typedef open_ring_type OG1
;
150 typedef open_polygon_type OG2
;
151 typedef closed_ring_type CG1
;
152 typedef closed_polygon_type CG2
;
153 typedef multi_linestring_type ML
;
155 typedef test_intersection_aal
<OG1
, OG2
, CG1
, CG2
, ML
> tester
;
159 from_wkt
<OG1
>("POLYGON((0 0,0 2,2 2,2 0))"),
160 from_wkt
<OG2
>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
161 from_wkt
<ML
>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
162 from_wkt
<ML
>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
167 BOOST_AUTO_TEST_CASE( test_intersection_ring_multipolygon_linestring
)
169 #ifdef BOOST_GEOMETRY_TEST_DEBUG
170 std::cout
<< std::endl
<< std::endl
<< std::endl
;
171 std::cout
<< "*** RING / MULTIPOLYGON / LINEAR INTERSECTION ***"
173 std::cout
<< std::endl
;
175 typedef open_ring_type OG1
;
176 typedef open_multipolygon_type OG2
;
177 typedef closed_ring_type CG1
;
178 typedef closed_multipolygon_type CG2
;
179 typedef multi_linestring_type ML
;
181 typedef test_intersection_aal
<OG1
, OG2
, CG1
, CG2
, ML
> tester
;
185 from_wkt
<OG1
>("POLYGON((0 0,0 2,2 2,2 0))"),
186 from_wkt
<OG2
>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
187 from_wkt
<ML
>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
188 from_wkt
<ML
>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
193 BOOST_AUTO_TEST_CASE( test_intersection_polygon_polygon_linestring
)
195 #ifdef BOOST_GEOMETRY_TEST_DEBUG
196 std::cout
<< std::endl
<< std::endl
<< std::endl
;
197 std::cout
<< "*** POLYGON / POLYGON / LINEAR INTERSECTION ***" << std::endl
;
198 std::cout
<< std::endl
;
200 typedef open_polygon_type OG
;
201 typedef closed_polygon_type CG
;
202 typedef multi_linestring_type ML
;
204 typedef test_intersection_aal
<OG
, OG
, CG
, CG
, ML
> tester
;
208 from_wkt
<OG
>("POLYGON((0 0,0 2,2 2,2 0))"),
209 from_wkt
<OG
>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
210 from_wkt
<ML
>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
211 from_wkt
<ML
>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
216 from_wkt
<OG
>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
217 from_wkt
<OG
>("POLYGON((2 2,2 7,7 7,7 2))"),
218 from_wkt
<ML
>("MULTILINESTRING((2 2,2 2),(2 2,2 7,7 7,7 2,2 2),(2 2,2 2))"),
219 from_wkt
<ML
>("MULTILINESTRING((2 2,2 2),(2 2,7 2,7 7,2 7,2 2),(2 2,2 2))")
224 from_wkt
<OG
>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
225 from_wkt
<OG
>("POLYGON((2 3,2 6,6 6,6 3))"),
226 from_wkt
<ML
>("MULTILINESTRING((2 3,2 6),(2 3,2 3))")
231 from_wkt
<OG
>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
232 from_wkt
<OG
>("POLYGON((2 3,2 7,6 7,6 3))"),
233 from_wkt
<ML
>("MULTILINESTRING((2 3,2 7,6 7),(2 3,2 3))")
238 from_wkt
<OG
>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
239 from_wkt
<OG
>("POLYGON((2 3,2 7,7 7,7 3))"),
240 from_wkt
<ML
>("MULTILINESTRING((2 3,2 7,7 7,7 3),(2 3,2 3))")
245 from_wkt
<OG
>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
246 from_wkt
<OG
>("POLYGON((2 3,2 7,7 7,7 3))"),
247 from_wkt
<ML
>("MULTILINESTRING((2 3,2 7,7 7,7 3),(2 3,2 3))")
252 from_wkt
<OG
>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
253 from_wkt
<OG
>("POLYGON((2 5,5 7,7 5,5 2))"),
254 from_wkt
<ML
>("MULTILINESTRING((2 5,2 5),(5 7,5 7),(7 5,7 5),(5 2,5 2))")
259 from_wkt
<OG
>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
260 from_wkt
<OG
>("POLYGON((2 5,4 7,6 7,7 5,5 2))"),
261 from_wkt
<ML
>("MULTILINESTRING((2 5,2 5),(4 7,6 7),(7 5,7 5),(5 2,5 2))")
266 from_wkt
<OG
>("POLYGON(())"),
267 from_wkt
<OG
>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
268 from_wkt
<ML
>("MULTILINESTRING()")
273 from_wkt
<OG
>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
274 from_wkt
<OG
>("POLYGON(())"),
275 from_wkt
<ML
>("MULTILINESTRING()")
280 from_wkt
<OG
>("POLYGON(())"),
281 from_wkt
<OG
>("POLYGON(())"),
282 from_wkt
<ML
>("MULTILINESTRING()")
287 from_wkt
<OG
>("POLYGON((),())"),
288 from_wkt
<OG
>("POLYGON((),(),())"),
289 from_wkt
<ML
>("MULTILINESTRING()")
294 from_wkt
<OG
>("POLYGON((2 1,2 4,4 4,4 0,1 0),())"),
295 from_wkt
<OG
>("POLYGON(())"),
296 from_wkt
<ML
>("MULTILINESTRING()")
301 BOOST_AUTO_TEST_CASE( test_intersection_polygon_multipolygon_linestring
)
303 #ifdef BOOST_GEOMETRY_TEST_DEBUG
304 std::cout
<< std::endl
<< std::endl
<< std::endl
;
305 std::cout
<< "*** POLYGON / MULTIPOLYGON / LINEAR INTERSECTION ***"
307 std::cout
<< std::endl
;
309 typedef open_polygon_type OG1
;
310 typedef open_multipolygon_type OG2
;
311 typedef closed_polygon_type CG1
;
312 typedef closed_multipolygon_type CG2
;
313 typedef multi_linestring_type ML
;
315 typedef test_intersection_aal
<OG1
, OG2
, CG1
, CG2
, ML
> tester
;
319 from_wkt
<OG1
>("POLYGON((0 0,0 2,2 2,2 0))"),
320 from_wkt
<OG2
>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
321 from_wkt
<ML
>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
322 from_wkt
<ML
>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
327 BOOST_AUTO_TEST_CASE( test_intersection_multipolygon_multipolygon_linestring
)
329 #ifdef BOOST_GEOMETRY_TEST_DEBUG
330 std::cout
<< std::endl
<< std::endl
<< std::endl
;
331 std::cout
<< "*** MULTIPOLYGON / MULTIPOLYGON / LINEAR INTERSECTION ***"
333 std::cout
<< std::endl
;
335 typedef open_multipolygon_type OG
;
336 typedef closed_multipolygon_type CG
;
337 typedef multi_linestring_type ML
;
339 typedef test_intersection_aal
<OG
, OG
, CG
, CG
, ML
> tester
;
343 from_wkt
<OG
>("MULTIPOLYGON(((0 0,0 2,2 2,2 0)))"),
344 from_wkt
<OG
>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
345 from_wkt
<ML
>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
346 from_wkt
<ML
>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
351 from_wkt
<OG
>("MULTIPOLYGON(((0 0,0 10,10 10,10 0),(2 2,8 2,8 8,2 8)))"),
352 from_wkt
<OG
>("MULTIPOLYGON(((2 4,2 6,8 6,8 4)))"),
353 from_wkt
<ML
>("MULTILINESTRING((2 4,2 4),(2 4,2 6),(8 6,8 4))")
358 from_wkt
<OG
>("MULTIPOLYGON()"),
359 from_wkt
<OG
>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
360 from_wkt
<ML
>("MULTILINESTRING()")
365 from_wkt
<OG
>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
366 from_wkt
<OG
>("MULTIPOLYGON()"),
367 from_wkt
<ML
>("MULTILINESTRING()")
372 from_wkt
<OG
>("MULTIPOLYGON()"),
373 from_wkt
<OG
>("MULTIPOLYGON()"),
374 from_wkt
<ML
>("MULTILINESTRING()")
379 from_wkt
<OG
>("MULTIPOLYGON((()),((),()))"),
380 from_wkt
<OG
>("MULTIPOLYGON()"),
381 from_wkt
<ML
>("MULTILINESTRING()")
386 from_wkt
<OG
>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0),(),()))"),
387 from_wkt
<OG
>("MULTIPOLYGON()"),
388 from_wkt
<ML
>("MULTILINESTRING()")