• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry
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_difference_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/point.hpp>
22 #include <boost/geometry/geometries/ring.hpp>
23 #include <boost/geometry/geometries/polygon.hpp>
24 #include <boost/geometry/geometries/multi_point.hpp>
25 #include <boost/geometry/geometries/multi_polygon.hpp>
26 
27 typedef bg::model::point<double, 2, bg::cs::cartesian> Pt;
28 typedef bg::model::ring<Pt> R;
29 typedef bg::model::polygon<Pt> Po;
30 typedef bg::model::multi_point<Pt> MPt;
31 typedef bg::model::multi_polygon<Po> MPo;
32 
BOOST_AUTO_TEST_CASE(test_difference_point_ring)33 BOOST_AUTO_TEST_CASE( test_difference_point_ring )
34 {
35     typedef test_set_op_of_pointlike_geometries
36         <
37             Pt, R, MPt, bg::overlay_difference
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()")
45     );
46 
47     tester::apply(
48         "pt-r-02",
49         from_wkt<Pt>("POINT(3 5)"),
50         from_wkt<R>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))"),
51         from_wkt<MPt>("MULTIPOINT()")
52     );
53 
54     tester::apply(
55         "pt-r-03",
56         from_wkt<Pt>("POINT(6 3)"),
57         from_wkt<R>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))"),
58         from_wkt<MPt>("MULTIPOINT(6 3)")
59     );
60 }
61 
BOOST_AUTO_TEST_CASE(test_difference_point_polygon)62 BOOST_AUTO_TEST_CASE( test_difference_point_polygon )
63 {
64     typedef test_set_op_of_pointlike_geometries
65         <
66             Pt, Po, MPt, bg::overlay_difference
67         > tester;
68 
69     tester::apply(
70         "pt-po-01",
71         from_wkt<Pt>("POINT(0 0)"),
72         from_wkt<Po>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))"),
73         from_wkt<MPt>("MULTIPOINT()")
74     );
75 
76     tester::apply(
77         "pt-po-02",
78         from_wkt<Pt>("POINT(4 4)"),
79         from_wkt<Po>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))"),
80         from_wkt<MPt>("MULTIPOINT()")
81     );
82 
83     tester::apply(
84         "pt-po-03",
85         from_wkt<Pt>("POINT(3 3)"),
86         from_wkt<Po>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))"),
87         from_wkt<MPt>("MULTIPOINT(3 3)")
88     );
89 
90     tester::apply(
91         "pt-po-04",
92         from_wkt<Pt>("POINT(6 0)"),
93         from_wkt<Po>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))"),
94         from_wkt<MPt>("MULTIPOINT(6 0)")
95     );
96 }
97 
BOOST_AUTO_TEST_CASE(test_difference_point_multipolygon)98 BOOST_AUTO_TEST_CASE( test_difference_point_multipolygon )
99 {
100     typedef test_set_op_of_pointlike_geometries
101         <
102             Pt, MPo, MPt, bg::overlay_difference
103         > tester;
104 
105     tester::apply(
106         "pt-mpo-01",
107         from_wkt<Pt>("POINT(0 0)"),
108         from_wkt<MPo>("MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),"
109                                    "((5 5, 5 7, 7 7, 7 5, 5 5)))"),
110         from_wkt<MPt>("MULTIPOINT()")
111     );
112 
113     tester::apply(
114         "pt-mpo-02",
115         from_wkt<Pt>("POINT(3 3)"),
116         from_wkt<MPo>("MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),"
117                                    "((5 5, 5 7, 7 7, 7 5, 5 5)))"),
118         from_wkt<MPt>("MULTIPOINT(3 3)")
119     );
120 
121     tester::apply(
122         "pt-mpo-03",
123         from_wkt<Pt>("POINT(4 4)"),
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)),"
125                                    "((5 5, 5 7, 7 7, 7 5, 5 5)))"),
126         from_wkt<MPt>("MULTIPOINT()")
127     );
128 
129     tester::apply(
130         "pt-mpo-04",
131         from_wkt<Pt>("POINT(5 5)"),
132         from_wkt<MPo>("MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),"
133                                    "((5 5, 5 7, 7 7, 7 5, 5 5)))"),
134         from_wkt<MPt>("MULTIPOINT()")
135     );
136 
137     tester::apply(
138         "pt-mpo-05",
139         from_wkt<Pt>("POINT(6 6)"),
140         from_wkt<MPo>("MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),"
141                                    "((5 5, 5 7, 7 7, 7 5, 5 5)))"),
142         from_wkt<MPt>("MULTIPOINT()")
143     );
144 }
145 
BOOST_AUTO_TEST_CASE(test_difference_multipoint_ring)146 BOOST_AUTO_TEST_CASE( test_difference_multipoint_ring )
147 {
148     typedef test_set_op_of_pointlike_geometries
149         <
150             MPt, R, MPt, bg::overlay_difference
151         > tester;
152 
153     tester::apply(
154         "mpt-r-01",
155         from_wkt<MPt>("MULTIPOINT(0 0, 1 1, 5 5, 6 6)"),
156         from_wkt<R>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))"),
157         from_wkt<MPt>("MULTIPOINT(6 6)")
158     );
159 
160     tester::apply(
161         "mpt-r-02",
162         from_wkt<MPt>("MULTIPOINT(3 5, 5 3, 3 0, 0 3, 3 6, 6 3, 3 -1, -1 3)"),
163         from_wkt<R>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))"),
164         from_wkt<MPt>("MULTIPOINT(3 6, 6 3, 3 -1, -1 3)")
165     );
166 }
167 
BOOST_AUTO_TEST_CASE(test_difference_multipoint_polygon)168 BOOST_AUTO_TEST_CASE( test_difference_multipoint_polygon )
169 {
170     typedef test_set_op_of_pointlike_geometries
171         <
172             MPt, Po, MPt, bg::overlay_difference
173         > tester;
174 
175     tester::apply(
176         "mpt-po-01",
177         from_wkt<MPt>("MULTIPOINT(0 0, 1 1, 4 4, 5 5, 6 6)"),
178         from_wkt<Po>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))"),
179         from_wkt<MPt>("MULTIPOINT(1 1, 6 6)")
180     );
181 
182     tester::apply(
183         "mpt-po-02",
184         from_wkt<MPt>("MULTIPOINT(3 5, 5 3, 3 0, 0 3, 3 6, 6 3, 3 -1, -1 3, 2 0.5, 0.5 2, 2 4, 4 2)"),
185         from_wkt<Po>("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0))"),
186         from_wkt<MPt>("MULTIPOINT(3 6, 6 3, 3 -1, -1 3)")
187     );
188 }
189 
BOOST_AUTO_TEST_CASE(test_difference_multipoint_multipolygon)190 BOOST_AUTO_TEST_CASE(test_difference_multipoint_multipolygon)
191 {
192     typedef test_set_op_of_pointlike_geometries
193         <
194         MPt, MPo, MPt, bg::overlay_difference
195         > tester;
196 
197     tester::apply(
198         "mpt-mpo-01",
199         from_wkt<MPt>("MULTIPOINT(0 0, 1 1, 4 4, 5 5, 6 6)"),
200         from_wkt<MPo>("MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),"
201                                    "((5 5, 5 7, 7 7, 7 5, 5 5)))"),
202         from_wkt<MPt>("MULTIPOINT(1 1)")
203     );
204 
205     tester::apply(
206         "mpt-mpo-02",
207         from_wkt<MPt>("MULTIPOINT(3 5, 5 3, 3 0, 0 3, 3 6, 6 3, 3 -1, -1 3, 2 0.5, 0.5 2, 2 4, 4 2, 6 5, 6 7, 5 6, 7 6)"),
208         from_wkt<MPo>("MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0),(0 0, 4 1, 4 4, 1 4, 0 0)),"
209                                    "((5 5, 5 7, 7 7, 7 5, 5 5)))"),
210         from_wkt<MPt>("MULTIPOINT(3 6, 6 3, 3 -1, -1 3)")
211     );
212 }
213