GeographicLib  2.1.1
GeodesicExact.cpp
Go to the documentation of this file.
1 /**
2  * \file GeodesicExact.cpp
3  * \brief Implementation for GeographicLib::GeodesicExact class
4  *
5  * Copyright (c) Charles Karney (2012-2022) <charles@karney.com> and licensed
6  * under the MIT/X11 License. For more information, see
7  * https://geographiclib.sourceforge.io/
8  *
9  * This is a reformulation of the geodesic problem. The notation is as
10  * follows:
11  * - at a general point (no suffix or 1 or 2 as suffix)
12  * - phi = latitude
13  * - beta = latitude on auxiliary sphere
14  * - omega = longitude on auxiliary sphere
15  * - lambda = longitude
16  * - alpha = azimuth of great circle
17  * - sigma = arc length along great circle
18  * - s = distance
19  * - tau = scaled distance (= sigma at multiples of pi/2)
20  * - at northwards equator crossing
21  * - beta = phi = 0
22  * - omega = lambda = 0
23  * - alpha = alpha0
24  * - sigma = s = 0
25  * - a 12 suffix means a difference, e.g., s12 = s2 - s1.
26  * - s and c prefixes mean sin and cos
27  **********************************************************************/
28 
31 
32 #if defined(_MSC_VER)
33 // Squelch warnings about potentially uninitialized local variables,
34 // constant conditional and enum-float expressions and mixing enums
35 # pragma warning (disable: 4701 4127 5055 5054)
36 #endif
37 
38 namespace GeographicLib {
39 
40  using namespace std;
41 
43  : maxit2_(maxit1_ + Math::digits() + 10)
44  // Underflow guard. We require
45  // tiny_ * epsilon() > 0
46  // tiny_ + epsilon() == epsilon()
47  , tiny_(sqrt(numeric_limits<real>::min()))
48  , tol0_(numeric_limits<real>::epsilon())
49  // Increase multiplier in defn of tol1_ from 100 to 200 to fix inverse
50  // case 52.784459512564 0 -52.784459512563990912 179.634407464943777557
51  // which otherwise failed for Visual Studio 10 (Release and Debug)
52  , tol1_(200 * tol0_)
53  , tol2_(sqrt(tol0_))
54  , tolb_(tol0_) // Check on bisection interval
55  , xthresh_(1000 * tol2_)
56  , _a(a)
57  , _f(f)
58  , _f1(1 - _f)
59  , _e2(_f * (2 - _f))
60  , _ep2(_e2 / Math::sq(_f1)) // e2 / (1 - e2)
61  , _n(_f / ( 2 - _f))
62  , _b(_a * _f1)
63  // The Geodesic class substitutes atanh(sqrt(e2)) for asinh(sqrt(ep2)) in
64  // the definition of _c2. The latter is more accurate for very oblate
65  // ellipsoids (which the Geodesic class does not attempt to handle).
66  , _c2((Math::sq(_a) + Math::sq(_b) *
67  (_f == 0 ? 1 :
68  (_f > 0 ? asinh(sqrt(_ep2)) : atan(sqrt(-_e2))) /
69  sqrt(fabs(_e2))))/2) // authalic radius squared
70  // The sig12 threshold for "really short". Using the auxiliary sphere
71  // solution with dnm computed at (bet1 + bet2) / 2, the relative error in
72  // the azimuth consistency check is sig12^2 * abs(f) * min(1, 1-f/2) / 2.
73  // (Error measured for 1/100 < b/a < 100 and abs(f) >= 1/1000. For a
74  // given f and sig12, the max error occurs for lines near the pole. If
75  // the old rule for computing dnm = (dn1 + dn2)/2 is used, then the error
76  // increases by a factor of 2.) Setting this equal to epsilon gives
77  // sig12 = etol2. Here 0.1 is a safety factor (error decreased by 100)
78  // and max(0.001, abs(f)) stops etol2 getting too large in the nearly
79  // spherical case.
80  , _etol2(real(0.1) * tol2_ /
81  sqrt( fmax(real(0.001), fabs(_f)) * fmin(real(1), 1 - _f/2) / 2 ))
82  {
83  if (!(isfinite(_a) && _a > 0))
84  throw GeographicErr("Equatorial radius is not positive");
85  if (!(isfinite(_b) && _b > 0))
86  throw GeographicErr("Polar semi-axis is not positive");
87 
88  // Required number of terms in DST for full accuracy for all precisions as
89  // a function of n in [-0.99, 0.99]. Values determined by running
90  // develop/AreaEst compiled with GEOGRAPHICLIB_PRECISION = 5. For
91  // precision 4 and 5, GEOGRAPHICLIB_DIGITS was set to, resp., 384 and 768.
92  // The error criterion is relative error less than or equal to epsilon/2 =
93  // 0.5^digits, with digits = 24, 53, 64, 113, 256. The first 4 are the the
94  // "standard" values for float, double, long double, and float128; the last
95  // is the default for GeographicLib + mpfr. Also listed is the value of
96  // alp0 resulting in the most error for the given N.
97  //
98  // float double long double quad mpfr
99  // n N alp0 N alp0 N alp0 N alp0 N alp0
100  // -0.99 1024 0.09 3072 0.05 4096 0.04 8192 43.50 16384 22.01
101  // -0.98 512 0.18 1536 0.10 2048 0.09 4096 0.06 8192 0.04
102  // -0.97 384 0.25 1024 0.16 1536 0.13 3072 0.09 6144 0.06
103  // -0.96 256 0.36 768 0.21 1024 0.18 2048 0.13 4096 0.09
104  // -0.95 192 0.47 768 0.23 768 0.23 1536 0.17 4096 0.10
105  // -0.94 192 0.51 512 0.31 768 0.26 1536 0.18 3072 0.13
106  // -0.93 192 0.55 384 0.39 512 0.34 1024 0.24 3072 0.14
107  // -0.92 128 0.73 384 0.42 512 0.37 1024 0.26 2048 0.18
108  // -0.91 128 0.77 384 0.45 384 0.45 768 0.32 2048 0.19
109  // -0.90 96 0.94 256 0.58 384 0.47 768 0.34 2048 0.21
110  // -0.89 96 0.99 256 0.61 384 0.50 768 0.35 1536 0.25
111  // -0.88 96 1.04 256 0.64 384 0.52 768 0.37 1536 0.26
112  // -0.87 96 1.09 192 0.77 256 0.67 512 0.47 1536 0.27
113  // -0.86 64 1.38 192 0.80 256 0.69 512 0.49 1536 0.28
114  // -0.85 64 1.43 192 0.83 256 0.72 512 0.51 1024 0.36
115  // -0.84 64 1.49 192 0.86 256 0.75 384 0.61 1024 0.37
116  // -0.83 64 1.54 192 0.89 192 0.89 384 0.63 1024 0.39
117  // -0.82 48 1.82 192 0.92 192 0.92 384 0.65 1024 0.40
118  // -0.81 48 1.88 128 1.16 192 0.95 384 0.67 1024 0.41
119  // -0.80 48 1.94 128 1.19 192 0.97 384 0.69 768 0.49
120  // -0.79 48 1.99 128 1.23 192 1.00 384 0.71 768 0.50
121  // -0.78 48 2.04 128 1.26 192 1.03 384 0.73 768 0.51
122  // -0.77 48 2.10 128 1.29 192 1.05 256 0.91 768 0.53
123  // -0.76 48 2.15 128 1.32 128 1.32 256 0.93 768 0.54
124  // -0.75 48 2.20 96 1.56 128 1.35 256 0.96 768 0.55
125  // -0.74 32 2.74 96 1.60 128 1.38 256 0.98 768 0.57
126  // -0.73 32 2.81 96 1.63 128 1.41 256 1.00 768 0.58
127  // -0.72 32 2.87 96 1.67 128 1.44 256 1.02 512 0.72
128  // -0.71 32 2.93 96 1.70 128 1.47 192 1.20 512 0.74
129  // -0.70 32 2.99 96 1.73 96 1.73 192 1.23 512 0.75
130  // -0.69 32 3.05 96 1.77 96 1.77 192 1.25 512 0.77
131  // -0.68 32 3.11 96 1.80 96 1.80 192 1.28 512 0.78
132  // -0.67 24 3.64 96 1.84 96 1.84 192 1.30 512 0.80
133  // -0.66 24 3.71 96 1.87 96 1.87 192 1.32 512 0.81
134  // -0.65 24 3.77 64 2.33 96 1.90 192 1.35 384 0.95
135  // -0.64 24 3.84 64 2.37 96 1.93 192 1.37 384 0.97
136  // -0.63 24 3.90 64 2.41 96 1.97 192 1.39 384 0.98
137  // -0.62 24 3.97 64 2.45 96 2.00 192 1.42 384 1.00
138  // -0.61 24 4.04 64 2.49 96 2.03 192 1.44 384 1.02
139  // -0.60 24 4.10 64 2.53 96 2.06 192 1.46 384 1.03
140  // -0.59 24 4.16 64 2.57 64 2.57 128 1.82 384 1.05
141  // -0.58 24 4.23 64 2.60 64 2.60 128 1.84 384 1.07
142  // -0.57 24 4.29 48 3.05 64 2.64 128 1.87 384 1.08
143  // -0.56 24 4.36 48 3.10 64 2.68 128 1.90 384 1.10
144  // -0.55 16 5.38 48 3.14 64 2.72 128 1.93 384 1.11
145  // -0.54 16 5.46 48 3.19 64 2.76 128 1.96 384 1.13
146  // -0.53 16 5.54 48 3.23 64 2.80 128 1.98 256 1.40
147  // -0.52 16 5.61 48 3.27 64 2.84 128 2.01 256 1.42
148  // -0.51 16 5.69 48 3.32 64 2.88 128 2.04 256 1.44
149  // -0.50 16 5.77 48 3.36 64 2.92 96 2.38 256 1.46
150  // -0.49 16 5.85 48 3.41 48 3.41 96 2.42 256 1.48
151  // -0.48 16 5.92 48 3.45 48 3.45 96 2.45 256 1.50
152  // -0.47 16 6.00 48 3.50 48 3.50 96 2.48 256 1.52
153  // -0.46 16 6.08 48 3.54 48 3.54 96 2.51 256 1.54
154  // -0.45 12 7.06 48 3.59 48 3.59 96 2.54 256 1.56
155  // -0.44 12 7.15 48 3.63 48 3.63 96 2.57 256 1.58
156  // -0.43 12 7.24 32 4.49 48 3.68 96 2.61 256 1.60
157  // -0.42 12 7.33 32 4.55 48 3.72 96 2.64 192 1.87
158  // -0.41 12 7.42 32 4.60 48 3.77 96 2.67 192 1.89
159  // -0.40 12 7.51 32 4.66 48 3.81 96 2.70 192 1.91
160  // -0.39 12 7.60 32 4.71 48 3.86 96 2.73 192 1.94
161  // -0.38 12 7.69 32 4.77 48 3.90 96 2.77 192 1.96
162  // -0.37 12 7.77 32 4.82 48 3.95 96 2.80 192 1.98
163  // -0.36 12 7.86 32 4.88 48 3.99 96 2.83 192 2.00
164  // -0.35 12 7.95 32 4.94 32 4.94 64 3.50 192 2.03
165  // -0.34 12 8.04 32 4.99 32 4.99 64 3.54 192 2.05
166  // -0.33 12 8.13 24 5.81 32 5.05 64 3.58 192 2.07
167  // -0.32 12 8.22 24 5.88 32 5.10 64 3.62 192 2.10
168  // -0.31 12 8.31 24 5.94 32 5.16 64 3.66 192 2.12
169  // -0.30 8 10.16 24 6.01 32 5.22 64 3.70 192 2.14
170  // -0.29 8 10.27 24 6.07 32 5.27 64 3.74 192 2.17
171  // -0.28 8 10.38 24 6.14 32 5.33 64 3.78 128 2.68
172  // -0.27 8 10.49 24 6.20 32 5.39 64 3.82 128 2.71
173  // -0.26 8 10.60 24 6.27 32 5.45 64 3.87 128 2.74
174  // -0.25 8 10.72 24 6.34 32 5.50 48 4.51 128 2.77
175  // -0.24 8 10.83 24 6.40 24 6.40 48 4.55 128 2.80
176  // -0.23 8 10.94 24 6.47 24 6.47 48 4.60 128 2.83
177  // -0.22 8 11.05 24 6.54 24 6.54 48 4.65 128 2.86
178  // -0.21 6 12.72 24 6.60 24 6.60 48 4.70 128 2.89
179  // -0.20 6 12.85 24 6.67 24 6.67 48 4.75 128 2.92
180  // -0.19 6 12.97 16 8.21 24 6.74 48 4.80 128 2.95
181  // -0.18 6 13.10 16 8.29 24 6.81 48 4.85 96 3.44
182  // -0.17 6 13.23 16 8.37 24 6.88 48 4.89 96 3.47
183  // -0.16 6 13.36 16 8.46 24 6.95 48 4.94 96 3.51
184  // -0.15 6 13.49 16 8.54 24 7.02 48 5.00 96 3.54
185  // -0.14 6 13.62 16 8.62 24 7.09 48 5.05 96 3.58
186  // -0.13 6 13.75 16 8.71 24 7.16 48 5.10 96 3.62
187  // -0.12 6 13.88 16 8.80 16 8.80 32 6.28 96 3.65
188  // -0.11 6 14.01 12 10.19 16 8.88 32 6.35 96 3.69
189  // -0.10 4 16.85 12 10.28 16 8.97 32 6.41 96 3.73
190  // -0.09 4 17.01 12 10.38 16 9.06 32 6.47 96 3.76
191  // -0.08 4 17.17 12 10.48 16 9.14 32 6.54 96 3.80
192  // -0.07 4 17.32 12 10.58 16 9.23 32 6.60 64 4.69
193  // -0.06 4 17.48 12 10.69 12 10.69 24 7.67 64 4.74
194  // -0.05 4 17.64 12 10.79 12 10.79 24 7.75 64 4.79
195  // -0.04 4 17.80 12 10.89 12 10.89 24 7.82 64 4.84
196  // -0.03 4 17.96 8 13.26 12 10.99 24 7.90 48 5.63
197  // -0.02 4 18.11 8 13.38 12 11.10 24 7.97 48 5.68
198  // -0.01 4 18.27 6 15.36 8 13.51 16 9.78 48 5.74
199  // 0.00 4 1.00 4 1.00 4 1.00 4 1.00 4 1.00
200  // 0.01 4 18.57 6 15.62 8 13.75 16 9.96 48 5.85
201  // 0.02 4 18.70 8 13.86 12 11.51 24 8.28 48 5.91
202  // 0.03 4 18.83 8 13.97 12 11.61 24 8.36 48 5.97
203  // 0.04 4 18.96 12 11.71 12 11.71 24 8.44 64 5.23
204  // 0.05 4 19.09 12 11.81 12 11.81 24 8.52 64 5.28
205  // 0.06 4 19.22 12 11.92 12 11.92 24 8.60 64 5.33
206  // 0.07 4 19.36 12 12.02 16 10.52 32 7.55 64 5.39
207  // 0.08 4 19.49 12 12.13 16 10.61 32 7.63 64 5.44
208  // 0.09 4 19.62 12 12.23 16 10.71 32 7.70 96 4.50
209  // 0.10 4 19.76 12 12.34 16 10.80 32 7.77 96 4.54
210  // 0.11 4 19.89 12 12.45 16 10.90 32 7.85 96 4.59
211  // 0.12 6 17.01 16 11.00 16 11.00 32 7.92 96 4.63
212  // 0.13 6 17.14 16 11.10 16 11.10 32 8.00 96 4.68
213  // 0.14 6 17.27 16 11.20 24 9.26 48 6.64 96 4.73
214  // 0.15 6 17.40 16 11.30 24 9.35 48 6.70 96 4.77
215  // 0.16 6 17.53 16 11.40 24 9.44 48 6.77 96 4.82
216  // 0.17 6 17.67 16 11.51 24 9.53 48 6.84 96 4.87
217  // 0.18 6 17.80 16 11.61 24 9.62 48 6.90 96 4.92
218  // 0.19 6 17.94 16 11.72 24 9.71 48 6.97 128 4.31
219  // 0.20 6 18.07 16 11.83 24 9.80 48 7.04 128 4.36
220  // 0.21 6 18.21 24 9.90 24 9.90 48 7.11 128 4.40
221  // 0.22 6 18.35 24 9.99 24 9.99 48 7.18 128 4.45
222  // 0.23 6 18.49 24 10.09 24 10.09 48 7.26 128 4.49
223  // 0.24 6 18.63 24 10.19 24 10.19 48 7.33 128 4.54
224  // 0.25 6 18.77 24 10.28 24 10.28 48 7.41 128 4.59
225  // 0.26 6 18.92 24 10.39 24 10.39 48 7.48 128 4.64
226  // 0.27 8 17.00 24 10.49 32 9.17 64 6.58 128 4.69
227  // 0.28 8 17.14 24 10.59 32 9.26 64 6.65 128 4.74
228  // 0.29 8 17.28 24 10.69 32 9.35 64 6.72 192 3.92
229  // 0.30 8 17.43 24 10.80 32 9.45 64 6.79 192 3.96
230  // 0.31 8 17.57 24 10.91 32 9.54 64 6.86 192 4.01
231  // 0.32 8 17.72 24 11.02 32 9.64 64 6.93 192 4.05
232  // 0.33 8 17.87 24 11.13 32 9.74 64 7.01 192 4.09
233  // 0.34 8 18.02 24 11.24 32 9.84 64 7.08 192 4.14
234  // 0.35 8 18.17 24 11.36 32 9.95 64 7.16 192 4.19
235  // 0.36 8 18.32 24 11.47 32 10.05 64 7.24 192 4.23
236  // 0.37 8 18.48 32 10.16 32 10.16 64 7.32 192 4.28
237  // 0.38 8 18.63 32 10.27 32 10.27 96 6.08 192 4.33
238  // 0.39 8 18.79 32 10.38 48 8.58 96 6.15 192 4.38
239  // 0.40 8 18.95 32 10.49 48 8.68 96 6.22 192 4.43
240  // 0.41 8 19.11 32 10.60 48 8.78 96 6.30 192 4.49
241  // 0.42 12 16.45 32 10.72 48 8.88 96 6.37 192 4.54
242  // 0.43 12 16.61 32 10.84 48 8.98 96 6.45 192 4.59
243  // 0.44 12 16.77 32 10.96 48 9.08 96 6.52 256 4.04
244  // 0.45 12 16.93 32 11.09 48 9.19 96 6.60 256 4.09
245  // 0.46 12 17.10 32 11.21 48 9.30 96 6.68 256 4.14
246  // 0.47 12 17.26 32 11.34 48 9.41 96 6.77 256 4.19
247  // 0.48 12 17.44 32 11.47 48 9.52 96 6.85 256 4.24
248  // 0.49 12 17.61 48 9.64 48 9.64 96 6.94 256 4.30
249  // 0.50 12 17.79 48 9.76 48 9.76 96 7.03 256 4.35
250  // 0.51 12 17.97 48 9.88 48 9.88 96 7.12 256 4.41
251  // 0.52 12 18.15 48 10.00 48 10.00 96 7.21 256 4.47
252  // 0.53 12 18.34 48 10.13 48 10.13 128 6.36 256 4.53
253  // 0.54 12 18.53 48 10.26 48 10.26 128 6.45 256 4.59
254  // 0.55 12 18.72 48 10.40 64 9.10 128 6.53 384 3.82
255  // 0.56 12 18.92 48 10.53 64 9.22 128 6.63 384 3.87
256  // 0.57 12 19.12 48 10.68 64 9.35 128 6.72 384 3.93
257  // 0.58 12 19.33 48 10.82 64 9.48 128 6.82 384 3.98
258  // 0.59 12 19.54 48 10.97 64 9.61 128 6.92 384 4.05
259  // 0.60 12 19.75 48 11.13 64 9.75 128 7.02 384 4.11
260  // 0.61 12 19.97 48 11.28 64 9.89 128 7.13 384 4.17
261  // 0.62 12 20.20 48 11.45 64 10.04 128 7.24 384 4.24
262  // 0.63 16 18.39 48 11.62 64 10.19 192 6.05 384 4.31
263  // 0.64 16 18.62 64 10.35 64 10.35 192 6.15 384 4.38
264  // 0.65 16 18.86 64 10.51 96 8.71 192 6.25 384 4.45
265  // 0.66 16 19.10 64 10.68 96 8.85 192 6.36 384 4.53
266  // 0.67 16 19.35 64 10.86 96 9.00 192 6.47 512 4.00
267  // 0.68 16 19.60 64 11.04 96 9.16 192 6.58 512 4.08
268  // 0.69 16 19.87 64 11.23 96 9.32 192 6.70 512 4.15
269  // 0.70 16 20.14 64 11.43 96 9.49 192 6.83 512 4.23
270  // 0.71 16 20.42 64 11.63 96 9.67 192 6.96 512 4.32
271  // 0.72 16 20.71 64 11.85 96 9.85 192 7.10 512 4.40
272  // 0.73 16 21.01 96 10.04 96 10.04 192 7.25 512 4.50
273  // 0.74 16 21.32 96 10.25 96 10.25 256 6.44 768 3.76
274  // 0.75 16 21.65 96 10.46 96 10.46 256 6.58 768 3.84
275  // 0.76 16 21.99 96 10.68 128 9.36 256 6.73 768 3.93
276  // 0.77 24 19.41 96 10.92 128 9.57 256 6.89 768 4.03
277  // 0.78 24 19.76 96 11.17 128 9.79 256 7.06 768 4.13
278  // 0.79 24 20.13 96 11.44 128 10.03 256 7.24 768 4.24
279  // 0.80 24 20.51 96 11.72 128 10.29 384 6.11 768 4.35
280  // 0.81 24 20.92 96 12.02 128 10.56 384 6.28 768 4.48
281  // 0.82 24 21.35 96 12.34 192 8.99 384 6.46 1024 4.00
282  // 0.83 24 21.81 128 11.16 192 9.26 384 6.66 1024 4.13
283  // 0.84 24 22.29 128 11.50 192 9.55 384 6.88 1024 4.26
284  // 0.85 24 22.82 128 11.86 192 9.87 384 7.11 1024 4.41
285  // 0.86 24 23.38 128 12.26 192 10.21 384 7.37 1024 4.58
286  // 0.87 24 24.00 128 12.70 192 10.59 512 6.67 1536 3.90
287  // 0.88 24 24.67 192 11.01 192 11.01 512 6.95 1536 4.06
288  // 0.89 24 25.41 192 11.48 256 10.07 512 7.26 1536 4.25
289  // 0.90 24 26.24 192 12.00 256 10.54 768 6.27 1536 4.47
290  // 0.91 24 27.17 192 12.61 256 11.09 768 6.62 2048 4.10
291  // 0.92 24 28.23 192 13.30 384 9.74 768 7.02 2048 4.35
292  // 0.93 24 29.45 256 12.46 384 10.38 768 7.50 3072 3.82
293  // 0.94 24 30.86 256 13.36 384 11.16 1024 7.05 3072 4.13
294  // 0.95 24 32.53 384 12.14 512 10.67 1024 7.72 3072 4.53
295  // 0.96 24 34.51 384 13.42 512 11.83 1536 7.09 4096 4.40
296  // 0.97 24 36.88 512 13.45 768 11.24 2048 7.11 6144 4.16
297  // 0.98 16 41.78 768 13.48 1024 11.88 3072 7.12 8192 4.42
298  // 0.99 8 44.82 1024 16.00 1536 13.51 6144 7.14 16384 4.43
299  static const int ndiv = 100;
300  // Encode N as small integer: 2,3,4,6,8,12... -> 0,1,2,3,4,5...
301  // using this awk script
302  //
303  // {
304  // n = $1;
305  // if (n % 3 == 0) {
306  // s = 1;
307  // n = n/3;
308  // } else {
309  // s = 0;
310  // n = n/2;
311  // }
312  // p = int( log(n)/log(2)+0.5 );
313  // printf "%d\n", 2*p+s;
314  // }
315  //
316  // A couple of changes have been made: (1) the decrease in N for float and
317  // n > 0.97 has been removed; (2) entrys of n=+/-1 have been included
318  // (incrementing the previous code value by 1).
319 #if GEOGRAPHICLIB_PRECISION == 1
320  static const unsigned char narr[2*ndiv+1] = {
321  19,18,16,15,14,13,13,13,12,12,11,11,11,11,10,10,10,10,9,9,9,9,9,9,9,9,8,
322  8,8,8,8,8,8,7,7,7,7,7,7,7,7,7,7,7,7,6,6,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,
323  5,5,5,5,5,5,5,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,
324  2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,
325  4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,
326  6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8
327  };
328 #elif GEOGRAPHICLIB_PRECISION == 2
329  static const unsigned char narr[2*ndiv+1] = {
330  22,21,19,18,17,17,16,15,15,15,14,14,14,13,13,13,13,13,13,12,12,12,12,12,
331  12,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,9,9,9,9,9,9,9,9,
332  9,9,9,9,9,9,8,8,8,8,8,8,8,8,8,8,7,7,7,7,7,7,7,7,7,7,7,7,7,7,6,6,6,6,6,6,
333  6,6,5,5,5,5,5,5,5,5,4,4,3,2,3,4,4,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,7,7,
334  7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,
335  9,9,9,9,9,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,12,12,
336  12,12,12,13,13,13,13,13,14,14,15,15,16,17,18,19
337  };
338 #elif GEOGRAPHICLIB_PRECISION == 3
339  static const unsigned char narr[2*ndiv+1] = {
340  23,22,20,19,18,17,17,16,16,15,15,15,15,14,14,14,14,13,13,13,13,13,13,13,
341  12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
342  10,10,10,9,9,9,9,9,9,9,9,9,9,9,9,9,9,8,8,8,8,8,8,8,8,8,8,8,7,7,7,7,7,7,7,
343  7,7,7,7,7,6,6,6,6,6,6,5,5,5,5,5,4,2,4,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,
344  7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
345  10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,12,12,12,
346  12,12,12,13,13,13,13,13,13,13,14,14,14,15,15,15,16,16,17,18,19,20
347  };
348 #elif GEOGRAPHICLIB_PRECISION == 4
349  static const unsigned char narr[2*ndiv+1] = {
350  25,24,22,21,20,19,19,18,18,17,17,17,17,16,16,16,15,15,15,15,15,15,15,14,
351  14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
352  12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
353  10,10,10,9,9,9,9,9,9,9,9,9,9,9,9,9,8,8,8,8,8,8,7,7,7,7,7,6,2,6,7,7,7,7,7,
354  8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,
355  11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
356  12,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,15,15,15,15,15,15,
357  15,16,16,16,17,17,17,17,18,18,19,20,21,23,24
358  };
359 #elif GEOGRAPHICLIB_PRECISION == 5
360  static const unsigned char narr[2*ndiv+1] = {
361  27,26,24,23,22,22,21,21,20,20,20,19,19,19,19,18,18,18,18,18,17,17,17,17,
362  17,17,17,17,16,16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,14,
363  14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
364  12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,10,10,10,
365  10,9,9,9,2,9,9,9,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,12,12,12,
366  12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,
367  14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,
368  16,16,16,16,17,17,17,17,17,17,17,17,18,18,18,18,18,19,19,19,19,20,20,21,
369  21,21,22,23,24,26,27
370  };
371 #else
372 #error "Bad value for GEOGRAPHICLIB_PRECISION"
373 #endif
374  real n = ndiv * _n; // n in [-ndiv, ndiv]
375  int j = ndiv + int(n < 0 ? floor(n) : ceil(n)); // j in [0, 2*ndiv]
376  int N = int(narr[j]);
377  // Decode 0,1,2,3,4,5... -> 2,3,4,6,8,12...
378  N = (N % 2 == 0 ? 2 : 3) * (1 << (N/2));
379 #if GEOGRAPHICLIB_PRECISION == 5
380  if (Math::digits() > 256) {
381  // Scale up N by the number of digits in the precision relative to
382  // the number used for the test = 256.
383  int M = (Math::digits() * N) / 256;
384  while (N < M) N = N % 3 == 0 ? 4*N/3 : 3*N/2;
385  }
386 #endif
387  _fft.reset(N);
388  _nC4 = N;
389  }
390 
392  static const GeodesicExact wgs84(Constants::WGS84_a(),
394  return wgs84;
395  }
396 
397  GeodesicLineExact GeodesicExact::Line(real lat1, real lon1, real azi1,
398  unsigned caps) const {
399  return GeodesicLineExact(*this, lat1, lon1, azi1, caps);
400  }
401 
402  Math::real GeodesicExact::GenDirect(real lat1, real lon1, real azi1,
403  bool arcmode, real s12_a12,
404  unsigned outmask,
405  real& lat2, real& lon2, real& azi2,
406  real& s12, real& m12,
407  real& M12, real& M21,
408  real& S12) const {
409  // Automatically supply DISTANCE_IN if necessary
410  if (!arcmode) outmask |= DISTANCE_IN;
411  return GeodesicLineExact(*this, lat1, lon1, azi1, outmask)
412  . // Note the dot!
413  GenPosition(arcmode, s12_a12, outmask,
414  lat2, lon2, azi2, s12, m12, M12, M21, S12);
415  }
416 
418  real azi1,
419  bool arcmode, real s12_a12,
420  unsigned caps) const {
421  azi1 = Math::AngNormalize(azi1);
422  real salp1, calp1;
423  // Guard against underflow in salp0. Also -0 is converted to +0.
424  Math::sincosd(Math::AngRound(azi1), salp1, calp1);
425  // Automatically supply DISTANCE_IN if necessary
426  if (!arcmode) caps |= DISTANCE_IN;
427  return GeodesicLineExact(*this, lat1, lon1, azi1, salp1, calp1,
428  caps, arcmode, s12_a12);
429  }
430 
432  real azi1, real s12,
433  unsigned caps) const {
434  return GenDirectLine(lat1, lon1, azi1, false, s12, caps);
435  }
436 
438  real azi1, real a12,
439  unsigned caps) const {
440  return GenDirectLine(lat1, lon1, azi1, true, a12, caps);
441  }
442 
443  Math::real GeodesicExact::GenInverse(real lat1, real lon1,
444  real lat2, real lon2,
445  unsigned outmask, real& s12,
446  real& salp1, real& calp1,
447  real& salp2, real& calp2,
448  real& m12, real& M12, real& M21,
449  real& S12) const {
450  // Compute longitude difference (AngDiff does this carefully). Result is
451  // in [-180, 180] but -180 is only for west-going geodesics. 180 is for
452  // east-going and meridional geodesics.
453  using std::isnan; // Needed for Centos 7, ubuntu 14
454  real lon12s, lon12 = Math::AngDiff(lon1, lon2, lon12s);
455  // Make longitude difference positive.
456  int lonsign = signbit(lon12) ? -1 : 1;
457  lon12 *= lonsign; lon12s *= lonsign;
458  real
459  lam12 = lon12 * Math::degree(),
460  slam12, clam12;
461  // Calculate sincos of lon12 + error (this applies AngRound internally).
462  Math::sincosde(lon12, lon12s, slam12, clam12);
463  // the supplementary longitude difference
464  lon12s = (Math::hd - lon12) - lon12s;
465 
466  // If really close to the equator, treat as on equator.
467  lat1 = Math::AngRound(Math::LatFix(lat1));
468  lat2 = Math::AngRound(Math::LatFix(lat2));
469  // Swap points so that point with higher (abs) latitude is point 1
470  // If one latitude is a nan, then it becomes lat1.
471  int swapp = fabs(lat1) < fabs(lat2) || isnan(lat2) ? -1 : 1;
472  if (swapp < 0) {
473  lonsign *= -1;
474  swap(lat1, lat2);
475  }
476  // Make lat1 <= -0
477  int latsign = signbit(lat1) ? 1 : -1;
478  lat1 *= latsign;
479  lat2 *= latsign;
480  // Now we have
481  //
482  // 0 <= lon12 <= 180
483  // -90 <= lat1 <= -0
484  // lat1 <= lat2 <= -lat1
485  //
486  // longsign, swapp, latsign register the transformation to bring the
487  // coordinates to this canonical form. In all cases, 1 means no change was
488  // made. We make these transformations so that there are few cases to
489  // check, e.g., on verifying quadrants in atan2. In addition, this
490  // enforces some symmetries in the results returned.
491 
492  real sbet1, cbet1, sbet2, cbet2, s12x, m12x;
493  // Initialize for the meridian. No longitude calculation is done in this
494  // case to let the parameter default to 0.
495  EllipticFunction E(-_ep2);
496 
497  Math::sincosd(lat1, sbet1, cbet1); sbet1 *= _f1;
498  // Ensure cbet1 = +epsilon at poles; doing the fix on beta means that sig12
499  // will be <= 2*tiny for two points at the same pole.
500  Math::norm(sbet1, cbet1); cbet1 = fmax(tiny_, cbet1);
501 
502  Math::sincosd(lat2, sbet2, cbet2); sbet2 *= _f1;
503  // Ensure cbet2 = +epsilon at poles
504  Math::norm(sbet2, cbet2); cbet2 = fmax(tiny_, cbet2);
505 
506  // If cbet1 < -sbet1, then cbet2 - cbet1 is a sensitive measure of the
507  // |bet1| - |bet2|. Alternatively (cbet1 >= -sbet1), abs(sbet2) + sbet1 is
508  // a better measure. This logic is used in assigning calp2 in Lambda12.
509  // Sometimes these quantities vanish and in that case we force bet2 = +/-
510  // bet1 exactly. An example where is is necessary is the inverse problem
511  // 48.522876735459 0 -48.52287673545898293 179.599720456223079643
512  // which failed with Visual Studio 10 (Release and Debug)
513 
514  if (cbet1 < -sbet1) {
515  if (cbet2 == cbet1)
516  sbet2 = copysign(sbet1, sbet2);
517  } else {
518  if (fabs(sbet2) == -sbet1)
519  cbet2 = cbet1;
520  }
521 
522  real
523  dn1 = (_f >= 0 ? sqrt(1 + _ep2 * Math::sq(sbet1)) :
524  sqrt(1 - _e2 * Math::sq(cbet1)) / _f1),
525  dn2 = (_f >= 0 ? sqrt(1 + _ep2 * Math::sq(sbet2)) :
526  sqrt(1 - _e2 * Math::sq(cbet2)) / _f1);
527 
528  real a12, sig12;
529 
530  bool meridian = lat1 == -Math::qd || slam12 == 0;
531 
532  if (meridian) {
533 
534  // Endpoints are on a single full meridian, so the geodesic might lie on
535  // a meridian.
536 
537  calp1 = clam12; salp1 = slam12; // Head to the target longitude
538  calp2 = 1; salp2 = 0; // At the target we're heading north
539 
540  real
541  // tan(bet) = tan(sig) * cos(alp)
542  ssig1 = sbet1, csig1 = calp1 * cbet1,
543  ssig2 = sbet2, csig2 = calp2 * cbet2;
544 
545  // sig12 = sig2 - sig1
546  sig12 = atan2(fmax(real(0), csig1 * ssig2 - ssig1 * csig2),
547  csig1 * csig2 + ssig1 * ssig2);
548  {
549  real dummy;
550  Lengths(E, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2,
551  cbet1, cbet2, outmask | REDUCEDLENGTH,
552  s12x, m12x, dummy, M12, M21);
553  }
554  // Add the check for sig12 since zero length geodesics might yield m12 <
555  // 0. Test case was
556  //
557  // echo 20.001 0 20.001 0 | GeodSolve -i
558  //
559  // In fact, we will have sig12 > pi/2 for meridional geodesic which is
560  // not a shortest path.
561  if (sig12 < 1 || m12x >= 0) {
562  // Need at least 2, to handle 90 0 90 180
563  if (sig12 < 3 * tiny_ ||
564  // Prevent negative s12 or m12 for short lines
565  (sig12 < tol0_ && (s12x < 0 || m12x < 0)))
566  sig12 = m12x = s12x = 0;
567  m12x *= _b;
568  s12x *= _b;
569  a12 = sig12 / Math::degree();
570  } else
571  // m12 < 0, i.e., prolate and too close to anti-podal
572  meridian = false;
573  }
574 
575  // somg12 == 2 marks that it needs to be calculated
576  real omg12 = 0, somg12 = 2, comg12 = 0;
577  if (!meridian &&
578  sbet1 == 0 && // and sbet2 == 0
579  (_f <= 0 || lon12s >= _f * Math::hd)) {
580 
581  // Geodesic runs along equator
582  calp1 = calp2 = 0; salp1 = salp2 = 1;
583  s12x = _a * lam12;
584  sig12 = omg12 = lam12 / _f1;
585  m12x = _b * sin(sig12);
586  if (outmask & GEODESICSCALE)
587  M12 = M21 = cos(sig12);
588  a12 = lon12 / _f1;
589 
590  } else if (!meridian) {
591 
592  // Now point1 and point2 belong within a hemisphere bounded by a
593  // meridian and geodesic is neither meridional or equatorial.
594 
595  // Figure a starting point for Newton's method
596  real dnm;
597  sig12 = InverseStart(E, sbet1, cbet1, dn1, sbet2, cbet2, dn2,
598  lam12, slam12, clam12,
599  salp1, calp1, salp2, calp2, dnm);
600 
601  if (sig12 >= 0) {
602  // Short lines (InverseStart sets salp2, calp2, dnm)
603  s12x = sig12 * _b * dnm;
604  m12x = Math::sq(dnm) * _b * sin(sig12 / dnm);
605  if (outmask & GEODESICSCALE)
606  M12 = M21 = cos(sig12 / dnm);
607  a12 = sig12 / Math::degree();
608  omg12 = lam12 / (_f1 * dnm);
609  } else {
610 
611  // Newton's method. This is a straightforward solution of f(alp1) =
612  // lambda12(alp1) - lam12 = 0 with one wrinkle. f(alp) has exactly one
613  // root in the interval (0, pi) and its derivative is positive at the
614  // root. Thus f(alp) is positive for alp > alp1 and negative for alp <
615  // alp1. During the course of the iteration, a range (alp1a, alp1b) is
616  // maintained which brackets the root and with each evaluation of
617  // f(alp) the range is shrunk, if possible. Newton's method is
618  // restarted whenever the derivative of f is negative (because the new
619  // value of alp1 is then further from the solution) or if the new
620  // estimate of alp1 lies outside (0,pi); in this case, the new starting
621  // guess is taken to be (alp1a + alp1b) / 2.
622  //
623  // initial values to suppress warnings (if loop is executed 0 times)
624  real ssig1 = 0, csig1 = 0, ssig2 = 0, csig2 = 0, domg12 = 0;
625  unsigned numit = 0;
626  // Bracketing range
627  real salp1a = tiny_, calp1a = 1, salp1b = tiny_, calp1b = -1;
628  for (bool tripn = false, tripb = false;; ++numit) {
629  // 1/4 meridian = 10e6 m and random input. max err is estimated max
630  // error in nm (checking solution of inverse problem by direct
631  // solution). iter is mean and sd of number of iterations
632  //
633  // max iter
634  // log2(b/a) err mean sd
635  // -7 387 5.33 3.68
636  // -6 345 5.19 3.43
637  // -5 269 5.00 3.05
638  // -4 210 4.76 2.44
639  // -3 115 4.55 1.87
640  // -2 69 4.35 1.38
641  // -1 36 4.05 1.03
642  // 0 15 0.01 0.13
643  // 1 25 5.10 1.53
644  // 2 96 5.61 2.09
645  // 3 318 6.02 2.74
646  // 4 985 6.24 3.22
647  // 5 2352 6.32 3.44
648  // 6 6008 6.30 3.45
649  // 7 19024 6.19 3.30
650  real dv;
651  real v = Lambda12(sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1,
652  slam12, clam12,
653  salp2, calp2, sig12, ssig1, csig1, ssig2, csig2,
654  E, domg12, numit < maxit1_, dv);
655  if (tripb ||
656  // Reversed test to allow escape with NaNs
657  !(fabs(v) >= (tripn ? 8 : 1) * tol0_) ||
658  // Enough bisections to get accurate result
659  numit == maxit2_)
660  break;
661  // Update bracketing values
662  if (v > 0 && (numit > maxit1_ || calp1/salp1 > calp1b/salp1b))
663  { salp1b = salp1; calp1b = calp1; }
664  else if (v < 0 && (numit > maxit1_ || calp1/salp1 < calp1a/salp1a))
665  { salp1a = salp1; calp1a = calp1; }
666  if (numit < maxit1_ && dv > 0) {
667  real
668  dalp1 = -v/dv;
669  // |dalp1| < pi test moved earlier because GEOGRAPHICLIB_PRECISION
670  // = 5 can result in dalp1 = 10^(10^8). Then sin(dalp1) takes ages
671  // (because of the need to do accurate range reduction).
672  if (fabs(dalp1) < Math::pi()) {
673  real
674  sdalp1 = sin(dalp1), cdalp1 = cos(dalp1),
675  nsalp1 = salp1 * cdalp1 + calp1 * sdalp1;
676  if (nsalp1 > 0) {
677  calp1 = calp1 * cdalp1 - salp1 * sdalp1;
678  salp1 = nsalp1;
679  Math::norm(salp1, calp1);
680  // In some regimes we don't get quadratic convergence because
681  // slope -> 0. So use convergence conditions based on epsilon
682  // instead of sqrt(epsilon).
683  tripn = fabs(v) <= 16 * tol0_;
684  continue;
685  }
686  }
687  }
688  // Either dv was not positive or updated value was outside legal
689  // range. Use the midpoint of the bracket as the next estimate.
690  // This mechanism is not needed for the WGS84 ellipsoid, but it does
691  // catch problems with more eccentric ellipsoids. Its efficacy is
692  // such for the WGS84 test set with the starting guess set to alp1 =
693  // 90deg:
694  // the WGS84 test set: mean = 5.21, sd = 3.93, max = 24
695  // WGS84 and random input: mean = 4.74, sd = 0.99
696  salp1 = (salp1a + salp1b)/2;
697  calp1 = (calp1a + calp1b)/2;
698  Math::norm(salp1, calp1);
699  tripn = false;
700  tripb = (fabs(salp1a - salp1) + (calp1a - calp1) < tolb_ ||
701  fabs(salp1 - salp1b) + (calp1 - calp1b) < tolb_);
702  }
703  {
704  real dummy;
705  Lengths(E, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2,
706  cbet1, cbet2, outmask, s12x, m12x, dummy, M12, M21);
707  }
708  m12x *= _b;
709  s12x *= _b;
710  a12 = sig12 / Math::degree();
711  if (outmask & AREA) {
712  // omg12 = lam12 - domg12
713  real sdomg12 = sin(domg12), cdomg12 = cos(domg12);
714  somg12 = slam12 * cdomg12 - clam12 * sdomg12;
715  comg12 = clam12 * cdomg12 + slam12 * sdomg12;
716  }
717  }
718  }
719 
720  if (outmask & DISTANCE)
721  s12 = real(0) + s12x; // Convert -0 to 0
722 
723  if (outmask & REDUCEDLENGTH)
724  m12 = real(0) + m12x; // Convert -0 to 0
725 
726  if (outmask & AREA) {
727  real
728  // From Lambda12: sin(alp1) * cos(bet1) = sin(alp0)
729  salp0 = salp1 * cbet1,
730  calp0 = hypot(calp1, salp1 * sbet1); // calp0 > 0
731  real alp12,
732  // Multiplier = a^2 * e^2 * cos(alpha0) * sin(alpha0).
733  A4 = Math::sq(_a) * calp0 * salp0 * _e2;
734  if (A4 != 0) {
735  real
736  k2 = Math::sq(calp0) * _ep2,
737  // From Lambda12: tan(bet) = tan(sig) * cos(alp)
738  ssig1 = sbet1, csig1 = calp1 * cbet1,
739  ssig2 = sbet2, csig2 = calp2 * cbet2;
740  Math::norm(ssig1, csig1);
741  Math::norm(ssig2, csig2);
742  I4Integrand i4(_ep2, k2);
743  vector<real> C4a(_nC4);
744  _fft.transform(i4, C4a.data());
745  real
746  B41 = DST::integral(ssig1, csig1, C4a.data(), _nC4),
747  B42 = DST::integral(ssig2, csig2, C4a.data(), _nC4);
748  S12 = A4 * (B42 - B41);
749  } else
750  // Avoid problems with indeterminate sig1, sig2 on equator
751  S12 = 0;
752 
753  if (!meridian && somg12 == 2) {
754  somg12 = sin(omg12); comg12 = cos(omg12);
755  }
756 
757  if (!meridian &&
758  // omg12 < 3/4 * pi
759  comg12 > -real(0.7071) && // Long difference not too big
760  sbet2 - sbet1 < real(1.75)) { // Lat difference not too big
761  // Use tan(Gamma/2) = tan(omg12/2)
762  // * (tan(bet1/2)+tan(bet2/2))/(1+tan(bet1/2)*tan(bet2/2))
763  // with tan(x/2) = sin(x)/(1+cos(x))
764  real domg12 = 1 + comg12, dbet1 = 1 + cbet1, dbet2 = 1 + cbet2;
765  alp12 = 2 * atan2( somg12 * ( sbet1 * dbet2 + sbet2 * dbet1 ),
766  domg12 * ( sbet1 * sbet2 + dbet1 * dbet2 ) );
767  } else {
768  // alp12 = alp2 - alp1, used in atan2 so no need to normalize
769  real
770  salp12 = salp2 * calp1 - calp2 * salp1,
771  calp12 = calp2 * calp1 + salp2 * salp1;
772  // The right thing appears to happen if alp1 = +/-180 and alp2 = 0, viz
773  // salp12 = -0 and alp12 = -180. However this depends on the sign
774  // being attached to 0 correctly. The following ensures the correct
775  // behavior.
776  if (salp12 == 0 && calp12 < 0) {
777  salp12 = tiny_ * calp1;
778  calp12 = -1;
779  }
780  alp12 = atan2(salp12, calp12);
781  }
782  S12 += _c2 * alp12;
783  S12 *= swapp * lonsign * latsign;
784  // Convert -0 to 0
785  S12 += 0;
786  }
787 
788  // Convert calp, salp to azimuth accounting for lonsign, swapp, latsign.
789  if (swapp < 0) {
790  swap(salp1, salp2);
791  swap(calp1, calp2);
792  if (outmask & GEODESICSCALE)
793  swap(M12, M21);
794  }
795 
796  salp1 *= swapp * lonsign; calp1 *= swapp * latsign;
797  salp2 *= swapp * lonsign; calp2 *= swapp * latsign;
798 
799  // Returned value in [0, 180]
800  return a12;
801  }
802 
803  Math::real GeodesicExact::GenInverse(real lat1, real lon1,
804  real lat2, real lon2,
805  unsigned outmask,
806  real& s12, real& azi1, real& azi2,
807  real& m12, real& M12, real& M21,
808  real& S12) const {
809  outmask &= OUT_MASK;
810  real salp1, calp1, salp2, calp2,
811  a12 = GenInverse(lat1, lon1, lat2, lon2,
812  outmask, s12, salp1, calp1, salp2, calp2,
813  m12, M12, M21, S12);
814  if (outmask & AZIMUTH) {
815  azi1 = Math::atan2d(salp1, calp1);
816  azi2 = Math::atan2d(salp2, calp2);
817  }
818  return a12;
819  }
820 
822  real lat2, real lon2,
823  unsigned caps) const {
824  real t, salp1, calp1, salp2, calp2,
825  a12 = GenInverse(lat1, lon1, lat2, lon2,
826  // No need to specify AZIMUTH here
827  0u, t, salp1, calp1, salp2, calp2,
828  t, t, t, t),
829  azi1 = Math::atan2d(salp1, calp1);
830  // Ensure that a12 can be converted to a distance
831  if (caps & (OUT_MASK & DISTANCE_IN)) caps |= DISTANCE;
832  return GeodesicLineExact(*this, lat1, lon1, azi1, salp1, calp1, caps,
833  true, a12);
834  }
835 
836  void GeodesicExact::Lengths(const EllipticFunction& E,
837  real sig12,
838  real ssig1, real csig1, real dn1,
839  real ssig2, real csig2, real dn2,
840  real cbet1, real cbet2, unsigned outmask,
841  real& s12b, real& m12b, real& m0,
842  real& M12, real& M21) const {
843  // Return m12b = (reduced length)/_b; also calculate s12b = distance/_b,
844  // and m0 = coefficient of secular term in expression for reduced length.
845 
846  outmask &= OUT_ALL;
847  // outmask & DISTANCE: set s12b
848  // outmask & REDUCEDLENGTH: set m12b & m0
849  // outmask & GEODESICSCALE: set M12 & M21
850 
851  // It's OK to have repeated dummy arguments,
852  // e.g., s12b = m0 = M12 = M21 = dummy
853 
854  if (outmask & DISTANCE)
855  // Missing a factor of _b
856  s12b = E.E() / (Math::pi() / 2) *
857  (sig12 + (E.deltaE(ssig2, csig2, dn2) - E.deltaE(ssig1, csig1, dn1)));
858  if (outmask & (REDUCEDLENGTH | GEODESICSCALE)) {
859  real
860  m0x = - E.k2() * E.D() / (Math::pi() / 2),
861  J12 = m0x *
862  (sig12 + (E.deltaD(ssig2, csig2, dn2) - E.deltaD(ssig1, csig1, dn1)));
863  if (outmask & REDUCEDLENGTH) {
864  m0 = m0x;
865  // Missing a factor of _b. Add parens around (csig1 * ssig2) and
866  // (ssig1 * csig2) to ensure accurate cancellation in the case of
867  // coincident points.
868  m12b = dn2 * (csig1 * ssig2) - dn1 * (ssig1 * csig2) -
869  csig1 * csig2 * J12;
870  }
871  if (outmask & GEODESICSCALE) {
872  real csig12 = csig1 * csig2 + ssig1 * ssig2;
873  real t = _ep2 * (cbet1 - cbet2) * (cbet1 + cbet2) / (dn1 + dn2);
874  M12 = csig12 + (t * ssig2 - csig2 * J12) * ssig1 / dn1;
875  M21 = csig12 - (t * ssig1 - csig1 * J12) * ssig2 / dn2;
876  }
877  }
878  }
879 
880  Math::real GeodesicExact::Astroid(real x, real y) {
881  // Solve k^4+2*k^3-(x^2+y^2-1)*k^2-2*y^2*k-y^2 = 0 for positive root k.
882  // This solution is adapted from Geocentric::Reverse.
883  real k;
884  real
885  p = Math::sq(x),
886  q = Math::sq(y),
887  r = (p + q - 1) / 6;
888  if ( !(q == 0 && r <= 0) ) {
889  real
890  // Avoid possible division by zero when r = 0 by multiplying equations
891  // for s and t by r^3 and r, resp.
892  S = p * q / 4, // S = r^3 * s
893  r2 = Math::sq(r),
894  r3 = r * r2,
895  // The discriminant of the quadratic equation for T3. This is zero on
896  // the evolute curve p^(1/3)+q^(1/3) = 1
897  disc = S * (S + 2 * r3);
898  real u = r;
899  if (disc >= 0) {
900  real T3 = S + r3;
901  // Pick the sign on the sqrt to maximize abs(T3). This minimizes loss
902  // of precision due to cancellation. The result is unchanged because
903  // of the way the T is used in definition of u.
904  T3 += T3 < 0 ? -sqrt(disc) : sqrt(disc); // T3 = (r * t)^3
905  // N.B. cbrt always returns the real root. cbrt(-8) = -2.
906  real T = cbrt(T3); // T = r * t
907  // T can be zero; but then r2 / T -> 0.
908  u += T + (T != 0 ? r2 / T : 0);
909  } else {
910  // T is complex, but the way u is defined the result is real.
911  real ang = atan2(sqrt(-disc), -(S + r3));
912  // There are three possible cube roots. We choose the root which
913  // avoids cancellation. Note that disc < 0 implies that r < 0.
914  u += 2 * r * cos(ang / 3);
915  }
916  real
917  v = sqrt(Math::sq(u) + q), // guaranteed positive
918  // Avoid loss of accuracy when u < 0.
919  uv = u < 0 ? q / (v - u) : u + v, // u+v, guaranteed positive
920  w = (uv - q) / (2 * v); // positive?
921  // Rearrange expression for k to avoid loss of accuracy due to
922  // subtraction. Division by 0 not possible because uv > 0, w >= 0.
923  k = uv / (sqrt(uv + Math::sq(w)) + w); // guaranteed positive
924  } else { // q == 0 && r <= 0
925  // y = 0 with |x| <= 1. Handle this case directly.
926  // for y small, positive root is k = abs(y)/sqrt(1-x^2)
927  k = 0;
928  }
929  return k;
930  }
931 
932  Math::real GeodesicExact::InverseStart(EllipticFunction& E,
933  real sbet1, real cbet1, real dn1,
934  real sbet2, real cbet2, real dn2,
935  real lam12, real slam12, real clam12,
936  real& salp1, real& calp1,
937  // Only updated if return val >= 0
938  real& salp2, real& calp2,
939  // Only updated for short lines
940  real& dnm) const {
941  // Return a starting point for Newton's method in salp1 and calp1 (function
942  // value is -1). If Newton's method doesn't need to be used, return also
943  // salp2 and calp2 and function value is sig12.
944  real
945  sig12 = -1, // Return value
946  // bet12 = bet2 - bet1 in [0, pi); bet12a = bet2 + bet1 in (-pi, 0]
947  sbet12 = sbet2 * cbet1 - cbet2 * sbet1,
948  cbet12 = cbet2 * cbet1 + sbet2 * sbet1;
949  real sbet12a = sbet2 * cbet1 + cbet2 * sbet1;
950  bool shortline = cbet12 >= 0 && sbet12 < real(0.5) &&
951  cbet2 * lam12 < real(0.5);
952  real somg12, comg12;
953  if (shortline) {
954  real sbetm2 = Math::sq(sbet1 + sbet2);
955  // sin((bet1+bet2)/2)^2
956  // = (sbet1 + sbet2)^2 / ((sbet1 + sbet2)^2 + (cbet1 + cbet2)^2)
957  sbetm2 /= sbetm2 + Math::sq(cbet1 + cbet2);
958  dnm = sqrt(1 + _ep2 * sbetm2);
959  real omg12 = lam12 / (_f1 * dnm);
960  somg12 = sin(omg12); comg12 = cos(omg12);
961  } else {
962  somg12 = slam12; comg12 = clam12;
963  }
964 
965  salp1 = cbet2 * somg12;
966  calp1 = comg12 >= 0 ?
967  sbet12 + cbet2 * sbet1 * Math::sq(somg12) / (1 + comg12) :
968  sbet12a - cbet2 * sbet1 * Math::sq(somg12) / (1 - comg12);
969 
970  real
971  ssig12 = hypot(salp1, calp1),
972  csig12 = sbet1 * sbet2 + cbet1 * cbet2 * comg12;
973 
974  if (shortline && ssig12 < _etol2) {
975  // really short lines
976  salp2 = cbet1 * somg12;
977  calp2 = sbet12 - cbet1 * sbet2 *
978  (comg12 >= 0 ? Math::sq(somg12) / (1 + comg12) : 1 - comg12);
979  Math::norm(salp2, calp2);
980  // Set return value
981  sig12 = atan2(ssig12, csig12);
982  } else if (fabs(_n) > real(0.1) || // Skip astroid calc if too eccentric
983  csig12 >= 0 ||
984  ssig12 >= 6 * fabs(_n) * Math::pi() * Math::sq(cbet1)) {
985  // Nothing to do, zeroth order spherical approximation is OK
986  } else {
987  // Scale lam12 and bet2 to x, y coordinate system where antipodal point
988  // is at origin and singular point is at y = 0, x = -1.
989  real x, y, lamscale, betscale;
990  real lam12x = atan2(-slam12, -clam12); // lam12 - pi
991  if (_f >= 0) { // In fact f == 0 does not get here
992  // x = dlong, y = dlat
993  {
994  real k2 = Math::sq(sbet1) * _ep2;
995  E.Reset(-k2, -_ep2, 1 + k2, 1 + _ep2);
996  lamscale = _e2/_f1 * cbet1 * 2 * E.H();
997  }
998  betscale = lamscale * cbet1;
999 
1000  x = lam12x / lamscale;
1001  y = sbet12a / betscale;
1002  } else { // _f < 0
1003  // x = dlat, y = dlong
1004  real
1005  cbet12a = cbet2 * cbet1 - sbet2 * sbet1,
1006  bet12a = atan2(sbet12a, cbet12a);
1007  real m12b, m0, dummy;
1008  // In the case of lon12 = 180, this repeats a calculation made in
1009  // Inverse.
1010  Lengths(E, Math::pi() + bet12a,
1011  sbet1, -cbet1, dn1, sbet2, cbet2, dn2,
1012  cbet1, cbet2, REDUCEDLENGTH, dummy, m12b, m0, dummy, dummy);
1013  x = -1 + m12b / (cbet1 * cbet2 * m0 * Math::pi());
1014  betscale = x < -real(0.01) ? sbet12a / x :
1015  -_f * Math::sq(cbet1) * Math::pi();
1016  lamscale = betscale / cbet1;
1017  y = lam12x / lamscale;
1018  }
1019 
1020  if (y > -tol1_ && x > -1 - xthresh_) {
1021  // strip near cut
1022  // Need real(x) here to cast away the volatility of x for min/max
1023  if (_f >= 0) {
1024  salp1 = fmin(real(1), -x); calp1 = - sqrt(1 - Math::sq(salp1));
1025  } else {
1026  calp1 = fmax(real(x > -tol1_ ? 0 : -1), x);
1027  salp1 = sqrt(1 - Math::sq(calp1));
1028  }
1029  } else {
1030  // Estimate alp1, by solving the astroid problem.
1031  //
1032  // Could estimate alpha1 = theta + pi/2, directly, i.e.,
1033  // calp1 = y/k; salp1 = -x/(1+k); for _f >= 0
1034  // calp1 = x/(1+k); salp1 = -y/k; for _f < 0 (need to check)
1035  //
1036  // However, it's better to estimate omg12 from astroid and use
1037  // spherical formula to compute alp1. This reduces the mean number of
1038  // Newton iterations for astroid cases from 2.24 (min 0, max 6) to 2.12
1039  // (min 0 max 5). The changes in the number of iterations are as
1040  // follows:
1041  //
1042  // change percent
1043  // 1 5
1044  // 0 78
1045  // -1 16
1046  // -2 0.6
1047  // -3 0.04
1048  // -4 0.002
1049  //
1050  // The histogram of iterations is (m = number of iterations estimating
1051  // alp1 directly, n = number of iterations estimating via omg12, total
1052  // number of trials = 148605):
1053  //
1054  // iter m n
1055  // 0 148 186
1056  // 1 13046 13845
1057  // 2 93315 102225
1058  // 3 36189 32341
1059  // 4 5396 7
1060  // 5 455 1
1061  // 6 56 0
1062  //
1063  // Because omg12 is near pi, estimate work with omg12a = pi - omg12
1064  real k = Astroid(x, y);
1065  real
1066  omg12a = lamscale * ( _f >= 0 ? -x * k/(1 + k) : -y * (1 + k)/k );
1067  somg12 = sin(omg12a); comg12 = -cos(omg12a);
1068  // Update spherical estimate of alp1 using omg12 instead of lam12
1069  salp1 = cbet2 * somg12;
1070  calp1 = sbet12a - cbet2 * sbet1 * Math::sq(somg12) / (1 - comg12);
1071  }
1072  }
1073  // Sanity check on starting guess. Backwards check allows NaN through.
1074  if (!(salp1 <= 0))
1075  Math::norm(salp1, calp1);
1076  else {
1077  salp1 = 1; calp1 = 0;
1078  }
1079  return sig12;
1080  }
1081 
1082  Math::real GeodesicExact::Lambda12(real sbet1, real cbet1, real dn1,
1083  real sbet2, real cbet2, real dn2,
1084  real salp1, real calp1,
1085  real slam120, real clam120,
1086  real& salp2, real& calp2,
1087  real& sig12,
1088  real& ssig1, real& csig1,
1089  real& ssig2, real& csig2,
1090  EllipticFunction& E,
1091  real& domg12,
1092  bool diffp, real& dlam12) const
1093  {
1094 
1095  if (sbet1 == 0 && calp1 == 0)
1096  // Break degeneracy of equatorial line. This case has already been
1097  // handled.
1098  calp1 = -tiny_;
1099 
1100  real
1101  // sin(alp1) * cos(bet1) = sin(alp0)
1102  salp0 = salp1 * cbet1,
1103  calp0 = hypot(calp1, salp1 * sbet1); // calp0 > 0
1104 
1105  real somg1, comg1, somg2, comg2, somg12, comg12, cchi1, cchi2, lam12;
1106  // tan(bet1) = tan(sig1) * cos(alp1)
1107  // tan(omg1) = sin(alp0) * tan(sig1) = tan(omg1)=tan(alp1)*sin(bet1)
1108  ssig1 = sbet1; somg1 = salp0 * sbet1;
1109  csig1 = comg1 = calp1 * cbet1;
1110  // Without normalization we have schi1 = somg1.
1111  cchi1 = _f1 * dn1 * comg1;
1112  Math::norm(ssig1, csig1);
1113  // Math::norm(somg1, comg1); -- don't need to normalize!
1114  // Math::norm(schi1, cchi1); -- don't need to normalize!
1115 
1116  // Enforce symmetries in the case abs(bet2) = -bet1. Need to be careful
1117  // about this case, since this can yield singularities in the Newton
1118  // iteration.
1119  // sin(alp2) * cos(bet2) = sin(alp0)
1120  salp2 = cbet2 != cbet1 ? salp0 / cbet2 : salp1;
1121  // calp2 = sqrt(1 - sq(salp2))
1122  // = sqrt(sq(calp0) - sq(sbet2)) / cbet2
1123  // and subst for calp0 and rearrange to give (choose positive sqrt
1124  // to give alp2 in [0, pi/2]).
1125  calp2 = cbet2 != cbet1 || fabs(sbet2) != -sbet1 ?
1126  sqrt(Math::sq(calp1 * cbet1) +
1127  (cbet1 < -sbet1 ?
1128  (cbet2 - cbet1) * (cbet1 + cbet2) :
1129  (sbet1 - sbet2) * (sbet1 + sbet2))) / cbet2 :
1130  fabs(calp1);
1131  // tan(bet2) = tan(sig2) * cos(alp2)
1132  // tan(omg2) = sin(alp0) * tan(sig2).
1133  ssig2 = sbet2; somg2 = salp0 * sbet2;
1134  csig2 = comg2 = calp2 * cbet2;
1135  // Without normalization we have schi2 = somg2.
1136  cchi2 = _f1 * dn2 * comg2;
1137  Math::norm(ssig2, csig2);
1138  // Math::norm(somg2, comg2); -- don't need to normalize!
1139  // Math::norm(schi2, cchi2); -- don't need to normalize!
1140 
1141  // sig12 = sig2 - sig1, limit to [0, pi]
1142  sig12 = atan2(fmax(real(0), csig1 * ssig2 - ssig1 * csig2),
1143  csig1 * csig2 + ssig1 * ssig2);
1144 
1145  // omg12 = omg2 - omg1, limit to [0, pi]
1146  somg12 = fmax(real(0), comg1 * somg2 - somg1 * comg2);
1147  comg12 = comg1 * comg2 + somg1 * somg2;
1148  real k2 = Math::sq(calp0) * _ep2;
1149  E.Reset(-k2, -_ep2, 1 + k2, 1 + _ep2);
1150  // chi12 = chi2 - chi1, limit to [0, pi]
1151  real
1152  schi12 = fmax(real(0), cchi1 * somg2 - somg1 * cchi2),
1153  cchi12 = cchi1 * cchi2 + somg1 * somg2;
1154  // eta = chi12 - lam120
1155  real eta = atan2(schi12 * clam120 - cchi12 * slam120,
1156  cchi12 * clam120 + schi12 * slam120);
1157  real deta12 = -_e2/_f1 * salp0 * E.H() / (Math::pi() / 2) *
1158  (sig12 + (E.deltaH(ssig2, csig2, dn2) - E.deltaH(ssig1, csig1, dn1)));
1159  lam12 = eta + deta12;
1160  // domg12 = deta12 + chi12 - omg12
1161  domg12 = deta12 + atan2(schi12 * comg12 - cchi12 * somg12,
1162  cchi12 * comg12 + schi12 * somg12);
1163  if (diffp) {
1164  if (calp2 == 0)
1165  dlam12 = - 2 * _f1 * dn1 / sbet1;
1166  else {
1167  real dummy;
1168  Lengths(E, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2,
1169  cbet1, cbet2, REDUCEDLENGTH,
1170  dummy, dlam12, dummy, dummy, dummy);
1171  dlam12 *= _f1 / (calp2 * cbet2);
1172  }
1173  }
1174 
1175  return lam12;
1176  }
1177 
1178  Math::real GeodesicExact::I4Integrand::asinhsqrt(real x) {
1179  // return asinh(sqrt(x))/sqrt(x)
1180  using std::sqrt; using std::asinh; using std::asin;
1181  return x == 0 ? 1 :
1182  (x > 0 ? asinh(sqrt(x))/sqrt(x) :
1183  asin(sqrt(-x))/sqrt(-x)); // NaNs end up here
1184  }
1185  Math::real GeodesicExact::I4Integrand::t(real x) {
1186  // This differs by from t as defined following Eq 61 in Karney (2013) by
1187  // the final subtraction of 1. This changes nothing since Eq 61 uses the
1188  // difference of two evaluations of t and improves the accuracy(?).
1189  using std::sqrt;
1190  // Group terms to minimize roundoff
1191  // with x = ep2, this is the same as
1192  // e2/(1-e2) + (atanh(e)/e - 1)
1193  return x + (sqrt(1 + x) * asinhsqrt(x) - 1);
1194  }
1195  Math::real GeodesicExact::I4Integrand::td(real x) {
1196  // d t(x) / dx
1197  using std::sqrt;
1198  return x == 0 ? 4/real(3) :
1199  // Group terms to minimize roundoff
1200  1 + (1 - asinhsqrt(x) / sqrt(1+x)) / (2*x);
1201  }
1202  // Math::real GeodesicExact::I4Integrand::Dt(real x, real y) {
1203  // // ( t(x) - t(y) ) / (x - y)
1204  // using std::sqrt; using std::fabs; using std::asinh; using std::asin;
1205  // if (x == y) return td(x);
1206  // if (x * y <= 0) return ( t(x) - t(y) ) / (x - y);
1207  // real
1208  // sx = sqrt(fabs(x)), sx1 = sqrt(1 + x),
1209  // sy = sqrt(fabs(y)), sy1 = sqrt(1 + y),
1210  // z = (x - y) / (sx * sy1 + sy * sx1),
1211  // d1 = 2 * sx * sy,
1212  // d2 = 2 * (x * sy * sy1 + y * sx * sx1);
1213  // return x > 0 ?
1214  // ( 1 + (asinh(z)/z) / d1 - (asinh(sx) + asinh(sy)) / d2 ) :
1215  // // NaNs fall through to here
1216  // ( 1 - (asin (z)/z) / d1 - (asin (sx) + asin (sy)) / d2 );
1217  // }
1218  Math::real GeodesicExact::I4Integrand::DtX(real y) const {
1219  // idiot version:
1220  // return ( tX - t(y) ) / (X - y);
1221  using std::sqrt; using std::fabs; using std::asinh; using std::asin;
1222  if (X == y) return tdX;
1223  if (X * y <= 0) return ( tX - t(y) ) / (X - y);
1224  real
1225  sy = sqrt(fabs(y)), sy1 = sqrt(1 + y),
1226  z = (X - y) / (sX * sy1 + sy * sX1),
1227  d1 = 2 * sX * sy,
1228  d2 = 2 * (X * sy * sy1 + y * sXX1);
1229  return X > 0 ?
1230  ( 1 + (asinh(z)/z) / d1 - (asinhsX + asinh(sy)) / d2 ) :
1231  // NaNs fall through to here
1232  ( 1 - (asin (z)/z) / d1 - (asinhsX + asin (sy)) / d2 );
1233  }
1234  GeodesicExact::I4Integrand::I4Integrand(real ep2, real k2)
1235  : X( ep2 )
1236  , tX( t(X) )
1237  , tdX( td(X) )
1238  , _k2( k2 )
1239  {
1240  using std::fabs; using std::sqrt; using std::asinh; using std::asin;
1241  sX = sqrt(fabs(X)); // ep
1242  sX1 = sqrt(1 + X); // 1/(1-f)
1243  sXX1 = sX * sX1;
1244  asinhsX = X > 0 ? asinh(sX) : asin(sX); // atanh(e)
1245  }
1246  Math::real GeodesicExact::I4Integrand::operator()(real sig) const {
1247  using std::sin;
1248  real ssig = sin(sig);
1249  return - DtX(_k2 * Math::sq(ssig)) * ssig/2;
1250  }
1251 
1252 } // namespace GeographicLib
GeographicLib::Math::real real
Definition: GeodSolve.cpp:31
Header for GeographicLib::GeodesicExact class.
Header for GeographicLib::GeodesicLineExact class.
void reset(int N)
Definition: DST.cpp:24
void transform(std::function< real(real)> f, real F[]) const
Definition: DST.cpp:77
static real integral(real sinx, real cosx, const real F[], int N)
Definition: DST.cpp:110
Elliptic integrals and functions.
Math::real deltaE(real sn, real cn, real dn) const
Math::real deltaD(real sn, real cn, real dn) const
Exact geodesic calculations.
GeodesicLineExact InverseLine(real lat1, real lon1, real lat2, real lon2, unsigned caps=ALL) const
GeodesicLineExact GenDirectLine(real lat1, real lon1, real azi1, bool arcmode, real s12_a12, unsigned caps=ALL) const
GeodesicLineExact DirectLine(real lat1, real lon1, real azi1, real s12, unsigned caps=ALL) const
Math::real GenDirect(real lat1, real lon1, real azi1, bool arcmode, real s12_a12, unsigned outmask, real &lat2, real &lon2, real &azi2, real &s12, real &m12, real &M12, real &M21, real &S12) const
GeodesicLineExact Line(real lat1, real lon1, real azi1, unsigned caps=ALL) const
static const GeodesicExact & WGS84()
GeodesicLineExact ArcDirectLine(real lat1, real lon1, real azi1, real a12, unsigned caps=ALL) const
Exception handling for GeographicLib.
Definition: Constants.hpp:316
Mathematical functions needed by GeographicLib.
Definition: Math.hpp:76
static T degree()
Definition: Math.hpp:200
static T LatFix(T x)
Definition: Math.hpp:300
static void sincosd(T x, T &sinx, T &cosx)
Definition: Math.cpp:106
static T atan2d(T y, T x)
Definition: Math.cpp:183
static void norm(T &x, T &y)
Definition: Math.hpp:222
static T AngRound(T x)
Definition: Math.cpp:97
static T sq(T x)
Definition: Math.hpp:212
static T AngNormalize(T x)
Definition: Math.cpp:71
static int digits()
Definition: Math.cpp:26
static void sincosde(T x, T t, T &sinx, T &cosx)
Definition: Math.cpp:126
static T pi()
Definition: Math.hpp:190
static T AngDiff(T x, T y, T &e)
Definition: Math.cpp:82
@ hd
degrees per half turn
Definition: Math.hpp:144
@ qd
degrees per quarter turn
Definition: Math.hpp:141
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
void swap(GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &a, GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &b)