1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2015, Oracle and/or its affiliates.
6 // Licensed under the Boost Software License version 1.0.
7 // http://www.boost.org/users/license.html
9 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
11 #ifndef BOOST_TEST_MODULE
12 #define BOOST_TEST_MODULE test_intersection_linear_linear_areal
15 #ifdef BOOST_GEOMETRY_TEST_DEBUG
16 #define BOOST_GEOMETRY_DEBUG_TURNS
17 #define BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER
20 #include <boost/test/included/unit_test.hpp>
22 #include <boost/range.hpp>
24 #include <boost/geometry/geometries/linestring.hpp>
25 #include <boost/geometry/geometries/multi_linestring.hpp>
26 #include <boost/geometry/geometries/ring.hpp>
27 #include <boost/geometry/geometries/polygon.hpp>
28 #include <boost/geometry/geometries/multi_polygon.hpp>
30 #include "test_intersection_linear_linear.hpp"
32 typedef bg::model::point
<double,2,bg::cs::cartesian
> point_type
;
33 typedef bg::model::multi_linestring
35 bg::model::linestring
<point_type
>
36 > multi_linestring_type
;
38 typedef bg::model::ring
<point_type
, true, false> open_ring_type
;
39 typedef bg::model::polygon
<point_type
, true, false> open_polygon_type
;
40 typedef bg::model::multi_polygon
<open_polygon_type
> open_multipolygon_type
;
42 typedef bg::model::ring
<point_type
> closed_ring_type
;
43 typedef bg::model::polygon
<point_type
> closed_polygon_type
;
44 typedef bg::model::multi_polygon
<closed_polygon_type
> closed_multipolygon_type
;
51 typename ClosedAreal1
,
52 typename ClosedAreal2
,
53 typename MultiLinestring
55 struct test_intersection_aal
57 static inline void apply(std::string
const& case_id
,
58 OpenAreal1
const& open_areal1
,
59 OpenAreal2
const& open_areal2
,
60 MultiLinestring
const& expected1
,
61 MultiLinestring
const& expected2
)
63 typedef test_intersection_of_geometries
65 OpenAreal1
, OpenAreal2
, MultiLinestring
68 tester::apply(open_areal1
, open_areal2
, expected1
, expected2
, case_id
);
70 ClosedAreal1 closed_areal1
;
71 ClosedAreal2 closed_areal2
;
72 bg::convert(open_areal1
, closed_areal1
);
73 bg::convert(open_areal2
, closed_areal2
);
75 typedef test_intersection_of_geometries
77 ClosedAreal1
, ClosedAreal2
, MultiLinestring
80 std::string case_id_closed
= case_id
+ "-closed";
82 #ifdef BOOST_GEOMETRY_TEST_DEBUG
83 std::cout
<< "testing closed areal geometries..." << std::endl
;
85 tester_of_closed::apply(closed_areal1
, closed_areal2
,
86 expected1
, expected2
, case_id_closed
);
89 static inline void apply(std::string
const& case_id
,
90 OpenAreal1
const& open_areal1
,
91 OpenAreal2
const& open_areal2
,
92 MultiLinestring
const& expected
)
94 apply(case_id
, open_areal1
, open_areal2
, expected
, expected
);
99 BOOST_AUTO_TEST_CASE( test_intersection_ring_ring_linestring
)
101 #ifdef BOOST_GEOMETRY_TEST_DEBUG
102 std::cout
<< std::endl
<< std::endl
<< std::endl
;
103 std::cout
<< "*** RING / RING / LINEAR INTERSECTION ***" << std::endl
;
104 std::cout
<< std::endl
;
106 typedef open_ring_type OG
;
107 typedef closed_ring_type CG
;
108 typedef multi_linestring_type ML
;
110 typedef test_intersection_aal
<OG
, OG
, CG
, CG
, ML
> tester
;
114 from_wkt
<OG
>("POLYGON((0 0,0 2,2 2,2 0))"),
115 from_wkt
<OG
>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
116 from_wkt
<ML
>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
117 from_wkt
<ML
>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
122 from_wkt
<OG
>("POLYGON(())"),
123 from_wkt
<OG
>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
124 from_wkt
<ML
>("MULTILINESTRING()")
129 from_wkt
<OG
>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
130 from_wkt
<OG
>("POLYGON(())"),
131 from_wkt
<ML
>("MULTILINESTRING()")
136 from_wkt
<OG
>("POLYGON(())"),
137 from_wkt
<OG
>("POLYGON(())"),
138 from_wkt
<ML
>("MULTILINESTRING()")
143 BOOST_AUTO_TEST_CASE( test_intersection_ring_polygon_linestring
)
145 #ifdef BOOST_GEOMETRY_TEST_DEBUG
146 std::cout
<< std::endl
<< std::endl
<< std::endl
;
147 std::cout
<< "*** RING / POLYGON / LINEAR INTERSECTION ***" << std::endl
;
148 std::cout
<< std::endl
;
150 typedef open_ring_type OG1
;
151 typedef open_polygon_type OG2
;
152 typedef closed_ring_type CG1
;
153 typedef closed_polygon_type CG2
;
154 typedef multi_linestring_type ML
;
156 typedef test_intersection_aal
<OG1
, OG2
, CG1
, CG2
, ML
> tester
;
160 from_wkt
<OG1
>("POLYGON((0 0,0 2,2 2,2 0))"),
161 from_wkt
<OG2
>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
162 from_wkt
<ML
>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
163 from_wkt
<ML
>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
168 BOOST_AUTO_TEST_CASE( test_intersection_ring_multipolygon_linestring
)
170 #ifdef BOOST_GEOMETRY_TEST_DEBUG
171 std::cout
<< std::endl
<< std::endl
<< std::endl
;
172 std::cout
<< "*** RING / MULTIPOLYGON / LINEAR INTERSECTION ***"
174 std::cout
<< std::endl
;
176 typedef open_ring_type OG1
;
177 typedef open_multipolygon_type OG2
;
178 typedef closed_ring_type CG1
;
179 typedef closed_multipolygon_type CG2
;
180 typedef multi_linestring_type ML
;
182 typedef test_intersection_aal
<OG1
, OG2
, CG1
, CG2
, ML
> tester
;
186 from_wkt
<OG1
>("POLYGON((0 0,0 2,2 2,2 0))"),
187 from_wkt
<OG2
>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
188 from_wkt
<ML
>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
189 from_wkt
<ML
>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
194 BOOST_AUTO_TEST_CASE( test_intersection_polygon_polygon_linestring
)
196 #ifdef BOOST_GEOMETRY_TEST_DEBUG
197 std::cout
<< std::endl
<< std::endl
<< std::endl
;
198 std::cout
<< "*** POLYGON / POLYGON / LINEAR INTERSECTION ***" << std::endl
;
199 std::cout
<< std::endl
;
201 typedef open_polygon_type OG
;
202 typedef closed_polygon_type CG
;
203 typedef multi_linestring_type ML
;
205 typedef test_intersection_aal
<OG
, OG
, CG
, CG
, ML
> tester
;
209 from_wkt
<OG
>("POLYGON((0 0,0 2,2 2,2 0))"),
210 from_wkt
<OG
>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
211 from_wkt
<ML
>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
212 from_wkt
<ML
>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
217 from_wkt
<OG
>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
218 from_wkt
<OG
>("POLYGON((2 2,2 7,7 7,7 2))"),
219 from_wkt
<ML
>("MULTILINESTRING((2 2,2 2),(2 2,2 7,7 7,7 2,2 2),(2 2,2 2))"),
220 from_wkt
<ML
>("MULTILINESTRING((2 2,2 2),(2 2,7 2,7 7,2 7,2 2),(2 2,2 2))")
225 from_wkt
<OG
>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
226 from_wkt
<OG
>("POLYGON((2 3,2 6,6 6,6 3))"),
227 from_wkt
<ML
>("MULTILINESTRING((2 3,2 6),(2 3,2 3))")
232 from_wkt
<OG
>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
233 from_wkt
<OG
>("POLYGON((2 3,2 7,6 7,6 3))"),
234 from_wkt
<ML
>("MULTILINESTRING((2 3,2 7,6 7),(2 3,2 3))")
239 from_wkt
<OG
>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
240 from_wkt
<OG
>("POLYGON((2 3,2 7,7 7,7 3))"),
241 from_wkt
<ML
>("MULTILINESTRING((2 3,2 7,7 7,7 3),(2 3,2 3))")
246 from_wkt
<OG
>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
247 from_wkt
<OG
>("POLYGON((2 3,2 7,7 7,7 3))"),
248 from_wkt
<ML
>("MULTILINESTRING((2 3,2 7,7 7,7 3),(2 3,2 3))")
253 from_wkt
<OG
>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
254 from_wkt
<OG
>("POLYGON((2 5,5 7,7 5,5 2))"),
255 from_wkt
<ML
>("MULTILINESTRING((2 5,2 5),(5 7,5 7),(7 5,7 5),(5 2,5 2))")
260 from_wkt
<OG
>("POLYGON((0 0,0 10,10 10,10 0),(2 2,7 2,7 7,2 7))"),
261 from_wkt
<OG
>("POLYGON((2 5,4 7,6 7,7 5,5 2))"),
262 from_wkt
<ML
>("MULTILINESTRING((2 5,2 5),(4 7,6 7),(7 5,7 5),(5 2,5 2))")
267 from_wkt
<OG
>("POLYGON(())"),
268 from_wkt
<OG
>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
269 from_wkt
<ML
>("MULTILINESTRING()")
274 from_wkt
<OG
>("POLYGON((2 1,2 4,4 4,4 0,1 0))"),
275 from_wkt
<OG
>("POLYGON(())"),
276 from_wkt
<ML
>("MULTILINESTRING()")
281 from_wkt
<OG
>("POLYGON(())"),
282 from_wkt
<OG
>("POLYGON(())"),
283 from_wkt
<ML
>("MULTILINESTRING()")
288 from_wkt
<OG
>("POLYGON((),())"),
289 from_wkt
<OG
>("POLYGON((),(),())"),
290 from_wkt
<ML
>("MULTILINESTRING()")
295 from_wkt
<OG
>("POLYGON((2 1,2 4,4 4,4 0,1 0),())"),
296 from_wkt
<OG
>("POLYGON(())"),
297 from_wkt
<ML
>("MULTILINESTRING()")
302 BOOST_AUTO_TEST_CASE( test_intersection_polygon_multipolygon_linestring
)
304 #ifdef BOOST_GEOMETRY_TEST_DEBUG
305 std::cout
<< std::endl
<< std::endl
<< std::endl
;
306 std::cout
<< "*** POLYGON / MULTIPOLYGON / LINEAR INTERSECTION ***"
308 std::cout
<< std::endl
;
310 typedef open_polygon_type OG1
;
311 typedef open_multipolygon_type OG2
;
312 typedef closed_polygon_type CG1
;
313 typedef closed_multipolygon_type CG2
;
314 typedef multi_linestring_type ML
;
316 typedef test_intersection_aal
<OG1
, OG2
, CG1
, CG2
, ML
> tester
;
320 from_wkt
<OG1
>("POLYGON((0 0,0 2,2 2,2 0))"),
321 from_wkt
<OG2
>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
322 from_wkt
<ML
>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
323 from_wkt
<ML
>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
328 BOOST_AUTO_TEST_CASE( test_intersection_multipolygon_multipolygon_linestring
)
330 #ifdef BOOST_GEOMETRY_TEST_DEBUG
331 std::cout
<< std::endl
<< std::endl
<< std::endl
;
332 std::cout
<< "*** MULTIPOLYGON / MULTIPOLYGON / LINEAR INTERSECTION ***"
334 std::cout
<< std::endl
;
336 typedef open_multipolygon_type OG
;
337 typedef closed_multipolygon_type CG
;
338 typedef multi_linestring_type ML
;
340 typedef test_intersection_aal
<OG
, OG
, CG
, CG
, ML
> tester
;
344 from_wkt
<OG
>("MULTIPOLYGON(((0 0,0 2,2 2,2 0)))"),
345 from_wkt
<OG
>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
346 from_wkt
<ML
>("MULTILINESTRING((2 1,2 2),(2 0,1 0),(2 1,2 1))"),
347 from_wkt
<ML
>("MULTILINESTRING((2 2,2 1),(2 0,1 0),(2 1,2 1))")
352 from_wkt
<OG
>("MULTIPOLYGON(((0 0,0 10,10 10,10 0),(2 2,8 2,8 8,2 8)))"),
353 from_wkt
<OG
>("MULTIPOLYGON(((2 4,2 6,8 6,8 4)))"),
354 from_wkt
<ML
>("MULTILINESTRING((2 4,2 4),(2 4,2 6),(8 6,8 4))")
359 from_wkt
<OG
>("MULTIPOLYGON()"),
360 from_wkt
<OG
>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
361 from_wkt
<ML
>("MULTILINESTRING()")
366 from_wkt
<OG
>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0)))"),
367 from_wkt
<OG
>("MULTIPOLYGON()"),
368 from_wkt
<ML
>("MULTILINESTRING()")
373 from_wkt
<OG
>("MULTIPOLYGON()"),
374 from_wkt
<OG
>("MULTIPOLYGON()"),
375 from_wkt
<ML
>("MULTILINESTRING()")
380 from_wkt
<OG
>("MULTIPOLYGON((()),((),()))"),
381 from_wkt
<OG
>("MULTIPOLYGON()"),
382 from_wkt
<ML
>("MULTILINESTRING()")
387 from_wkt
<OG
>("MULTIPOLYGON(((2 1,2 4,4 4,4 0,1 0),(),()))"),
388 from_wkt
<OG
>("MULTIPOLYGON()"),
389 from_wkt
<ML
>("MULTILINESTRING()")