File: disjoint_seg_box.cpp

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (407 lines) | stat: -rw-r--r-- 17,141 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
// Boost.Geometry

// Copyright (c) 2016-2019 Oracle and/or its affiliates.

// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle

// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/adapted/c_array.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
#include <test_common/test_point.hpp>

#include <boost/geometry/formulas/andoyer_inverse.hpp>
#include <boost/geometry/formulas/thomas_inverse.hpp>
#include <boost/geometry/formulas/vincenty_inverse.hpp>

#include <boost/geometry/strategies/strategies.hpp>

#include <boost/geometry/algorithms/disjoint.hpp>

#include <geometry_test_common.hpp>

#include "test_disjoint_seg_box.hpp"


namespace bg = boost::geometry;

//Tests for disjoint(point, box), disjoint(box, box) and disjoint(segment, box)

template <typename P>
void disjoint_tests_1()
{
    test_disjoint<bg::model::box<P>, P>("BOX(1 1,3 3)", "POINT(4 4)", true);
    test_disjoint<bg::model::box<P>, P>("BOX(1 1,3 3)", "POINT(2 2)", false);
    test_disjoint<bg::model::box<P>, P>("BOX(1 1,3 3)", "POINT(3 3)", false);
    test_disjoint<bg::model::box<P>, P>("BOX(1 1,3 3)", "POINT(2 3)", false);

    test_disjoint<bg::model::box<P>, bg::model::box<P> >("BOX(1 1,3 3)",
                                                         "BOX(1 4,5 5)",
                                                         true);
    test_disjoint<bg::model::box<P>, bg::model::box<P> >("BOX(1 1,3 3)",
                                                         "BOX(2 2,4 4)",
                                                         false);
    test_disjoint<bg::model::box<P>, bg::model::box<P> >("BOX(1 1,3 3)",
                                                         "BOX(3 3,4 4)",
                                                         false);
    test_disjoint<bg::model::box<P>, bg::model::box<P> >("BOX(1 1,3 3)",
                                                         "BOX(2 3,4 4)",
                                                         false);

    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(1 1,3 3)",
                                                             "SEGMENT(1 4, 5 5)",
                                                             true);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(1 1,3 3)",
                                                             "SEGMENT(3 3, 5 5)",
                                                             false);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(1 1,3 3)",
                                                             "SEGMENT(1 1, 4 1)",
                                                             false);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(1 1,3 3)",
                                                             "SEGMENT(1 2, 5 5)",
                                                             false);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(1 1,3 3)",
                                                             "SEGMENT(1 2, 3 2)",
                                                             false);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(1 1,3 3)",
                                                             "SEGMENT(0 0, 4 0)",
                                                             true);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(1 1,3 3)",
                                                             "SEGMENT(2 2, 4 4)",
                                                             false);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(1 1,3 3)",
                                                             "SEGMENT(4 4, 2 2)",
                                                             false);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(1 1,3 3)",
                                                             "SEGMENT(1.5 1.5, 2 2)",
                                                             false);
}

template <typename P>
void disjoint_tests_2(bool expected_result)
{
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(1 1,3 3)",
                                                             "SEGMENT(1 0.999, 10 0.999)",
                                                             expected_result);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(1 1,3 3)",
                                                             "SEGMENT(10 0.999, 1 0.999)",
                                                             expected_result);
}

template <typename P>
void disjoint_tests_3(bool expected_result)
{
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(3 4.42, 100 5)",
                                                             "SEGMENT(2 2.9, 100 2.9)",
                                                             expected_result);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(3 4.42, 100 5)",
                                                             "SEGMENT(100 2.9, 2 2.9)",
                                                             expected_result);
}

template <typename P>
void disjoint_tests_4(bool expected_result)
{
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(1 1,3 3)",
                                                             "SEGMENT(0 0.99999999, 2 0.99999999)",
                                                             expected_result);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(1 1,3 3)",
                                                             "SEGMENT(2 0.99999999, 0 0.99999999)",
                                                             expected_result);
}

