]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/strategies/envelope_segment.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / geometry / test / strategies / envelope_segment.cpp
1 // Boost.Geometry
2
3 // Copyright (c) 2016-2018 Oracle and/or its affiliates.
4
5 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7
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)
11
12 #include <geometry_test_common.hpp>
13 #include <boost/geometry/io/wkt/wkt.hpp>
14 #include <boost/geometry/geometries/box.hpp>
15 #include <boost/geometry/strategies/geographic/envelope_segment.hpp>
16 #include <boost/geometry/strategies/spherical/envelope_segment.hpp>
17
18 template
19 <
20 typename FormulaPolicy,
21 typename P,
22 typename CT
23 >
24 void test_strategies_lat(P p1, P p2, CT expected_max, CT expected_min,
25 CT expected_max_sph, CT expected_min_sph, CT error = 0.0001)
26 {
27 bg::model::box<P> box;
28
29 bg::strategy::envelope::geographic_segment
30 <
31 FormulaPolicy,
32 bg::srs::spheroid<CT>,
33 CT
34 > strategy_geo;
35
36 strategy_geo.apply(p1, p2, box);
37
38 CT p_min_degree_geo = bg::get<0, 1>(box);
39 CT p_max_degree_geo = bg::get<1, 1>(box);
40
41 BOOST_CHECK_CLOSE(p_max_degree_geo, expected_max, error);
42 BOOST_CHECK_CLOSE(p_min_degree_geo, expected_min, error);
43
44 typedef bg::strategy::envelope::spherical_segment<CT> strategy_sph_t;
45
46 strategy_sph_t::apply(p1, p2, box);
47
48 CT p_min_degree_sph = bg::get<0, 1>(box);
49 CT p_max_degree_sph = bg::get<1, 1>(box);
50
51 BOOST_CHECK_CLOSE(p_max_degree_sph, expected_max_sph, error);
52 BOOST_CHECK_CLOSE(p_min_degree_sph, expected_min_sph, error);
53 }
54
55
56 template <typename CT>
57 void test_all()
58 {
59 typedef bg::model::point<CT, 2, bg::cs::geographic<bg::degree> > Pg;
60
61 // Short segments
62 test_strategies_lat<bg::strategy::thomas>
63 (Pg(1, 1), Pg(10, 5), 5.0, 1.0, 5.0, 1.0);
64
65 test_strategies_lat<bg::strategy::thomas>
66 (Pg(1, 1), Pg(10, 1), 1.0031124506594733, 1.0, 1.0030915676477881, 1.0);
67 test_strategies_lat<bg::strategy::thomas>
68 (Pg(-5, 1), Pg(4, 1), 1.0031124506594733, 1.0, 1.0030915676477881, 1.0);
69 test_strategies_lat<bg::strategy::thomas>
70 (Pg(175, 1), Pg(184, 1), 1.0031124506594733, 1.0, 1.0030915676477881, 1.0);
71 test_strategies_lat<bg::strategy::thomas>
72 (Pg(355, 1), Pg(4, 1), 1.0031124506594733, 1.0, 1.0030915676477881, 1.0);
73
74 // Reverse direction
75 test_strategies_lat<bg::strategy::thomas>
76 (Pg(1, 2), Pg(70, 1), 2.0239716998355468, 1.0, 2.0228167431951536, 1.0);
77 test_strategies_lat<bg::strategy::thomas>
78 (Pg(70, 1), Pg(1, 2), 2.0239716998351849, 1.0, 2.022816743195063, 1.0);
79
80 // Long segments
81 test_strategies_lat<bg::strategy::thomas>
82 (Pg(0, 1), Pg(170, 1), 11.975026023950877, 1.0, 11.325049479775814, 1.0);
83 test_strategies_lat<bg::strategy::thomas>
84 (Pg(0, 1), Pg(179, 1), 68.452669316418039, 1.0, 63.437566893227093, 1.0);
85 test_strategies_lat<bg::strategy::thomas>
86 (Pg(0, 1), Pg(179.5, 1), 78.84050225214871, 1.0, 75.96516822754981, 1.0);
87 test_strategies_lat<bg::strategy::thomas>
88 (Pg(0, 1), Pg(180.5, 1), 78.84050225214871, 1.0, 75.965168227550194, 1.0);
89 test_strategies_lat<bg::strategy::thomas>
90 (Pg(0, 1), Pg(180, 1), 90.0, 1.0, 90.0, 1.0);
91
92 // South hemisphere
93 test_strategies_lat<bg::strategy::thomas>
94 (Pg(1, -1), Pg(10, -5), -1.0, -5.0, -1.0, -5.0);
95 test_strategies_lat<bg::strategy::thomas>
96 (Pg(1, -1), Pg(10, -1), -1.0, -1.0031124506594733, -1.0, -1.0030915676477881);
97 test_strategies_lat<bg::strategy::thomas>
98 (Pg(1, -1), Pg(170, -1), -1.0, -10.85834257048573, -1.0, -10.321374780571153);
99
100 // Different strategies for inverse
101 test_strategies_lat<bg::strategy::thomas>
102 (Pg(1, 1), Pg(10, 1), 1.0031124506594733, 1.0,
103 1.0030915676477881, 1.0, 0.00000001);
104 test_strategies_lat<bg::strategy::andoyer>
105 (Pg(1, 1), Pg(10, 1), 1.0031124504591062, 1.0,
106 1.0030915676477881, 1.0, 0.00000001);
107 test_strategies_lat<bg::strategy::vincenty>
108 (Pg(1, 1), Pg(10, 1), 1.0031124508942098, 1.0,
109 1.0030915676477881, 1.0, 0.00000001);
110
111 // Meridian and equator
112 test_strategies_lat<bg::strategy::thomas>
113 (Pg(1, 10), Pg(1, -10), 10.0, -10.0, 10.0, -10.0);
114 test_strategies_lat<bg::strategy::thomas>
115 (Pg(1, 0), Pg(10, 0), 0.0, 0.0, 0.0, 0.0);
116
117 // One endpoint in northern hemisphere and the other in southern hemisphere
118 test_strategies_lat<bg::strategy::thomas>
119 (Pg(1, 1), Pg(150, -5), 1.0, -8.1825389632359933, 1.0, -8.0761230625567588);
120 test_strategies_lat<bg::strategy::thomas>
121 (Pg(150, -5), Pg(1, 1), 1.0, -8.1825389632359933, 1.0, -8.0761230625568015);
122 test_strategies_lat<bg::strategy::thomas>
123 (Pg(150, 5), Pg(1, -1), 8.1825389632359933, -1.0, 8.0761230625568015, -1.0);
124 }
125
126
127
128 int test_main( int , char* [] )
129 {
130 test_all<double>();
131
132 return 0;
133 }
134