• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef BOOST_TEST_MODULE
11 #define BOOST_TEST_MODULE test_intersection_pointlike_areal
12 #endif
13 
14 #include <iostream>
15 #include <algorithm>
16 
17 #include <boost/test/included/unit_test.hpp>
18 
19 #include "../test_set_ops_pointlike.hpp"
20 
21 #include <boost/geometry/geometries/multi_point.hpp>
22 #include <boost/geometry/geometries/multi_polygon.hpp>
23 #include <boost/geometry/geometries/point.hpp>
24 #include <boost/geometry/geometries/polygon.hpp>
25 #include <boost/geometry/geometries/ring.hpp>
26 
27 typedef bg::model::point<double, 2, bg::cs::cartesian> Pt;
28 typedef bg::model::polygon<Pt> Po;
29 typedef bg::model::ring<Pt> R;
30 typedef bg::model::multi_point<Pt> MPt;
31 typedef bg::model::multi_polygon<Po> MPo;
32 
BOOST_AUTO_TEST_CASE(test_intersection_point_ring)33 BOOST_AUTO_TEST_CASE( test_intersection_point_ring )
34 {
35     typedef test_set_op_of_pointlike_geometries
36         <
37             Pt, R, MPt, bg::overlay_intersection
38         > tester;
39 
40     tester::apply(
41         "pt-r-01",
42         from_wkt<Pt>("POINT(0 0)"),
43         from_wkt<R>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))"),
44         from_wkt<MPt>("MULTIPOINT(0 0)")
45     );
46 
47     tester::apply(
48         "pt-r-02",
49         from_wkt<Pt>("POINT(1 1)"),
50         from_wkt<R>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))"),
51         from_wkt<MPt>("MULTIPOINT(1 1)")
52     );
53 
54     tester::apply(
55         "pt-r-03",
56         from_wkt<Pt>("POINT(6 6)"),
57         from_wkt<R>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))"),
58         from_wkt<MPt>("MULTIPOINT()")
59     );
60 }
61 
62 
BOOST_AUTO_TEST_CASE(test_intersection_point_polygon)63 BOOST_AUTO_TEST_CASE( test_intersection_point_polygon )
64 {
65     typedef test_set_op_of_pointlike_geometries
66         <
67             Pt, Po, MPt, bg::overlay_intersection
68         > tester;
69 
70     tester::apply(
71         "pt-po-01",
72         from_wkt<Pt>("POINT(0 0)"),
73         from_wkt<Po>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 3 1, 3 3, 1 3, 0 0))"),
74         from_wkt<MPt>("MULTIPOINT(0 0)")
75     );
76 
77     tester::apply(
78         "pt-po-02",
79         from_wkt<Pt>("POINT(1 1)"),
80         from_wkt<Po>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 3 1, 3 3, 1 3, 0 0))"),
81         from_wkt<MPt>("MULTIPOINT()")
82     );
83 
84     tester::apply(
85         "pt-po-03",
86         from_wkt<Pt>("POINT(3 3)"),
87         from_wkt<Po>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 3 1, 3 3, 1 3, 0 0))"),
88         from_wkt<MPt>("MULTIPOINT(3 3)")
89     );
90 
91     tester::apply(
92         "pt-po-04",
93         from_wkt<Pt>("POINT(4 4)"),
94         from_wkt<Po>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 3 1, 3 3, 1 3, 0 0))"),
95         from_wkt<MPt>("MULTIPOINT(4 4)")
96     );
97 
98     tester::apply(
99         "pt-po-05",
100         from_wkt<Pt>("POINT(6 6)"),
101         from_wkt<Po>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 3 1, 3 3, 1 3, 0 0))"),
102         from_wkt<MPt>("MULTIPOINT()")
103     );
104 }
105 
106 
BOOST_AUTO_TEST_CASE(test_intersection_point_multipolygon)107 BOOST_AUTO_TEST_CASE( test_intersection_point_multipolygon )
108 {
109     typedef test_set_op_of_pointlike_geometries
110         <
111             Pt, MPo, MPt, bg::overlay_intersection
112         > tester;
113 
114     tester::apply(
115         "pt-mpo-01",
116         from_wkt<Pt>("POINT(0 0)"),
117         from_wkt<MPo>("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)))"),
118         from_wkt<MPt>("MULTIPOINT(0 0)")
119     );
120 
121     tester::apply(
122         "pt-mpo-02",
123         from_wkt<Pt>("POINT(1 1)"),
124         from_wkt<MPo>("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)))"),
125         from_wkt<MPt>("MULTIPOINT(1 1)")
126     );
127 
128     tester::apply(
129         "pt-mpo-03",
130         from_wkt<Pt>("POINT(2 2)"),
131         from_wkt<MPo>("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)))"),
132         from_wkt<MPt>("MULTIPOINT(2 2)")
133     );
134 
135     tester::apply(
136         "pt-mpo-04",
137         from_wkt<Pt>("POINT(3 3)"),
138         from_wkt<MPo>("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)))"),
139         from_wkt<MPt>("MULTIPOINT()")
140     );
141 }
142 
BOOST_AUTO_TEST_CASE(test_intersection_multipoint_ring)143 BOOST_AUTO_TEST_CASE( test_intersection_multipoint_ring )
144 {
145     typedef test_set_op_of_pointlike_geometries
146         <
147             MPt, R, MPt, bg::overlay_intersection
148         > tester;
149 
150     tester::apply(
151         "mpt-r-01",
152         from_wkt<MPt>("MULTIPOINT(0 0, 1 1, 6 6)"),
153         from_wkt<R>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))"),
154         from_wkt<MPt>("MULTIPOINT(0 0, 1 1)")
155     );
156 }
157 
158 
BOOST_AUTO_TEST_CASE(test_intersection_multipoint_polygon)159 BOOST_AUTO_TEST_CASE( test_intersection_multipoint_polygon )
160 {
161     typedef test_set_op_of_pointlike_geometries
162         <
163             MPt, Po, MPt, bg::overlay_intersection
164         > tester;
165 
166     tester::apply(
167         "mpt-po-01",
168         from_wkt<MPt>("MULTIPOINT(0 0, 1 1, 3 3, 4 4, 6 6)"),
169         from_wkt<Po>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 3 1, 3 3, 1 3, 0 0))"),
170         from_wkt<MPt>("MULTIPOINT(0 0, 3 3, 4 4)")
171     );
172 }
173 
174 
BOOST_AUTO_TEST_CASE(test_intersection_multipoint_multipolygon)175 BOOST_AUTO_TEST_CASE( test_intersection_multipoint_multipolygon )
176 {
177     typedef test_set_op_of_pointlike_geometries
178         <
179             MPt, MPo, MPt, bg::overlay_intersection
180         > tester;
181 
182     tester::apply(
183         "mpt-mpo-01",
184         from_wkt<MPt>("MULTIPOINT(0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6)"),
185         from_wkt<MPo>("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)))"),
186         // NOTE: This is caused by the fact that intersection(MPt, MPt)
187         //       used internally does not filter duplicates out.
188         from_wkt<MPt>("MULTIPOINT(0 0, 0 0, 1 1, 2 2, 4 4, 5 5)")
189     );
190 }