1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2015, Oracle and/or its affiliates.
5 // Licensed under the Boost Software License version 1.0.
6 // http://www.boost.org/users/license.html
8 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
10 #ifndef BOOST_TEST_MODULE
11 #define BOOST_TEST_MODULE test_intersection_pointlike_linear
17 #include <boost/test/included/unit_test.hpp>
19 #include "../test_set_ops_pointlike.hpp"
21 #include <boost/geometry/geometries/point.hpp>
22 #include <boost/geometry/geometries/linestring.hpp>
23 #include <boost/geometry/geometries/segment.hpp>
24 #include <boost/geometry/geometries/multi_point.hpp>
25 #include <boost/geometry/geometries/multi_linestring.hpp>
27 typedef bg::model::point
<double, 2, bg::cs::cartesian
> point_type
;
28 typedef bg::model::segment
<point_type
> segment_type
;
29 typedef bg::model::linestring
<point_type
> linestring_type
;
30 typedef bg::model::multi_point
<point_type
> multi_point_type
;
31 typedef bg::model::multi_linestring
<linestring_type
> multi_linestring_type
;
34 //===========================================================================
35 //===========================================================================
36 //===========================================================================
39 BOOST_AUTO_TEST_CASE( test_intersection_point_segment
)
41 #ifdef BOOST_GEOMETRY_TEST_DEBUG
42 std::cout
<< std::endl
<< std::endl
<< std::endl
;
43 std::cout
<< "*** POINT / SEGMENT INTERSECTION ***" << std::endl
;
44 std::cout
<< std::endl
;
48 typedef segment_type S
;
49 typedef multi_point_type MP
;
51 typedef test_set_op_of_pointlike_geometries
53 P
, S
, MP
, bg::overlay_intersection
58 from_wkt
<P
>("POINT(0 0)"),
59 from_wkt
<S
>("SEGMENT(1 1,2 2)"),
60 from_wkt
<MP
>("MULTIPOINT()")
65 from_wkt
<P
>("POINT(0 0)"),
66 from_wkt
<S
>("SEGMENT(0 0,1 1)"),
67 from_wkt
<MP
>("MULTIPOINT(0 0)")
72 from_wkt
<P
>("POINT(1 1)"),
73 from_wkt
<S
>("SEGMENT(0 0,2 2)"),
74 from_wkt
<MP
>("MULTIPOINT(1 1)")
79 from_wkt
<P
>("POINT(3 3)"),
80 from_wkt
<S
>("SEGMENT(0 0,2 2)"),
81 from_wkt
<MP
>("MULTIPOINT()")
86 BOOST_AUTO_TEST_CASE( test_intersection_point_linestring
)
88 #ifdef BOOST_GEOMETRY_TEST_DEBUG
89 std::cout
<< std::endl
<< std::endl
<< std::endl
;
90 std::cout
<< "*** POINT / LINESTRING INTERSECTION ***" << std::endl
;
91 std::cout
<< std::endl
;
95 typedef linestring_type L
;
96 typedef multi_point_type MP
;
98 typedef test_set_op_of_pointlike_geometries
100 P
, L
, MP
, bg::overlay_intersection
105 from_wkt
<P
>("POINT(0 0)"),
106 from_wkt
<L
>("LINESTRING(1 1,2 2)"),
107 from_wkt
<MP
>("MULTIPOINT()")
112 from_wkt
<P
>("POINT(0 0)"),
113 from_wkt
<L
>("LINESTRING(0 0,1 1)"),
114 from_wkt
<MP
>("MULTIPOINT(0 0)")
119 from_wkt
<P
>("POINT(1 1)"),
120 from_wkt
<L
>("LINESTRING(0 0,2 2)"),
121 from_wkt
<MP
>("MULTIPOINT(1 1)")
126 from_wkt
<P
>("POINT(3 3)"),
127 from_wkt
<L
>("LINESTRING(0 0,2 2)"),
128 from_wkt
<MP
>("MULTIPOINT()")
131 // linestrings with more than two points
134 from_wkt
<P
>("POINT(1 1)"),
135 from_wkt
<L
>("LINESTRING(0 0,1 1,2 2)"),
136 from_wkt
<MP
>("MULTIPOINT(1 1)")
141 from_wkt
<P
>("POINT(2 2)"),
142 from_wkt
<L
>("LINESTRING(0 0,1 1,4 4)"),
143 from_wkt
<MP
>("MULTIPOINT(2 2)")
148 from_wkt
<P
>("POINT(10 10)"),
149 from_wkt
<L
>("LINESTRING(0 0,1 1,4 4)"),
150 from_wkt
<MP
>("MULTIPOINT()")
155 from_wkt
<P
>("POINT(0 1)"),
156 from_wkt
<L
>("LINESTRING(0 0,1 1,4 4)"),
157 from_wkt
<MP
>("MULTIPOINT()")
162 from_wkt
<P
>("POINT(4 4)"),
163 from_wkt
<L
>("LINESTRING(0 0,1 1,4 4)"),
164 from_wkt
<MP
>("MULTIPOINT(4 4)")
169 from_wkt
<P
>("POINT(0 0)"),
170 from_wkt
<L
>("LINESTRING(0 0,1 1,4 4)"),
171 from_wkt
<MP
>("MULTIPOINT(0 0)")
176 BOOST_AUTO_TEST_CASE( test_intersection_point_multilinestring
)
178 #ifdef BOOST_GEOMETRY_TEST_DEBUG
179 std::cout
<< std::endl
<< std::endl
<< std::endl
;
180 std::cout
<< "*** POINT / MULTILINESTRING INTERSECTION ***" << std::endl
;
181 std::cout
<< std::endl
;
184 typedef point_type P
;
185 typedef multi_linestring_type ML
;
186 typedef multi_point_type MP
;
188 typedef test_set_op_of_pointlike_geometries
190 P
, ML
, MP
, bg::overlay_intersection
195 from_wkt
<P
>("POINT(0 0)"),
196 from_wkt
<ML
>("MULTILINESTRING((1 1,2 2))"),
197 from_wkt
<MP
>("MULTIPOINT()")
202 from_wkt
<P
>("POINT(0 0)"),
203 from_wkt
<ML
>("MULTILINESTRING((0 0,1 1))"),
204 from_wkt
<MP
>("MULTIPOINT(0 0)")
209 from_wkt
<P
>("POINT(1 1)"),
210 from_wkt
<ML
>("MULTILINESTRING((0 0,2 2))"),
211 from_wkt
<MP
>("MULTIPOINT(1 1)")
216 from_wkt
<P
>("POINT(3 3)"),
217 from_wkt
<ML
>("MULTILINESTRING((0 0,2 2))"),
218 from_wkt
<MP
>("MULTIPOINT()")
221 // linestrings with more than two points
224 from_wkt
<P
>("POINT(1 1)"),
225 from_wkt
<ML
>("MULTILINESTRING((0 0,1 1,2 2))"),
226 from_wkt
<MP
>("MULTIPOINT(1 1)")
231 from_wkt
<P
>("POINT(2 2)"),
232 from_wkt
<ML
>("MULTILINESTRING((0 0,1 1,4 4))"),
233 from_wkt
<MP
>("MULTIPOINT(2 2)")
238 from_wkt
<P
>("POINT(10 10)"),
239 from_wkt
<ML
>("MULTILINESTRING((0 0,1 1,4 4))"),
240 from_wkt
<MP
>("MULTIPOINT()")
245 from_wkt
<P
>("POINT(0 1)"),
246 from_wkt
<ML
>("MULTILINESTRING((0 0,1 1,4 4))"),
247 from_wkt
<MP
>("MULTIPOINT()")
252 from_wkt
<P
>("POINT(4 4)"),
253 from_wkt
<ML
>("MULTILINESTRING((0 0,1 1,4 4))"),
254 from_wkt
<MP
>("MULTIPOINT(4 4)")
259 from_wkt
<P
>("POINT(0 0)"),
260 from_wkt
<ML
>("MULTILINESTRING((0 0,1 1,4 4))"),
261 from_wkt
<MP
>("MULTIPOINT(0 0)")
264 // multilinestrings with more than one linestring
267 from_wkt
<P
>("POINT(0 0)"),
268 from_wkt
<ML
>("MULTILINESTRING((-10,-10),(0 0,1 1,4 4))"),
269 from_wkt
<MP
>("MULTIPOINT(0 0)")
274 from_wkt
<P
>("POINT(0 0)"),
275 from_wkt
<ML
>("MULTILINESTRING((-10 0,0 0,10 0),(0 0,1 1,4 4))"),
276 from_wkt
<MP
>("MULTIPOINT(0 0)")
281 from_wkt
<P
>("POINT(0 0)"),
282 from_wkt
<ML
>("MULTILINESTRING((-10 0,10 0),(0 0,1 1,4 4))"),
283 from_wkt
<MP
>("MULTIPOINT(0 0)")
288 from_wkt
<P
>("POINT(-20 0)"),
289 from_wkt
<ML
>("MULTILINESTRING((-10 0,10 0),(0 0,1 1,4 4))"),
290 from_wkt
<MP
>("MULTIPOINT()")
295 from_wkt
<P
>("POINT(0 1)"),
296 from_wkt
<ML
>("MULTILINESTRING((-10 0,10 0),(0 0,1 1,4 4))"),
297 from_wkt
<MP
>("MULTIPOINT()")
302 from_wkt
<P
>("POINT(1 0)"),
303 from_wkt
<ML
>("MULTILINESTRING((-10 0,10 0),(-1 0,2 0,20 0))"),
304 from_wkt
<MP
>("MULTIPOINT(1 0)")
309 from_wkt
<P
>("POINT(1 0)"),
310 from_wkt
<ML
>("MULTILINESTRING((-10 0,10 0),(0 -1,0 2,0 4))"),
311 from_wkt
<MP
>("MULTIPOINT(1 0)")
316 BOOST_AUTO_TEST_CASE( test_intersection_multipoint_segment
)
318 #ifdef BOOST_GEOMETRY_TEST_DEBUG
319 std::cout
<< std::endl
<< std::endl
<< std::endl
;
320 std::cout
<< "*** MULTIPOINT / SEGMENT INTERSECTION ***" << std::endl
;
321 std::cout
<< std::endl
;
324 typedef multi_point_type MP
;
325 typedef segment_type S
;
327 typedef test_set_op_of_pointlike_geometries
329 MP
, S
, MP
, bg::overlay_intersection
334 from_wkt
<MP
>("MULTIPOINT(0 0)"),
335 from_wkt
<S
>("SEGMENT(1 1,2 2)"),
336 from_wkt
<MP
>("MULTIPOINT()")
341 from_wkt
<MP
>("MULTIPOINT(0 0)"),
342 from_wkt
<S
>("SEGMENT(0 0,1 1)"),
343 from_wkt
<MP
>("MULTIPOINT(0 0)")
348 from_wkt
<MP
>("MULTIPOINT(0 0,0 0)"),
349 from_wkt
<S
>("SEGMENT(1 1,2 2)"),
350 from_wkt
<MP
>("MULTIPOINT()")
355 from_wkt
<MP
>("MULTIPOINT(0 0,0 0)"),
356 from_wkt
<S
>("SEGMENT(0 0,1 1)"),
357 from_wkt
<MP
>("MULTIPOINT(0 0,0 0)")
362 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,1 0)"),
363 from_wkt
<S
>("SEGMENT(1 1,2 2)"),
364 from_wkt
<MP
>("MULTIPOINT()")
369 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,1 0)"),
370 from_wkt
<S
>("SEGMENT(1 0,2 0)"),
371 from_wkt
<MP
>("MULTIPOINT(1 0)")
376 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
377 from_wkt
<S
>("SEGMENT(0 0,1 0)"),
378 from_wkt
<MP
>("MULTIPOINT(0 0,0 0)")
383 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
384 from_wkt
<S
>("SEGMENT(0 0,3 0)"),
385 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)")
390 from_wkt
<MP
>("MULTIPOINT()"),
391 from_wkt
<S
>("SEGMENT(0 0,1 1)"),
392 from_wkt
<MP
>("MULTIPOINT()")
397 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
398 from_wkt
<S
>("SEGMENT(-1 0,1 0)"),
399 from_wkt
<MP
>("MULTIPOINT(0 0,0 0)")
404 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
405 from_wkt
<S
>("SEGMENT(1 0,3 0)"),
406 from_wkt
<MP
>("MULTIPOINT(2 0)")
411 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
412 from_wkt
<S
>("SEGMENT(-1 0,3 0)"),
413 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)")
418 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
419 from_wkt
<S
>("SEGMENT(3 0,3 0)"),
420 from_wkt
<MP
>("MULTIPOINT()")
425 from_wkt
<MP
>("MULTIPOINT(0 0,2 0,0 0)"),
426 from_wkt
<S
>("SEGMENT(3 0,3 0)"),
427 from_wkt
<MP
>("MULTIPOINT()")
432 from_wkt
<MP
>("MULTIPOINT(0 0,2 0,0 0,2 0)"),
433 from_wkt
<S
>("SEGMENT(3 0,3 0)"),
434 from_wkt
<MP
>("MULTIPOINT()")
439 from_wkt
<MP
>("MULTIPOINT(0 0,2 0,0 0,2 0,0 0)"),
440 from_wkt
<S
>("SEGMENT(3 0,3 0)"),
441 from_wkt
<MP
>("MULTIPOINT()")
446 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
447 from_wkt
<S
>("SEGMENT(2 0,2 0)"),
448 from_wkt
<MP
>("MULTIPOINT(2 0)")
453 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
454 from_wkt
<S
>("SEGMENT(0 0,0 0)"),
455 from_wkt
<MP
>("MULTIPOINT(0 0,0 0)")
460 from_wkt
<MP
>("MULTIPOINT()"),
461 from_wkt
<S
>("SEGMENT(0 0,1 0)"),
462 from_wkt
<MP
>("MULTIPOINT()")
467 from_wkt
<MP
>("MULTIPOINT(0 0,2 0,0 0,2 0,0 0)"),
468 from_wkt
<S
>("SEGMENT(-1 0,10 0)"),
469 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,0 0,2 0,2 0)")
474 BOOST_AUTO_TEST_CASE( test_intersection_multipoint_linestring
)
476 #ifdef BOOST_GEOMETRY_TEST_DEBUG
477 std::cout
<< std::endl
<< std::endl
<< std::endl
;
478 std::cout
<< "*** MULTIPOINT / LINESTRING INTERSECTION ***" << std::endl
;
479 std::cout
<< std::endl
;
482 typedef multi_point_type MP
;
483 typedef linestring_type L
;
485 typedef test_set_op_of_pointlike_geometries
487 MP
, L
, MP
, bg::overlay_intersection
492 from_wkt
<MP
>("MULTIPOINT(0 0)"),
493 from_wkt
<L
>("LINESTRING(1 1,2 2,3 3,4 4,5 5)"),
494 from_wkt
<MP
>("MULTIPOINT()")
499 from_wkt
<MP
>("MULTIPOINT(0 0)"),
500 from_wkt
<L
>("LINESTRING(0 0,1 1)"),
501 from_wkt
<MP
>("MULTIPOINT(0 0)")
506 from_wkt
<MP
>("MULTIPOINT(0 0,0 0)"),
507 from_wkt
<L
>("LINESTRING(1 1,2 2)"),
508 from_wkt
<MP
>("MULTIPOINT()")
513 from_wkt
<MP
>("MULTIPOINT(0 0,0 0)"),
514 from_wkt
<L
>("LINESTRING(0 0,1 1)"),
515 from_wkt
<MP
>("MULTIPOINT(0 0,0 0)")
520 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,1 0)"),
521 from_wkt
<L
>("LINESTRING(1 1,2 2)"),
522 from_wkt
<MP
>("MULTIPOINT()")
527 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,1 0)"),
528 from_wkt
<L
>("LINESTRING(1 0,2 0)"),
529 from_wkt
<MP
>("MULTIPOINT(1 0)")
534 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
535 from_wkt
<L
>("LINESTRING(0 0,1 0)"),
536 from_wkt
<MP
>("MULTIPOINT(0 0,0 0)")
541 from_wkt
<MP
>("MULTIPOINT()"),
542 from_wkt
<L
>("LINESTRING(0 0,1 1)"),
543 from_wkt
<MP
>("MULTIPOINT()")
548 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
549 from_wkt
<L
>("LINESTRING(-1 0,1 0)"),
550 from_wkt
<MP
>("MULTIPOINT(0 0,0 0)")
555 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
556 from_wkt
<L
>("LINESTRING(1 0,3 0)"),
557 from_wkt
<MP
>("MULTIPOINT(2 0)")
562 from_wkt
<MP
>("MULTIPOINT(2 0,0 0,2 0,0 0,2 0)"),
563 from_wkt
<L
>("LINESTRING(1 0,3 0)"),
564 from_wkt
<MP
>("MULTIPOINT(2 0,2 0,2 0)")
569 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
570 from_wkt
<L
>("LINESTRING(-1 0,3 0)"),
571 from_wkt
<MP
>("MULTIPOINT(2 0,0 0,0 0)")
576 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
577 from_wkt
<L
>("LINESTRING(3 0,3 0)"),
578 from_wkt
<MP
>("MULTIPOINT()")
583 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
584 from_wkt
<L
>("LINESTRING(2 0,2 0)"),
585 from_wkt
<MP
>("MULTIPOINT(2 0)")
590 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,2 0)"),
591 from_wkt
<L
>("LINESTRING(0 0,0 0)"),
592 from_wkt
<MP
>("MULTIPOINT(0 0,0 0)")
597 from_wkt
<MP
>("MULTIPOINT()"),
598 from_wkt
<L
>("LINESTRING(0 0,1 0,2 0,3 0)"),
599 from_wkt
<MP
>("MULTIPOINT()")
604 from_wkt
<MP
>("MULTIPOINT()"),
605 from_wkt
<L
>("LINESTRING()"),
606 from_wkt
<MP
>("MULTIPOINT()")
611 BOOST_AUTO_TEST_CASE( test_intersection_multipoint_multilinestring
)
613 #ifdef BOOST_GEOMETRY_TEST_DEBUG
614 std::cout
<< std::endl
<< std::endl
<< std::endl
;
615 std::cout
<< "*** MULTIPOINT / MULTILINESTRING INTERSECTION ***"
617 std::cout
<< std::endl
;
620 typedef multi_point_type MP
;
621 typedef multi_linestring_type ML
;
623 typedef test_set_op_of_pointlike_geometries
625 MP
, ML
, MP
, bg::overlay_intersection
630 from_wkt
<MP
>("MULTIPOINT(0 0,1 0,2 0)"),
631 from_wkt
<ML
>("MULTILINESTRING((1 0,1 1,1 1,4 4))"),
632 from_wkt
<MP
>("MULTIPOINT(1 0)")
637 from_wkt
<MP
>("MULTIPOINT(2 2,3 3,0 0,0 0,2 2,1 1,1 1,1 0,1 0)"),
638 from_wkt
<ML
>("MULTILINESTRING((1 0,1 1,1 1,4 4))"),
639 from_wkt
<MP
>("MULTIPOINT(2 2,2 2,3 3,1 1,1 1,1 0,1 0)")
644 from_wkt
<MP
>("MULTIPOINT(5 5,3 3,0 0,0 0,5 5,1 1,1 1,1 0,1 0)"),
645 from_wkt
<ML
>("MULTILINESTRING((1 0,1 1,1 1,4 4))"),
646 from_wkt
<MP
>("MULTIPOINT(1 0,1 0,3 3,1 1,1 1)")
651 from_wkt
<MP
>("MULTIPOINT(0 0,1 1,1 0,1 1)"),
652 from_wkt
<ML
>("MULTILINESTRING((1 0,0 0,1 1,0 0))"),
653 from_wkt
<MP
>("MULTIPOINT(1 0,0 0,1 1,1 1)")
658 from_wkt
<MP
>("MULTIPOINT(0 0,1 0,2 0,5 0)"),
659 from_wkt
<ML
>("MULTILINESTRING((0 1,0 0,1 2,1 0),\
660 (0 1,2 0,0 10,2 0,2 10,5 10,5 0,5 10))"),
661 from_wkt
<MP
>("MULTIPOINT(0 0,1 0,2 0,5 0)")
666 from_wkt
<MP
>("MULTIPOINT(0 0,1 1,1 0,1 1)"),
667 from_wkt
<ML
>("MULTILINESTRING(())"),
668 from_wkt
<MP
>("MULTIPOINT()")
673 from_wkt
<MP
>("MULTIPOINT()"),
674 from_wkt
<ML
>("MULTILINESTRING(())"),
675 from_wkt
<MP
>("MULTIPOINT()")
680 from_wkt
<MP
>("MULTIPOINT()"),
681 from_wkt
<ML
>("MULTILINESTRING((0 0,1 0),(9 0,10 0))"),
682 from_wkt
<MP
>("MULTIPOINT()")
687 from_wkt
<MP
>("MULTIPOINT(0 0,1 1,0 0,0 0,0 0,0 0,0 0,0 0,\
688 0 0,0 0,0 0,0 0,0 0)"),
689 from_wkt
<ML
>("MULTILINESTRING((0 0,0 1),(0 0,2 0),(0 0,0 3),\
690 (0 0,4 0),(0 0,0 5),(0 0,6 0),(0 0,7 0),(0 0,8 0))"),
691 from_wkt
<MP
>("MULTIPOINT(0 0,0 0,0 0,0 0,0 0,0 0,0 0,\
692 0 0,0 0,0 0,0 0,0 0)")
697 from_wkt
<MP
>("MULTIPOINT(0 0,1 1,0 0)"),
698 from_wkt
<ML
>("MULTILINESTRING((0 0,0 1),(0 0,2 0),(0 0,0 3),\
699 (0 0,4 0),(0 0,0 5),(0 0,6 0),(0 0,7 0),(0 0,8 0))"),
700 from_wkt
<MP
>("MULTIPOINT(0 0,0 0)")