]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/within/within_sph_geo.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / within / within_sph_geo.cpp
1 // Boost.Geometry
2
3 // Copyright (c) 2016-2018 Oracle and/or its affiliates.
4 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
5
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 #include "test_within.hpp"
11
12
13 #include <boost/geometry/geometries/geometries.hpp>
14
15
16 template <typename Point>
17 void test_point_box_by_side()
18 {
19 // Test spherical boxes
20 // See also http://www.gcmap.com/mapui?P=1E45N-19E45N-19E55N-1E55N-1E45N,10E55.1N,10E45.1N
21 typedef bg::model::box<Point> box_t;
22 bg::strategy::within::point_in_box_by_side<> by_side;
23 box_t box;
24 bg::read_wkt("POLYGON((1 45,19 55))", box);
25 BOOST_CHECK_EQUAL(bg::within(Point(10, 55.1), box, by_side), true);
26 BOOST_CHECK_EQUAL(bg::within(Point(10, 55.2), box, by_side), true);
27 BOOST_CHECK_EQUAL(bg::within(Point(10, 55.3), box, by_side), true);
28 BOOST_CHECK_EQUAL(bg::within(Point(10, 55.4), box, by_side), false);
29
30 BOOST_CHECK_EQUAL(bg::within(Point(10, 45.1), box, by_side), false);
31 BOOST_CHECK_EQUAL(bg::within(Point(10, 45.2), box, by_side), false);
32 BOOST_CHECK_EQUAL(bg::within(Point(10, 45.3), box, by_side), false);
33 BOOST_CHECK_EQUAL(bg::within(Point(10, 45.4), box, by_side), true);
34
35 // By default Box is not a polygon in spherical CS, edges are defined by small circles
36 BOOST_CHECK_EQUAL(bg::within(Point(10, 45.1), box), true);
37 BOOST_CHECK_EQUAL(bg::within(Point(10, 54.9), box), true);
38 BOOST_CHECK_EQUAL(bg::within(Point(10, 55), box), false);
39 BOOST_CHECK_EQUAL(bg::within(Point(10, 45), box), false);
40
41 // Crossing the dateline (Near Tuvalu)
42 // http://www.gcmap.com/mapui?P=178E10S-178W10S-178W6S-178E6S-178E10S,180W5.999S,180E9.999S
43 // http://en.wikipedia.org/wiki/Tuvalu
44
45 box_t tuvalu(Point(178, -10), Point(-178, -6));
46 BOOST_CHECK_EQUAL(bg::within(Point(180, -8), tuvalu, by_side), true);
47 BOOST_CHECK_EQUAL(bg::within(Point(-180, -8), tuvalu, by_side), true);
48 BOOST_CHECK_EQUAL(bg::within(Point(180, -5.999), tuvalu, by_side), false);
49 BOOST_CHECK_EQUAL(bg::within(Point(180, -10.001), tuvalu, by_side), true);
50
51 // The above definition of a Box is not valid
52 // min should be lesser than max
53 // By default Box is not a polygon in spherical CS, edges are defined by small circles
54 box_t tuvalu2(Point(178, -10), Point(182, -6));
55 BOOST_CHECK_EQUAL(bg::within(Point(180, -8), tuvalu2), true);
56 BOOST_CHECK_EQUAL(bg::within(Point(-180, -8), tuvalu2), true);
57 BOOST_CHECK_EQUAL(bg::within(Point(180, -6.001), tuvalu2), true);
58 BOOST_CHECK_EQUAL(bg::within(Point(180, -5.999), tuvalu2), false);
59 BOOST_CHECK_EQUAL(bg::within(Point(180, -9.999), tuvalu2), true);
60 BOOST_CHECK_EQUAL(bg::within(Point(180, -10.001), tuvalu2), false);
61 }
62
63
64 template <typename P>
65 void test_point_box()
66 {
67 typedef bg::model::box<P> box_t;
68
69 test_geometry<P, box_t>("POINT(0 0)", "BOX(0 0, 1 1)", false);
70 test_geometry<P, box_t>("POINT(1 1)", "BOX(0 0, 2 2)", true);
71
72 test_geometry<P, box_t>("POINT(180 1)", "BOX(170 0, 190 2)", true);
73 test_geometry<P, box_t>("POINT(-180 1)", "BOX(170 0, 190 2)", true);
74 test_geometry<P, box_t>("POINT(180 1)", "BOX(170 0, 180 2)", false);
75 test_geometry<P, box_t>("POINT(-180 1)", "BOX(170 0, 180 2)", false);
76 test_geometry<P, box_t>("POINT(179 1)", "BOX(170 0, 190 2)", true);
77 test_geometry<P, box_t>("POINT(-179 1)", "BOX(170 0, 190 2)", true);
78 test_geometry<P, box_t>("POINT(179 1)", "BOX(170 0, 180 2)", true);
79 test_geometry<P, box_t>("POINT(-179 1)", "BOX(170 0, 180 2)", false);
80 test_geometry<P, box_t>("POINT(169 1)", "BOX(170 0, 180 2)", false);
81
82 test_point_box_by_side<P>();
83 }
84
85 template <typename P>
86 void test_box_box()
87 {
88 typedef bg::model::box<P> box_t;
89
90 test_geometry<box_t, box_t>("BOX(0 0, 1 1)", "BOX(0 0, 1 1)", true);
91
92 test_geometry<box_t, box_t>("BOX(-170 0,-160 1)", "BOX(-180 0, 180 1)", true);
93 test_geometry<box_t, box_t>("BOX(-170 0,-160 1)", "BOX(170 0, 200 1)", true);
94 test_geometry<box_t, box_t>("BOX(-170 0,-150 1)", "BOX(170 0, 200 1)", false);
95 test_geometry<box_t, box_t>("BOX(0 0,1 1)", "BOX(170 0, 370 1)", true);
96 test_geometry<box_t, box_t>("BOX(0 0,10 1)", "BOX(170 0, 370 1)", true);
97 test_geometry<box_t, box_t>("BOX(-180 0,10 1)", "BOX(170 0, 370 1)", true);
98 test_geometry<box_t, box_t>("BOX(-180 0,20 1)", "BOX(170 0, 370 1)", false);
99 test_geometry<box_t, box_t>("BOX(10 0,20 1)", "BOX(170 0, 370 1)", false);
100 test_geometry<box_t, box_t>("BOX(160 0,180 1)", "BOX(170 0, 370 1)", false);
101
102 test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(180 0, 190 1)", true); // invalid?
103 test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(180 0, 191 1)", true); // invalid?
104 test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(179 0, 190 1)", true);
105 test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(181 0, 190 1)", false); // invalid?
106 test_geometry<box_t, box_t>("BOX(-180 0,-170 1)", "BOX(180 0, 189 1)", false); // invalid?
107 }
108
109
110 template <typename P>
111 void test_cs()
112 {
113 test_point_box<P>();
114 test_box_box<P>();
115 }
116
117
118 int test_main( int , char* [] )
119 {
120 test_cs<bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree> > >();
121 test_cs<bg::model::point<double, 2, bg::cs::geographic<bg::degree> > >();
122
123 #if defined(HAVE_TTMATH)
124 test_cs<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
125 test_cs<bg::model::point<ttmath_big, 2, bg::cs::geographic<bg::degree> > >();
126 #endif
127
128 return 0;
129 }