template <typename P, typename CT>
void disjoint_tests_with_strategy(bool expected_result)
{
    bg::strategy::disjoint::segment_box_geographic
    <
        bg::strategy::andoyer,
        bg::srs::spheroid<CT>,
        CT
    > geographic_andoyer;

    bg::strategy::disjoint::segment_box_geographic
    <
        bg::strategy::thomas,
        bg::srs::spheroid<CT>,
        CT
    > geographic_thomas;

    bg::strategy::disjoint::segment_box_geographic
    <
        bg::strategy::vincenty,
        bg::srs::spheroid<CT>,
        CT
    > geographic_vincenty;

    test_disjoint_strategy<bg::model::box<P>, bg::model::segment<P> >
            ("BOX(1 1,3 3)", "SEGMENT(1 0.999, 10 0.999)",
             expected_result, geographic_andoyer);
    test_disjoint_strategy<bg::model::box<P>, bg::model::segment<P> >
            ("BOX(1 1,3 3)", "SEGMENT(1 0.999, 10 0.999)",
             expected_result, geographic_thomas);
    test_disjoint_strategy<bg::model::box<P>, bg::model::segment<P> >
            ("BOX(1 1,3 3)", "SEGMENT(1 0.999, 10 0.999)",
             expected_result, geographic_vincenty);
}

