]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/area/area_geo.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / area / area_geo.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
5
6 // This file was modified by Oracle on 2015, 2016, 2017.
7 // Modifications copyright (c) 2015-2017, Oracle and/or its affiliates.
8 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10
11 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
12 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
13
14 // Use, modification and distribution is subject to the Boost Software License,
15 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
16 // http://www.boost.org/LICENSE_1_0.txt)
17
18 #include <boost/geometry.hpp>
19 #include <geometry_test_common.hpp>
20
21 namespace bg = boost::geometry;
22
23 struct custom_karney
24 {
25 template
26 <
27 typename CT,
28 bool EnableDistance,
29 bool EnableAzimuth,
30 bool EnableReverseAzimuth = false,
31 bool EnableReducedLength = false,
32 bool EnableGeodesicScale = false
33 >
34 struct inverse
35 : bg::formula::detail::karney_inverse
36 <
37 CT, EnableDistance,
38 EnableAzimuth, EnableReverseAzimuth,
39 EnableReducedLength, EnableGeodesicScale,
40 4
41 >
42 {};
43 };
44
45 //Testing geographic strategies
46 template <typename CT>
47 void test_geo_strategies()
48 {
49 std::string poly = "POLYGON((52 0, 41 -74, -23 -43, -26 28, 52 0))";
50
51 typedef bg::model::point<CT, 2, bg::cs::geographic<bg::degree> > pt_geo;
52
53 bg::strategy::area::geographic<> geographic_default;
54
55 bg::strategy::area::geographic<bg::strategy::andoyer, 1>
56 geographic_andoyer1;
57 bg::strategy::area::geographic<bg::strategy::andoyer, 2>
58 geographic_andoyer2;
59 bg::strategy::area::geographic<bg::strategy::andoyer, 3>
60 geographic_andoyer3;
61 bg::strategy::area::geographic<bg::strategy::andoyer, 4>
62 geographic_andoyer4;
63 bg::strategy::area::geographic<bg::strategy::andoyer, 5>
64 geographic_andoyer5;
65
66 bg::strategy::area::geographic<bg::strategy::thomas, 1>
67 geographic_thomas1;
68 bg::strategy::area::geographic<bg::strategy::thomas, 2>
69 geographic_thomas2;
70 bg::strategy::area::geographic<bg::strategy::thomas, 3>
71 geographic_thomas3;
72 bg::strategy::area::geographic<bg::strategy::thomas, 4>
73 geographic_thomas4;
74 bg::strategy::area::geographic<bg::strategy::thomas, 5>
75 geographic_thomas5;
76
77 bg::strategy::area::geographic<bg::strategy::vincenty, 1>
78 geographic_vincenty1;
79 bg::strategy::area::geographic<bg::strategy::vincenty, 2>
80 geographic_vincenty2;
81 bg::strategy::area::geographic<bg::strategy::vincenty, 3>
82 geographic_vincenty3;
83 bg::strategy::area::geographic<bg::strategy::vincenty, 4>
84 geographic_vincenty4;
85 bg::strategy::area::geographic<bg::strategy::vincenty, 5>
86 geographic_vincenty5;
87
88 bg::strategy::area::geographic<bg::strategy::karney, 1>
89 geographic_karney1;
90 bg::strategy::area::geographic<bg::strategy::karney, 2>
91 geographic_karney2;
92 bg::strategy::area::geographic<bg::strategy::karney, 3>
93 geographic_karney3;
94 bg::strategy::area::geographic<bg::strategy::karney, 4>
95 geographic_karney4;
96 bg::strategy::area::geographic<bg::strategy::karney, 5>
97 geographic_karney5;
98
99 bg::strategy::area::geographic<custom_karney, 3>
100 geographic_custom_karney3;
101
102 bg::strategy::area::geographic<bg::strategy::andoyer>
103 geographic_andoyer_default;
104 bg::strategy::area::geographic<bg::strategy::thomas>
105 geographic_thomas_default;
106 bg::strategy::area::geographic<bg::strategy::vincenty>
107 geographic_vincenty_default;
108
109 bg::model::polygon<pt_geo> geometry_geo;
110
111 //GeographicLib 63316536351834.289
112 //PostGIS (v2.2.2) 6.33946+13
113 //MS SQL SERVER 632930207487035
114
115 bg::read_wkt(poly, geometry_geo);
116 CT area;
117 CT err = 0.0000001;
118
119 CT area_default = bg::area(geometry_geo);
120 BOOST_CHECK_CLOSE(area_default, 63316423532570.688, err);
121 area = bg::area(geometry_geo, geographic_default);
122 BOOST_CHECK_CLOSE(area, 63316423532570.688, err);
123
124 CT area_less_accurate = bg::area(geometry_geo, geographic_andoyer1);
125 BOOST_CHECK_CLOSE(area, 63316423532570.688, err);
126 area = bg::area(geometry_geo, geographic_andoyer2);
127 BOOST_CHECK_CLOSE(area, 63316423410597.016, err);
128 area = bg::area(geometry_geo, geographic_andoyer3);
129 BOOST_CHECK_CLOSE(area, 63316423410701.703, err);
130 area = bg::area(geometry_geo, geographic_andoyer4);
131 BOOST_CHECK_CLOSE(area, 63316423410701.602, err);
132 area = bg::area(geometry_geo, geographic_andoyer5);
133 BOOST_CHECK_CLOSE(area, 63316423410701.602, err);
134
135 area = bg::area(geometry_geo, geographic_thomas1);
136 BOOST_CHECK_CLOSE(area, 63316536214315.32, err);
137 area = bg::area(geometry_geo, geographic_thomas2);
138 BOOST_CHECK_CLOSE(area, 63316536092341.266, err);
139 area = bg::area(geometry_geo, geographic_thomas3);
140 BOOST_CHECK_CLOSE(area, 63316536092445.961, err);
141 area = bg::area(geometry_geo, geographic_thomas4);
142 BOOST_CHECK_CLOSE(area, 63316536092445.859, err);
143 area = bg::area(geometry_geo, geographic_thomas5);
144 BOOST_CHECK_CLOSE(area, 63316536092445.859, err);
145
146 area = bg::area(geometry_geo, geographic_vincenty1);
147 BOOST_CHECK_CLOSE(area, 63316536473798.984, err);
148 area = bg::area(geometry_geo, geographic_vincenty2);
149 BOOST_CHECK_CLOSE(area, 63316536351824.93, err);
150 area = bg::area(geometry_geo, geographic_vincenty3);
151 BOOST_CHECK_CLOSE(area, 63316536351929.625, err);
152 area = bg::area(geometry_geo, geographic_vincenty4);
153 BOOST_CHECK_CLOSE(area, 63316536351929.523, err);
154 area = bg::area(geometry_geo, geographic_vincenty5);
155 BOOST_CHECK_CLOSE(area, 63316536351929.523, err);
156
157 area = bg::area(geometry_geo, geographic_karney1);
158 BOOST_CHECK_CLOSE(area, 63316536473703.75, err);
159 area = bg::area(geometry_geo, geographic_karney2);
160 BOOST_CHECK_CLOSE(area, 63316536351729.695, err);
161 area = bg::area(geometry_geo, geographic_karney3);
162 BOOST_CHECK_CLOSE(area, 63316536351834.383, err);
163 area = bg::area(geometry_geo, geographic_custom_karney3);
164 BOOST_CHECK_CLOSE(area, 63316536351834.352, err);
165 area = bg::area(geometry_geo, geographic_karney4);
166 BOOST_CHECK_CLOSE(area, 63316536351834.281, err);
167 CT area_most_accurate = bg::area(geometry_geo, geographic_karney5);
168 BOOST_CHECK_CLOSE(area, 63316536351834.281, err);
169
170 area = bg::area(geometry_geo, geographic_andoyer_default);
171 BOOST_CHECK_CLOSE(area, 63316423532570.688, err);
172 area = bg::area(geometry_geo, geographic_thomas_default);
173 BOOST_CHECK_CLOSE(area, 63316536092341.266, err);
174 area = bg::area(geometry_geo, geographic_vincenty_default);
175 BOOST_CHECK_CLOSE(area, 63316536351929.523, err);
176
177 BOOST_CHECK_CLOSE(area_most_accurate, area_less_accurate, .001);
178 BOOST_CHECK_CLOSE(area_most_accurate, area_default, .001);
179
180 /*
181 // timings and accuracy
182 std::cout.precision(25);
183 std::size_t exp_times = 100000;
184 { clock_t startTime = clock();
185 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer1);
186 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
187 std::cout << area << std::endl;}
188 { clock_t startTime = clock();
189 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer2);
190 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
191 std::cout << area << std::endl;}
192 { clock_t startTime = clock();
193 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer3);
194 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
195 std::cout << area << std::endl;}
196 { clock_t startTime = clock();
197 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer4);
198 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
199 std::cout << area << std::endl;}
200 { clock_t startTime = clock();
201 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_andoyer5);
202 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
203 std::cout << area << std::endl;}
204 { clock_t startTime = clock();
205 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas1);
206 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
207 std::cout << area << std::endl;}
208 { clock_t startTime = clock();
209 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas2);
210 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
211 std::cout << area << std::endl;}
212 { clock_t startTime = clock();
213 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas3);
214 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
215 std::cout << area << std::endl;}
216 { clock_t startTime = clock();
217 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas4);
218 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
219 std::cout << area << std::endl;}
220 { clock_t startTime = clock();
221 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_thomas5);
222 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
223 std::cout << area << std::endl;}
224 { clock_t startTime = clock();
225 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty1);
226 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
227 std::cout << area << std::endl;}
228 { clock_t startTime = clock();
229 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty2);
230 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
231 std::cout << area << std::endl;}
232 { clock_t startTime = clock();
233 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty3);
234 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
235 std::cout << area << std::endl;}
236 { clock_t startTime = clock();
237 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty4);
238 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
239 std::cout << area << std::endl;}
240 { clock_t startTime = clock();
241 for (int j=0; j < exp_times; j++) area = bg::area(geometry_geo, geographic_vincenty5);
242 std::cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " ";
243 std::cout << area << std::endl;}
244 */
245 }
246
247 int test_main(int, char* [])
248 {
249
250 test_geo_strategies<double>();
251
252 return 0;
253 }