• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 
3 // Copyright (c) 2014-2017, Oracle and/or its affiliates.
4 
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7 
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
10 
11 
12 #ifndef BOOST_TEST_MODULE
13 #define BOOST_TEST_MODULE test_disjoint_coverage
14 #endif
15 
16 // unit test to test disjoint for all geometry combinations
17 
18 #include <iostream>
19 
20 #include <boost/test/included/unit_test.hpp>
21 
22 #include <boost/geometry/core/tag.hpp>
23 #include <boost/geometry/core/tags.hpp>
24 
25 #include <boost/geometry/strategies/strategies.hpp>
26 
27 #include <boost/geometry/io/wkt/wkt.hpp>
28 #include <boost/geometry/io/dsv/write.hpp>
29 
30 #include <boost/geometry/geometries/geometries.hpp>
31 
32 #include <boost/geometry/algorithms/disjoint.hpp>
33 
34 #include <from_wkt.hpp>
35 
36 
37 #ifdef HAVE_TTMATH
38 #include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
39 #endif
40 
41 namespace bg = ::boost::geometry;
42 
43 //============================================================================
44 
45 struct test_disjoint
46 {
47     template <typename Geometry1, typename Geometry2>
applytest_disjoint48     static inline void apply(std::string const& case_id,
49                              Geometry1 const& geometry1,
50                              Geometry2 const& geometry2,
51                              bool expected_result)
52     {
53         bool result = bg::disjoint(geometry1, geometry2);
54         BOOST_CHECK_MESSAGE(result == expected_result,
55             "case ID: " << case_id << ", G1: " << bg::wkt(geometry1)
56             << ", G2: " << bg::wkt(geometry2) << " -> Expected: "
57             << expected_result << ", detected: " << result);
58 
59         result = bg::disjoint(geometry2, geometry1);
60         BOOST_CHECK_MESSAGE(result == expected_result,
61             "case ID: " << case_id << ", G1: " << bg::wkt(geometry2)
62             << ", G2: " << bg::wkt(geometry1) << " -> Expected: "
63             << expected_result << ", detected: " << result);
64 
65 #ifdef BOOST_GEOMETRY_TEST_DEBUG
66         std::cout << "case ID: " << case_id << "; G1 - G2: ";
67         std::cout << bg::wkt(geometry1) << " - ";
68         std::cout << bg::wkt(geometry2) << std::endl;
69         std::cout << std::boolalpha;
70         std::cout << "expected/computed result: "
71                   << expected_result << " / " << result << std::endl;
72         std::cout << std::endl;
73         std::cout << std::noboolalpha;
74 #endif
75     }
76 };
77 
78 //============================================================================
79 
80 // pointlike-areal geometries
81 template <typename P>
test_point_box()82 inline void test_point_box()
83 {
84     typedef test_disjoint tester;
85     typedef bg::model::box<P> B;
86 
87     tester::apply("p-b-01",
88                   from_wkt<P>("POINT(0 0)"),
89                   from_wkt<B>("BOX(0 0,1 1)"),
90                   false);
91 
92     tester::apply("p-b-02",
93                   from_wkt<P>("POINT(2 2)"),
94                   from_wkt<B>("BOX(0 0,1 0)"),
95                   true);
96 }
97 
98 template <typename P>
test_point_ring()99 inline void test_point_ring()
100 {
101     typedef bg::model::ring<P, false, false> R; // ccw, open
102 
103     typedef test_disjoint tester;
104 
105     tester::apply("p-r-01",
106                   from_wkt<P>("POINT(0 0)"),
107                   from_wkt<R>("POLYGON((0 0,1 0,0 1))"),
108                   false);
109 
110     tester::apply("p-r-02",
111                   from_wkt<P>("POINT(1 1)"),
112                   from_wkt<R>("POLYGON((0 0,1 0,0 1))"),
113                   true);
114 }
115 
116 template <typename P>
test_point_polygon()117 inline void test_point_polygon()
118 {
119     typedef bg::model::polygon<P, false, false> PL; // ccw, open
120 
121     typedef test_disjoint tester;
122 
123     tester::apply("p-pg-01",
124                   from_wkt<P>("POINT(0 0)"),
125                   from_wkt<PL>("POLYGON((0 0,1 0,0 1))"),
126                   false);
127 
128     tester::apply("p-pg-02",
129                   from_wkt<P>("POINT(1 1)"),
130                   from_wkt<PL>("POLYGON((0 0,1 0,0 1))"),
131                   true);
132 }
133 
134 template <typename P>
test_point_multipolygon()135 inline void test_point_multipolygon()
136 {
137     typedef bg::model::polygon<P, false, false> PL; // ccw, open
138     typedef bg::model::multi_polygon<PL> MPL;
139 
140     typedef test_disjoint tester;
141 
142     tester::apply("p-mpg-01",
143                   from_wkt<P>("POINT(0 0)"),
144                   from_wkt<MPL>("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"),
145                   false);
146 
147     tester::apply("p-mpg-02",
148                   from_wkt<P>("POINT(1 1)"),
149                   from_wkt<MPL>("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"),
150                   true);
151 }
152 
153 template <typename P>
test_multipoint_box()154 inline void test_multipoint_box()
155 {
156     typedef test_disjoint tester;
157     typedef bg::model::multi_point<P> MP;
158     typedef bg::model::box<P> B;
159 
160     tester::apply("mp-b-01",
161                   from_wkt<MP>("MULTIPOINT(0 0,1 1)"),
162                   from_wkt<B>("BOX(0 0,2 2)"),
163                   false);
164 
165     tester::apply("mp-b-02",
166                   from_wkt<MP>("MULTIPOINT(1 1,3 3)"),
167                   from_wkt<B>("BOX(0 0,2 2)"),
168                   false);
169 
170     tester::apply("mp-b-03",
171                   from_wkt<MP>("MULTIPOINT(3 3,4 4)"),
172                   from_wkt<B>("BOX(0 0,2 2)"),
173                   true);
174 
175     tester::apply("mp-b-04",
176                   from_wkt<MP>("MULTIPOINT()"),
177                   from_wkt<B>("BOX(0 0,2 2)"),
178                   true);
179 }
180 
181 template <typename P>
test_multipoint_ring()182 inline void test_multipoint_ring()
183 {
184     typedef bg::model::multi_point<P> MP;
185     typedef bg::model::ring<P, false, false> R; // ccw, open
186 
187     typedef test_disjoint tester;
188 
189     tester::apply("mp-r-01",
190                   from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
191                   from_wkt<R>("POLYGON((0 0,1 0,0 1))"),
192                   false);
193 
194     tester::apply("mp-r-02",
195                   from_wkt<MP>("MULTIPOINT(1 0,1 1)"),
196                   from_wkt<R>("POLYGON((0 0,1 0,0 1))"),
197                   false);
198 
199     tester::apply("mp-r-03",
200                   from_wkt<MP>("MULTIPOINT(1 1,2 2)"),
201                   from_wkt<R>("POLYGON((0 0,1 0,0 1))"),
202                   true);
203 }
204 
205 template <typename P>
test_multipoint_polygon()206 inline void test_multipoint_polygon()
207 {
208     typedef bg::model::multi_point<P> MP;
209     typedef bg::model::polygon<P, false, false> PL; // ccw, open
210 
211     typedef test_disjoint tester;
212 
213     tester::apply("mp-pg-01",
214                   from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
215                   from_wkt<PL>("POLYGON((0 0,1 0,0 1))"),
216                   false);
217 
218     tester::apply("mp-pg-02",
219                   from_wkt<MP>("MULTIPOINT(0 0,2 0)"),
220                   from_wkt<PL>("POLYGON((0 0,1 0,0 1))"),
221                   false);
222 
223     tester::apply("mp-pg-03",
224                   from_wkt<MP>("MULTIPOINT(1 1,2 0)"),
225                   from_wkt<PL>("POLYGON((0 0,1 0,0 1))"),
226                   true);
227 
228     tester::apply("mp-pg-04",
229                   from_wkt<MP>("MULTIPOINT(1 1,2 3)"),
230                   from_wkt<PL>("POLYGON((0 0,1 0,0 1))"),
231                   true);
232 }
233 
234 template <typename P>
test_multipoint_multipolygon()235 inline void test_multipoint_multipolygon()
236 {
237     typedef bg::model::multi_point<P> MP;
238     typedef bg::model::polygon<P, false, false> PL; // ccw, open
239     typedef bg::model::multi_polygon<PL> MPL;
240 
241     typedef test_disjoint tester;
242 
243     tester::apply("mp-mp-01",
244                   from_wkt<MP>("MULTIPOINT(0 0,2 0)"),
245                   from_wkt<MPL>("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"),
246                   false);
247 
248     tester::apply("mp-mp-02",
249                   from_wkt<MP>("MULTIPOINT(0 0,1 0)"),
250                   from_wkt<MPL>("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"),
251                   false);
252 
253     tester::apply("mp-mp-03",
254                   from_wkt<MP>("MULTIPOINT(1 1,2 0)"),
255                   from_wkt<MPL>("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"),
256                   false);
257 
258     tester::apply("mp-mp-04",
259                   from_wkt<MP>("MULTIPOINT(1 1,2 3)"),
260                   from_wkt<MPL>("MULTIPOLYGON(((0 0,1 0,0 1)),((2 0,3 0,2 1)))"),
261                   true);
262 }
263 
264 //============================================================================
265 
266 template <typename CoordinateType>
test_pointlike_areal()267 inline void test_pointlike_areal()
268 {
269     typedef bg::model::point<CoordinateType, 2, bg::cs::cartesian> point_type;
270 
271     test_point_polygon<point_type>();
272     test_point_multipolygon<point_type>();
273     test_point_ring<point_type>();
274     test_point_box<point_type>();
275 
276     test_multipoint_polygon<point_type>();
277     test_multipoint_multipolygon<point_type>();
278     test_multipoint_ring<point_type>();
279 
280     test_multipoint_box<point_type>();
281 }
282 
283 //============================================================================
284 
BOOST_AUTO_TEST_CASE(test_pointlike_areal_all)285 BOOST_AUTO_TEST_CASE( test_pointlike_areal_all )
286 {
287     test_pointlike_areal<double>();
288     test_pointlike_areal<int>();
289 #ifdef HAVE_TTMATH
290     test_pointlike_areal<ttmath_big>();
291 #endif
292 }
293