template <typename P>
void disjoint_tests_sph_geo()
{
    //Case A: box intersects without containing the vertex
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(0 6, 120 7)",
                                                             "SEGMENT(0 5, 120 5)",
                                                             false);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(0 -6, 120 -7)",
                                                             "SEGMENT(0 -5, 120 -5)",
                                                             false);

    //Case B: box intersects and contains the vertex
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(0 9, 120 10)",
                                                             "SEGMENT(0 5, 120 5)",
                                                             false);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(0 -10, 120 -9)",
                                                             "SEGMENT(0 -5, 120 -5)",
                                                             false);

    //Case C: bounding boxes disjoint
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(0 10, 10 20)",
                                                             "SEGMENT(0 5, 120 5)",
                                                             true);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(0 -20, 10 -10)",
                                                             "SEGMENT(0 -5, 120 -5)",
                                                             true);

    //Case D: bounding boxes intersect but box segment are disjoint
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(0 9, 0.1 20)",
                                                             "SEGMENT(0 5, 120 5)",
                                                             true);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(0 -20, 0.1 -9)",
                                                             "SEGMENT(0 -5, 120 -5)",
                                                             true);

    //Case E: geodesic intersects box but box segment are disjoint
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(121 0, 122 10)",
                                                             "SEGMENT(0 5, 120 5)",
                                                             true);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(121 -10, 122 0)",
                                                             "SEGMENT(0 -5, 120 -5)",
                                                             true);

    //Case F: segment crosses box
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(100 0, 110 20)",
                                                             "SEGMENT(0 5, 120 5)",
                                                             false);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(100 -20, 110 0)",
                                                             "SEGMENT(0 -5, 120 -5)",
                                                             false);

    //Case G: box contains one segment endpoint
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(110 0, 130 10)",
                                                             "SEGMENT(0 5, 120 5)",
                                                             false);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(110 -10, 130 0)",
                                                             "SEGMENT(0 -5, 120 -5)",
                                                             false);

    //Case H: box below segment
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(50 0, 70 6)",
                                                             "SEGMENT(0 5, 120 5)",
                                                             true);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(50 -6, 70 0)",
                                                             "SEGMENT(0 -5, 120 -5)",
                                                             true);

    //Case I: box contains segment
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(-10 0, 130 10)",
                                                             "SEGMENT(0 5, 120 5)",
                                                             false);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(-10 -10, 130 0)",
                                                             "SEGMENT(0 -5, 120 -5)",
                                                             false);

    //ascending segment
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(0 10, 120 10.1)",
                                                             "SEGMENT(0 5, 120 5.1)",
                                                             false);

    //descending segment
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(0 9.8, 120 10)",
                                                             "SEGMENT(0 5, 120 4.9)",
                                                             false);

    //ascending segment both hemispheres
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(100 5, 120 6)",
                                                             "SEGMENT(0 -1, 120 4.9)",
                                                             false);

    //descending segment both hemispheres
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(0 5, 20 6)",
                                                             "SEGMENT(0 4.9, 120 -1)",
                                                             false);

    //https://github.com/boostorg/geometry/issues/579
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(10 10,20 20)",
                                                             "SEGMENT(12 2,12 1)",
                                                             true);
    test_disjoint<bg::model::box<P>, bg::model::segment<P> >("BOX(10 10,20 20)",
                                                             "SEGMENT(12 1,12 2)",
                                                             true);

    //based on https://github.com/boostorg/geometry/issues/851
    test_disjoint
    <
        bg::model::box<P>,
        bg::model::segment<P>
    >("BOX(13.381347 50.625, 13.40332 50.646972)",
      "SEGMENT(9.18 48.78,13.4 52.52)",
      true);

    test_disjoint
    <
        bg::model::box<P>,
        bg::model::segment<P>
    >("BOX(11.22802734375 50.972264889367494, 11.359863281250002 51.06211251399776)",
      "SEGMENT(9.18 48.78,13.4 52.52)",
      true);

    test_disjoint
    <
        bg::model::box<P>,
        bg::model::segment<P>
    >("BOX(10.9423828125 50.527396813293024, 12.06298828125 50.65294336725708)",
      "SEGMENT(9.18 48.78,13.4 52.52)",
      false);

    test_disjoint
    <
        bg::model::box<P>,
        bg::model::segment<P>
    >("BOX(13.238525390625 52.49448734004673, 13.3319091796875 52.549636074382306)",
      "SEGMENT(9.18 48.78,13.4 52.52)",
      true);

    test_disjoint
    <
        bg::model::box<P>,
        bg::model::segment<P>
    >("BOX(13.40332 -50.646972, 13.381347 -50.625)",
      "SEGMENT(9.18 -48.78,13.4 -52.52)",
      true);

    test_disjoint
    <
        bg::model::box<P>,
        bg::model::segment<P>
    >("BOX(11.359863281250002 -51.06211251399776,11.22802734375 -50.972264889367494)",
      "SEGMENT(9.18 -48.78,13.4 -52.52)",
      true);

    test_disjoint
    <
        bg::model::box<P>,
        bg::model::segment<P>
    >("BOX(0 1,1 2)",
      "SEGMENT(0 0,0 3)",
      false);

    test_disjoint
    <
        bg::model::box<P>,
        bg::model::segment<P>
    >("BOX(0 1,1 2)",
      "SEGMENT(1 0,1 3)",
      false);

    test_disjoint
    <
        bg::model::box<P>,
        bg::model::segment<P>
    >("BOX(1 0,2 1)",
      "SEGMENT(0 0,3 0)",
      false);

    test_disjoint
    <
        bg::model::box<P>,
        bg::model::segment<P>
    >("BOX(1 0,2 1)",
      "SEGMENT(0 1,3 1)",
      true);

    // segment on the equator
    test_disjoint
    <
        bg::model::box<P>,
        bg::model::segment<P>
    >("BOX(1 1,2 2)",
      "SEGMENT(0 0,3 0)",
      true);
    test_disjoint
    <
        bg::model::box<P>,
        bg::model::segment<P>
    >("BOX(2 -2,1 -1)",
      "SEGMENT(0 0,3 0)",
      true);
    test_disjoint
    <
        bg::model::box<P>,
        bg::model::segment<P>
    >("BOX(1 -1,2 1)",
      "SEGMENT(0 0,3 0)",
      false);
    test_disjoint
    <
        bg::model::box<P>,
        bg::model::segment<P>
    >("BOX(4 -1,5 1)",
      "SEGMENT(0 0,3 0)",
      true);
}

template <typename CT>
void test_all()
{
    typedef bg::model::d2::point_xy<CT> point;
    typedef bg::model::point<CT, 2,
            bg::cs::spherical_equatorial<bg::degree> > sph_point;
    typedef bg::model::point<CT, 2,
            bg::cs::geographic<bg::degree> > geo_point;

    disjoint_tests_1<point>();
    disjoint_tests_1<sph_point>();
    disjoint_tests_1<geo_point>();

    disjoint_tests_2<point>(true);
    disjoint_tests_2<sph_point>(false);
    disjoint_tests_2<geo_point>(false);

    //illustrate difference between spherical and geographic computation on same data
    disjoint_tests_3<point>(true);
    disjoint_tests_3<sph_point>(true);
    disjoint_tests_3<geo_point>(false);

    disjoint_tests_4<sph_point>(false);
    disjoint_tests_4<geo_point>(false);

    disjoint_tests_with_strategy<geo_point, CT>(false);

    disjoint_tests_sph_geo<sph_point>();
    disjoint_tests_sph_geo<geo_point>();
}


int test_main( int , char* [] )
{
    test_all<float>();
    test_all<double>();

    return 0;
}