1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2014-2017, Oracle and/or its affiliates.
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
12 #ifndef BOOST_TEST_MODULE
13 #define BOOST_TEST_MODULE test_disjoint_coverage
16 // unit test to test disjoint for all geometry combinations
20 #include <boost/test/included/unit_test.hpp>
22 #include <boost/geometry/core/tag.hpp>
23 #include <boost/geometry/core/tags.hpp>
25 #include <boost/geometry/strategies/strategies.hpp>
27 #include <boost/geometry/io/wkt/wkt.hpp>
28 #include <boost/geometry/io/dsv/write.hpp>
30 #include <boost/geometry/geometries/geometries.hpp>
32 #include <boost/geometry/algorithms/disjoint.hpp>
34 #include <from_wkt.hpp>
38 #include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
41 namespace bg
= ::boost::geometry
;
43 //============================================================================
47 template <typename Geometry1
, typename Geometry2
>
48 static inline void apply(std::string
const& case_id
,
49 Geometry1
const& geometry1
,
50 Geometry2
const& geometry2
,
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
);
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
);
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
;
78 //============================================================================
80 // pointlike-areal geometries
82 inline void test_point_box()
84 typedef test_disjoint tester
;
85 typedef bg::model::box
<P
> B
;
87 tester::apply("p-b-01",
88 from_wkt
<P
>("POINT(0 0)"),
89 from_wkt
<B
>("BOX(0 0,1 1)"),
92 tester::apply("p-b-02",
93 from_wkt
<P
>("POINT(2 2)"),
94 from_wkt
<B
>("BOX(0 0,1 0)"),
99 inline void test_point_ring()
101 typedef bg::model::ring
<P
, false, false> R
; // ccw, open
103 typedef test_disjoint tester
;
105 tester::apply("p-r-01",
106 from_wkt
<P
>("POINT(0 0)"),
107 from_wkt
<R
>("POLYGON((0 0,1 0,0 1))"),
110 tester::apply("p-r-02",
111 from_wkt
<P
>("POINT(1 1)"),
112 from_wkt
<R
>("POLYGON((0 0,1 0,0 1))"),
116 template <typename P
>
117 inline void test_point_polygon()
119 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
121 typedef test_disjoint tester
;
123 tester::apply("p-pg-01",
124 from_wkt
<P
>("POINT(0 0)"),
125 from_wkt
<PL
>("POLYGON((0 0,1 0,0 1))"),
128 tester::apply("p-pg-02",
129 from_wkt
<P
>("POINT(1 1)"),
130 from_wkt
<PL
>("POLYGON((0 0,1 0,0 1))"),
134 template <typename P
>
135 inline void test_point_multipolygon()
137 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
138 typedef bg::model::multi_polygon
<PL
> MPL
;
140 typedef test_disjoint tester
;
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)))"),
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)))"),
153 template <typename P
>
154 inline void test_multipoint_box()
156 typedef test_disjoint tester
;
157 typedef bg::model::multi_point
<P
> MP
;
158 typedef bg::model::box
<P
> B
;
160 tester::apply("mp-b-01",
161 from_wkt
<MP
>("MULTIPOINT(0 0,1 1)"),
162 from_wkt
<B
>("BOX(0 0,2 2)"),
165 tester::apply("mp-b-02",
166 from_wkt
<MP
>("MULTIPOINT(1 1,3 3)"),
167 from_wkt
<B
>("BOX(0 0,2 2)"),
170 tester::apply("mp-b-03",
171 from_wkt
<MP
>("MULTIPOINT(3 3,4 4)"),
172 from_wkt
<B
>("BOX(0 0,2 2)"),
175 tester::apply("mp-b-04",
176 from_wkt
<MP
>("MULTIPOINT()"),
177 from_wkt
<B
>("BOX(0 0,2 2)"),
181 template <typename P
>
182 inline void test_multipoint_ring()
184 typedef bg::model::multi_point
<P
> MP
;
185 typedef bg::model::ring
<P
, false, false> R
; // ccw, open
187 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
205 template <typename P
>
206 inline void test_multipoint_polygon()
208 typedef bg::model::multi_point
<P
> MP
;
209 typedef bg::model::polygon
<P
, false, false> PL
; // ccw, open
211 typedef test_disjoint tester
;
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))"),
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))"),
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))"),
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))"),
234 template <typename P
>
235 inline void test_multipoint_multipolygon()
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
;
241 typedef test_disjoint tester
;
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)))"),
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)))"),
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)))"),
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)))"),
264 //============================================================================
266 template <typename CoordinateType
>
267 inline void test_pointlike_areal()
269 typedef bg::model::point
<CoordinateType
, 2, bg::cs::cartesian
> point_type
;
271 test_point_polygon
<point_type
>();
272 test_point_multipolygon
<point_type
>();
273 test_point_ring
<point_type
>();
274 test_point_box
<point_type
>();
276 test_multipoint_polygon
<point_type
>();
277 test_multipoint_multipolygon
<point_type
>();
278 test_multipoint_ring
<point_type
>();
280 test_multipoint_box
<point_type
>();
283 //============================================================================
285 BOOST_AUTO_TEST_CASE( test_pointlike_areal_all
)
287 test_pointlike_areal
<double>();
288 test_pointlike_areal
<int>();
290 test_pointlike_areal
<ttmath_big
>();