3 // Copyright (c) 2016-2017 Oracle and/or its affiliates.
5 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8 // Use, modification and distribution is subject to the Boost Software License,
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
12 #include <boost/geometry/geometries/box.hpp>
13 #include <boost/geometry/geometries/point_xy.hpp>
14 #include <boost/geometry/geometries/geometries.hpp>
15 #include <boost/geometry/geometries/adapted/c_array.hpp>
16 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
17 #include <test_common/test_point.hpp>
19 #include <boost/geometry/formulas/andoyer_inverse.hpp>
20 #include <boost/geometry/formulas/thomas_inverse.hpp>
21 #include <boost/geometry/formulas/vincenty_inverse.hpp>
23 #include <boost/geometry/strategies/strategies.hpp>
25 #include <boost/geometry/algorithms/disjoint.hpp>
27 #include <geometry_test_common.hpp>
29 #include "test_disjoint_seg_box.hpp"
32 namespace bg
= boost::geometry
;
34 //Tests for disjoint(point, box), disjoint(box, box) and disjoint(segment, box)
37 void disjoint_tests_1()
39 test_disjoint
<bg::model::box
<P
>, P
>("BOX(1 1,3 3)", "POINT(4 4)", true);
40 test_disjoint
<bg::model::box
<P
>, P
>("BOX(1 1,3 3)", "POINT(2 2)", false);
41 test_disjoint
<bg::model::box
<P
>, P
>("BOX(1 1,3 3)", "POINT(3 3)", false);
42 test_disjoint
<bg::model::box
<P
>, P
>("BOX(1 1,3 3)", "POINT(2 3)", false);
44 test_disjoint
<bg::model::box
<P
>, bg::model::box
<P
> >("BOX(1 1,3 3)",
47 test_disjoint
<bg::model::box
<P
>, bg::model::box
<P
> >("BOX(1 1,3 3)",
50 test_disjoint
<bg::model::box
<P
>, bg::model::box
<P
> >("BOX(1 1,3 3)",
53 test_disjoint
<bg::model::box
<P
>, bg::model::box
<P
> >("BOX(1 1,3 3)",
57 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(1 1,3 3)",
60 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(1 1,3 3)",
63 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(1 1,3 3)",
66 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(1 1,3 3)",
69 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(1 1,3 3)",
72 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(1 1,3 3)",
75 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(1 1,3 3)",
78 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(1 1,3 3)",
81 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(1 1,3 3)",
82 "SEGMENT(1.5 1.5, 2 2)",
87 void disjoint_tests_2(bool expected_result
)
89 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(1 1,3 3)",
90 "SEGMENT(1 0.999, 10 0.999)",
92 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(1 1,3 3)",
93 "SEGMENT(10 0.999, 1 0.999)",
98 void disjoint_tests_3(bool expected_result
)
100 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(3 4.42, 100 5)",
101 "SEGMENT(2 2.9, 100 2.9)",
103 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(3 4.42, 100 5)",
104 "SEGMENT(100 2.9, 2 2.9)",
108 template <typename P
>
109 void disjoint_tests_4(bool expected_result
)
111 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(1 1,3 3)",
112 "SEGMENT(0 0.99999999, 2 0.99999999)",
114 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(1 1,3 3)",
115 "SEGMENT(2 0.99999999, 0 0.99999999)",
119 template <typename P
, typename CT
>
120 void disjoint_tests_with_strategy(bool expected_result
)
122 bg::strategy::disjoint::segment_box_geographic
124 bg::strategy::andoyer
,
125 bg::srs::spheroid
<CT
>,
127 > geographic_andoyer
;
129 bg::strategy::disjoint::segment_box_geographic
131 bg::strategy::thomas
,
132 bg::srs::spheroid
<CT
>,
136 bg::strategy::disjoint::segment_box_geographic
138 bg::strategy::vincenty
,
139 bg::srs::spheroid
<CT
>,
141 > geographic_vincenty
;
143 test_disjoint_strategy
<bg::model::box
<P
>, bg::model::segment
<P
> >
144 ("BOX(1 1,3 3)", "SEGMENT(1 0.999, 10 0.999)",
145 expected_result
, geographic_andoyer
);
146 test_disjoint_strategy
<bg::model::box
<P
>, bg::model::segment
<P
> >
147 ("BOX(1 1,3 3)", "SEGMENT(1 0.999, 10 0.999)",
148 expected_result
, geographic_thomas
);
149 test_disjoint_strategy
<bg::model::box
<P
>, bg::model::segment
<P
> >
150 ("BOX(1 1,3 3)", "SEGMENT(1 0.999, 10 0.999)",
151 expected_result
, geographic_vincenty
);
154 template <typename P
>
155 void disjoint_tests_sph_geo()
157 //Case A: box intersects without containing the vertex
158 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(0 6, 120 7)",
159 "SEGMENT(0 5, 120 5)",
161 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(0 -6, 120 -7)",
162 "SEGMENT(0 -5, 120 -5)",
165 //Case B: box intersects and contains the vertex
166 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(0 9, 120 10)",
167 "SEGMENT(0 5, 120 5)",
169 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(0 -10, 120 -9)",
170 "SEGMENT(0 -5, 120 -5)",
173 //Case C: bounding boxes disjoint
174 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(0 10, 10 20)",
175 "SEGMENT(0 5, 120 5)",
177 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(0 -20, 10 -10)",
178 "SEGMENT(0 -5, 120 -5)",
181 //Case D: bounding boxes intersect but box segment are disjoint
182 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(0 9, 0.1 20)",
183 "SEGMENT(0 5, 120 5)",
185 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(0 -20, 0.1 -9)",
186 "SEGMENT(0 -5, 120 -5)",
189 //Case E: geodesic intersects box but box segment are disjoint
190 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(121 0, 122 10)",
191 "SEGMENT(0 5, 120 5)",
193 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(121 -10, 122 0)",
194 "SEGMENT(0 -5, 120 -5)",
197 //Case F: segment crosses box
198 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(100 0, 110 20)",
199 "SEGMENT(0 5, 120 5)",
201 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(100 -20, 110 0)",
202 "SEGMENT(0 -5, 120 -5)",
205 //Case G: box contains one segment endpoint
206 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(110 0, 130 10)",
207 "SEGMENT(0 5, 120 5)",
209 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(110 -10, 130 0)",
210 "SEGMENT(0 -5, 120 -5)",
213 //Case H: box below segment
214 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(50 0, 70 6)",
215 "SEGMENT(0 5, 120 5)",
217 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(50 -6, 70 0)",
218 "SEGMENT(0 -5, 120 -5)",
221 //Case I: box contains segment
222 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(-10 0, 130 10)",
223 "SEGMENT(0 5, 120 5)",
225 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(-10 -10, 130 0)",
226 "SEGMENT(0 -5, 120 -5)",
230 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(0 10, 120 10.1)",
231 "SEGMENT(0 5, 120 5.1)",
235 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(0 9.8, 120 10)",
236 "SEGMENT(0 5, 120 4.9)",
239 //ascending segment both hemispheres
240 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(100 5, 120 6)",
241 "SEGMENT(0 -1, 120 4.9)",
244 //descending segment both hemispheres
245 test_disjoint
<bg::model::box
<P
>, bg::model::segment
<P
> >("BOX(0 5, 20 6)",
246 "SEGMENT(0 4.9, 120 -1)",
250 template <typename CT
>
253 typedef bg::model::d2::point_xy
<CT
> point
;
254 typedef bg::model::point
<CT
, 2,
255 bg::cs::spherical_equatorial
<bg::degree
> > sph_point
;
256 typedef bg::model::point
<CT
, 2,
257 bg::cs::geographic
<bg::degree
> > geo_point
;
259 disjoint_tests_1
<point
>();
260 disjoint_tests_1
<sph_point
>();
261 disjoint_tests_1
<geo_point
>();
263 disjoint_tests_2
<point
>(true);
264 disjoint_tests_2
<sph_point
>(false);
265 disjoint_tests_2
<geo_point
>(false);
267 //illustrate difference between spherical and geographic computation on same data
268 disjoint_tests_3
<point
>(true);
269 disjoint_tests_3
<sph_point
>(true);
270 disjoint_tests_3
<geo_point
>(false);
272 disjoint_tests_4
<sph_point
>(false);
273 disjoint_tests_4
<geo_point
>(false);
275 disjoint_tests_with_strategy
<geo_point
, CT
>(false);
277 disjoint_tests_sph_geo
<sph_point
>();
278 disjoint_tests_sph_geo
<geo_point
>();
282 int test_main( int , char* [] )
288 common_tests
<bg::model::d2::point_xy
<ttmath_big
> >();
289 common_tests
<bg::model::point
<ttmath_big
, 3, bg::cs::cartesian
> >();