@math.gl/geospatial 5.0.0-rc.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/README.md +6 -6
  2. package/dist/coordinates.cjs +2523 -0
  3. package/dist/coordinates.cjs.map +6 -0
  4. package/dist/coordinates.d.ts +4 -0
  5. package/dist/coordinates.d.ts.map +1 -1
  6. package/dist/coordinates.js +2 -0
  7. package/dist/coordinates.js.map +1 -1
  8. package/dist/entries/ellipsoid.cjs +1209 -0
  9. package/dist/entries/ellipsoid.cjs.map +6 -0
  10. package/dist/entries/ellipsoid.d.ts +3 -19
  11. package/dist/entries/ellipsoid.d.ts.map +1 -1
  12. package/dist/entries/ellipsoid.js +1 -9
  13. package/dist/entries/ellipsoid.js.map +1 -1
  14. package/dist/expressions.cjs +726 -0
  15. package/dist/expressions.cjs.map +6 -0
  16. package/dist/geodesics.cjs +3195 -0
  17. package/dist/geodesics.cjs.map +6 -0
  18. package/dist/geodesics.d.ts +18 -0
  19. package/dist/geodesics.d.ts.map +1 -0
  20. package/dist/geodesics.js +13 -0
  21. package/dist/geodesics.js.map +1 -0
  22. package/dist/geographic-atlas/sampling.d.ts +1 -1
  23. package/dist/geographic-atlas/sampling.d.ts.map +1 -1
  24. package/dist/geographic-atlas/sampling.js +1 -1
  25. package/dist/geographic-atlas/sampling.js.map +1 -1
  26. package/dist/geographic-cuts.cjs +4160 -0
  27. package/dist/geographic-cuts.cjs.map +6 -0
  28. package/dist/geographic-cuts.d.ts +2 -0
  29. package/dist/geographic-cuts.d.ts.map +1 -1
  30. package/dist/geographic-cuts.js +1 -0
  31. package/dist/geographic-cuts.js.map +1 -1
  32. package/dist/geographic-seams/subdivide-cut.d.ts +1 -1
  33. package/dist/geographic-seams/subdivide-cut.d.ts.map +1 -1
  34. package/dist/geographic-seams/subdivide-cut.js +1 -1
  35. package/dist/geographic-seams/subdivide-cut.js.map +1 -1
  36. package/dist/geographic-seams/types.shared.cjs +32 -0
  37. package/dist/geographic-seams/types.shared.cjs.map +6 -0
  38. package/dist/globe.cjs +4223 -0
  39. package/dist/globe.cjs.map +6 -0
  40. package/dist/index.d.ts +2 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +2 -0
  43. package/dist/index.js.map +1 -1
  44. package/dist/maps/map-transition.shared.cjs +364 -0
  45. package/dist/maps/map-transition.shared.cjs.map +6 -0
  46. package/dist/maps/myriahedral/unfold.d.ts +1 -1
  47. package/dist/maps/myriahedral/unfold.d.ts.map +1 -1
  48. package/dist/maps/myriahedral/unfold.js +1 -1
  49. package/dist/maps/myriahedral/unfold.js.map +1 -1
  50. package/dist/maps/presets.cjs +2 -2
  51. package/dist/maps/presets.cjs.map +2 -2
  52. package/dist/maps/transitions.cjs +3 -342
  53. package/dist/maps/transitions.cjs.map +3 -3
  54. package/dist/maps.cjs +15 -319
  55. package/dist/maps.cjs.map +3 -3
  56. package/dist/projection/experimental/core.cjs +63 -1317
  57. package/dist/projection/experimental/core.cjs.map +3 -3
  58. package/dist/projection/experimental/core.d.ts +1 -1
  59. package/dist/projection/experimental/core.d.ts.map +1 -1
  60. package/dist/projection/experimental/crs/projjson.cjs +26 -45
  61. package/dist/projection/experimental/crs/projjson.cjs.map +3 -3
  62. package/dist/projection/experimental/crs/types.shared.cjs +44 -0
  63. package/dist/projection/experimental/crs/types.shared.cjs.map +6 -0
  64. package/dist/projection/experimental/crs/wkt.cjs +36 -52
  65. package/dist/projection/experimental/crs/wkt.cjs.map +3 -3
  66. package/dist/projection/experimental/entries/projections/ob_tran.cjs +9 -23
  67. package/dist/projection/experimental/entries/projections/ob_tran.cjs.map +3 -3
  68. package/dist/projection/experimental/lazy-projections/aea.cjs +1 -1
  69. package/dist/projection/experimental/lazy-projections/aea.js +1 -1
  70. package/dist/projection/experimental/lazy-projections/aeqd.cjs +1 -1
  71. package/dist/projection/experimental/lazy-projections/aeqd.js +1 -1
  72. package/dist/projection/experimental/lazy-projections/bonne.cjs +1 -1
  73. package/dist/projection/experimental/lazy-projections/bonne.js +1 -1
  74. package/dist/projection/experimental/lazy-projections/cass.cjs +1 -1
  75. package/dist/projection/experimental/lazy-projections/cass.js +1 -1
  76. package/dist/projection/experimental/lazy-projections/cea.cjs +1 -1
  77. package/dist/projection/experimental/lazy-projections/cea.js +1 -1
  78. package/dist/projection/experimental/lazy-projections/eck6.cjs +1 -1
  79. package/dist/projection/experimental/lazy-projections/eck6.js +1 -1
  80. package/dist/projection/experimental/lazy-projections/eqc.cjs +1 -1
  81. package/dist/projection/experimental/lazy-projections/eqc.js +1 -1
  82. package/dist/projection/experimental/lazy-projections/eqdc.cjs +1 -1
  83. package/dist/projection/experimental/lazy-projections/eqdc.js +1 -1
  84. package/dist/projection/experimental/lazy-projections/eqearth.cjs +1 -1
  85. package/dist/projection/experimental/lazy-projections/eqearth.js +1 -1
  86. package/dist/projection/experimental/lazy-projections/equi.cjs +1 -1
  87. package/dist/projection/experimental/lazy-projections/equi.js +1 -1
  88. package/dist/projection/experimental/lazy-projections/etmerc.cjs +1 -1
  89. package/dist/projection/experimental/lazy-projections/etmerc.js +1 -1
  90. package/dist/projection/experimental/lazy-projections/geocent.cjs +1 -1
  91. package/dist/projection/experimental/lazy-projections/geocent.js +1 -1
  92. package/dist/projection/experimental/lazy-projections/geos.cjs +1 -1
  93. package/dist/projection/experimental/lazy-projections/geos.js +1 -1
  94. package/dist/projection/experimental/lazy-projections/gnom.cjs +1 -1
  95. package/dist/projection/experimental/lazy-projections/gnom.js +1 -1
  96. package/dist/projection/experimental/lazy-projections/gstmerc.cjs +1 -1
  97. package/dist/projection/experimental/lazy-projections/gstmerc.js +1 -1
  98. package/dist/projection/experimental/lazy-projections/index.cjs +60 -903
  99. package/dist/projection/experimental/lazy-projections/index.cjs.map +3 -3
  100. package/dist/projection/experimental/lazy-projections/krovak.cjs +1 -1
  101. package/dist/projection/experimental/lazy-projections/krovak.js +1 -1
  102. package/dist/projection/experimental/lazy-projections/laea.cjs +1 -1
  103. package/dist/projection/experimental/lazy-projections/laea.js +1 -1
  104. package/dist/projection/experimental/lazy-projections/lcc.cjs +1 -1
  105. package/dist/projection/experimental/lazy-projections/lcc.js +1 -1
  106. package/dist/projection/experimental/lazy-projections/merc.cjs +1 -1
  107. package/dist/projection/experimental/lazy-projections/merc.js +1 -1
  108. package/dist/projection/experimental/lazy-projections/mill.cjs +1 -1
  109. package/dist/projection/experimental/lazy-projections/mill.js +1 -1
  110. package/dist/projection/experimental/lazy-projections/moll.cjs +1 -1
  111. package/dist/projection/experimental/lazy-projections/moll.js +1 -1
  112. package/dist/projection/experimental/lazy-projections/nzmg.cjs +1 -1
  113. package/dist/projection/experimental/lazy-projections/nzmg.js +1 -1
  114. package/dist/projection/experimental/lazy-projections/ob_tran.cjs +1 -1
  115. package/dist/projection/experimental/lazy-projections/ob_tran.js +1 -1
  116. package/dist/projection/experimental/lazy-projections/omerc.cjs +1 -1
  117. package/dist/projection/experimental/lazy-projections/omerc.js +1 -1
  118. package/dist/projection/experimental/lazy-projections/ortho.cjs +1 -1
  119. package/dist/projection/experimental/lazy-projections/ortho.js +1 -1
  120. package/dist/projection/experimental/lazy-projections/poly.cjs +1 -1
  121. package/dist/projection/experimental/lazy-projections/poly.js +1 -1
  122. package/dist/projection/experimental/lazy-projections/qsc.cjs +1 -1
  123. package/dist/projection/experimental/lazy-projections/qsc.js +1 -1
  124. package/dist/projection/experimental/lazy-projections/robin.cjs +1 -1
  125. package/dist/projection/experimental/lazy-projections/robin.js +1 -1
  126. package/dist/projection/experimental/lazy-projections/sinu.cjs +1 -1
  127. package/dist/projection/experimental/lazy-projections/sinu.js +1 -1
  128. package/dist/projection/experimental/lazy-projections/somerc.cjs +1 -1
  129. package/dist/projection/experimental/lazy-projections/somerc.js +1 -1
  130. package/dist/projection/experimental/lazy-projections/stere.cjs +1 -1
  131. package/dist/projection/experimental/lazy-projections/stere.js +1 -1
  132. package/dist/projection/experimental/lazy-projections/sterea.cjs +1 -1
  133. package/dist/projection/experimental/lazy-projections/sterea.js +1 -1
  134. package/dist/projection/experimental/lazy-projections/tmerc.cjs +1 -1
  135. package/dist/projection/experimental/lazy-projections/tmerc.js +1 -1
  136. package/dist/projection/experimental/lazy-projections/tpers.cjs +1 -1
  137. package/dist/projection/experimental/lazy-projections/tpers.js +1 -1
  138. package/dist/projection/experimental/lazy-projections/utm.cjs +1 -1
  139. package/dist/projection/experimental/lazy-projections/utm.js +1 -1
  140. package/dist/projection/experimental/lazy-projections/vandg.cjs +1 -1
  141. package/dist/projection/experimental/lazy-projections/vandg.js +1 -1
  142. package/dist/projection/experimental/projection-engine.shared.cjs +1184 -0
  143. package/dist/projection/experimental/projection-engine.shared.cjs.map +6 -0
  144. package/dist/projection/experimental/typescript-projection.shared.cjs +1703 -0
  145. package/dist/projection/experimental/typescript-projection.shared.cjs.map +6 -0
  146. package/dist/projection/index.cjs +622 -1535
  147. package/dist/projection/index.cjs.map +3 -3
  148. package/dist/projection/pipeline.cjs +44 -58
  149. package/dist/projection/pipeline.cjs.map +3 -3
  150. package/dist/projection/transform-analysis.cjs +20 -936
  151. package/dist/projection/transform-analysis.cjs.map +3 -3
  152. package/dist/subdivide-geodesic-polyline.d.ts +1 -1
  153. package/dist/subdivide-geodesic-polyline.d.ts.map +1 -1
  154. package/dist/subdivide-geodesic-polyline.js +1 -1
  155. package/dist/subdivide-geodesic-polyline.js.map +1 -1
  156. package/dist/subdivide-globe-mesh.d.ts +1 -1
  157. package/dist/subdivide-globe-mesh.d.ts.map +1 -1
  158. package/dist/subdivide-globe-mesh.js +1 -1
  159. package/dist/subdivide-globe-mesh.js.map +1 -1
  160. package/dist/subdivide-rhumb-polyline.d.ts +1 -1
  161. package/dist/subdivide-rhumb-polyline.d.ts.map +1 -1
  162. package/dist/subdivide-rhumb-polyline.js +1 -1
  163. package/dist/subdivide-rhumb-polyline.js.map +1 -1
  164. package/dist/tasks/index.cjs +808 -2993
  165. package/dist/tasks/index.cjs.map +3 -3
  166. package/dist/terrain/geometry.d.ts +1 -1
  167. package/dist/terrain/geometry.d.ts.map +1 -1
  168. package/dist/terrain/geometry.js +1 -1
  169. package/dist/terrain/geometry.js.map +1 -1
  170. package/dist/terrain/index.cjs +2 -2
  171. package/dist/terrain/index.cjs.map +1 -1
  172. package/dist/tiles.cjs +354 -0
  173. package/dist/tiles.cjs.map +6 -0
  174. package/package.json +139 -117
  175. package/src/coordinates.ts +5 -0
  176. package/src/entries/ellipsoid.ts +7 -32
  177. package/src/geodesics.ts +40 -0
  178. package/src/geographic-atlas/sampling.ts +1 -1
  179. package/src/geographic-cuts.ts +21 -0
  180. package/src/geographic-seams/subdivide-cut.ts +1 -1
  181. package/src/index.ts +2 -0
  182. package/src/maps/myriahedral/unfold.ts +1 -1
  183. package/src/projection/experimental/core.ts +1 -1
  184. package/src/projection/experimental/lazy-projections/aea.ts +1 -1
  185. package/src/projection/experimental/lazy-projections/aeqd.ts +1 -1
  186. package/src/projection/experimental/lazy-projections/bonne.ts +1 -1
  187. package/src/projection/experimental/lazy-projections/cass.ts +1 -1
  188. package/src/projection/experimental/lazy-projections/cea.ts +1 -1
  189. package/src/projection/experimental/lazy-projections/eck6.ts +1 -1
  190. package/src/projection/experimental/lazy-projections/eqc.ts +1 -1
  191. package/src/projection/experimental/lazy-projections/eqdc.ts +1 -1
  192. package/src/projection/experimental/lazy-projections/eqearth.ts +1 -1
  193. package/src/projection/experimental/lazy-projections/equi.ts +1 -1
  194. package/src/projection/experimental/lazy-projections/etmerc.ts +1 -1
  195. package/src/projection/experimental/lazy-projections/geocent.ts +1 -1
  196. package/src/projection/experimental/lazy-projections/geos.ts +1 -1
  197. package/src/projection/experimental/lazy-projections/gnom.ts +1 -1
  198. package/src/projection/experimental/lazy-projections/gstmerc.ts +1 -1
  199. package/src/projection/experimental/lazy-projections/krovak.ts +1 -1
  200. package/src/projection/experimental/lazy-projections/laea.ts +1 -1
  201. package/src/projection/experimental/lazy-projections/lcc.ts +1 -1
  202. package/src/projection/experimental/lazy-projections/merc.ts +1 -1
  203. package/src/projection/experimental/lazy-projections/mill.ts +1 -1
  204. package/src/projection/experimental/lazy-projections/moll.ts +1 -1
  205. package/src/projection/experimental/lazy-projections/nzmg.ts +1 -1
  206. package/src/projection/experimental/lazy-projections/ob_tran.ts +1 -1
  207. package/src/projection/experimental/lazy-projections/omerc.ts +1 -1
  208. package/src/projection/experimental/lazy-projections/ortho.ts +1 -1
  209. package/src/projection/experimental/lazy-projections/poly.ts +1 -1
  210. package/src/projection/experimental/lazy-projections/qsc.ts +1 -1
  211. package/src/projection/experimental/lazy-projections/robin.ts +1 -1
  212. package/src/projection/experimental/lazy-projections/sinu.ts +1 -1
  213. package/src/projection/experimental/lazy-projections/somerc.ts +1 -1
  214. package/src/projection/experimental/lazy-projections/stere.ts +1 -1
  215. package/src/projection/experimental/lazy-projections/sterea.ts +1 -1
  216. package/src/projection/experimental/lazy-projections/tmerc.ts +1 -1
  217. package/src/projection/experimental/lazy-projections/tpers.ts +1 -1
  218. package/src/projection/experimental/lazy-projections/utm.ts +1 -1
  219. package/src/projection/experimental/lazy-projections/vandg.ts +1 -1
  220. package/src/subdivide-geodesic-polyline.ts +2 -2
  221. package/src/subdivide-globe-mesh.ts +2 -2
  222. package/src/subdivide-rhumb-polyline.ts +2 -2
  223. package/src/terrain/geometry.ts +1 -1
  224. package/dist/index.cjs +0 -18674
  225. package/dist/index.cjs.map +0 -6
  226. package/dist/turf-expressions.cjs +0 -1997
  227. package/dist/turf-expressions.cjs.map +0 -6
  228. package/dist/turf-expressions.d.ts +0 -3
  229. package/dist/turf-expressions.d.ts.map +0 -1
  230. package/dist/turf-expressions.js +0 -7
  231. package/dist/turf-expressions.js.map +0 -1
  232. package/src/turf-expressions.ts +0 -7
@@ -0,0 +1,3195 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // dist/geodesics.js
20
+ var geodesics_exports = {};
21
+ __export(geodesics_exports, {
22
+ EllipsoidGeodesic: () => EllipsoidGeodesic,
23
+ EllipsoidGeodesicExact: () => EllipsoidGeodesicExact,
24
+ EllipsoidRhumb: () => EllipsoidRhumb,
25
+ GEODESIC_BUFFER_FIELDS: () => GEODESIC_BUFFER_FIELDS,
26
+ GeodesicIntersections: () => GeodesicIntersections,
27
+ GeodesicLineBuffer: () => GeodesicLineBuffer,
28
+ GeodesicPath: () => GeodesicPath,
29
+ GeodesicPolygon: () => GeodesicPolygon,
30
+ GeodesicPolygonExact: () => GeodesicPolygonExact,
31
+ RHUMB_BUFFER_FIELDS: () => RHUMB_BUFFER_FIELDS,
32
+ RhumbDomainError: () => RhumbDomainError,
33
+ RhumbLineBuffer: () => RhumbLineBuffer,
34
+ RhumbPath: () => RhumbPath,
35
+ RhumbPolygon: () => RhumbPolygon
36
+ });
37
+ module.exports = __toCommonJS(geodesics_exports);
38
+
39
+ // dist/vendor/geographiclib-geodesic/runtime.js
40
+ var geodesic = {};
41
+ geodesic.Constants = {};
42
+ geodesic.Math = {};
43
+ geodesic.Accumulator = {};
44
+ (function(c) {
45
+ "use strict";
46
+ c.WGS84 = { a: 6378137, f: 1 / 298.257223563 };
47
+ c.version = {
48
+ major: 2,
49
+ minor: 2,
50
+ patch: 0
51
+ };
52
+ c.version_string = "2.2.0";
53
+ })(geodesic.Constants);
54
+ (function(m) {
55
+ "use strict";
56
+ m.digits = 53;
57
+ m.epsilon = Math.pow(0.5, m.digits - 1);
58
+ m.degree = Math.PI / 180;
59
+ m.sq = function(x) {
60
+ return x * x;
61
+ };
62
+ m.hypot = function(x, y) {
63
+ return Math.sqrt(x * x + y * y);
64
+ };
65
+ m.cbrt = Math.cbrt || function(x) {
66
+ var y = Math.pow(Math.abs(x), 1 / 3);
67
+ return x > 0 ? y : x < 0 ? -y : x;
68
+ };
69
+ m.log1p = Math.log1p || function(x) {
70
+ var y = 1 + x, z = y - 1;
71
+ return z === 0 ? x : x * Math.log(y) / z;
72
+ };
73
+ m.atanh = Math.atanh || function(x) {
74
+ var y = Math.abs(x);
75
+ y = m.log1p(2 * y / (1 - y)) / 2;
76
+ return x > 0 ? y : x < 0 ? -y : x;
77
+ };
78
+ m.copysign = function(x, y) {
79
+ return Math.abs(x) * (y < 0 || y === 0 && 1 / y < 0 ? -1 : 1);
80
+ };
81
+ m.sum = function(u, v) {
82
+ var s = u + v, up = s - v, vpp = s - up, t;
83
+ up -= u;
84
+ vpp -= v;
85
+ t = s ? 0 - (up + vpp) : s;
86
+ return { s, t };
87
+ };
88
+ m.polyval = function(N, p, s, x) {
89
+ var y = N < 0 ? 0 : p[s++];
90
+ while (--N >= 0)
91
+ y = y * x + p[s++];
92
+ return y;
93
+ };
94
+ m.AngRound = function(x) {
95
+ var z = 1 / 16, y = Math.abs(x);
96
+ y = y < z ? z - (z - y) : y;
97
+ return m.copysign(y, x);
98
+ };
99
+ m.remainder = function(x, y) {
100
+ x %= y;
101
+ return x < -y / 2 ? x + y : x < y / 2 ? x : x - y;
102
+ };
103
+ m.AngNormalize = function(x) {
104
+ var y = m.remainder(x, 360);
105
+ return Math.abs(y) === 180 ? m.copysign(180, x) : y;
106
+ };
107
+ m.LatFix = function(x) {
108
+ return Math.abs(x) > 90 ? NaN : x;
109
+ };
110
+ m.AngDiff = function(x, y) {
111
+ var r = m.sum(m.remainder(-x, 360), m.remainder(y, 360)), d, e;
112
+ r = m.sum(m.remainder(r.s, 360), r.t);
113
+ d = r.s;
114
+ e = r.t;
115
+ if (d === 0 || Math.abs(d) === 180)
116
+ d = m.copysign(d, e === 0 ? y - x : -e);
117
+ return { d, e };
118
+ };
119
+ m.sincosd = function(x) {
120
+ var d, r, q, s, c, sinx, cosx;
121
+ d = x % 360;
122
+ q = Math.round(d / 90);
123
+ d -= 90 * q;
124
+ r = d * this.degree;
125
+ s = Math.sin(r);
126
+ c = Math.cos(r);
127
+ if (Math.abs(d) === 45) {
128
+ c = Math.sqrt(0.5);
129
+ s = m.copysign(c, r);
130
+ } else if (Math.abs(d) === 30) {
131
+ c = Math.sqrt(0.75);
132
+ s = m.copysign(0.5, r);
133
+ }
134
+ switch (q & 3) {
135
+ case 0:
136
+ sinx = s;
137
+ cosx = c;
138
+ break;
139
+ case 1:
140
+ sinx = c;
141
+ cosx = -s;
142
+ break;
143
+ case 2:
144
+ sinx = -s;
145
+ cosx = -c;
146
+ break;
147
+ default:
148
+ sinx = -c;
149
+ cosx = s;
150
+ break;
151
+ }
152
+ cosx += 0;
153
+ if (sinx === 0)
154
+ sinx = m.copysign(sinx, x);
155
+ return { s: sinx, c: cosx };
156
+ };
157
+ m.sincosde = function(x, t) {
158
+ var d, r, q, s, c, sinx, cosx;
159
+ d = x % 360;
160
+ q = Math.round(d / 90);
161
+ d = m.AngRound(d - 90 * q + t);
162
+ r = d * this.degree;
163
+ s = Math.sin(r);
164
+ c = Math.cos(r);
165
+ if (Math.abs(d) === 45) {
166
+ c = Math.sqrt(0.5);
167
+ s = m.copysign(c, r);
168
+ } else if (Math.abs(d) === 30) {
169
+ c = Math.sqrt(0.75);
170
+ s = m.copysign(0.5, r);
171
+ }
172
+ switch (q & 3) {
173
+ case 0:
174
+ sinx = s;
175
+ cosx = c;
176
+ break;
177
+ case 1:
178
+ sinx = c;
179
+ cosx = -s;
180
+ break;
181
+ case 2:
182
+ sinx = -s;
183
+ cosx = -c;
184
+ break;
185
+ default:
186
+ sinx = -c;
187
+ cosx = s;
188
+ break;
189
+ }
190
+ cosx += 0;
191
+ if (sinx === 0)
192
+ sinx = m.copysign(sinx, x + t);
193
+ return { s: sinx, c: cosx };
194
+ };
195
+ m.atan2d = function(y, x) {
196
+ var q = 0, ang;
197
+ if (Math.abs(y) > Math.abs(x)) {
198
+ [y, x] = [x, y];
199
+ q = 2;
200
+ }
201
+ if (m.copysign(1, x) < 0) {
202
+ x = -x;
203
+ ++q;
204
+ }
205
+ ang = Math.atan2(y, x) / this.degree;
206
+ switch (q) {
207
+ // Note that atan2d(-0.0, 1.0) will return -0. However, we expect that
208
+ // atan2d will not be called with y = -0. If need be, include
209
+ //
210
+ // case 0: ang = 0 + ang; break;
211
+ //
212
+ // and handle mpfr as in AngRound.
213
+ case 1:
214
+ ang = m.copysign(180, y) - ang;
215
+ break;
216
+ case 2:
217
+ ang = 90 - ang;
218
+ break;
219
+ case 3:
220
+ ang = -90 + ang;
221
+ break;
222
+ default:
223
+ break;
224
+ }
225
+ return ang;
226
+ };
227
+ })(geodesic.Math);
228
+ (function(a, m) {
229
+ "use strict";
230
+ a.Accumulator = function(y) {
231
+ this.Set(y);
232
+ };
233
+ a.Accumulator.prototype.Set = function(y) {
234
+ if (!y)
235
+ y = 0;
236
+ if (y.constructor === a.Accumulator) {
237
+ this._s = y._s;
238
+ this._t = y._t;
239
+ } else {
240
+ this._s = y;
241
+ this._t = 0;
242
+ }
243
+ };
244
+ a.Accumulator.prototype.Add = function(y) {
245
+ var u = m.sum(y, this._t), v = m.sum(u.s, this._s);
246
+ u = u.t;
247
+ this._s = v.s;
248
+ this._t = v.t;
249
+ if (this._s === 0)
250
+ this._s = u;
251
+ else
252
+ this._t += u;
253
+ };
254
+ a.Accumulator.prototype.Sum = function(y) {
255
+ var b;
256
+ if (!y)
257
+ return this._s;
258
+ else {
259
+ b = new a.Accumulator(this);
260
+ b.Add(y);
261
+ return b._s;
262
+ }
263
+ };
264
+ a.Accumulator.prototype.Negate = function() {
265
+ this._s *= -1;
266
+ this._t *= -1;
267
+ };
268
+ a.Accumulator.prototype.Remainder = function(y) {
269
+ this._s = m.remainder(this._s, y);
270
+ this.Add(0);
271
+ };
272
+ })(geodesic.Accumulator, geodesic.Math);
273
+ geodesic.Geodesic = {};
274
+ geodesic.GeodesicLine = {};
275
+ geodesic.PolygonArea = {};
276
+ (function(g, l, p, m, c) {
277
+ "use strict";
278
+ var GEOGRAPHICLIB_GEODESIC_ORDER = 6, nA1_ = GEOGRAPHICLIB_GEODESIC_ORDER, nA2_ = GEOGRAPHICLIB_GEODESIC_ORDER, nA3_ = GEOGRAPHICLIB_GEODESIC_ORDER, nA3x_ = nA3_, nC3x_, nC4x_, maxit1_ = 20, maxit2_ = maxit1_ + m.digits + 10, tol0_ = m.epsilon, tol1_ = 200 * tol0_, tol2_ = Math.sqrt(tol0_), tolb_ = tol0_, xthresh_ = 1e3 * tol2_, CAP_NONE = 0, CAP_ALL = 31, OUT_ALL = 32640, astroid, A1m1f_coeff, C1f_coeff, C1pf_coeff, A2m1f_coeff, C2f_coeff, A3_coeff, C3_coeff, C4_coeff;
279
+ g.tiny_ = Math.sqrt(Number.MIN_VALUE / Number.EPSILON);
280
+ g.nC1_ = GEOGRAPHICLIB_GEODESIC_ORDER;
281
+ g.nC1p_ = GEOGRAPHICLIB_GEODESIC_ORDER;
282
+ g.nC2_ = GEOGRAPHICLIB_GEODESIC_ORDER;
283
+ g.nC3_ = GEOGRAPHICLIB_GEODESIC_ORDER;
284
+ g.nC4_ = GEOGRAPHICLIB_GEODESIC_ORDER;
285
+ nC3x_ = g.nC3_ * (g.nC3_ - 1) / 2;
286
+ nC4x_ = g.nC4_ * (g.nC4_ + 1) / 2;
287
+ g.CAP_C1 = 1 << 0;
288
+ g.CAP_C1p = 1 << 1;
289
+ g.CAP_C2 = 1 << 2;
290
+ g.CAP_C3 = 1 << 3;
291
+ g.CAP_C4 = 1 << 4;
292
+ g.NONE = 0;
293
+ g.ARC = 1 << 6;
294
+ g.LATITUDE = 1 << 7 | CAP_NONE;
295
+ g.LONGITUDE = 1 << 8 | g.CAP_C3;
296
+ g.AZIMUTH = 1 << 9 | CAP_NONE;
297
+ g.DISTANCE = 1 << 10 | g.CAP_C1;
298
+ g.STANDARD = g.LATITUDE | g.LONGITUDE | g.AZIMUTH | g.DISTANCE;
299
+ g.DISTANCE_IN = 1 << 11 | g.CAP_C1 | g.CAP_C1p;
300
+ g.REDUCEDLENGTH = 1 << 12 | g.CAP_C1 | g.CAP_C2;
301
+ g.GEODESICSCALE = 1 << 13 | g.CAP_C1 | g.CAP_C2;
302
+ g.AREA = 1 << 14 | g.CAP_C4;
303
+ g.ALL = OUT_ALL | CAP_ALL;
304
+ g.LONG_UNROLL = 1 << 15;
305
+ g.OUT_MASK = OUT_ALL | g.LONG_UNROLL;
306
+ g.SinCosSeries = function(sinp, sinx, cosx, c2, delta) {
307
+ if (delta !== void 0) {
308
+ var h = delta / 2, sh = Math.sin(h), ch = Math.cos(h);
309
+ return -2 * g.SinCosSeries(false, cosx * ch - sinx * sh, sinx * ch + cosx * sh, c2.map(function(v, i) {
310
+ return (i % 2 ? -v : v) * Math.sin((2 * i + 1) * h);
311
+ }));
312
+ }
313
+ var k = c2.length, n = k - (sinp ? 1 : 0), ar = 2 * (cosx - sinx) * (cosx + sinx), y0 = n & 1 ? c2[--k] : 0, y1 = 0;
314
+ n = Math.floor(n / 2);
315
+ while (n--) {
316
+ y1 = ar * y0 - y1 + c2[--k];
317
+ y0 = ar * y1 - y0 + c2[--k];
318
+ }
319
+ return sinp ? 2 * sinx * cosx * y0 : (
320
+ // sin(2 * x) * y0
321
+ cosx * (y0 - y1)
322
+ );
323
+ };
324
+ astroid = function(x, y) {
325
+ var k, p2 = m.sq(x), q = m.sq(y), r = (p2 + q - 1) / 6, S, r2, r3, disc, u, T3, T, ang, v, uv, w;
326
+ if (!(q === 0 && r <= 0)) {
327
+ S = p2 * q / 4;
328
+ r2 = m.sq(r);
329
+ r3 = r * r2;
330
+ disc = S * (S + 2 * r3);
331
+ u = r;
332
+ if (disc >= 0) {
333
+ T3 = S + r3;
334
+ T3 += T3 < 0 ? -Math.sqrt(disc) : Math.sqrt(disc);
335
+ T = m.cbrt(T3);
336
+ u += T + (T !== 0 ? r2 / T : 0);
337
+ } else {
338
+ ang = Math.atan2(Math.sqrt(-disc), -(S + r3));
339
+ u += 2 * r * Math.cos(ang / 3);
340
+ }
341
+ v = Math.sqrt(m.sq(u) + q);
342
+ uv = u < 0 ? q / (v - u) : u + v;
343
+ w = (uv - q) / (2 * v);
344
+ k = uv / (Math.sqrt(uv + m.sq(w)) + w);
345
+ } else {
346
+ k = 0;
347
+ }
348
+ return k;
349
+ };
350
+ A1m1f_coeff = [
351
+ // (1-eps)*A1-1, polynomial in eps2 of order 3
352
+ 1,
353
+ 4,
354
+ 64,
355
+ 0,
356
+ 256
357
+ ];
358
+ g.A1m1f = function(eps) {
359
+ var p2 = Math.floor(nA1_ / 2), t = m.polyval(p2, A1m1f_coeff, 0, m.sq(eps)) / A1m1f_coeff[p2 + 1];
360
+ return (t + eps) / (1 - eps);
361
+ };
362
+ C1f_coeff = [
363
+ // C1[1]/eps^1, polynomial in eps2 of order 2
364
+ -1,
365
+ 6,
366
+ -16,
367
+ 32,
368
+ // C1[2]/eps^2, polynomial in eps2 of order 2
369
+ -9,
370
+ 64,
371
+ -128,
372
+ 2048,
373
+ // C1[3]/eps^3, polynomial in eps2 of order 1
374
+ 9,
375
+ -16,
376
+ 768,
377
+ // C1[4]/eps^4, polynomial in eps2 of order 1
378
+ 3,
379
+ -5,
380
+ 512,
381
+ // C1[5]/eps^5, polynomial in eps2 of order 0
382
+ -7,
383
+ 1280,
384
+ // C1[6]/eps^6, polynomial in eps2 of order 0
385
+ -7,
386
+ 2048
387
+ ];
388
+ g.C1f = function(eps, c2) {
389
+ var eps2 = m.sq(eps), d = eps, o = 0, l2, p2;
390
+ for (l2 = 1; l2 <= g.nC1_; ++l2) {
391
+ p2 = Math.floor((g.nC1_ - l2) / 2);
392
+ c2[l2] = d * m.polyval(p2, C1f_coeff, o, eps2) / C1f_coeff[o + p2 + 1];
393
+ o += p2 + 2;
394
+ d *= eps;
395
+ }
396
+ };
397
+ C1pf_coeff = [
398
+ // C1p[1]/eps^1, polynomial in eps2 of order 2
399
+ 205,
400
+ -432,
401
+ 768,
402
+ 1536,
403
+ // C1p[2]/eps^2, polynomial in eps2 of order 2
404
+ 4005,
405
+ -4736,
406
+ 3840,
407
+ 12288,
408
+ // C1p[3]/eps^3, polynomial in eps2 of order 1
409
+ -225,
410
+ 116,
411
+ 384,
412
+ // C1p[4]/eps^4, polynomial in eps2 of order 1
413
+ -7173,
414
+ 2695,
415
+ 7680,
416
+ // C1p[5]/eps^5, polynomial in eps2 of order 0
417
+ 3467,
418
+ 7680,
419
+ // C1p[6]/eps^6, polynomial in eps2 of order 0
420
+ 38081,
421
+ 61440
422
+ ];
423
+ g.C1pf = function(eps, c2) {
424
+ var eps2 = m.sq(eps), d = eps, o = 0, l2, p2;
425
+ for (l2 = 1; l2 <= g.nC1p_; ++l2) {
426
+ p2 = Math.floor((g.nC1p_ - l2) / 2);
427
+ c2[l2] = d * m.polyval(p2, C1pf_coeff, o, eps2) / C1pf_coeff[o + p2 + 1];
428
+ o += p2 + 2;
429
+ d *= eps;
430
+ }
431
+ };
432
+ A2m1f_coeff = [
433
+ // (eps+1)*A2-1, polynomial in eps2 of order 3
434
+ -11,
435
+ -28,
436
+ -192,
437
+ 0,
438
+ 256
439
+ ];
440
+ g.A2m1f = function(eps) {
441
+ var p2 = Math.floor(nA2_ / 2), t = m.polyval(p2, A2m1f_coeff, 0, m.sq(eps)) / A2m1f_coeff[p2 + 1];
442
+ return (t - eps) / (1 + eps);
443
+ };
444
+ C2f_coeff = [
445
+ // C2[1]/eps^1, polynomial in eps2 of order 2
446
+ 1,
447
+ 2,
448
+ 16,
449
+ 32,
450
+ // C2[2]/eps^2, polynomial in eps2 of order 2
451
+ 35,
452
+ 64,
453
+ 384,
454
+ 2048,
455
+ // C2[3]/eps^3, polynomial in eps2 of order 1
456
+ 15,
457
+ 80,
458
+ 768,
459
+ // C2[4]/eps^4, polynomial in eps2 of order 1
460
+ 7,
461
+ 35,
462
+ 512,
463
+ // C2[5]/eps^5, polynomial in eps2 of order 0
464
+ 63,
465
+ 1280,
466
+ // C2[6]/eps^6, polynomial in eps2 of order 0
467
+ 77,
468
+ 2048
469
+ ];
470
+ g.C2f = function(eps, c2) {
471
+ var eps2 = m.sq(eps), d = eps, o = 0, l2, p2;
472
+ for (l2 = 1; l2 <= g.nC2_; ++l2) {
473
+ p2 = Math.floor((g.nC2_ - l2) / 2);
474
+ c2[l2] = d * m.polyval(p2, C2f_coeff, o, eps2) / C2f_coeff[o + p2 + 1];
475
+ o += p2 + 2;
476
+ d *= eps;
477
+ }
478
+ };
479
+ g.Geodesic = function(a, f) {
480
+ this.a = a;
481
+ this.f = f;
482
+ this._f1 = 1 - this.f;
483
+ this._e2 = this.f * (2 - this.f);
484
+ this._ep2 = this._e2 / m.sq(this._f1);
485
+ this._n = this.f / (2 - this.f);
486
+ this._b = this.a * this._f1;
487
+ this._c2 = (m.sq(this.a) + m.sq(this._b) * (this._e2 === 0 ? 1 : (this._e2 > 0 ? m.atanh(Math.sqrt(this._e2)) : Math.atan(Math.sqrt(-this._e2))) / Math.sqrt(Math.abs(this._e2)))) / 2;
488
+ this._etol2 = 0.1 * tol2_ / Math.sqrt(Math.max(1e-3, Math.abs(this.f)) * Math.min(1, 1 - this.f / 2) / 2);
489
+ if (!(isFinite(this.a) && this.a > 0))
490
+ throw new Error("Equatorial radius is not positive");
491
+ if (!(isFinite(this._b) && this._b > 0))
492
+ throw new Error("Polar semi-axis is not positive");
493
+ this._A3x = new Array(nA3x_);
494
+ this._C3x = new Array(nC3x_);
495
+ this._C4x = new Array(nC4x_);
496
+ this.A3coeff();
497
+ this.C3coeff();
498
+ this.C4coeff();
499
+ };
500
+ A3_coeff = [
501
+ // A3, coeff of eps^5, polynomial in n of order 0
502
+ -3,
503
+ 128,
504
+ // A3, coeff of eps^4, polynomial in n of order 1
505
+ -2,
506
+ -3,
507
+ 64,
508
+ // A3, coeff of eps^3, polynomial in n of order 2
509
+ -1,
510
+ -3,
511
+ -1,
512
+ 16,
513
+ // A3, coeff of eps^2, polynomial in n of order 2
514
+ 3,
515
+ -1,
516
+ -2,
517
+ 8,
518
+ // A3, coeff of eps^1, polynomial in n of order 1
519
+ 1,
520
+ -1,
521
+ 2,
522
+ // A3, coeff of eps^0, polynomial in n of order 0
523
+ 1,
524
+ 1
525
+ ];
526
+ g.Geodesic.prototype.A3coeff = function() {
527
+ var o = 0, k = 0, j, p2;
528
+ for (j = nA3_ - 1; j >= 0; --j) {
529
+ p2 = Math.min(nA3_ - j - 1, j);
530
+ this._A3x[k++] = m.polyval(p2, A3_coeff, o, this._n) / A3_coeff[o + p2 + 1];
531
+ o += p2 + 2;
532
+ }
533
+ };
534
+ C3_coeff = [
535
+ // C3[1], coeff of eps^5, polynomial in n of order 0
536
+ 3,
537
+ 128,
538
+ // C3[1], coeff of eps^4, polynomial in n of order 1
539
+ 2,
540
+ 5,
541
+ 128,
542
+ // C3[1], coeff of eps^3, polynomial in n of order 2
543
+ -1,
544
+ 3,
545
+ 3,
546
+ 64,
547
+ // C3[1], coeff of eps^2, polynomial in n of order 2
548
+ -1,
549
+ 0,
550
+ 1,
551
+ 8,
552
+ // C3[1], coeff of eps^1, polynomial in n of order 1
553
+ -1,
554
+ 1,
555
+ 4,
556
+ // C3[2], coeff of eps^5, polynomial in n of order 0
557
+ 5,
558
+ 256,
559
+ // C3[2], coeff of eps^4, polynomial in n of order 1
560
+ 1,
561
+ 3,
562
+ 128,
563
+ // C3[2], coeff of eps^3, polynomial in n of order 2
564
+ -3,
565
+ -2,
566
+ 3,
567
+ 64,
568
+ // C3[2], coeff of eps^2, polynomial in n of order 2
569
+ 1,
570
+ -3,
571
+ 2,
572
+ 32,
573
+ // C3[3], coeff of eps^5, polynomial in n of order 0
574
+ 7,
575
+ 512,
576
+ // C3[3], coeff of eps^4, polynomial in n of order 1
577
+ -10,
578
+ 9,
579
+ 384,
580
+ // C3[3], coeff of eps^3, polynomial in n of order 2
581
+ 5,
582
+ -9,
583
+ 5,
584
+ 192,
585
+ // C3[4], coeff of eps^5, polynomial in n of order 0
586
+ 7,
587
+ 512,
588
+ // C3[4], coeff of eps^4, polynomial in n of order 1
589
+ -14,
590
+ 7,
591
+ 512,
592
+ // C3[5], coeff of eps^5, polynomial in n of order 0
593
+ 21,
594
+ 2560
595
+ ];
596
+ g.Geodesic.prototype.C3coeff = function() {
597
+ var o = 0, k = 0, l2, j, p2;
598
+ for (l2 = 1; l2 < g.nC3_; ++l2) {
599
+ for (j = g.nC3_ - 1; j >= l2; --j) {
600
+ p2 = Math.min(g.nC3_ - j - 1, j);
601
+ this._C3x[k++] = m.polyval(p2, C3_coeff, o, this._n) / C3_coeff[o + p2 + 1];
602
+ o += p2 + 2;
603
+ }
604
+ }
605
+ };
606
+ C4_coeff = [
607
+ // C4[0], coeff of eps^5, polynomial in n of order 0
608
+ 97,
609
+ 15015,
610
+ // C4[0], coeff of eps^4, polynomial in n of order 1
611
+ 1088,
612
+ 156,
613
+ 45045,
614
+ // C4[0], coeff of eps^3, polynomial in n of order 2
615
+ -224,
616
+ -4784,
617
+ 1573,
618
+ 45045,
619
+ // C4[0], coeff of eps^2, polynomial in n of order 3
620
+ -10656,
621
+ 14144,
622
+ -4576,
623
+ -858,
624
+ 45045,
625
+ // C4[0], coeff of eps^1, polynomial in n of order 4
626
+ 64,
627
+ 624,
628
+ -4576,
629
+ 6864,
630
+ -3003,
631
+ 15015,
632
+ // C4[0], coeff of eps^0, polynomial in n of order 5
633
+ 100,
634
+ 208,
635
+ 572,
636
+ 3432,
637
+ -12012,
638
+ 30030,
639
+ 45045,
640
+ // C4[1], coeff of eps^5, polynomial in n of order 0
641
+ 1,
642
+ 9009,
643
+ // C4[1], coeff of eps^4, polynomial in n of order 1
644
+ -2944,
645
+ 468,
646
+ 135135,
647
+ // C4[1], coeff of eps^3, polynomial in n of order 2
648
+ 5792,
649
+ 1040,
650
+ -1287,
651
+ 135135,
652
+ // C4[1], coeff of eps^2, polynomial in n of order 3
653
+ 5952,
654
+ -11648,
655
+ 9152,
656
+ -2574,
657
+ 135135,
658
+ // C4[1], coeff of eps^1, polynomial in n of order 4
659
+ -64,
660
+ -624,
661
+ 4576,
662
+ -6864,
663
+ 3003,
664
+ 135135,
665
+ // C4[2], coeff of eps^5, polynomial in n of order 0
666
+ 8,
667
+ 10725,
668
+ // C4[2], coeff of eps^4, polynomial in n of order 1
669
+ 1856,
670
+ -936,
671
+ 225225,
672
+ // C4[2], coeff of eps^3, polynomial in n of order 2
673
+ -8448,
674
+ 4992,
675
+ -1144,
676
+ 225225,
677
+ // C4[2], coeff of eps^2, polynomial in n of order 3
678
+ -1440,
679
+ 4160,
680
+ -4576,
681
+ 1716,
682
+ 225225,
683
+ // C4[3], coeff of eps^5, polynomial in n of order 0
684
+ -136,
685
+ 63063,
686
+ // C4[3], coeff of eps^4, polynomial in n of order 1
687
+ 1024,
688
+ -208,
689
+ 105105,
690
+ // C4[3], coeff of eps^3, polynomial in n of order 2
691
+ 3584,
692
+ -3328,
693
+ 1144,
694
+ 315315,
695
+ // C4[4], coeff of eps^5, polynomial in n of order 0
696
+ -128,
697
+ 135135,
698
+ // C4[4], coeff of eps^4, polynomial in n of order 1
699
+ -2560,
700
+ 832,
701
+ 405405,
702
+ // C4[5], coeff of eps^5, polynomial in n of order 0
703
+ 128,
704
+ 99099
705
+ ];
706
+ g.Geodesic.prototype.C4coeff = function() {
707
+ var o = 0, k = 0, l2, j, p2;
708
+ for (l2 = 0; l2 < g.nC4_; ++l2) {
709
+ for (j = g.nC4_ - 1; j >= l2; --j) {
710
+ p2 = g.nC4_ - j - 1;
711
+ this._C4x[k++] = m.polyval(p2, C4_coeff, o, this._n) / C4_coeff[o + p2 + 1];
712
+ o += p2 + 2;
713
+ }
714
+ }
715
+ };
716
+ g.Geodesic.prototype.A3f = function(eps) {
717
+ return m.polyval(nA3x_ - 1, this._A3x, 0, eps);
718
+ };
719
+ g.Geodesic.prototype.C3f = function(eps, c2) {
720
+ var mult = 1, o = 0, l2, p2;
721
+ for (l2 = 1; l2 < g.nC3_; ++l2) {
722
+ p2 = g.nC3_ - l2 - 1;
723
+ mult *= eps;
724
+ c2[l2] = mult * m.polyval(p2, this._C3x, o, eps);
725
+ o += p2 + 1;
726
+ }
727
+ };
728
+ g.Geodesic.prototype.C4f = function(eps, c2) {
729
+ var mult = 1, o = 0, l2, p2;
730
+ for (l2 = 0; l2 < g.nC4_; ++l2) {
731
+ p2 = g.nC4_ - l2 - 1;
732
+ c2[l2] = mult * m.polyval(p2, this._C4x, o, eps);
733
+ o += p2 + 1;
734
+ mult *= eps;
735
+ }
736
+ };
737
+ g.Geodesic.prototype.Lengths = function(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, outmask, C1a, C2a) {
738
+ outmask &= g.OUT_MASK;
739
+ var vals = {}, m0x = 0, J12 = 0, A1 = 0, A2 = 0, B1, B2, l2, csig12, t;
740
+ if (outmask & (g.DISTANCE | g.REDUCEDLENGTH | g.GEODESICSCALE)) {
741
+ A1 = g.A1m1f(eps);
742
+ g.C1f(eps, C1a);
743
+ if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
744
+ A2 = g.A2m1f(eps);
745
+ g.C2f(eps, C2a);
746
+ m0x = A1 - A2;
747
+ A2 = 1 + A2;
748
+ }
749
+ A1 = 1 + A1;
750
+ }
751
+ if (outmask & g.DISTANCE) {
752
+ B1 = g.SinCosSeries(true, ssig2, csig2, C1a) - g.SinCosSeries(true, ssig1, csig1, C1a);
753
+ vals.s12b = A1 * (sig12 + B1);
754
+ if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
755
+ B2 = g.SinCosSeries(true, ssig2, csig2, C2a) - g.SinCosSeries(true, ssig1, csig1, C2a);
756
+ J12 = m0x * sig12 + (A1 * B1 - A2 * B2);
757
+ }
758
+ } else if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
759
+ for (l2 = 1; l2 <= g.nC2_; ++l2)
760
+ C2a[l2] = A1 * C1a[l2] - A2 * C2a[l2];
761
+ J12 = m0x * sig12 + (g.SinCosSeries(true, ssig2, csig2, C2a) - g.SinCosSeries(true, ssig1, csig1, C2a));
762
+ }
763
+ if (outmask & g.REDUCEDLENGTH) {
764
+ vals.m0 = m0x;
765
+ vals.m12b = dn2 * (csig1 * ssig2) - dn1 * (ssig1 * csig2) - csig1 * csig2 * J12;
766
+ } else
767
+ vals.m12b = NaN;
768
+ if (outmask & g.GEODESICSCALE) {
769
+ csig12 = csig1 * csig2 + ssig1 * ssig2;
770
+ t = this._ep2 * (cbet1 - cbet2) * (cbet1 + cbet2) / (dn1 + dn2);
771
+ vals.M12 = csig12 + (t * ssig2 - csig2 * J12) * ssig1 / dn1;
772
+ vals.M21 = csig12 - (t * ssig1 - csig1 * J12) * ssig2 / dn2;
773
+ }
774
+ return vals;
775
+ };
776
+ g.Geodesic.prototype.InverseStart = function(sbet1, cbet1, dn1, sbet2, cbet2, dn2, lam12, slam12, clam12, C1a, C2a) {
777
+ var vals = {}, sbet12 = sbet2 * cbet1 - cbet2 * sbet1, cbet12 = cbet2 * cbet1 + sbet2 * sbet1, sbet12a, shortline, omg12, sbetm2, somg12, comg12, t, ssig12, csig12, x, y, lamscale, betscale, k2, eps, cbet12a, bet12a, m12b, m0, nvals, k, omg12a, lam12x;
778
+ vals.sig12 = -1;
779
+ sbet12a = sbet2 * cbet1;
780
+ sbet12a += cbet2 * sbet1;
781
+ shortline = cbet12 >= 0 && sbet12 < 0.5 && cbet2 * lam12 < 0.5;
782
+ if (shortline) {
783
+ sbetm2 = m.sq(sbet1 + sbet2);
784
+ sbetm2 /= sbetm2 + m.sq(cbet1 + cbet2);
785
+ vals.dnm = Math.sqrt(1 + this._ep2 * sbetm2);
786
+ omg12 = lam12 / (this._f1 * vals.dnm);
787
+ somg12 = Math.sin(omg12);
788
+ comg12 = Math.cos(omg12);
789
+ } else {
790
+ somg12 = slam12;
791
+ comg12 = clam12;
792
+ }
793
+ vals.salp1 = cbet2 * somg12;
794
+ vals.calp1 = comg12 >= 0 ? sbet12 + cbet2 * sbet1 * m.sq(somg12) / (1 + comg12) : sbet12a - cbet2 * sbet1 * m.sq(somg12) / (1 - comg12);
795
+ ssig12 = m.hypot(vals.salp1, vals.calp1);
796
+ csig12 = sbet1 * sbet2 + cbet1 * cbet2 * comg12;
797
+ if (shortline && ssig12 < this._etol2) {
798
+ vals.salp2 = cbet1 * somg12;
799
+ vals.calp2 = sbet12 - cbet1 * sbet2 * (comg12 >= 0 ? m.sq(somg12) / (1 + comg12) : 1 - comg12);
800
+ t = m.hypot(vals.salp2, vals.calp2);
801
+ vals.salp2 /= t;
802
+ vals.calp2 /= t;
803
+ vals.sig12 = Math.atan2(ssig12, csig12);
804
+ } else if (Math.abs(this._n) > 0.1 || // Skip astroid calc if too eccentric
805
+ csig12 >= 0 || ssig12 >= 6 * Math.abs(this._n) * Math.PI * m.sq(cbet1)) {
806
+ } else {
807
+ lam12x = Math.atan2(-slam12, -clam12);
808
+ if (this.f >= 0) {
809
+ k2 = m.sq(sbet1) * this._ep2;
810
+ eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
811
+ lamscale = this.f * cbet1 * this.A3f(eps) * Math.PI;
812
+ betscale = lamscale * cbet1;
813
+ x = lam12x / lamscale;
814
+ y = sbet12a / betscale;
815
+ } else {
816
+ cbet12a = cbet2 * cbet1 - sbet2 * sbet1;
817
+ bet12a = Math.atan2(sbet12a, cbet12a);
818
+ nvals = this.Lengths(this._n, Math.PI + bet12a, sbet1, -cbet1, dn1, sbet2, cbet2, dn2, cbet1, cbet2, g.REDUCEDLENGTH, C1a, C2a);
819
+ m12b = nvals.m12b;
820
+ m0 = nvals.m0;
821
+ x = -1 + m12b / (cbet1 * cbet2 * m0 * Math.PI);
822
+ betscale = x < -0.01 ? sbet12a / x : -this.f * m.sq(cbet1) * Math.PI;
823
+ lamscale = betscale / cbet1;
824
+ y = lam12 / lamscale;
825
+ }
826
+ if (y > -tol1_ && x > -1 - xthresh_) {
827
+ if (this.f >= 0) {
828
+ vals.salp1 = Math.min(1, -x);
829
+ vals.calp1 = -Math.sqrt(1 - m.sq(vals.salp1));
830
+ } else {
831
+ vals.calp1 = Math.max(x > -tol1_ ? 0 : -1, x);
832
+ vals.salp1 = Math.sqrt(1 - m.sq(vals.calp1));
833
+ }
834
+ } else {
835
+ k = astroid(x, y);
836
+ omg12a = lamscale * (this.f >= 0 ? -x * k / (1 + k) : -y * (1 + k) / k);
837
+ somg12 = Math.sin(omg12a);
838
+ comg12 = -Math.cos(omg12a);
839
+ vals.salp1 = cbet2 * somg12;
840
+ vals.calp1 = sbet12a - cbet2 * sbet1 * m.sq(somg12) / (1 - comg12);
841
+ }
842
+ }
843
+ if (!(vals.salp1 <= 0)) {
844
+ t = m.hypot(vals.salp1, vals.calp1);
845
+ vals.salp1 /= t;
846
+ vals.calp1 /= t;
847
+ } else {
848
+ vals.salp1 = 1;
849
+ vals.calp1 = 0;
850
+ }
851
+ return vals;
852
+ };
853
+ g.Geodesic.prototype.Lambda12 = function(sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1, slam120, clam120, diffp, C1a, C2a, C3a) {
854
+ var vals = {}, t, salp0, calp0, somg1, comg1, somg2, comg2, somg12, comg12, B312, eta, k2, nvals;
855
+ if (sbet1 === 0 && calp1 === 0)
856
+ calp1 = -g.tiny_;
857
+ salp0 = salp1 * cbet1;
858
+ calp0 = m.hypot(calp1, salp1 * sbet1);
859
+ vals.ssig1 = sbet1;
860
+ somg1 = salp0 * sbet1;
861
+ vals.csig1 = comg1 = calp1 * cbet1;
862
+ t = m.hypot(vals.ssig1, vals.csig1);
863
+ vals.ssig1 /= t;
864
+ vals.csig1 /= t;
865
+ vals.salp2 = cbet2 !== cbet1 ? salp0 / cbet2 : salp1;
866
+ vals.calp2 = cbet2 !== cbet1 || Math.abs(sbet2) !== -sbet1 ? Math.sqrt(m.sq(calp1 * cbet1) + (cbet1 < -sbet1 ? (cbet2 - cbet1) * (cbet1 + cbet2) : (sbet1 - sbet2) * (sbet1 + sbet2))) / cbet2 : Math.abs(calp1);
867
+ vals.ssig2 = sbet2;
868
+ somg2 = salp0 * sbet2;
869
+ vals.csig2 = comg2 = vals.calp2 * cbet2;
870
+ t = m.hypot(vals.ssig2, vals.csig2);
871
+ vals.ssig2 /= t;
872
+ vals.csig2 /= t;
873
+ vals.sig12 = Math.atan2(Math.max(0, vals.csig1 * vals.ssig2 - vals.ssig1 * vals.csig2), vals.csig1 * vals.csig2 + vals.ssig1 * vals.ssig2);
874
+ somg12 = Math.max(0, comg1 * somg2 - somg1 * comg2);
875
+ comg12 = comg1 * comg2 + somg1 * somg2;
876
+ eta = Math.atan2(somg12 * clam120 - comg12 * slam120, comg12 * clam120 + somg12 * slam120);
877
+ k2 = m.sq(calp0) * this._ep2;
878
+ vals.eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
879
+ this.C3f(vals.eps, C3a);
880
+ B312 = g.SinCosSeries(true, vals.ssig2, vals.csig2, C3a) - g.SinCosSeries(true, vals.ssig1, vals.csig1, C3a);
881
+ vals.domg12 = -this.f * this.A3f(vals.eps) * salp0 * (vals.sig12 + B312);
882
+ vals.lam12 = eta + vals.domg12;
883
+ if (diffp) {
884
+ if (vals.calp2 === 0)
885
+ vals.dlam12 = -2 * this._f1 * dn1 / sbet1;
886
+ else {
887
+ nvals = this.Lengths(vals.eps, vals.sig12, vals.ssig1, vals.csig1, dn1, vals.ssig2, vals.csig2, dn2, cbet1, cbet2, g.REDUCEDLENGTH, C1a, C2a);
888
+ vals.dlam12 = nvals.m12b;
889
+ vals.dlam12 *= this._f1 / (vals.calp2 * cbet2);
890
+ }
891
+ }
892
+ return vals;
893
+ };
894
+ g.Geodesic.prototype.Inverse = function(lat1, lon1, lat2, lon2, outmask) {
895
+ var r, vals;
896
+ if (!outmask)
897
+ outmask = g.STANDARD;
898
+ if (outmask === g.LONG_UNROLL)
899
+ outmask |= g.STANDARD;
900
+ outmask &= g.OUT_MASK;
901
+ r = this.InverseInt(lat1, lon1, lat2, lon2, outmask);
902
+ vals = r.vals;
903
+ if (outmask & g.AZIMUTH) {
904
+ vals.azi1 = m.atan2d(r.salp1, r.calp1);
905
+ vals.azi2 = m.atan2d(r.salp2, r.calp2);
906
+ }
907
+ return vals;
908
+ };
909
+ g.Geodesic.prototype.InverseInt = function(lat1, lon1, lat2, lon2, outmask) {
910
+ var vals = {}, lon12, lon12s, lonsign, t, swapp, latsign, sbet1, cbet1, sbet2, cbet2, s12x, m12x, dn1, dn2, lam12, slam12, clam12, sig12, calp1, salp1, calp2, salp2, C1a, C2a, C3a, meridian, nvals, ssig1, csig1, ssig2, csig2, eps, omg12, dnm, numit, salp1a, calp1a, salp1b, calp1b, tripn, tripb, v, dv, dalp1, sdalp1, cdalp1, nsalp1, lengthmask, salp0, calp0, alp12, k2, A4, C4a, B41, B42, somg12, comg12, domg12, dbet1, dbet2, salp12, calp12, sdomg12, cdomg12;
911
+ vals.lat1 = lat1 = m.LatFix(lat1);
912
+ vals.lat2 = lat2 = m.LatFix(lat2);
913
+ lat1 = m.AngRound(lat1);
914
+ lat2 = m.AngRound(lat2);
915
+ lon12 = m.AngDiff(lon1, lon2);
916
+ lon12s = lon12.e;
917
+ lon12 = lon12.d;
918
+ if (outmask & g.LONG_UNROLL) {
919
+ vals.lon1 = lon1;
920
+ vals.lon2 = lon1 + lon12 + lon12s;
921
+ } else {
922
+ vals.lon1 = m.AngNormalize(lon1);
923
+ vals.lon2 = m.AngNormalize(lon2);
924
+ }
925
+ lonsign = m.copysign(1, lon12);
926
+ lon12 *= lonsign;
927
+ lon12s *= lonsign;
928
+ lam12 = lon12 * m.degree;
929
+ t = m.sincosde(lon12, lon12s);
930
+ slam12 = t.s;
931
+ clam12 = t.c;
932
+ lon12s = 180 - lon12 - lon12s;
933
+ swapp = Math.abs(lat1) < Math.abs(lat2) || isNaN(lat2) ? -1 : 1;
934
+ if (swapp < 0) {
935
+ lonsign *= -1;
936
+ [lat2, lat1] = [lat1, lat2];
937
+ }
938
+ latsign = m.copysign(1, -lat1);
939
+ lat1 *= latsign;
940
+ lat2 *= latsign;
941
+ t = m.sincosd(lat1);
942
+ sbet1 = this._f1 * t.s;
943
+ cbet1 = t.c;
944
+ t = m.hypot(sbet1, cbet1);
945
+ sbet1 /= t;
946
+ cbet1 /= t;
947
+ cbet1 = Math.max(g.tiny_, cbet1);
948
+ t = m.sincosd(lat2);
949
+ sbet2 = this._f1 * t.s;
950
+ cbet2 = t.c;
951
+ t = m.hypot(sbet2, cbet2);
952
+ sbet2 /= t;
953
+ cbet2 /= t;
954
+ cbet2 = Math.max(g.tiny_, cbet2);
955
+ if (cbet1 < -sbet1) {
956
+ if (cbet2 === cbet1)
957
+ sbet2 = m.copysign(sbet1, sbet2);
958
+ } else {
959
+ if (Math.abs(sbet2) === -sbet1)
960
+ cbet2 = cbet1;
961
+ }
962
+ dn1 = Math.sqrt(1 + this._ep2 * m.sq(sbet1));
963
+ dn2 = Math.sqrt(1 + this._ep2 * m.sq(sbet2));
964
+ C1a = new Array(g.nC1_ + 1);
965
+ C2a = new Array(g.nC2_ + 1);
966
+ C3a = new Array(g.nC3_);
967
+ meridian = lat1 === -90 || slam12 === 0;
968
+ if (meridian) {
969
+ calp1 = clam12;
970
+ salp1 = slam12;
971
+ calp2 = 1;
972
+ salp2 = 0;
973
+ ssig1 = sbet1;
974
+ csig1 = calp1 * cbet1;
975
+ ssig2 = sbet2;
976
+ csig2 = calp2 * cbet2;
977
+ sig12 = Math.atan2(Math.max(0, csig1 * ssig2 - ssig1 * csig2), csig1 * csig2 + ssig1 * ssig2);
978
+ nvals = this.Lengths(this._n, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, outmask | g.DISTANCE | g.REDUCEDLENGTH, C1a, C2a);
979
+ s12x = nvals.s12b;
980
+ m12x = nvals.m12b;
981
+ if (outmask & g.GEODESICSCALE) {
982
+ vals.M12 = nvals.M12;
983
+ vals.M21 = nvals.M21;
984
+ }
985
+ if (sig12 < tol2_ || m12x >= 0) {
986
+ if (sig12 < 3 * g.tiny_ || // Prevent negative s12 or m12 for short lines
987
+ sig12 < tol0_ && (s12x < 0 || m12x < 0))
988
+ sig12 = m12x = s12x = 0;
989
+ m12x *= this._b;
990
+ s12x *= this._b;
991
+ vals.a12 = sig12 / m.degree;
992
+ } else
993
+ meridian = false;
994
+ }
995
+ somg12 = 2;
996
+ if (!meridian && sbet1 === 0 && // and sbet2 == 0
997
+ (this.f <= 0 || lon12s >= this.f * 180)) {
998
+ calp1 = calp2 = 0;
999
+ salp1 = salp2 = 1;
1000
+ s12x = this.a * lam12;
1001
+ sig12 = omg12 = lam12 / this._f1;
1002
+ m12x = this._b * Math.sin(sig12);
1003
+ if (outmask & g.GEODESICSCALE)
1004
+ vals.M12 = vals.M21 = Math.cos(sig12);
1005
+ vals.a12 = lon12 / this._f1;
1006
+ } else if (!meridian) {
1007
+ nvals = this.InverseStart(sbet1, cbet1, dn1, sbet2, cbet2, dn2, lam12, slam12, clam12, C1a, C2a);
1008
+ sig12 = nvals.sig12;
1009
+ salp1 = nvals.salp1;
1010
+ calp1 = nvals.calp1;
1011
+ if (sig12 >= 0) {
1012
+ salp2 = nvals.salp2;
1013
+ calp2 = nvals.calp2;
1014
+ dnm = nvals.dnm;
1015
+ s12x = sig12 * this._b * dnm;
1016
+ m12x = m.sq(dnm) * this._b * Math.sin(sig12 / dnm);
1017
+ if (outmask & g.GEODESICSCALE)
1018
+ vals.M12 = vals.M21 = Math.cos(sig12 / dnm);
1019
+ vals.a12 = sig12 / m.degree;
1020
+ omg12 = lam12 / (this._f1 * dnm);
1021
+ } else {
1022
+ numit = 0;
1023
+ salp1a = g.tiny_;
1024
+ calp1a = 1;
1025
+ salp1b = g.tiny_;
1026
+ calp1b = -1;
1027
+ for (tripn = false, tripb = false; ; ++numit) {
1028
+ nvals = this.Lambda12(sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1, slam12, clam12, numit < maxit1_, C1a, C2a, C3a);
1029
+ v = nvals.lam12;
1030
+ salp2 = nvals.salp2;
1031
+ calp2 = nvals.calp2;
1032
+ sig12 = nvals.sig12;
1033
+ ssig1 = nvals.ssig1;
1034
+ csig1 = nvals.csig1;
1035
+ ssig2 = nvals.ssig2;
1036
+ csig2 = nvals.csig2;
1037
+ eps = nvals.eps;
1038
+ domg12 = nvals.domg12;
1039
+ dv = nvals.dlam12;
1040
+ if (tripb || !(Math.abs(v) >= (tripn ? 8 : 1) * tol0_) || numit == maxit2_)
1041
+ break;
1042
+ if (v > 0 && (numit < maxit1_ || calp1 / salp1 > calp1b / salp1b)) {
1043
+ salp1b = salp1;
1044
+ calp1b = calp1;
1045
+ } else if (v < 0 && (numit < maxit1_ || calp1 / salp1 < calp1a / salp1a)) {
1046
+ salp1a = salp1;
1047
+ calp1a = calp1;
1048
+ }
1049
+ if (numit < maxit1_ && dv > 0) {
1050
+ dalp1 = -v / dv;
1051
+ if (Math.abs(dalp1) < Math.PI) {
1052
+ sdalp1 = Math.sin(dalp1);
1053
+ cdalp1 = Math.cos(dalp1);
1054
+ nsalp1 = salp1 * cdalp1 + calp1 * sdalp1;
1055
+ if (nsalp1 > 0) {
1056
+ calp1 = calp1 * cdalp1 - salp1 * sdalp1;
1057
+ salp1 = nsalp1;
1058
+ t = m.hypot(salp1, calp1);
1059
+ salp1 /= t;
1060
+ calp1 /= t;
1061
+ tripn = Math.abs(v) <= 16 * tol0_;
1062
+ continue;
1063
+ }
1064
+ }
1065
+ }
1066
+ salp1 = (salp1a + salp1b) / 2;
1067
+ calp1 = (calp1a + calp1b) / 2;
1068
+ t = m.hypot(salp1, calp1);
1069
+ salp1 /= t;
1070
+ calp1 /= t;
1071
+ tripn = false;
1072
+ tripb = Math.abs(salp1a - salp1) + (calp1a - calp1) < tolb_ || Math.abs(salp1 - salp1b) + (calp1 - calp1b) < tolb_;
1073
+ }
1074
+ lengthmask = outmask | (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE) ? g.DISTANCE : g.NONE);
1075
+ nvals = this.Lengths(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, lengthmask, C1a, C2a);
1076
+ s12x = nvals.s12b;
1077
+ m12x = nvals.m12b;
1078
+ if (outmask & g.GEODESICSCALE) {
1079
+ vals.M12 = nvals.M12;
1080
+ vals.M21 = nvals.M21;
1081
+ }
1082
+ m12x *= this._b;
1083
+ s12x *= this._b;
1084
+ vals.a12 = sig12 / m.degree;
1085
+ if (outmask & g.AREA) {
1086
+ sdomg12 = Math.sin(domg12);
1087
+ cdomg12 = Math.cos(domg12);
1088
+ somg12 = slam12 * cdomg12 - clam12 * sdomg12;
1089
+ comg12 = clam12 * cdomg12 + slam12 * sdomg12;
1090
+ }
1091
+ }
1092
+ }
1093
+ if (outmask & g.DISTANCE)
1094
+ vals.s12 = 0 + s12x;
1095
+ if (outmask & g.REDUCEDLENGTH)
1096
+ vals.m12 = 0 + m12x;
1097
+ if (outmask & g.AREA) {
1098
+ salp0 = salp1 * cbet1;
1099
+ calp0 = m.hypot(calp1, salp1 * sbet1);
1100
+ if (calp0 !== 0 && salp0 !== 0) {
1101
+ ssig1 = sbet1;
1102
+ csig1 = calp1 * cbet1;
1103
+ ssig2 = sbet2;
1104
+ csig2 = calp2 * cbet2;
1105
+ k2 = m.sq(calp0) * this._ep2;
1106
+ eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
1107
+ A4 = m.sq(this.a) * calp0 * salp0 * this._e2;
1108
+ t = m.hypot(ssig1, csig1);
1109
+ ssig1 /= t;
1110
+ csig1 /= t;
1111
+ t = m.hypot(ssig2, csig2);
1112
+ ssig2 /= t;
1113
+ csig2 /= t;
1114
+ C4a = new Array(g.nC4_);
1115
+ this.C4f(eps, C4a);
1116
+ B41 = g.SinCosSeries(false, ssig1, csig1, C4a);
1117
+ B42 = g.SinCosSeries(false, ssig2, csig2, C4a);
1118
+ vals.S12 = A4 * (sig12 < 0.01 ? g.SinCosSeries(false, ssig1, csig1, C4a, sig12) : B42 - B41);
1119
+ } else
1120
+ vals.S12 = 0;
1121
+ if (!meridian && somg12 == 2) {
1122
+ somg12 = Math.sin(omg12);
1123
+ comg12 = Math.cos(omg12);
1124
+ }
1125
+ if (!meridian && comg12 > -0.7071 && // Long difference not too big
1126
+ sbet2 - sbet1 < 1.75) {
1127
+ domg12 = 1 + comg12;
1128
+ dbet1 = 1 + cbet1;
1129
+ dbet2 = 1 + cbet2;
1130
+ alp12 = 2 * Math.atan2(somg12 * (sbet1 * dbet2 + sbet2 * dbet1), domg12 * (sbet1 * sbet2 + dbet1 * dbet2));
1131
+ } else {
1132
+ salp12 = salp2 * calp1 - calp2 * salp1;
1133
+ calp12 = calp2 * calp1 + salp2 * salp1;
1134
+ if (salp12 === 0 && calp12 < 0) {
1135
+ salp12 = g.tiny_ * calp1;
1136
+ calp12 = -1;
1137
+ }
1138
+ alp12 = Math.atan2(salp12, calp12);
1139
+ }
1140
+ vals.S12 += this._c2 * alp12;
1141
+ vals.S12 *= swapp * lonsign * latsign;
1142
+ vals.S12 += 0;
1143
+ }
1144
+ if (swapp < 0) {
1145
+ [salp2, salp1] = [salp1, salp2];
1146
+ [calp2, calp1] = [calp1, calp2];
1147
+ if (outmask & g.GEODESICSCALE) {
1148
+ [vals.M21, vals.M12] = [vals.M12, vals.M21];
1149
+ }
1150
+ }
1151
+ salp1 *= swapp * lonsign;
1152
+ calp1 *= swapp * latsign;
1153
+ salp2 *= swapp * lonsign;
1154
+ calp2 *= swapp * latsign;
1155
+ return {
1156
+ vals,
1157
+ salp1,
1158
+ calp1,
1159
+ salp2,
1160
+ calp2
1161
+ };
1162
+ };
1163
+ g.Geodesic.prototype.GenDirect = function(lat1, lon1, azi1, arcmode, s12_a12, outmask) {
1164
+ var line;
1165
+ if (!outmask)
1166
+ outmask = g.STANDARD;
1167
+ else if (outmask === g.LONG_UNROLL)
1168
+ outmask |= g.STANDARD;
1169
+ if (!arcmode)
1170
+ outmask |= g.DISTANCE_IN;
1171
+ line = new l.GeodesicLine(this, lat1, lon1, azi1, outmask);
1172
+ return line.GenPosition(arcmode, s12_a12, outmask);
1173
+ };
1174
+ g.Geodesic.prototype.Direct = function(lat1, lon1, azi1, s12, outmask) {
1175
+ return this.GenDirect(lat1, lon1, azi1, false, s12, outmask);
1176
+ };
1177
+ g.Geodesic.prototype.ArcDirect = function(lat1, lon1, azi1, a12, outmask) {
1178
+ return this.GenDirect(lat1, lon1, azi1, true, a12, outmask);
1179
+ };
1180
+ g.Geodesic.prototype.Line = function(lat1, lon1, azi1, caps) {
1181
+ return new l.GeodesicLine(this, lat1, lon1, azi1, caps);
1182
+ };
1183
+ g.Geodesic.prototype.DirectLine = function(lat1, lon1, azi1, s12, caps) {
1184
+ return this.GenDirectLine(lat1, lon1, azi1, false, s12, caps);
1185
+ };
1186
+ g.Geodesic.prototype.ArcDirectLine = function(lat1, lon1, azi1, a12, caps) {
1187
+ return this.GenDirectLine(lat1, lon1, azi1, true, a12, caps);
1188
+ };
1189
+ g.Geodesic.prototype.GenDirectLine = function(lat1, lon1, azi1, arcmode, s12_a12, caps) {
1190
+ var t;
1191
+ if (!caps)
1192
+ caps = g.STANDARD | g.DISTANCE_IN;
1193
+ if (!arcmode)
1194
+ caps |= g.DISTANCE_IN;
1195
+ t = new l.GeodesicLine(this, lat1, lon1, azi1, caps);
1196
+ t.GenSetDistance(arcmode, s12_a12);
1197
+ return t;
1198
+ };
1199
+ g.Geodesic.prototype.InverseLine = function(lat1, lon1, lat2, lon2, caps) {
1200
+ var r, t, azi1;
1201
+ if (!caps)
1202
+ caps = g.STANDARD | g.DISTANCE_IN;
1203
+ r = this.InverseInt(lat1, lon1, lat2, lon2, g.ARC);
1204
+ azi1 = m.atan2d(r.salp1, r.calp1);
1205
+ if (caps & (g.OUT_MASK & g.DISTANCE_IN))
1206
+ caps |= g.DISTANCE;
1207
+ t = new l.GeodesicLine(this, lat1, lon1, azi1, caps, r.salp1, r.calp1);
1208
+ t.SetArc(r.vals.a12);
1209
+ return t;
1210
+ };
1211
+ g.Geodesic.prototype.Polygon = function(polyline) {
1212
+ return new p.PolygonArea(this, polyline);
1213
+ };
1214
+ g.WGS84 = new g.Geodesic(c.WGS84.a, c.WGS84.f);
1215
+ })(geodesic.Geodesic, geodesic.GeodesicLine, geodesic.PolygonArea, geodesic.Math, geodesic.Constants);
1216
+ (function(g, l, m) {
1217
+ "use strict";
1218
+ l.GeodesicLine = function(geod, lat1, lon1, azi1, caps, salp1, calp1) {
1219
+ var t, cbet1, sbet1, eps, s, c;
1220
+ if (!caps)
1221
+ caps = g.STANDARD | g.DISTANCE_IN;
1222
+ this.a = geod.a;
1223
+ this.f = geod.f;
1224
+ this._b = geod._b;
1225
+ this._c2 = geod._c2;
1226
+ this._f1 = geod._f1;
1227
+ this.caps = caps | g.LATITUDE | g.AZIMUTH | g.LONG_UNROLL;
1228
+ this.lat1 = m.LatFix(lat1);
1229
+ this.lon1 = lon1;
1230
+ if (typeof salp1 === "undefined" || typeof calp1 === "undefined") {
1231
+ this.azi1 = m.AngNormalize(azi1);
1232
+ t = m.sincosd(m.AngRound(this.azi1));
1233
+ this.salp1 = t.s;
1234
+ this.calp1 = t.c;
1235
+ } else {
1236
+ this.azi1 = azi1;
1237
+ this.salp1 = salp1;
1238
+ this.calp1 = calp1;
1239
+ }
1240
+ t = m.sincosd(m.AngRound(this.lat1));
1241
+ sbet1 = this._f1 * t.s;
1242
+ cbet1 = t.c;
1243
+ t = m.hypot(sbet1, cbet1);
1244
+ sbet1 /= t;
1245
+ cbet1 /= t;
1246
+ cbet1 = Math.max(g.tiny_, cbet1);
1247
+ this._dn1 = Math.sqrt(1 + geod._ep2 * m.sq(sbet1));
1248
+ this._salp0 = this.salp1 * cbet1;
1249
+ this._calp0 = m.hypot(this.calp1, this.salp1 * sbet1);
1250
+ this._ssig1 = sbet1;
1251
+ this._somg1 = this._salp0 * sbet1;
1252
+ this._csig1 = this._comg1 = sbet1 !== 0 || this.calp1 !== 0 ? cbet1 * this.calp1 : 1;
1253
+ t = m.hypot(this._ssig1, this._csig1);
1254
+ this._ssig1 /= t;
1255
+ this._csig1 /= t;
1256
+ this._k2 = m.sq(this._calp0) * geod._ep2;
1257
+ eps = this._k2 / (2 * (1 + Math.sqrt(1 + this._k2)) + this._k2);
1258
+ if (this.caps & g.CAP_C1) {
1259
+ this._A1m1 = g.A1m1f(eps);
1260
+ this._C1a = new Array(g.nC1_ + 1);
1261
+ g.C1f(eps, this._C1a);
1262
+ this._B11 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C1a);
1263
+ s = Math.sin(this._B11);
1264
+ c = Math.cos(this._B11);
1265
+ this._stau1 = this._ssig1 * c + this._csig1 * s;
1266
+ this._ctau1 = this._csig1 * c - this._ssig1 * s;
1267
+ }
1268
+ if (this.caps & g.CAP_C1p) {
1269
+ this._C1pa = new Array(g.nC1p_ + 1);
1270
+ g.C1pf(eps, this._C1pa);
1271
+ }
1272
+ if (this.caps & g.CAP_C2) {
1273
+ this._A2m1 = g.A2m1f(eps);
1274
+ this._C2a = new Array(g.nC2_ + 1);
1275
+ g.C2f(eps, this._C2a);
1276
+ this._B21 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C2a);
1277
+ }
1278
+ if (this.caps & g.CAP_C3) {
1279
+ this._C3a = new Array(g.nC3_);
1280
+ geod.C3f(eps, this._C3a);
1281
+ this._A3c = -this.f * this._salp0 * geod.A3f(eps);
1282
+ this._B31 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C3a);
1283
+ }
1284
+ if (this.caps & g.CAP_C4) {
1285
+ this._C4a = new Array(g.nC4_);
1286
+ geod.C4f(eps, this._C4a);
1287
+ this._A4 = m.sq(this.a) * this._calp0 * this._salp0 * geod._e2;
1288
+ this._B41 = g.SinCosSeries(false, this._ssig1, this._csig1, this._C4a);
1289
+ }
1290
+ this.a13 = this.s13 = NaN;
1291
+ };
1292
+ l.GeodesicLine.prototype.GenPosition = function(arcmode, s12_a12, outmask, vals = {}) {
1293
+ var sig12, ssig12, csig12, B12, AB1, ssig2, csig2, tau12, s, c, serr, omg12, lam12, lon12, E, sbet2, cbet2, somg2, comg2, salp2, calp2, dn2, B22, AB2, J12, t, B42, salp12, calp12;
1294
+ if (!outmask)
1295
+ outmask = g.STANDARD;
1296
+ else if (outmask === g.LONG_UNROLL)
1297
+ outmask |= g.STANDARD;
1298
+ outmask &= this.caps & g.OUT_MASK;
1299
+ vals.lat1 = this.lat1;
1300
+ vals.azi1 = this.azi1;
1301
+ vals.lon1 = outmask & g.LONG_UNROLL ? this.lon1 : m.AngNormalize(this.lon1);
1302
+ if (arcmode)
1303
+ vals.a12 = s12_a12;
1304
+ else
1305
+ vals.s12 = s12_a12;
1306
+ if (!(arcmode || this.caps & g.DISTANCE_IN & g.OUT_MASK)) {
1307
+ vals.a12 = NaN;
1308
+ return vals;
1309
+ }
1310
+ B12 = 0;
1311
+ AB1 = 0;
1312
+ if (arcmode) {
1313
+ sig12 = s12_a12 * m.degree;
1314
+ t = m.sincosd(s12_a12);
1315
+ ssig12 = t.s;
1316
+ csig12 = t.c;
1317
+ } else {
1318
+ tau12 = s12_a12 / (this._b * (1 + this._A1m1));
1319
+ s = Math.sin(tau12);
1320
+ c = Math.cos(tau12);
1321
+ B12 = -g.SinCosSeries(true, this._stau1 * c + this._ctau1 * s, this._ctau1 * c - this._stau1 * s, this._C1pa);
1322
+ sig12 = tau12 - (B12 - this._B11);
1323
+ ssig12 = Math.sin(sig12);
1324
+ csig12 = Math.cos(sig12);
1325
+ if (Math.abs(this.f) > 0.01) {
1326
+ ssig2 = this._ssig1 * csig12 + this._csig1 * ssig12;
1327
+ csig2 = this._csig1 * csig12 - this._ssig1 * ssig12;
1328
+ B12 = g.SinCosSeries(true, ssig2, csig2, this._C1a);
1329
+ serr = (1 + this._A1m1) * (sig12 + (B12 - this._B11)) - s12_a12 / this._b;
1330
+ sig12 = sig12 - serr / Math.sqrt(1 + this._k2 * m.sq(ssig2));
1331
+ ssig12 = Math.sin(sig12);
1332
+ csig12 = Math.cos(sig12);
1333
+ }
1334
+ }
1335
+ ssig2 = this._ssig1 * csig12 + this._csig1 * ssig12;
1336
+ csig2 = this._csig1 * csig12 - this._ssig1 * ssig12;
1337
+ dn2 = Math.sqrt(1 + this._k2 * m.sq(ssig2));
1338
+ if (outmask & (g.DISTANCE | g.REDUCEDLENGTH | g.GEODESICSCALE)) {
1339
+ if (arcmode || Math.abs(this.f) > 0.01)
1340
+ B12 = g.SinCosSeries(true, ssig2, csig2, this._C1a);
1341
+ AB1 = (1 + this._A1m1) * (B12 - this._B11);
1342
+ }
1343
+ sbet2 = this._calp0 * ssig2;
1344
+ cbet2 = m.hypot(this._salp0, this._calp0 * csig2);
1345
+ if (cbet2 === 0)
1346
+ cbet2 = csig2 = g.tiny_;
1347
+ salp2 = this._salp0;
1348
+ calp2 = this._calp0 * csig2;
1349
+ if (arcmode && outmask & g.DISTANCE)
1350
+ vals.s12 = this._b * ((1 + this._A1m1) * sig12 + AB1);
1351
+ if (outmask & g.LONGITUDE) {
1352
+ somg2 = this._salp0 * ssig2;
1353
+ comg2 = csig2;
1354
+ E = m.copysign(1, this._salp0);
1355
+ omg12 = outmask & g.LONG_UNROLL ? E * (sig12 - (Math.atan2(ssig2, csig2) - Math.atan2(this._ssig1, this._csig1)) + (Math.atan2(E * somg2, comg2) - Math.atan2(E * this._somg1, this._comg1))) : Math.atan2(somg2 * this._comg1 - comg2 * this._somg1, comg2 * this._comg1 + somg2 * this._somg1);
1356
+ lam12 = omg12 + this._A3c * (sig12 + (g.SinCosSeries(true, ssig2, csig2, this._C3a) - this._B31));
1357
+ lon12 = lam12 / m.degree;
1358
+ vals.lon2 = outmask & g.LONG_UNROLL ? this.lon1 + lon12 : m.AngNormalize(m.AngNormalize(this.lon1) + m.AngNormalize(lon12));
1359
+ }
1360
+ if (outmask & g.LATITUDE)
1361
+ vals.lat2 = m.atan2d(sbet2, this._f1 * cbet2);
1362
+ if (outmask & g.AZIMUTH)
1363
+ vals.azi2 = m.atan2d(salp2, calp2);
1364
+ if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
1365
+ B22 = g.SinCosSeries(true, ssig2, csig2, this._C2a);
1366
+ AB2 = (1 + this._A2m1) * (B22 - this._B21);
1367
+ J12 = (this._A1m1 - this._A2m1) * sig12 + (AB1 - AB2);
1368
+ if (outmask & g.REDUCEDLENGTH)
1369
+ vals.m12 = this._b * (dn2 * (this._csig1 * ssig2) - this._dn1 * (this._ssig1 * csig2) - this._csig1 * csig2 * J12);
1370
+ if (outmask & g.GEODESICSCALE) {
1371
+ t = this._k2 * (ssig2 - this._ssig1) * (ssig2 + this._ssig1) / (this._dn1 + dn2);
1372
+ vals.M12 = csig12 + (t * ssig2 - csig2 * J12) * this._ssig1 / this._dn1;
1373
+ vals.M21 = csig12 - (t * this._ssig1 - this._csig1 * J12) * ssig2 / dn2;
1374
+ }
1375
+ }
1376
+ if (outmask & g.AREA) {
1377
+ B42 = g.SinCosSeries(false, ssig2, csig2, this._C4a);
1378
+ if (this._calp0 === 0 || this._salp0 === 0) {
1379
+ salp12 = salp2 * this.calp1 - calp2 * this.salp1;
1380
+ calp12 = calp2 * this.calp1 + salp2 * this.salp1;
1381
+ } else {
1382
+ salp12 = this._calp0 * this._salp0 * (csig12 <= 0 ? this._csig1 * (1 - csig12) + ssig12 * this._ssig1 : ssig12 * (this._csig1 * ssig12 / (1 + csig12) + this._ssig1));
1383
+ calp12 = m.sq(this._salp0) + m.sq(this._calp0) * this._csig1 * csig2;
1384
+ }
1385
+ vals.S12 = this._c2 * Math.atan2(salp12, calp12) + this._A4 * (Math.abs(sig12) < 0.01 ? g.SinCosSeries(false, this._ssig1, this._csig1, this._C4a, sig12) : B42 - this._B41);
1386
+ }
1387
+ if (!arcmode)
1388
+ vals.a12 = sig12 / m.degree;
1389
+ return vals;
1390
+ };
1391
+ l.GeodesicLine.prototype.Position = function(s12, outmask) {
1392
+ return this.GenPosition(false, s12, outmask);
1393
+ };
1394
+ l.GeodesicLine.prototype.ArcPosition = function(a12, outmask) {
1395
+ return this.GenPosition(true, a12, outmask);
1396
+ };
1397
+ l.GeodesicLine.prototype.GenSetDistance = function(arcmode, s13_a13) {
1398
+ if (arcmode)
1399
+ this.SetArc(s13_a13);
1400
+ else
1401
+ this.SetDistance(s13_a13);
1402
+ };
1403
+ l.GeodesicLine.prototype.SetDistance = function(s13) {
1404
+ var r;
1405
+ this.s13 = s13;
1406
+ r = this.GenPosition(false, this.s13, g.ARC);
1407
+ this.a13 = 0 + r.a12;
1408
+ };
1409
+ l.GeodesicLine.prototype.SetArc = function(a13) {
1410
+ var r;
1411
+ this.a13 = a13;
1412
+ r = this.GenPosition(true, this.a13, g.DISTANCE);
1413
+ this.s13 = 0 + r.s12;
1414
+ };
1415
+ })(geodesic.Geodesic, geodesic.GeodesicLine, geodesic.Math);
1416
+
1417
+ // dist/geodesic-exact/quadrature.js
1418
+ var X16 = [
1419
+ 0.09501250983763744,
1420
+ 0.2816035507792589,
1421
+ 0.4580167776572274,
1422
+ 0.6178762444026438,
1423
+ 0.755404408355003,
1424
+ 0.8656312023878318,
1425
+ 0.9445750230732326,
1426
+ 0.9894009349916499
1427
+ ];
1428
+ var W16 = [
1429
+ 0.1894506104550685,
1430
+ 0.1826034150449236,
1431
+ 0.16915651939500254,
1432
+ 0.14959598881657674,
1433
+ 0.12462897125553388,
1434
+ 0.09515851168249279,
1435
+ 0.06225352393864789,
1436
+ 0.027152459411754096
1437
+ ];
1438
+ var X8 = [0.1834346424956498, 0.525532409916329, 0.7966664774136267, 0.9602898564975363];
1439
+ var W8 = [0.362683783378362, 0.3137066458778873, 0.2223810344533745, 0.1012285362903763];
1440
+ function integrate(f, start, length) {
1441
+ if (length === 0)
1442
+ return 0;
1443
+ function rule(x, w, a, h) {
1444
+ const mid = a + h / 2, half = h / 2;
1445
+ let sum = 0;
1446
+ for (let i = 0; i < x.length; i++)
1447
+ sum += w[i] * (f(mid - half * x[i]) + f(mid + half * x[i]));
1448
+ return half * sum;
1449
+ }
1450
+ function visit(a, h, depth) {
1451
+ const high = rule(X16, W16, a, h), low = rule(X8, W8, a, h);
1452
+ if (!Number.isFinite(high))
1453
+ throw new RangeError("Nonfinite elliptic integral");
1454
+ if (Math.abs(high - low) <= 2e-15 * Math.abs(h) + 8 * Number.EPSILON * Math.abs(high))
1455
+ return high;
1456
+ if (depth === 16)
1457
+ throw new RangeError("Elliptic quadrature did not converge");
1458
+ return visit(a, h / 2, depth + 1) + visit(a + h / 2, h / 2, depth + 1);
1459
+ }
1460
+ return visit(start, length, 0);
1461
+ }
1462
+ function ellipticIntegrals(k2, ep2) {
1463
+ const dn = (x) => Math.sqrt(1 + k2 * Math.sin(x) ** 2);
1464
+ const densityD = (x) => Math.sin(x) ** 2 / dn(x);
1465
+ const densityH = (x) => Math.cos(x) ** 2 / ((1 + ep2 * Math.sin(x) ** 2) * dn(x));
1466
+ const complete = /* @__PURE__ */ new Map();
1467
+ const total = (f) => {
1468
+ let v = complete.get(f);
1469
+ if (v === void 0) {
1470
+ v = integrate(f, 0, Math.PI);
1471
+ complete.set(f, v);
1472
+ }
1473
+ return v;
1474
+ };
1475
+ const periodic = (f, start, delta) => {
1476
+ const turns = Math.trunc(delta / Math.PI), remainder = delta - turns * Math.PI;
1477
+ return (turns ? turns * total(f) : 0) + integrate(f, start % Math.PI, remainder);
1478
+ };
1479
+ return {
1480
+ E: (s, d) => periodic(dn, s, d),
1481
+ J: (s, d) => k2 * periodic(densityD, s, d),
1482
+ H: (s, d) => periodic(densityH, s, d),
1483
+ meanE: () => total(dn) / Math.PI,
1484
+ meanJ: () => k2 * total(densityD) / Math.PI
1485
+ };
1486
+ }
1487
+
1488
+ // dist/geodesic-exact/inverse-engine.js
1489
+ var library = geodesic.Geodesic;
1490
+ var angleMath = geodesic.Math;
1491
+ function exactInverseEngine(a, b) {
1492
+ const engine = new library.Geodesic(a, (a - b) / a);
1493
+ engine.Lengths = function(eps, delta, s1, c1, d1, s2, c2, d2, cb1, cb2) {
1494
+ const k2 = 4 * eps / (1 - eps) ** 2, I = ellipticIntegrals(k2, this._ep2), start = Math.atan2(s1, c1);
1495
+ const J = I.J(start, delta), t = this._ep2 * (cb1 - cb2) * (cb1 + cb2) / (d1 + d2);
1496
+ const cosine = c1 * c2 + s1 * s2;
1497
+ return {
1498
+ s12b: I.E(start, delta),
1499
+ m12b: d2 * (c1 * s2) - d1 * (s1 * c2) - c1 * c2 * J,
1500
+ m0: I.meanJ(),
1501
+ M12: cosine + (t * s2 - c2 * J) * s1 / d1,
1502
+ M21: cosine - (t * s1 - c1 * J) * s2 / d2
1503
+ };
1504
+ };
1505
+ engine.InverseStart = function(sb1, cb1, _d1, sb2, cb2, _d2, _lam, sl, cl) {
1506
+ let s = cb2 * sl, c = cb1 * sb2 - sb1 * cb2 * cl;
1507
+ const length = Math.hypot(s, c);
1508
+ if (length > 0 && s > 0) {
1509
+ s /= length;
1510
+ c /= length;
1511
+ } else {
1512
+ s = 1;
1513
+ c = 0;
1514
+ }
1515
+ return { sig12: -1, salp1: s, calp1: c };
1516
+ };
1517
+ const baseLambda = engine.Lambda12;
1518
+ engine.Lambda12 = function(sb1, cb1, dn1, sb2, cb2, dn2, sa1, ca1, sl, cl, diff, c1a, c2a, c3a) {
1519
+ const result = baseLambda.call(this, sb1, cb1, dn1, sb2, cb2, dn2, sa1, ca1, sl, cl, diff, c1a, c2a, c3a);
1520
+ const sa0 = sa1 * cb1, ca0 = Math.hypot(ca1, sa1 * sb1), k2 = ca0 * ca0 * this._ep2;
1521
+ const om1 = sa0 * sb1, co1 = ca1 * cb1, om2 = sa0 * sb2, co2 = result.calp2 * cb2;
1522
+ const ch1 = this._f1 * dn1 * co1, ch2 = this._f1 * dn2 * co2;
1523
+ const sch = Math.max(0, ch1 * om2 - om1 * ch2), cch = ch1 * ch2 + om1 * om2;
1524
+ const so = Math.max(0, co1 * om2 - om1 * co2), co = co1 * co2 + om1 * om2;
1525
+ const correction = -this._e2 / this._f1 * sa0 * ellipticIntegrals(k2, this._ep2).H(Math.atan2(result.ssig1, result.csig1), result.sig12);
1526
+ result.lam12 = Math.atan2(sch * cl - cch * sl, cch * cl + sch * sl) + correction;
1527
+ result.domg12 = correction + Math.atan2(sch * co - cch * so, cch * co + sch * so);
1528
+ return result;
1529
+ };
1530
+ return engine;
1531
+ }
1532
+
1533
+ // dist/geodesic-exact/area.js
1534
+ function derivative(x) {
1535
+ if (Math.abs(x) < 0.125) {
1536
+ let coefficient = 1 / 3, power = 1, sum = 1;
1537
+ for (let n = 1; n <= 24; n++) {
1538
+ sum += n * coefficient * power;
1539
+ coefficient *= -2 * n / (2 * n + 3);
1540
+ power *= x;
1541
+ }
1542
+ return sum;
1543
+ }
1544
+ const root = Math.sqrt(Math.abs(x));
1545
+ const ratio = (x > 0 ? Math.asinh(root) : Math.asin(root)) / root;
1546
+ return 1 + (1 - ratio / Math.sqrt(1 + x)) / (2 * x);
1547
+ }
1548
+ function value(x) {
1549
+ if (Math.abs(x) < 0.125) {
1550
+ let term = x / 3, sum = x;
1551
+ for (let n = 1; n <= 24; n++) {
1552
+ const next = sum + term;
1553
+ if (next === sum)
1554
+ break;
1555
+ sum = next;
1556
+ term *= -2 * n * x / (2 * n + 3);
1557
+ }
1558
+ return sum;
1559
+ }
1560
+ const root = Math.sqrt(Math.abs(x));
1561
+ return x + (Math.sqrt(1 + x) * (x > 0 ? Math.asinh(root) : Math.asin(root)) / root - 1);
1562
+ }
1563
+ function areaCorrection(ep2, k2, s1, c1, delta) {
1564
+ const remainder = delta % (2 * Math.PI), tX = value(ep2);
1565
+ return integrate((theta) => {
1566
+ const s = s1 * Math.cos(theta) + c1 * Math.sin(theta), y = k2 * s * s;
1567
+ const divided = ep2 === y ? derivative(y) : Math.abs(y) <= 1e-8 * Math.abs(ep2) ? (tX - value(y)) / (ep2 - y) : integrate((u) => derivative(y + (ep2 - y) * u), 0, 1);
1568
+ return -s * divided / 2;
1569
+ }, 0, remainder);
1570
+ }
1571
+
1572
+ // dist/ellipsoid-helpers/surface-polygon.js
1573
+ var Accumulator = geodesic.Accumulator.Accumulator;
1574
+ var math = geodesic.Math;
1575
+ var SurfacePolygon = class {
1576
+ constructor(solver, options = {}) {
1577
+ this.count = 0;
1578
+ this.firstLat = 0;
1579
+ this.firstLon = 0;
1580
+ this.lastLat = 0;
1581
+ this.lastLon = 0;
1582
+ this.crossings = 0;
1583
+ this.perimeter = new Accumulator();
1584
+ this.area = new Accumulator();
1585
+ this.geodesic = solver;
1586
+ this.polyline = Boolean(options.polyline);
1587
+ this.area0 = this.geodesic.surfaceArea;
1588
+ if (!(Number.isFinite(this.area0) && this.area0 > 0)) {
1589
+ throw new Error("Polygon area exceeds representable range");
1590
+ }
1591
+ }
1592
+ get number() {
1593
+ return this.count;
1594
+ }
1595
+ clear() {
1596
+ this.count = this.crossings = 0;
1597
+ this.firstLat = this.firstLon = this.lastLat = this.lastLon = 0;
1598
+ this.perimeter = new Accumulator();
1599
+ this.area = new Accumulator();
1600
+ return this;
1601
+ }
1602
+ addPoint(latitude, longitude, options = {}) {
1603
+ if (!(Number.isFinite(latitude) && Math.abs(latitude) <= 90 && Number.isFinite(longitude))) {
1604
+ throw new Error("Polygon point requires finite longitude and latitude in [-90, 90]");
1605
+ }
1606
+ if (this.count) {
1607
+ const edge = this.geodesic.inverse(this.lastLat, this.lastLon, latitude, longitude, {
1608
+ area: !this.polyline,
1609
+ longitudeTurns: options.longitudeTurns,
1610
+ unrollLongitude: Boolean(options.longitudeTurns)
1611
+ });
1612
+ this.accumulate(edge.s12, this.polyline ? 0 : edge.S12);
1613
+ if (!this.polyline) {
1614
+ this.crossings = (this.crossings + (options.longitudeTurns ? transitDirect(this.lastLon, edge.lon2) : transit(this.lastLon, longitude))) % 2;
1615
+ }
1616
+ } else {
1617
+ this.firstLat = latitude;
1618
+ this.firstLon = longitude;
1619
+ }
1620
+ this.lastLat = latitude;
1621
+ this.lastLon = longitude;
1622
+ ++this.count;
1623
+ return this;
1624
+ }
1625
+ addEdge(azimuth, distance) {
1626
+ if (!this.count)
1627
+ throw new Error("Add a starting point before adding an edge");
1628
+ const edge = this.geodesic.direct(this.lastLat, this.lastLon, azimuth, distance, {
1629
+ area: !this.polyline,
1630
+ unrollLongitude: true
1631
+ });
1632
+ if (!(Number.isFinite(edge.lat2) && Number.isFinite(edge.lon2)))
1633
+ throw new Error("Unrepresentable geodesic edge");
1634
+ this.accumulate(distance, this.polyline ? 0 : edge.S12);
1635
+ if (!this.polyline) {
1636
+ this.crossings = (this.crossings + transitDirect(this.lastLon, edge.lon2)) % 2;
1637
+ }
1638
+ this.lastLat = edge.lat2;
1639
+ this.lastLon = edge.lon2;
1640
+ ++this.count;
1641
+ return this;
1642
+ }
1643
+ compute(options = {}) {
1644
+ if (this.count < 2)
1645
+ return this.polyline ? { number: this.count, perimeter: 0 } : { number: this.count, perimeter: 0, area: 0 };
1646
+ if (this.polyline)
1647
+ return { number: this.count, perimeter: this.perimeter.Sum() };
1648
+ const edge = this.geodesic.inverse(this.lastLat, this.lastLon, this.firstLat, this.firstLon, {
1649
+ area: true
1650
+ });
1651
+ const total = new Accumulator(this.area);
1652
+ total.Add(edge.S12);
1653
+ const area0 = this.area0;
1654
+ total.Remainder(area0);
1655
+ if ((this.crossings + transit(this.lastLon, this.firstLon)) % 2 !== 0) {
1656
+ total.Add((total.Sum() < 0 ? 1 : -1) * area0 / 2);
1657
+ }
1658
+ if (!options.reverse)
1659
+ total.Negate();
1660
+ if (options.unsigned) {
1661
+ if (total.Sum() >= area0)
1662
+ total.Add(-area0);
1663
+ else if (total.Sum() < 0)
1664
+ total.Add(area0);
1665
+ } else {
1666
+ if (total.Sum() > area0 / 2)
1667
+ total.Add(-area0);
1668
+ else if (total.Sum() <= -area0 / 2)
1669
+ total.Add(area0);
1670
+ }
1671
+ return { number: this.count, perimeter: this.perimeter.Sum(edge.s12), area: 0 + total.Sum() };
1672
+ }
1673
+ /** Nonmutating preview, with the same compensated arithmetic as insertion. */
1674
+ testPoint(latitude, longitude, options = {}) {
1675
+ return this.copy().addPoint(latitude, longitude, options).compute(options);
1676
+ }
1677
+ testEdge(azimuth, distance, options = {}) {
1678
+ return this.copy().addEdge(azimuth, distance).compute(options);
1679
+ }
1680
+ accumulate(distance, area) {
1681
+ if (![distance, area, this.perimeter.Sum(distance), this.area.Sum(area)].every(Number.isFinite)) {
1682
+ throw new Error("Unrepresentable geodesic sum");
1683
+ }
1684
+ this.perimeter.Add(distance);
1685
+ if (!this.polyline)
1686
+ this.area.Add(area);
1687
+ }
1688
+ copy() {
1689
+ const copy = Object.create(Object.getPrototypeOf(this));
1690
+ Object.assign(copy, this);
1691
+ copy.perimeter = new Accumulator(this.perimeter);
1692
+ copy.area = new Accumulator(this.area);
1693
+ return copy;
1694
+ }
1695
+ };
1696
+ function transit(a, b) {
1697
+ const delta = math.AngDiff(a, b).d;
1698
+ a = math.AngNormalize(a);
1699
+ b = math.AngNormalize(b);
1700
+ return delta > 0 && (a < 0 && b >= 0 || a > 0 && b === 0) ? 1 : delta < 0 && a >= 0 && b < 0 ? -1 : 0;
1701
+ }
1702
+ function transitDirect(a, b) {
1703
+ a %= 720;
1704
+ b %= 720;
1705
+ return (b >= 0 && b < 360 || b < -360 ? 0 : 1) - (a >= 0 && a < 360 || a < -360 ? 0 : 1);
1706
+ }
1707
+
1708
+ // dist/geodesic-exact/polygon.js
1709
+ var GeodesicPolygonExact = class extends SurfacePolygon {
1710
+ constructor(parameters, options = {}) {
1711
+ const solver = new EllipsoidGeodesicExact(parameters);
1712
+ super({
1713
+ surfaceArea: solver.surfaceArea,
1714
+ inverse: (a, b, c, d, opts) => solver.inverse(a, b % 720, c, d % 720, opts),
1715
+ direct: (a, b, c, d, opts) => solver.direct(a, b % 720, c, d, opts)
1716
+ }, options);
1717
+ }
1718
+ addPoint(latitude, longitude, options = {}) {
1719
+ if (Math.abs(longitude) > 1e6)
1720
+ throw new RangeError("Exact polygon longitude exceeds input profile");
1721
+ if (options.longitudeTurns !== void 0 && options.longitudeTurns !== 0)
1722
+ throw new RangeError("Exact geodesic point insertion does not select winding routes; use addEdge");
1723
+ return super.addPoint(latitude, longitude);
1724
+ }
1725
+ };
1726
+
1727
+ // dist/geodesic-exact.js
1728
+ var DEG = Math.PI / 180;
1729
+ function point(lat, lon) {
1730
+ if (!Number.isFinite(lat) || Math.abs(lat) > 90 || !Number.isFinite(lon) || Math.abs(lon) > 1e6)
1731
+ throw new RangeError("Expected latitude in [-90,90] and longitude in [-1e6,1e6]");
1732
+ }
1733
+ function finite(x) {
1734
+ if (!Number.isFinite(x))
1735
+ throw new RangeError("Expected finite geodesic argument");
1736
+ }
1737
+ var EllipsoidGeodesicExact = class {
1738
+ constructor({ semiMajorAxis: a, semiMinorAxis: b }) {
1739
+ if (!Number.isFinite(a) || !Number.isFinite(b) || Math.min(a, b) < 1e-60 || Math.max(a, b) > 1e60 || b / a < 0.25 || b / a > 4)
1740
+ throw new RangeError("Exact geodesics require axes in [1e-60,1e60] and b/a in [0.25,4]");
1741
+ this.axes = Object.freeze([a, b]);
1742
+ this.engine = exactInverseEngine(a, b);
1743
+ }
1744
+ get semiMajorAxis() {
1745
+ return this.axes[0];
1746
+ }
1747
+ get semiMinorAxis() {
1748
+ return this.axes[1];
1749
+ }
1750
+ get surfaceArea() {
1751
+ return 4 * Math.PI * this.engine._c2;
1752
+ }
1753
+ inverse(lat1, lon1, lat2, lon2, options = {}) {
1754
+ point(lat1, lon1);
1755
+ point(lat2, lon2);
1756
+ const result = this.engine.Inverse(lat1, lon1, lat2, lon2, library.ALL & ~library.AREA | (options.unrollLongitude ? library.LONG_UNROLL : 0));
1757
+ if (![result.s12, result.azi1, result.azi2, result.m12, result.M12, result.M21, result.a12].every(Number.isFinite))
1758
+ throw new RangeError("Exact inverse did not converge");
1759
+ let azimuth = result.azi1, distance = result.s12;
1760
+ const target = angleMath.sincosd(lat2), f1 = this.semiMinorAxis / this.semiMajorAxis;
1761
+ const denominator = Math.sqrt(1 - (1 - f1 * f1) * target.s * target.s);
1762
+ const meridian = this.semiMajorAxis * f1 * f1 / denominator ** 3;
1763
+ const parallel = this.semiMajorAxis * target.c / denominator;
1764
+ for (let iteration = 0; iteration < 8; iteration++) {
1765
+ const endpoint = this.direct(lat1, lon1, azimuth, distance, { area: options.area });
1766
+ const north = meridian * (lat2 - endpoint.lat2) * DEG;
1767
+ const east = parallel * angleMath.AngNormalize(angleMath.AngNormalize(lon2) - endpoint.lon2) * DEG;
1768
+ const rounding = 8 * Number.EPSILON * (options.area && distance !== 0 && Math.abs(distance) < 1e-5 * Math.max(this.semiMajorAxis, this.semiMinorAxis) ? Math.abs(distance) : Math.max(this.semiMajorAxis, this.semiMinorAxis)) + 4 * Number.EPSILON * DEG * (Math.abs(meridian) * (Math.abs(lat2) + Math.abs(endpoint.lat2)) + Math.abs(parallel) * (Math.abs(angleMath.AngNormalize(lon2)) + Math.abs(endpoint.lon2)));
1769
+ if (Math.hypot(north, east) <= rounding) {
1770
+ let edgeArea = endpoint.S12;
1771
+ if (options.area && Math.abs(lat1) < Math.abs(lat2) && Math.abs(lat2) < 90) {
1772
+ edgeArea = -this.inverse(lat2, lon2, lat1, lon1, { area: true }).S12;
1773
+ }
1774
+ return {
1775
+ ...endpoint,
1776
+ lat2,
1777
+ lon1: result.lon1,
1778
+ lon2: result.lon2,
1779
+ ...options.area ? { S12: edgeArea } : {},
1780
+ ...options.area && Math.abs(lat2) === 90 ? { S12: this.engine._c2 * angleMath.AngNormalize(result.azi2 - result.azi1) * DEG } : {},
1781
+ // At an exact pole, preserve the inverse framework's requested-meridian
1782
+ // bearing; a rounded direct endpoint cannot determine that convention.
1783
+ azi2: Math.abs(lat2) === 90 ? result.azi2 : endpoint.azi2
1784
+ };
1785
+ }
1786
+ if (distance === 0 || (options.area ? endpoint.m12 === 0 : Math.abs(endpoint.m12) < 1e-15 * this.semiMajorAxis))
1787
+ break;
1788
+ const heading = angleMath.sincosd(endpoint.azi2);
1789
+ distance += heading.c * north + heading.s * east;
1790
+ azimuth += (heading.c * east - heading.s * north) / endpoint.m12 / DEG;
1791
+ }
1792
+ throw new RangeError("Exact inverse endpoint residual");
1793
+ }
1794
+ direct(lat, lon, azimuth, distance, options = {}) {
1795
+ return this.line(lat, lon, azimuth, options).position(distance);
1796
+ }
1797
+ line(lat, lon, azimuth, options = {}) {
1798
+ point(lat, lon);
1799
+ finite(azimuth);
1800
+ const a = this.semiMajorAxis, b = this.semiMinorAxis, f1 = b / a, ep2 = (a / b) ** 2 - 1, e2 = 1 - f1 * f1;
1801
+ const phi = angleMath.sincosd(lat), alpha = angleMath.sincosd(angleMath.AngNormalize(azimuth));
1802
+ const norm = Math.hypot(phi.s * f1, phi.c), sb1 = phi.s * f1 / norm, cb1 = Math.max(1e-150, phi.c / norm);
1803
+ const sa0 = alpha.s * cb1, ca0 = Math.hypot(alpha.c, alpha.s * sb1);
1804
+ let s1 = sb1, c1 = sb1 !== 0 || alpha.c !== 0 ? cb1 * alpha.c : 1;
1805
+ const sigmaNorm = Math.hypot(s1, c1);
1806
+ s1 /= sigmaNorm;
1807
+ c1 /= sigmaNorm;
1808
+ const sig1 = Math.atan2(s1, c1);
1809
+ const k2 = ca0 * ca0 * ep2, I = ellipticIntegrals(k2, ep2), dn1 = Math.sqrt(1 + k2 * s1 * s1);
1810
+ const sign = sa0 < 0 || Object.is(sa0, -0) ? -1 : 1;
1811
+ const includeArea = Boolean(options.area);
1812
+ const unroll = Boolean(options.unrollLongitude), azi1 = angleMath.AngNormalize(azimuth);
1813
+ const distanceLimit = b * I.E(sig1, 4 * Math.PI);
1814
+ const evaluate = (delta, distance, arcDegrees) => {
1815
+ const phase = arcDegrees === void 0 ? { s: Math.sin(delta), c: Math.cos(delta) } : angleMath.sincosd(arcDegrees);
1816
+ const s2 = s1 * phase.c + c1 * phase.s, c2 = c1 * phase.c - s1 * phase.s;
1817
+ const dn2 = Math.sqrt(1 + k2 * s2 * s2), J = I.J(sig1, delta);
1818
+ const chi2 = Math.atan2(sign * sa0 * s2, f1 * dn2 * c2), signedChi1 = Math.atan2(sign * sa0 * s1, f1 * dn1 * c1);
1819
+ const t = k2 * (s2 - s1) * (s2 + s1) / (dn1 + dn2);
1820
+ const turns = Math.trunc(arcDegrees === void 0 ? delta / Math.PI : arcDegrees / 180), remainder = arcDegrees === void 0 ? delta - turns * Math.PI : arcDegrees - turns * 180;
1821
+ const parity = Math.abs(turns % 2) === 1 ? -1 : 1;
1822
+ const sr = phase.s * parity;
1823
+ const endS = s2 * parity, endC = c2 * parity;
1824
+ const chi = sa0 === 0 ? Math.round(sign * (delta - (Math.atan2(s2, c2) - Math.atan2(s1, c1)) + (chi2 - signedChi1)) / Math.PI) * Math.PI : sign * (turns * Math.PI + (remainder === 0 ? 0 : Math.atan2(sign * sa0 * f1 * (dn1 * sr - t * s1 * endC), f1 * f1 * dn1 * dn2 * c1 * endC + sa0 * sa0 * s1 * endS)));
1825
+ const longitude = (unroll ? lon : angleMath.AngNormalize(lon)) + (chi - e2 / f1 * sa0 * I.H(sig1, delta)) / DEG;
1826
+ const cosine = phase.c;
1827
+ return {
1828
+ lat1: lat,
1829
+ lon1: unroll ? lon : angleMath.AngNormalize(lon),
1830
+ azi1,
1831
+ lat2: angleMath.atan2d(ca0 * s2, f1 * Math.hypot(sa0, ca0 * c2)),
1832
+ lon2: unroll ? longitude : angleMath.AngNormalize(longitude),
1833
+ azi2: angleMath.atan2d(sa0, ca0 * c2),
1834
+ s12: distance === void 0 ? b * I.E(sig1, delta) : distance,
1835
+ a12: delta / DEG,
1836
+ m12: b * (dn2 * (c1 * s2) - dn1 * (s1 * c2) - c1 * c2 * J),
1837
+ M12: cosine + (t * s2 - c2 * J) * s1 / dn1,
1838
+ M21: cosine - (t * s1 - c1 * J) * s2 / dn2,
1839
+ ...includeArea ? {
1840
+ S12: (() => {
1841
+ const sd = phase.s, cd = phase.c;
1842
+ const sine = ca0 * sa0 * (cd <= 0 ? c1 * (1 - cd) + sd * s1 : sd * (c1 * sd / (1 + cd) + s1));
1843
+ const cosine2 = sa0 * sa0 + ca0 * ca0 * c1 * c2;
1844
+ const angle2 = ca0 === 0 || sa0 === 0 ? Math.atan2(sa0 * alpha.c - ca0 * c2 * alpha.s, ca0 * c2 * alpha.c + sa0 * alpha.s) : Math.atan2(sine, cosine2);
1845
+ return this.engine._c2 * angle2 + (a * a * e2 * ca0 * sa0 === 0 ? 0 : a * a * e2 * ca0 * sa0 * areaCorrection(ep2, k2, s1, c1, delta));
1846
+ })()
1847
+ } : {}
1848
+ };
1849
+ };
1850
+ return {
1851
+ arcPosition: (arc) => {
1852
+ finite(arc);
1853
+ if (Math.abs(arc) > 720)
1854
+ throw new RangeError("Exact line arc exceeds 720 degrees");
1855
+ return evaluate(arc * DEG, void 0, arc);
1856
+ },
1857
+ position: (distance) => {
1858
+ finite(distance);
1859
+ if (Math.abs(distance) > distanceLimit)
1860
+ throw new RangeError("Exact line distance exceeds support profile");
1861
+ const target = distance / b, lowDn = Math.min(1, a / b), highDn = Math.max(1, a / b);
1862
+ let lower = Math.max(-4 * Math.PI, Math.min(target / lowDn, target / highDn)), upper = Math.min(4 * Math.PI, Math.max(target / lowDn, target / highDn));
1863
+ let delta = Math.max(lower, Math.min(upper, target / I.meanE()));
1864
+ for (let i = 0; i < 80; i++) {
1865
+ const residual = I.E(sig1, delta) - target;
1866
+ if (Math.abs(residual) <= Number.EPSILON * Math.max(Math.abs(target), 1e-300))
1867
+ return evaluate(delta, distance);
1868
+ if (residual > 0)
1869
+ upper = delta;
1870
+ else
1871
+ lower = delta;
1872
+ const next = delta - residual / Math.sqrt(1 + k2 * Math.sin(sig1 + delta) ** 2);
1873
+ const value2 = next > lower && next < upper ? next : (lower + upper) / 2;
1874
+ if (value2 === delta)
1875
+ return evaluate(delta, distance);
1876
+ delta = value2;
1877
+ }
1878
+ throw new RangeError("Exact distance inversion did not converge");
1879
+ }
1880
+ };
1881
+ }
1882
+ };
1883
+
1884
+ // dist/geodesic-buffer.js
1885
+ var GEODESIC_BUFFER_FIELDS = Object.freeze([
1886
+ "lat2",
1887
+ "lon2",
1888
+ "azi2",
1889
+ "s12",
1890
+ "a12",
1891
+ "m12",
1892
+ "M12",
1893
+ "M21"
1894
+ ]);
1895
+ var RHUMB_BUFFER_FIELDS = Object.freeze(["lat2", "lon2", "azi12", "s12"]);
1896
+ function shared(value2) {
1897
+ return ArrayBuffer.isView(value2) && typeof SharedArrayBuffer !== "undefined" && value2.buffer instanceof SharedArrayBuffer;
1898
+ }
1899
+ var LineBuffer = class {
1900
+ constructor(evaluate, capacity, fields) {
1901
+ this.evaluate = evaluate;
1902
+ this.scratch = {};
1903
+ this.control = { busy: false };
1904
+ if (!Number.isSafeInteger(capacity) || capacity < 0 || capacity > 1e6)
1905
+ throw new RangeError("Buffer capacity must be in [0,1000000]");
1906
+ this.capacity = capacity;
1907
+ this.fields = Object.freeze([...fields]);
1908
+ this.stride = fields.length;
1909
+ this.stage = new Float64Array(capacity * this.stride);
1910
+ Object.freeze(this);
1911
+ }
1912
+ /** Atomically write interleaved rows; input/output aliasing is supported. */
1913
+ positions(distances, output) {
1914
+ if (this.control.busy)
1915
+ throw new RangeError("Packed line samplers are not reentrant");
1916
+ this.control.busy = true;
1917
+ try {
1918
+ return this.write(distances, output);
1919
+ } finally {
1920
+ this.control.busy = false;
1921
+ }
1922
+ }
1923
+ write(distances, output) {
1924
+ const count = distances.length;
1925
+ if (!Number.isSafeInteger(count) || count < 0 || count > this.capacity || !(output instanceof Float64Array) || output.length < count * this.stride || shared(distances) || shared(output))
1926
+ throw new RangeError("Invalid packed line storage");
1927
+ for (let i = 0; i < count; i++)
1928
+ if (!Number.isFinite(distances[i]))
1929
+ throw new RangeError("Expected finite distances");
1930
+ for (let i = 0; i < count; i++) {
1931
+ const result = this.evaluate(distances[i], this.scratch);
1932
+ for (let field = 0; field < this.stride; field++) {
1933
+ const value2 = result[this.fields[field]];
1934
+ if (!Number.isFinite(value2))
1935
+ throw new RangeError("Line result or requested field is not representable");
1936
+ this.stage[i * this.stride + field] = value2;
1937
+ }
1938
+ }
1939
+ for (let i = 0; i < count * this.stride; i++)
1940
+ output[i] = this.stage[i];
1941
+ return output;
1942
+ }
1943
+ };
1944
+ var GeodesicLineBuffer = class extends LineBuffer {
1945
+ constructor(line, capacity, options = {}) {
1946
+ if (!line || typeof line.position !== "function")
1947
+ throw new RangeError("Expected a geodesic line");
1948
+ const position = line.position.bind(line);
1949
+ super((distance, result) => position(distance, void 0, void 0, result), capacity, options.area ? [...GEODESIC_BUFFER_FIELDS, "S12"] : GEODESIC_BUFFER_FIELDS);
1950
+ }
1951
+ };
1952
+ var RhumbLineBuffer = class extends LineBuffer {
1953
+ constructor(line, capacity, options = {}) {
1954
+ if (!line || typeof line.position !== "function")
1955
+ throw new RangeError("Expected a rhumb line");
1956
+ const position = line.position.bind(line);
1957
+ super((distance, result) => position(distance, void 0, void 0, result), capacity, options.area ? [...RHUMB_BUFFER_FIELDS, "S12"] : RHUMB_BUFFER_FIELDS);
1958
+ }
1959
+ };
1960
+
1961
+ // dist/ellipsoid-geodesic.js
1962
+ var library2 = geodesic.Geodesic;
1963
+ var EllipsoidGeodesic = class {
1964
+ constructor({ semiMajorAxis: a, semiMinorAxis: b }) {
1965
+ this.engine = createGeodesicEngine({ semiMajorAxis: a, semiMinorAxis: b });
1966
+ }
1967
+ /** Total area in squared axis units, with the same normalization as S12. */
1968
+ get surfaceArea() {
1969
+ return 4 * Math.PI * this.engine._c2;
1970
+ }
1971
+ inverse(lat1, lon1, lat2, lon2, options = {}) {
1972
+ validatePoint(lat1, lon1);
1973
+ validatePoint(lat2, lon2);
1974
+ return this.engine.Inverse(lat1, lon1, lat2, lon2, outputMask(options));
1975
+ }
1976
+ direct(latitude, longitude, azimuth, distance, options = {}) {
1977
+ return this.line(latitude, longitude, azimuth, options).position(distance);
1978
+ }
1979
+ arcDirect(latitude, longitude, azimuth, arc, options = {}) {
1980
+ return this.line(latitude, longitude, azimuth, options).arcPosition(arc);
1981
+ }
1982
+ line(latitude, longitude, azimuth, options = {}) {
1983
+ validatePoint(latitude, longitude);
1984
+ validateFinite(azimuth);
1985
+ const selectedMask = outputMask(options);
1986
+ const line = this.engine.Line(latitude, longitude, azimuth, selectedMask | library2.DISTANCE_IN);
1987
+ return {
1988
+ // Fourth argument is an internal result request; ordinary Array.map arguments remain ignored.
1989
+ position(distance, _index, _array, output) {
1990
+ validateFinite(distance);
1991
+ return line.GenPosition(false, distance, selectedMask, output);
1992
+ },
1993
+ arcPosition(arc) {
1994
+ validateFinite(arc);
1995
+ return line.ArcPosition(arc, selectedMask);
1996
+ }
1997
+ };
1998
+ }
1999
+ };
2000
+ function validatePoint(latitude, longitude) {
2001
+ if (!(Number.isFinite(latitude) && Math.abs(latitude) <= 90 && Number.isFinite(longitude))) {
2002
+ throw new Error("Invalid geodesic coordinates");
2003
+ }
2004
+ }
2005
+ function outputMask(options) {
2006
+ return library2.ALL & ~(options.area ? 0 : library2.AREA) | (options.unrollLongitude ? library2.LONG_UNROLL : 0);
2007
+ }
2008
+ function validateFinite(value2) {
2009
+ if (!Number.isFinite(value2))
2010
+ throw new Error("Nonfinite axis, azimuth, distance or arc");
2011
+ }
2012
+ var nonAreaGeodesicMask = library2.ALL & ~library2.AREA;
2013
+ function createGeodesicEngine({ semiMajorAxis: a, semiMinorAxis: b }) {
2014
+ validateFinite(a);
2015
+ validateFinite(b);
2016
+ return new library2.Geodesic(a, (a - b) / a);
2017
+ }
2018
+
2019
+ // dist/geodesic-polygon.js
2020
+ var GeodesicPolygon = class extends SurfacePolygon {
2021
+ constructor(parameters, options = {}) {
2022
+ super(new EllipsoidGeodesic(parameters), options);
2023
+ }
2024
+ addPoint(latitude, longitude) {
2025
+ return super.addPoint(latitude, longitude);
2026
+ }
2027
+ };
2028
+
2029
+ // dist/ellipsoid-helpers/rhumb-pole-distance.js
2030
+ var Q = 10n ** 48n;
2031
+ var PI = 3141592653589793238462643383279502884197169399375n;
2032
+ var mul = (x, y) => x * y / Q;
2033
+ var div = (x, y) => x * Q / y;
2034
+ function exact(x) {
2035
+ const bytes = new DataView(new ArrayBuffer(8));
2036
+ bytes.setFloat64(0, x);
2037
+ const bits = bytes.getBigUint64(0), exponent = Number(bits >> 52n & 2047n);
2038
+ const mantissa = bits & (1n << 52n) - 1n | (exponent ? 1n << 52n : 0n);
2039
+ const shift = exponent ? exponent - 1075 : -1074;
2040
+ const value2 = shift >= 0 ? mantissa * Q << BigInt(shift) : mantissa * Q >> BigInt(-shift);
2041
+ return bits >> 63n ? -value2 : value2;
2042
+ }
2043
+ function sc(x) {
2044
+ let s = x, c = Q, ts = x, tc = Q;
2045
+ const square = mul(x, x);
2046
+ for (let n = 1n; n < 160n; n++) {
2047
+ ts = -mul(ts, square) / (2n * n * (2n * n + 1n));
2048
+ tc = -mul(tc, square) / ((2n * n - 1n) * (2n * n));
2049
+ s += ts;
2050
+ c += tc;
2051
+ if (ts === 0n && tc === 0n)
2052
+ break;
2053
+ }
2054
+ return [s, c];
2055
+ }
2056
+ function remainingPoleDistance(a, b, latitude, azimuth, distance, sign) {
2057
+ const unit = 2 ** Math.floor(Math.log2(a));
2058
+ a /= unit;
2059
+ b /= unit;
2060
+ distance /= unit;
2061
+ const ratio = div(exact(b), exact(a));
2062
+ const theta = mul(90n * Q - BigInt(sign) * exact(latitude), PI) / 180n;
2063
+ const [s, c] = sc(theta), prolate = ratio > Q;
2064
+ const square = mul(ratio, ratio);
2065
+ const k = prolate ? Q - div(Q, square) : Q - square;
2066
+ const z = prolate ? s : c, other = prolate ? c : s;
2067
+ const zz = mul(z, z);
2068
+ let integral = theta, total = theta, coefficient = Q, power = z;
2069
+ for (let n = 1n; n < 480n; n++) {
2070
+ integral = ((2n * n - 1n) * integral + (prolate ? -1n : 1n) * mul(power, other)) / (2n * n);
2071
+ coefficient = mul(coefficient, k) * (2n * n + 1n) / (2n * n);
2072
+ const term = mul(coefficient, integral);
2073
+ total += term;
2074
+ power = mul(power, zz);
2075
+ if (term === 0n)
2076
+ break;
2077
+ }
2078
+ const gap = prolate ? div(total, ratio) : mul(total, square);
2079
+ const angle2 = mul(exact(azimuth % 360), PI) / 180n;
2080
+ const north = mul(div(exact(distance), exact(a)), sc(angle2)[1]);
2081
+ return Number(gap - BigInt(sign) * north) / Number(Q);
2082
+ }
2083
+
2084
+ // dist/ellipsoid-metrics.js
2085
+ var DEG2 = Math.PI / 180;
2086
+ var NODES = [
2087
+ 0.09501250983763744,
2088
+ 0.2816035507792589,
2089
+ 0.4580167776572274,
2090
+ 0.6178762444026438,
2091
+ 0.755404408355003,
2092
+ 0.8656312023878318,
2093
+ 0.9445750230732326,
2094
+ 0.9894009349916499
2095
+ ];
2096
+ var WEIGHTS = [
2097
+ 0.1894506104550685,
2098
+ 0.1826034150449236,
2099
+ 0.16915651939500254,
2100
+ 0.14959598881657674,
2101
+ 0.12462897125553388,
2102
+ 0.09515851168249279,
2103
+ 0.06225352393864789,
2104
+ 0.027152459411754096
2105
+ ];
2106
+ var KINDS = [
2107
+ "geocentric",
2108
+ "parametric",
2109
+ "rectifying",
2110
+ "authalic",
2111
+ "conformal",
2112
+ "isometric"
2113
+ ];
2114
+ var EllipsoidMetrics = class {
2115
+ constructor({ semiMajorAxis: a, semiMinorAxis: b }) {
2116
+ const r = b / a;
2117
+ if (!(Number.isFinite(a) && Number.isFinite(b) && a > 0 && b > 0 && r >= 0.5 && r <= 2)) {
2118
+ throw new Error("Ellipsoid metrics require finite positive axes with 0.5 <= b/a <= 2");
2119
+ }
2120
+ this.semiMajorAxis = a;
2121
+ this.semiMinorAxis = b;
2122
+ this.ratio = r;
2123
+ this.e2 = (1 - r) * (1 + r);
2124
+ this.qPole = 1 + r * r * this.eccentricIntegral(1);
2125
+ this.quarter = integrate2((t) => this.meridianIntegrand(t), 0, Math.PI / 2);
2126
+ this.quarterMeridian = a * this.quarter;
2127
+ this.surfaceArea = 2 * Math.PI * a * a * this.qPole;
2128
+ this.volume = 4 * Math.PI / 3 * a * b * a;
2129
+ if (![this.quarterMeridian, this.surfaceArea, this.volume].every((v) => Number.isFinite(v) && v > 0)) {
2130
+ throw new Error("Ellipsoid metrics exceed representable length/area/volume range");
2131
+ }
2132
+ Object.freeze(this);
2133
+ }
2134
+ meridianDistance(latitude) {
2135
+ validateLatitude(latitude);
2136
+ return Math.sign(latitude) * this.semiMajorAxis * this.meridian(Math.abs(latitude));
2137
+ }
2138
+ meridionalCurvatureRadius(latitude) {
2139
+ validateLatitude(latitude);
2140
+ return this.semiMajorAxis * this.meridianIntegrand(latitude * DEG2);
2141
+ }
2142
+ transverseCurvatureRadius(latitude) {
2143
+ validateLatitude(latitude);
2144
+ const [s, c] = sincos(latitude);
2145
+ return this.semiMajorAxis / Math.hypot(c, this.ratio * s);
2146
+ }
2147
+ normalCurvatureRadius(latitude, azimuth) {
2148
+ if (!Number.isFinite(azimuth))
2149
+ throw new Error("Azimuth must be finite");
2150
+ const [s, c] = sincos(azimuth % 180);
2151
+ return 1 / (c * c / this.meridionalCurvatureRadius(latitude) + s * s / this.transverseCurvatureRadius(latitude));
2152
+ }
2153
+ latitudeToAuxiliary(latitude, kind) {
2154
+ validateKind(kind);
2155
+ validateLatitude(latitude);
2156
+ if (latitude === 0)
2157
+ return latitude;
2158
+ if (Math.abs(latitude) === 90)
2159
+ return kind === "isometric" ? Math.sign(latitude) * Infinity : latitude;
2160
+ if (this.ratio === 1 && kind !== "isometric")
2161
+ return latitude;
2162
+ const sign = Math.sign(latitude);
2163
+ const phi = Math.abs(latitude);
2164
+ const [s, c] = sincos(phi);
2165
+ switch (kind) {
2166
+ case "geocentric":
2167
+ return sign * angle(this.ratio * this.ratio * s, c);
2168
+ case "parametric":
2169
+ return sign * angle(this.ratio * s, c);
2170
+ case "rectifying":
2171
+ return sign * (phi <= 45 ? this.meridian(phi) / this.quarter * 90 : 90 - integrate2((t) => this.meridianIntegrand(Math.PI / 2 - t), 0, (90 - phi) * DEG2) / this.quarter * 90);
2172
+ case "authalic": {
2173
+ if (phi <= 45) {
2174
+ const q = this.ratio ** 2 * (s / (c * c + (this.ratio * s) ** 2) + this.eccentricIntegral(s));
2175
+ return sign * Math.asin(q / this.qPole) / DEG2;
2176
+ }
2177
+ const cap = integrate2((t) => {
2178
+ const st = Math.sin(t), ct = Math.cos(t);
2179
+ const d = st * st + (this.ratio * ct) ** 2;
2180
+ return 2 * this.ratio ** 2 * st / (d * d);
2181
+ }, 0, (90 - phi) * DEG2);
2182
+ return sign * (90 - 2 * Math.asin(Math.sqrt(cap / (2 * this.qPole))) / DEG2);
2183
+ }
2184
+ default: {
2185
+ const psi = Math.asinh(s / c) - this.e2 * this.eccentricIntegral(s);
2186
+ return sign * (kind === "isometric" ? psi / DEG2 : psi < 1 ? Math.atan(Math.sinh(psi)) / DEG2 : 90 - 2 * Math.atan(Math.exp(-psi)) / DEG2);
2187
+ }
2188
+ }
2189
+ }
2190
+ latitudeFromAuxiliary(latitude, kind) {
2191
+ validateKind(kind);
2192
+ if (kind === "isometric" && Math.abs(latitude) === Infinity)
2193
+ return Math.sign(latitude) * 90;
2194
+ if (kind !== "isometric")
2195
+ validateLatitude(latitude);
2196
+ else if (!Number.isFinite(latitude))
2197
+ throw new Error("Isometric latitude must be finite or a pole infinity");
2198
+ if (latitude === 0)
2199
+ return latitude;
2200
+ if (kind !== "isometric" && Math.abs(latitude) === 90)
2201
+ return latitude;
2202
+ if (this.ratio === 1 && kind !== "isometric")
2203
+ return latitude;
2204
+ const sign = Math.sign(latitude), target = Math.abs(latitude);
2205
+ if (kind === "geocentric" || kind === "parametric") {
2206
+ const [s, c] = sincos(target);
2207
+ return sign * angle(s, c * (kind === "geocentric" ? this.ratio ** 2 : this.ratio));
2208
+ }
2209
+ let lo = 0, hi = 90;
2210
+ for (let i = 0; i < 64; ++i) {
2211
+ const mid = (lo + hi) / 2;
2212
+ if (mid === lo || mid === hi)
2213
+ break;
2214
+ if (this.latitudeToAuxiliary(mid, kind) < target)
2215
+ lo = mid;
2216
+ else
2217
+ hi = mid;
2218
+ }
2219
+ return sign * ((lo + hi) / 2);
2220
+ }
2221
+ eccentricIntegral(s) {
2222
+ const e = Math.sqrt(Math.abs(this.e2));
2223
+ return e === 0 ? s : (this.e2 > 0 ? Math.atanh(e * s) : Math.atan(e * s)) / e;
2224
+ }
2225
+ meridianIntegrand(t) {
2226
+ return this.ratio ** 2 / Math.hypot(Math.cos(t), this.ratio * Math.sin(t)) ** 3;
2227
+ }
2228
+ meridian(phi) {
2229
+ return phi <= 45 ? integrate2((t) => this.meridianIntegrand(t), 0, phi * DEG2) : this.quarter - integrate2((t) => this.meridianIntegrand(Math.PI / 2 - t), 0, (90 - phi) * DEG2);
2230
+ }
2231
+ };
2232
+ function validateLatitude(value2) {
2233
+ if (!(Number.isFinite(value2) && Math.abs(value2) <= 90))
2234
+ throw new Error("Latitude must be in [-90, 90] degrees");
2235
+ }
2236
+ function validateKind(kind) {
2237
+ if (!KINDS.includes(kind))
2238
+ throw new Error("Unknown auxiliary latitude");
2239
+ }
2240
+ function sincos(degrees) {
2241
+ const a = Math.abs(degrees);
2242
+ if (a <= 45)
2243
+ return [Math.sin(degrees * DEG2), Math.cos(degrees * DEG2)];
2244
+ return [Math.sign(degrees) * Math.cos((90 - a) * DEG2), Math.sin((90 - a) * DEG2)];
2245
+ }
2246
+ function angle(s, c) {
2247
+ return s > c ? 90 - Math.atan2(c, s) / DEG2 : Math.atan2(s, c) / DEG2;
2248
+ }
2249
+ function integrate2(f, lo, hi) {
2250
+ let sum = 0;
2251
+ for (let j = 0; j < 8; ++j) {
2252
+ const h = (hi - lo) / 16, mid = lo + (2 * j + 1) * h;
2253
+ let part = 0;
2254
+ for (let i = 0; i < 8; ++i)
2255
+ part += WEIGHTS[i] * (f(mid - h * NODES[i]) + f(mid + h * NODES[i]));
2256
+ sum += h * part;
2257
+ }
2258
+ return sum;
2259
+ }
2260
+
2261
+ // dist/ellipsoid-rhumb.js
2262
+ var RhumbDomainError = class extends RangeError {
2263
+ constructor(reason) {
2264
+ super(reason === "pole" ? "Rhumb longitude/bearing is undefined at an exact pole" : "Rhumb crosses a pole; continuation longitude is undefined");
2265
+ this.reason = reason;
2266
+ this.name = "RhumbDomainError";
2267
+ }
2268
+ };
2269
+ var DEG3 = Math.PI / 180;
2270
+ var EllipsoidRhumb = class {
2271
+ constructor({ semiMajorAxis: a, semiMinorAxis: b }) {
2272
+ if (!(Number.isFinite(a) && Number.isFinite(b) && a > 0 && b > 0))
2273
+ throw new RangeError("Rhumbs require finite positive axes");
2274
+ this.a = a;
2275
+ this.b = b;
2276
+ this.r = b / a;
2277
+ this.metrics = new EllipsoidMetrics({ semiMajorAxis: 1, semiMinorAxis: this.r });
2278
+ this.surfaceArea = a * this.metrics.surfaceArea * a;
2279
+ if (!(Number.isFinite(this.surfaceArea) && this.surfaceArea > 0))
2280
+ throw new RangeError("Rhumb surface area is unrepresentable");
2281
+ Object.freeze(this);
2282
+ }
2283
+ inverse(lat1, lon1, lat2, lon2, options = {}) {
2284
+ validateRhumbPoint(lat1, lon1);
2285
+ validateRhumbPoint(lat2, lon2);
2286
+ const turns = options.longitudeTurns ?? 0;
2287
+ if (!Number.isSafeInteger(turns))
2288
+ throw new RangeError("Rhumb longitudeTurns must be a safe integer");
2289
+ const longitude = angleDifference(lon1, lon2) + 360 * turns;
2290
+ if (!Number.isFinite(longitude))
2291
+ throw new RangeError("Unrepresentable rhumb winding");
2292
+ const dphi = (lat2 - lat1) * DEG3;
2293
+ const [meanM, meanP] = this.means(lat1, lat2);
2294
+ const dx = longitude * DEG3 * meanM / meanP;
2295
+ const distance = this.a * Math.hypot(dphi * meanM, dx);
2296
+ const azi = Math.atan2(longitude * DEG3, dphi * meanP) / DEG3;
2297
+ const result = {
2298
+ lat1,
2299
+ lon1,
2300
+ lat2,
2301
+ lon2: options.unrollLongitude ? lon1 + longitude : normalize(lon2),
2302
+ azi12: azi,
2303
+ s12: distance
2304
+ };
2305
+ if (options.area)
2306
+ result.S12 = this.area(lat1, lat2, longitude * DEG3);
2307
+ if (!Number.isFinite(distance))
2308
+ throw new RangeError("Unrepresentable rhumb distance");
2309
+ return result;
2310
+ }
2311
+ direct(latitude, longitude, azimuth, distance, options = {}) {
2312
+ return this.line(latitude, longitude, azimuth, options).position(distance);
2313
+ }
2314
+ line(latitude, longitude, azimuth, options = {}) {
2315
+ validateRhumbPoint(latitude, longitude);
2316
+ if (!Number.isFinite(azimuth))
2317
+ throw new RangeError("Rhumb azimuth must be finite");
2318
+ const [sa, ca] = sincosDegrees(azimuth);
2319
+ const area = Boolean(options.area), unroll = Boolean(options.unrollLongitude);
2320
+ const azi = normalize(azimuth);
2321
+ const evaluate = (distance, _index, _array, output) => {
2322
+ if (!Number.isFinite(distance))
2323
+ throw new RangeError("Rhumb distance must be finite");
2324
+ const delta = distance / this.a;
2325
+ if (!Number.isFinite(delta))
2326
+ throw new RangeError("Unrepresentable rhumb distance");
2327
+ const north = delta * ca;
2328
+ let poleDistance;
2329
+ if (north !== 0) {
2330
+ const gap = north > 0 ? this.meridianDelta(latitude, 90) : this.meridianDelta(-90, latitude);
2331
+ poleDistance = gap - Math.abs(north);
2332
+ if (Math.abs(poleDistance) < 1e-4 * gap)
2333
+ poleDistance = remainingPoleDistance(this.a, this.b, latitude, azimuth, distance, Math.sign(north));
2334
+ if (poleDistance < 0)
2335
+ throw new RhumbDomainError("pole-crossing");
2336
+ if (poleDistance === 0)
2337
+ throw new RhumbDomainError("pole");
2338
+ }
2339
+ const polar = north === 0 ? void 0 : this.polarEndpoint(latitude, north, poleDistance);
2340
+ const lat2 = north === 0 ? latitude : (polar == null ? void 0 : polar.latitude) ?? this.inverseMeridian(latitude, north);
2341
+ if (Math.abs(lat2) === 90)
2342
+ throw new RhumbDomainError("pole");
2343
+ const [meanM, meanP] = (polar == null ? void 0 : polar.means) ?? this.means(latitude, lat2);
2344
+ const dlon = delta * sa * meanP / meanM / DEG3;
2345
+ const lon2 = unroll ? longitude + dlon : normalize(normalize(longitude) + dlon);
2346
+ if (!Number.isFinite(lon2))
2347
+ throw new RangeError("Unrepresentable rhumb longitude");
2348
+ const result = output ?? {};
2349
+ result.lat1 = latitude;
2350
+ result.lon1 = longitude;
2351
+ result.lat2 = lat2;
2352
+ result.lon2 = lon2;
2353
+ result.azi12 = azi;
2354
+ result.s12 = distance;
2355
+ if (!area)
2356
+ delete result.S12;
2357
+ if (area)
2358
+ result.S12 = this.area(latitude, lat2, dlon * DEG3, polar == null ? void 0 : polar.psi);
2359
+ return result;
2360
+ };
2361
+ return { position: evaluate };
2362
+ }
2363
+ means(lat1, lat2) {
2364
+ const d = (lat2 - lat1) * DEG3;
2365
+ const mid = (lat1 + lat2) / 2;
2366
+ const meanM = this.meridianMean(lat1, lat2);
2367
+ const cmin = Math.min(latitudeSinCos(lat1)[1], latitudeSinCos(lat2)[1]);
2368
+ const meanP = Math.abs(d) < 0.25 * cmin ? integrate2((t) => {
2369
+ const [s, c] = latitudeSinCos(mid + t * (lat2 - lat1) / 2);
2370
+ return this.r ** 2 / (c * (c * c + (this.r * s) ** 2));
2371
+ }, -1, 1) / 2 : (this.psi(lat2) - this.psi(lat1)) / d;
2372
+ return [meanM, meanP];
2373
+ }
2374
+ psi(latitude) {
2375
+ return this.metrics.latitudeToAuxiliary(latitude, "isometric") * DEG3;
2376
+ }
2377
+ polarEndpoint(latitude, north, poleDistance) {
2378
+ const sign = Math.abs(latitude) > 80 && Math.abs(north) < Math.abs(this.meridianDelta(0, latitude)) ? Math.sign(latitude) : Math.sign(north), theta1 = (90 - sign * latitude) * DEG3, limit = 10 * DEG3;
2379
+ const density = (theta2) => this.r ** 2 / Math.hypot(Math.sin(theta2), this.r * Math.cos(theta2)) ** 3;
2380
+ const gap = (theta2) => integrate2(density, 0, theta2);
2381
+ const target = sign === Math.sign(north) ? poleDistance : this.meridianDelta(sign > 0 ? latitude : -90, sign > 0 ? 90 : latitude) - sign * north;
2382
+ if (!(target > 0 && target < gap(limit)))
2383
+ return void 0;
2384
+ let lo = 0, hi = limit, theta = target * this.r;
2385
+ if (!(theta > lo && theta < hi))
2386
+ theta = theta1;
2387
+ for (let i = 0; i < 64; i++) {
2388
+ const residual = gap(theta) - target;
2389
+ if (residual === 0)
2390
+ break;
2391
+ if (residual < 0)
2392
+ lo = theta;
2393
+ else
2394
+ hi = theta;
2395
+ const next = theta - residual / density(theta);
2396
+ if (next === theta)
2397
+ break;
2398
+ theta = next > lo && next < hi ? next : (lo + hi) / 2;
2399
+ if (theta === lo || theta === hi)
2400
+ break;
2401
+ if (i === 63)
2402
+ throw new Error("Rhumb polar meridian inversion did not converge");
2403
+ }
2404
+ const span = theta - theta1, mid = (theta + theta1) / 2;
2405
+ const meanM = integrate2((t) => density(mid + t * span / 2), -1, 1) / 2;
2406
+ const meanP = Math.abs(span) < 0.25 * Math.min(Math.sin(theta), Math.sin(theta1)) ? integrate2((t) => {
2407
+ const x = mid + t * span / 2, c = Math.sin(x), s = Math.cos(x);
2408
+ return this.r ** 2 / (c * (c * c + (this.r * s) ** 2));
2409
+ }, -1, 1) / 2 : -(this.polarPsi(theta) - this.polarPsi(theta1)) / span;
2410
+ return {
2411
+ latitude: sign * (90 - theta / DEG3),
2412
+ means: [meanM, meanP],
2413
+ psi: sign * this.polarPsi(theta)
2414
+ };
2415
+ }
2416
+ polarPsi(theta) {
2417
+ const s = Math.cos(theta), c = Math.sin(theta), e2 = (1 - this.r) * (1 + this.r), e = Math.sqrt(Math.abs(e2));
2418
+ const I = e === 0 ? s : (e2 > 0 ? Math.atanh(e * s) : Math.atan(e * s)) / e;
2419
+ return Math.asinh(s / c) - e2 * I;
2420
+ }
2421
+ meridianMean(lat1, lat2) {
2422
+ const mid = (lat1 + lat2) / 2;
2423
+ return integrate2((t) => {
2424
+ const [s, c] = latitudeSinCos(mid + t * (lat2 - lat1) / 2);
2425
+ return this.r ** 2 / Math.hypot(c, this.r * s) ** 3;
2426
+ }, -1, 1) / 2;
2427
+ }
2428
+ meridianDelta(lat1, lat2) {
2429
+ return (lat2 - lat1) * DEG3 * this.meridianMean(lat1, lat2);
2430
+ }
2431
+ inverseMeridian(start, displacement) {
2432
+ let lo = -90, hi = 90;
2433
+ let phi = start + displacement / this.metrics.meridionalCurvatureRadius(start) / DEG3;
2434
+ if (!(phi > lo && phi < hi))
2435
+ phi = (start + Math.sign(displacement) * 90) / 2;
2436
+ for (let i = 0; i < 64; i++) {
2437
+ const residual = this.meridianDelta(start, phi) - displacement;
2438
+ if (residual === 0)
2439
+ return phi;
2440
+ if (residual < 0)
2441
+ lo = phi;
2442
+ else
2443
+ hi = phi;
2444
+ const next = phi - residual / this.metrics.meridionalCurvatureRadius(phi) / DEG3;
2445
+ if (next === phi)
2446
+ return phi;
2447
+ phi = next > lo && next < hi ? next : (lo + hi) / 2;
2448
+ if (phi === lo || phi === hi) {
2449
+ const candidates = [lo, hi].filter((v) => Math.abs(v) < 90);
2450
+ return candidates.reduce((best, v) => Math.abs(this.meridianDelta(start, v) - displacement) < Math.abs(this.meridianDelta(start, best) - displacement) ? v : best);
2451
+ }
2452
+ }
2453
+ throw new Error("Rhumb meridian inversion did not converge");
2454
+ }
2455
+ inversePsi(psi) {
2456
+ let lo = -90, hi = 90, phi = Math.atan(Math.sinh(psi)) / DEG3;
2457
+ if (Math.abs(phi) === 90)
2458
+ phi = Math.sign(psi) * (90 - 2 ** -46);
2459
+ for (let i = 0; i < 32; i++) {
2460
+ const value2 = this.psi(phi) - psi;
2461
+ if (value2 === 0)
2462
+ return phi;
2463
+ if (value2 < 0)
2464
+ lo = phi;
2465
+ else
2466
+ hi = phi;
2467
+ const [s, c] = latitudeSinCos(phi);
2468
+ const next = phi - value2 * c * (c * c + (this.r * s) ** 2) / this.r ** 2 / DEG3;
2469
+ if (next === phi)
2470
+ return phi;
2471
+ phi = next > lo && next < hi ? next : (lo + hi) / 2;
2472
+ if (phi === lo || phi === hi)
2473
+ return phi;
2474
+ }
2475
+ throw new Error("Rhumb isometric inversion did not converge");
2476
+ }
2477
+ potential(latitude) {
2478
+ const [s, c] = latitudeSinCos(latitude), e2 = (1 - this.r) * (1 + this.r), e = Math.sqrt(Math.abs(e2));
2479
+ const I = e === 0 ? s : (e2 > 0 ? Math.atanh(e * s) : Math.atan(e * s)) / e;
2480
+ return this.r ** 2 * (s / (c * c + (this.r * s) ** 2) + I) / 2;
2481
+ }
2482
+ area(lat1, lat2, dlon, endpointPsi) {
2483
+ if (dlon === 0 || lat1 === -lat2)
2484
+ return 0;
2485
+ if (lat1 === lat2) {
2486
+ const value3 = this.a * dlon * (this.a * this.potential(lat1));
2487
+ if (!Number.isFinite(value3))
2488
+ throw new RangeError("Unrepresentable rhumb area");
2489
+ return value3;
2490
+ }
2491
+ const p1 = this.psi(lat1), p2 = endpointPsi ?? this.psi(lat2), mid = (p1 + p2) / 2, half = (p2 - p1) / 2;
2492
+ const pieces = Math.max(1, Math.ceil(Math.abs(p2 - p1) / 2));
2493
+ let sum = 0;
2494
+ for (let j = 0; j < pieces; j++)
2495
+ sum += integrate2((t) => this.potential(this.inversePsi(mid + half * t)), -1 + 2 * j / pieces, -1 + 2 * (j + 1) / pieces);
2496
+ const value2 = this.a * dlon * (this.a * (sum / 2));
2497
+ if (!Number.isFinite(value2))
2498
+ throw new RangeError("Unrepresentable rhumb area");
2499
+ return value2;
2500
+ }
2501
+ };
2502
+ function validateRhumbPoint(latitude, longitude) {
2503
+ if (!(Number.isFinite(latitude) && Math.abs(latitude) <= 90 && Number.isFinite(longitude)))
2504
+ throw new RangeError("Rhumb coordinates require finite longitude and latitude in [-90,90]");
2505
+ if (Math.abs(latitude) === 90)
2506
+ throw new RhumbDomainError("pole");
2507
+ }
2508
+ function latitudeSinCos(phi) {
2509
+ const p = Math.abs(phi);
2510
+ return p <= 45 ? [Math.sin(phi * DEG3), Math.cos(phi * DEG3)] : [Math.sign(phi) * Math.cos((90 - p) * DEG3), Math.sin((90 - p) * DEG3)];
2511
+ }
2512
+ function sincosDegrees(angle2) {
2513
+ const reduced = angle2 % 360, q = Math.round(reduced / 90), d = reduced - 90 * q, x = d * DEG3;
2514
+ const s = Math.sin(x), c = Math.cos(x);
2515
+ switch ((q % 4 + 4) % 4) {
2516
+ case 0:
2517
+ return [s, c];
2518
+ case 1:
2519
+ return [c, -s];
2520
+ case 2:
2521
+ return [-s, -c];
2522
+ default:
2523
+ return [-c, s];
2524
+ }
2525
+ }
2526
+ function normalize(angle2) {
2527
+ let a = angle2 % 360;
2528
+ if (a > 180)
2529
+ a -= 360;
2530
+ if (a < -180)
2531
+ a += 360;
2532
+ return a;
2533
+ }
2534
+ function angleDifference(a, b) {
2535
+ let [d, e] = twoSum(-normalize(a), normalize(b));
2536
+ [d, e] = twoSum(normalize(d), e);
2537
+ if (Math.abs(d) === 180)
2538
+ return (e === 0 ? b < a : e > 0) ? -180 : 180;
2539
+ return d === 0 ? b < a ? -0 : 0 : d;
2540
+ }
2541
+ function twoSum(a, b) {
2542
+ const s = a + b, v = s - a;
2543
+ return [s, a - (s - v) + (b - v)];
2544
+ }
2545
+
2546
+ // dist/rhumb-polygon.js
2547
+ var RhumbPolygon = class extends SurfacePolygon {
2548
+ constructor(parameters, options = {}) {
2549
+ super(new EllipsoidRhumb(parameters), options);
2550
+ }
2551
+ addPoint(latitude, longitude, options = {}) {
2552
+ validateRhumbPoint(latitude, longitude);
2553
+ if (!Number.isSafeInteger(options.longitudeTurns ?? 0))
2554
+ throw new RangeError("Rhumb longitudeTurns must be a safe integer");
2555
+ return super.addPoint(latitude, longitude, options);
2556
+ }
2557
+ };
2558
+
2559
+ // dist/ellipsoid-helpers/intersection-bounds.js
2560
+ var IntersectionBounds = class {
2561
+ constructor(solver, ratio, radius) {
2562
+ this.solver = solver;
2563
+ this.halfCircumference = Math.PI * radius;
2564
+ this.margin = this.halfCircumference * Number.EPSILON ** (1 / 5);
2565
+ this.capture = ratio <= 1 ? Math.PI * ratio : this.polarMinimum(ratio);
2566
+ this.spacing = this.capture - this.margin;
2567
+ if (!(Number.isFinite(this.spacing) && this.spacing > 0))
2568
+ throw new Error("Unresolved geodesic capture bound");
2569
+ }
2570
+ conjugate(line, guess, semi = false, reference = { m12: 0, M12: 1, M21: 1 }) {
2571
+ const { m12, M12, M21 } = reference;
2572
+ let s = guess;
2573
+ for (let i = 0; i < 100; i++) {
2574
+ const p = line.position(s);
2575
+ const m = p.m12 * M12 - m12 * p.M12;
2576
+ const forward = p.M12 * M21 + (m12 === 0 ? 0 : (1 - M12 * M21) * p.m12 / m12);
2577
+ const reverse = p.M21 * M12 + (p.m12 === 0 ? 0 : (1 - p.M12 * p.M21) * m12 / p.m12);
2578
+ const step = semi ? m * forward / (1 - forward * reverse) : -m / reverse;
2579
+ if (!Number.isFinite(step))
2580
+ throw new Error("Unresolved conjugate distance");
2581
+ const next = s + step;
2582
+ if (next === s || Math.abs(step) <= 5e-14)
2583
+ return next;
2584
+ s = next;
2585
+ }
2586
+ throw new Error("Conjugate distance did not converge");
2587
+ }
2588
+ polarDistance(latitude, ratio) {
2589
+ return this.conjugate(this.solver.line(latitude, 0, 0), (1 + (1 - ratio) / 2) * Math.PI / 2, true);
2590
+ }
2591
+ polarMinimum(ratio) {
2592
+ let lat0 = 63, lat1 = 65, lat2 = 64;
2593
+ let s0 = this.polarDistance(lat0, ratio), s1 = this.polarDistance(lat1, ratio), s2 = this.polarDistance(lat2, ratio);
2594
+ let best = s2;
2595
+ for (let i = 0; i < 10; i++) {
2596
+ const denominator = (lat1 - lat0) * s2 + (lat0 - lat2) * s1 + (lat2 - lat1) * s0;
2597
+ if (denominator === 0)
2598
+ break;
2599
+ const next = ((lat1 - lat0) * (lat1 + lat0) * s2 + (lat0 - lat2) * (lat0 + lat2) * s1 + (lat2 - lat1) * (lat2 + lat1) * s0) / (2 * denominator);
2600
+ if (!(Number.isFinite(next) && next >= 0 && next <= 90))
2601
+ break;
2602
+ lat0 = lat1;
2603
+ s0 = s1;
2604
+ lat1 = lat2;
2605
+ s1 = s2;
2606
+ lat2 = next;
2607
+ s2 = this.polarDistance(lat2, ratio);
2608
+ best = Math.min(best, s2);
2609
+ }
2610
+ return 2 * best;
2611
+ }
2612
+ };
2613
+
2614
+ // dist/geodesic-intersections.js
2615
+ var DEG4 = Math.PI / 180;
2616
+ var EPS = 3 * Number.EPSILON;
2617
+ var math2 = geodesic.Math;
2618
+ var GeodesicIntersections = class {
2619
+ constructor({ semiMajorAxis: a, semiMinorAxis: b }) {
2620
+ this.tolerance = 5e-14;
2621
+ const r = b / a;
2622
+ if (!(Number.isFinite(a) && Number.isFinite(b) && a > 0 && b > 0 && r >= 0.99 && r <= 1.01))
2623
+ throw new RangeError("Intersections require finite positive axes with 0.99 <= b/a <= 1.01");
2624
+ this.a = a;
2625
+ this.r = r;
2626
+ this.solver = new EllipsoidGeodesic({ semiMajorAxis: 1, semiMinorAxis: r });
2627
+ this.radius = Math.sqrt(this.solver.surfaceArea / (4 * Math.PI));
2628
+ this.bounds = new IntersectionBounds(this.solver, r, this.radius);
2629
+ Object.freeze(this);
2630
+ }
2631
+ /** Find all discovered roots in the L1 ball |s-originS|+|t-originT| <= maxDistance. */
2632
+ all(a, b, options) {
2633
+ return this.search(a, b, options, false);
2634
+ }
2635
+ search(a, b, options, normalized) {
2636
+ const A = this.solver.line(a.latitude, a.longitude, a.azimuth), B = this.solver.line(b.latitude, b.longitude, b.azimuth);
2637
+ const d = normalized ? options.maxDistance : options.maxDistance / this.a, origin = options.origin ?? [0, 0];
2638
+ const x = origin[0] / this.a, y = origin[1] / this.a;
2639
+ if (!(Number.isFinite(d) && d > 0 && (normalized ? d <= 4 * this.bounds.halfCircumference : options.maxDistance <= 4 * this.bounds.halfCircumference * this.a) && Number.isFinite(x) && Number.isFinite(y) && Math.max(Math.abs(origin[0]), Math.abs(origin[1])) <= 4 * this.bounds.halfCircumference * this.a))
2640
+ throw new RangeError("Intersection search requires finite bounds within four half-circumferences");
2641
+ if (this.r === 1) {
2642
+ const analytic = this.sphere(a, b, A, B, d, x, y);
2643
+ if (analytic)
2644
+ return analytic;
2645
+ }
2646
+ const extended = d + this.bounds.margin;
2647
+ const m = Math.ceil(extended / this.bounds.spacing), n = m - 1;
2648
+ const spacing = extended / m;
2649
+ const seeds = [[x, y, spacing, 0]];
2650
+ for (let i = -n; i <= n; i += 2)
2651
+ for (let j = -n; j <= n; j += 2)
2652
+ if (i || j)
2653
+ seeds.push([x + spacing * (i + j) / 2, y + spacing * (i - j) / 2, spacing, 0]);
2654
+ let failed = 0, unresolved = 0;
2655
+ const isolated = [], lines = [];
2656
+ const equal = (p, q) => Math.abs(p.x - q.x) + Math.abs(p.y - q.y) <= this.bounds.margin;
2657
+ const canonical = (p, c) => {
2658
+ const shift = (x + c * y - (p.x + c * p.y)) / 2;
2659
+ return { ...p, x: p.x + shift, y: p.y + c * shift, c };
2660
+ };
2661
+ const retry = (seed) => {
2662
+ ++failed;
2663
+ if (seed[3] === 3) {
2664
+ ++unresolved;
2665
+ return;
2666
+ }
2667
+ const half = seed[2] / 2, depth = seed[3] + 1;
2668
+ for (const [dx, dy] of [
2669
+ [half, 0],
2670
+ [-half, 0],
2671
+ [0, half],
2672
+ [0, -half]
2673
+ ])
2674
+ seeds.push([seed[0] + dx, seed[1] + dy, half, depth]);
2675
+ };
2676
+ for (const seed of seeds) {
2677
+ const root = this.refine(A, B, seed[0], seed[1]);
2678
+ if (!root) {
2679
+ retry(seed);
2680
+ continue;
2681
+ }
2682
+ if (root.c) {
2683
+ const q = canonical(root, root.c);
2684
+ if (!this.point(A, B, q)) {
2685
+ retry(seed);
2686
+ continue;
2687
+ }
2688
+ if (!lines.some((p) => p.c === q.c && equal(p, q)))
2689
+ lines.push(q);
2690
+ } else if (!isolated.some((p) => equal(p, root)))
2691
+ isolated.push(root);
2692
+ }
2693
+ const roots = [], coincidences = [];
2694
+ for (const p of isolated) {
2695
+ if (lines.some((q) => equal(canonical(p, q.c), q)))
2696
+ continue;
2697
+ if (Math.abs(p.x - x) + Math.abs(p.y - y) > d + this.tolerance)
2698
+ continue;
2699
+ const point2 = this.point(A, B, p);
2700
+ if (point2)
2701
+ roots.push(point2);
2702
+ else {
2703
+ ++failed;
2704
+ ++unresolved;
2705
+ }
2706
+ }
2707
+ for (const p of lines) {
2708
+ if (Math.abs(p.x - x) + Math.abs(p.y - y) <= d + this.tolerance)
2709
+ coincidences.push({
2710
+ s: p.x * this.a,
2711
+ t: p.y * this.a,
2712
+ direction: p.c
2713
+ });
2714
+ }
2715
+ this.sort(roots, origin);
2716
+ this.sort(coincidences, origin);
2717
+ return {
2718
+ intersections: roots,
2719
+ coincidences,
2720
+ complete: unresolved === 0,
2721
+ attemptedSeeds: seeds.length,
2722
+ failedSeeds: failed
2723
+ };
2724
+ }
2725
+ /** Without an explicit radius, search the full native global profile.
2726
+ * A returned root from any complete centered L1 search is globally closest:
2727
+ * every point outside that ball is farther from its center.
2728
+ */
2729
+ closest(a, b, options = {}) {
2730
+ const settings = {
2731
+ ...options,
2732
+ maxDistance: options.maxDistance ?? 4 * this.bounds.halfCircumference
2733
+ };
2734
+ const search = this.search(a, b, settings, options.maxDistance === void 0);
2735
+ const candidates = [...search.intersections];
2736
+ for (const c of search.coincidences) {
2737
+ const point2 = this.coincidencePoint(a, b, c);
2738
+ if (point2)
2739
+ candidates.push(point2);
2740
+ else {
2741
+ search.complete = false;
2742
+ ++search.failedSeeds;
2743
+ }
2744
+ }
2745
+ this.sort(candidates, settings.origin ?? [0, 0]);
2746
+ return { ...search, intersection: candidates[0] };
2747
+ }
2748
+ /** Global next crossing, excluding the shared parameter origin. For a
2749
+ * coincident continuum use GeographicLib's nearest-conjugate convention.
2750
+ */
2751
+ next(latitude, longitude, azimuthA, azimuthB, maxDistance) {
2752
+ const a = { latitude, longitude, azimuth: azimuthA }, b = { latitude, longitude, azimuth: azimuthB };
2753
+ const bound = maxDistance === void 0 ? 4 * this.bounds.halfCircumference : maxDistance / this.a;
2754
+ const search = this.search(a, b, { maxDistance: maxDistance ?? bound }, maxDistance === void 0);
2755
+ search.intersections = search.intersections.filter((p) => Math.abs(p.s / this.a) + Math.abs(p.t / this.a) > this.bounds.margin);
2756
+ const candidates = [...search.intersections];
2757
+ const A = this.solver.line(latitude, longitude, azimuthA);
2758
+ for (const c of search.coincidences) {
2759
+ if (Math.abs(c.s / this.a) + Math.abs(c.t / this.a) > this.bounds.margin) {
2760
+ const point2 = this.coincidencePoint(a, b, c);
2761
+ if (point2)
2762
+ candidates.push(point2);
2763
+ else {
2764
+ search.complete = false;
2765
+ ++search.failedSeeds;
2766
+ }
2767
+ } else {
2768
+ for (const sign of [-1, 1]) {
2769
+ try {
2770
+ const s = this.bounds.conjugate(A, sign * this.bounds.halfCircumference);
2771
+ const point2 = this.coincidencePoint(a, b, {
2772
+ s: s * this.a,
2773
+ t: c.direction * s * this.a,
2774
+ direction: c.direction
2775
+ });
2776
+ if (point2)
2777
+ candidates.push(point2);
2778
+ else {
2779
+ search.complete = false;
2780
+ ++search.failedSeeds;
2781
+ }
2782
+ } catch {
2783
+ search.complete = false;
2784
+ ++search.failedSeeds;
2785
+ }
2786
+ }
2787
+ }
2788
+ }
2789
+ const bounded = candidates.filter((p) => Math.abs(p.s / this.a) + Math.abs(p.t / this.a) <= bound + this.tolerance);
2790
+ this.sort(bounded, [0, 0]);
2791
+ return { ...search, intersection: bounded[0] };
2792
+ }
2793
+ coincidencePoint(a, b, c) {
2794
+ return this.point(this.solver.line(a.latitude, a.longitude, a.azimuth), this.solver.line(b.latitude, b.longitude, b.azimuth), { x: c.s / this.a, y: c.t / this.a, c: c.direction, iterations: 0 });
2795
+ }
2796
+ segments(a0, a1, b0, b1) {
2797
+ const ia = this.solver.inverse(...a0, ...a1), ib = this.solver.inverse(...b0, ...b1);
2798
+ if (this.ambiguous(a0, a1, ia) || this.ambiguous(b0, b1, ib))
2799
+ return { status: "ambiguous", complete: false };
2800
+ const sa = ia.s12, sb = ib.s12;
2801
+ if (sa === 0 || sb === 0) {
2802
+ const p = sa === 0 ? a0 : b0, start = sa === 0 ? b0 : a0, end = sa === 0 ? b1 : a1, len = sa === 0 ? sb : sa;
2803
+ const ip = this.solver.inverse(...start, ...p);
2804
+ const d0 = ip.s12;
2805
+ const route = this.solver.inverse(...start, ...end);
2806
+ const projected = this.solver.direct(start[0], start[1], route.azi1, d0);
2807
+ const residual = this.solver.inverse(projected.lat2, projected.lon2, ...p).s12;
2808
+ if (d0 > len + this.tolerance || residual > this.tolerance)
2809
+ return { status: "disjoint", complete: true };
2810
+ return {
2811
+ status: "intersection",
2812
+ complete: true,
2813
+ point: {
2814
+ s: (sa === 0 ? 0 : d0) * this.a,
2815
+ t: (sb === 0 ? 0 : d0) * this.a,
2816
+ latitude: p[0],
2817
+ longitude: p[1],
2818
+ residual: residual * this.a,
2819
+ crossingAngle: 0,
2820
+ iterations: 0
2821
+ }
2822
+ };
2823
+ }
2824
+ const search = this.all({ latitude: a0[0], longitude: a0[1], azimuth: ia.azi1 }, { latitude: b0[0], longitude: b0[1], azimuth: ib.azi1 }, {
2825
+ origin: [sa * this.a / 2, sb * this.a / 2],
2826
+ maxDistance: (sa + sb) * this.a / 2 + this.tolerance * this.a
2827
+ });
2828
+ for (const c of search.coincidences) {
2829
+ const offset = c.t / this.a - c.direction * c.s / this.a;
2830
+ const lo = Math.max(0, c.direction === 1 ? -offset : offset - sb), hi = Math.min(sa, c.direction === 1 ? sb - offset : offset);
2831
+ if (hi >= lo - this.tolerance) {
2832
+ if (hi - lo > this.tolerance)
2833
+ return {
2834
+ status: "overlap",
2835
+ intervalA: [lo * this.a, hi * this.a],
2836
+ intervalB: [(c.direction * lo + offset) * this.a, (c.direction * hi + offset) * this.a],
2837
+ complete: search.complete
2838
+ };
2839
+ const s = (lo + hi) / 2, t = c.direction * s + offset;
2840
+ const A = this.solver.line(a0[0], a0[1], ia.azi1), B = this.solver.line(b0[0], b0[1], ib.azi1);
2841
+ const point3 = this.point(A, B, { x: s, y: t, c: 0, iterations: 0 });
2842
+ if (point3)
2843
+ return { status: "intersection", point: point3, complete: search.complete };
2844
+ search.complete = false;
2845
+ ++search.failedSeeds;
2846
+ }
2847
+ }
2848
+ const point2 = search.intersections.find((p) => p.s / this.a >= -this.tolerance && p.s / this.a <= sa + this.tolerance && p.t / this.a >= -this.tolerance && p.t / this.a <= sb + this.tolerance);
2849
+ return point2 ? { status: "intersection", point: point2, complete: search.complete } : { status: search.complete ? "disjoint" : "not-found", complete: search.complete };
2850
+ }
2851
+ ambiguous(start, end, path) {
2852
+ if (path.a12 > 180 - 1e-10)
2853
+ return true;
2854
+ if (Math.abs(start[0]) === 90 || Math.abs(end[0]) === 90)
2855
+ return false;
2856
+ if (start[0] === -end[0] && math2.AngDiff(path.azi1, path.azi2).d !== 0)
2857
+ return true;
2858
+ const longitude = math2.AngDiff(start[1], end[1]);
2859
+ return Math.abs(longitude.d) === 180 && longitude.e === 0 && path.azi1 !== 0 && Math.abs(path.azi1) !== 180;
2860
+ }
2861
+ refine(A, B, x, y) {
2862
+ for (let i = 0; i < 100; i++) {
2863
+ const a = A.position(x), b = B.position(y), v = this.solver.inverse(a.lat2, a.lon2, b.lat2, b.lon2);
2864
+ const X = math2.AngDiff(a.azi2, v.azi1), Y = math2.AngDiff(b.azi2, v.azi2), XY = math2.AngDiff(X.d, Y.d);
2865
+ const orientation = XY.d + (XY.e + Y.e - X.e) < 0 ? -1 : 1;
2866
+ const sx = math2.sincosde(orientation * X.d, orientation * X.e), sy = math2.sincosde(orientation * Y.d, orientation * Y.e);
2867
+ let dx, dy, c = 0;
2868
+ if (v.s12 <= EPS * this.radius) {
2869
+ if (Math.abs(sx.s - sy.s) <= EPS && Math.abs(sx.c - sy.c) <= EPS)
2870
+ c = 1;
2871
+ else if (Math.abs(sx.s + sy.s) <= EPS && Math.abs(sx.c + sy.c) <= EPS)
2872
+ c = -1;
2873
+ return { x, y, c, iterations: i };
2874
+ }
2875
+ if (Math.abs(sx.s) <= EPS && Math.abs(sy.s) <= EPS) {
2876
+ c = sx.c * sy.c > 0 ? 1 : -1;
2877
+ dx = sx.c * v.s12 / 2;
2878
+ dy = -sy.c * v.s12 / 2;
2879
+ } else {
2880
+ const sz = Math.sin(v.s12 / this.radius), cz = Math.cos(v.s12 / this.radius);
2881
+ dx = this.radius * Math.atan2(sy.s * sz, sy.s * sx.c * cz - sy.c * sx.s);
2882
+ dy = this.radius * Math.atan2(sx.s * sz, -sx.s * sy.c * cz + sx.c * sy.s);
2883
+ }
2884
+ if (!(Number.isFinite(dx) && Number.isFinite(dy)))
2885
+ return void 0;
2886
+ x += dx;
2887
+ y += dy;
2888
+ if (Math.max(Math.abs(x), Math.abs(y)) > 12 * Math.PI * this.radius)
2889
+ return void 0;
2890
+ if (c)
2891
+ return { x, y, c, iterations: i + 1 };
2892
+ if (Math.abs(dx) + Math.abs(dy) <= this.tolerance) {
2893
+ const root = { x, y, c, iterations: i + 1 };
2894
+ if (this.point(A, B, root))
2895
+ return root;
2896
+ }
2897
+ }
2898
+ return void 0;
2899
+ }
2900
+ point(A, B, p) {
2901
+ const s = p.x * this.a, t = p.y * this.a;
2902
+ if (!(Number.isFinite(s) && Number.isFinite(t)) || Math.abs(s / this.a - p.x) > this.tolerance || Math.abs(t / this.a - p.y) > this.tolerance)
2903
+ return void 0;
2904
+ const a = A.position(p.x), b = B.position(p.y), v = this.solver.inverse(a.lat2, a.lon2, b.lat2, b.lon2);
2905
+ if (!(Number.isFinite(v.s12) && v.s12 <= this.tolerance && Number.isFinite(p.x * this.a) && Number.isFinite(p.y * this.a)))
2906
+ return void 0;
2907
+ const ta = frame({ latitude: a.lat2, longitude: a.lon2, azimuth: a.azi2 })[1];
2908
+ const tb = frame({ latitude: b.lat2, longitude: b.lon2, azimuth: b.azi2 })[1];
2909
+ const angle2 = Math.atan2(Math.hypot(...cross(ta, tb)), Math.abs(dot(ta, tb))) / DEG4;
2910
+ return {
2911
+ s: p.x * this.a,
2912
+ t: p.y * this.a,
2913
+ latitude: a.lat2,
2914
+ longitude: a.lon2,
2915
+ residual: v.s12 * this.a,
2916
+ crossingAngle: angle2,
2917
+ iterations: p.iterations,
2918
+ ...p.c ? { coincidence: p.c } : {}
2919
+ };
2920
+ }
2921
+ sphere(a, b, A, B, d, x, y) {
2922
+ const [pa, ta, na] = frame(a), [pb, tb, nb] = frame(b), crossing = cross(na, nb), length = Math.hypot(...crossing);
2923
+ if (length > 0 && length < Math.sqrt(Number.EPSILON))
2924
+ return void 0;
2925
+ if (length <= EPS) {
2926
+ const sign = dot(na, nb) >= 0 ? 1 : -1;
2927
+ const offset = Math.atan2(dot(pa, tb), dot(pa, pb));
2928
+ const coincidences = [];
2929
+ for (let k = Math.ceil((y - sign * x - d - offset) / (2 * Math.PI)); k <= Math.floor((y - sign * x + d - offset) / (2 * Math.PI)); k++) {
2930
+ const shift = offset + 2 * Math.PI * k;
2931
+ const sx = (x + sign * (y - shift)) / 2;
2932
+ const sy = sign * sx + shift;
2933
+ if (Math.abs(sx - x) + Math.abs(sy - y) <= d + this.tolerance)
2934
+ coincidences.push({ s: sx * this.a, t: sy * this.a, direction: sign });
2935
+ }
2936
+ let failed2 = 0;
2937
+ const checked = coincidences.filter((c) => {
2938
+ const p = this.point(A, B, {
2939
+ x: c.s / this.a,
2940
+ y: c.t / this.a,
2941
+ c: c.direction,
2942
+ iterations: 0
2943
+ });
2944
+ if (!p)
2945
+ ++failed2;
2946
+ return Boolean(p);
2947
+ });
2948
+ return {
2949
+ intersections: [],
2950
+ coincidences: checked,
2951
+ complete: failed2 === 0,
2952
+ attemptedSeeds: 0,
2953
+ failedSeeds: failed2
2954
+ };
2955
+ }
2956
+ const result = [];
2957
+ let failed = 0;
2958
+ for (const sign of [-1, 1]) {
2959
+ const p = crossing.map((v) => sign * v / length);
2960
+ const s = Math.atan2(dot(p, ta), dot(p, pa)), t = Math.atan2(dot(p, tb), dot(p, pb));
2961
+ const k0 = Math.ceil((x - d - s) / (2 * Math.PI)), k1 = Math.floor((x + d - s) / (2 * Math.PI));
2962
+ const l0 = Math.ceil((y - d - t) / (2 * Math.PI)), l1 = Math.floor((y + d - t) / (2 * Math.PI));
2963
+ for (let k = k0; k <= k1; k++)
2964
+ for (let l = l0; l <= l1; l++) {
2965
+ const sx = s + 2 * Math.PI * k, sy = t + 2 * Math.PI * l;
2966
+ if (Math.abs(sx - x) + Math.abs(sy - y) > d + this.tolerance)
2967
+ continue;
2968
+ const point2 = this.point(A, B, { x: sx, y: sy, c: 0, iterations: 0 });
2969
+ if (point2)
2970
+ result.push(point2);
2971
+ else
2972
+ ++failed;
2973
+ }
2974
+ }
2975
+ this.sort(result, [x * this.a, y * this.a]);
2976
+ return {
2977
+ intersections: result,
2978
+ coincidences: [],
2979
+ complete: failed === 0,
2980
+ attemptedSeeds: 0,
2981
+ failedSeeds: failed
2982
+ };
2983
+ }
2984
+ sort(points, origin) {
2985
+ const x = origin[0] / this.a, y = origin[1] / this.a;
2986
+ points.sort((p, q) => Math.abs(p.s / this.a - x) + Math.abs(p.t / this.a - y) - (Math.abs(q.s / this.a - x) + Math.abs(q.t / this.a - y)) || p.s / this.a - q.s / this.a || p.t / this.a - q.t / this.a);
2987
+ }
2988
+ };
2989
+ function frame(p) {
2990
+ const [s, c] = sincos2(p.latitude), [sl, cl] = sincos2(p.longitude), [sa, ca] = sincos2(p.azimuth);
2991
+ const point2 = [c * cl, c * sl, s], north = [-s * cl, -s * sl, c], east = [-sl, cl, 0];
2992
+ const tangent = north.map((v, i) => ca * v + sa * east[i]);
2993
+ return [point2, tangent, cross(point2, tangent)];
2994
+ }
2995
+ function sincos2(degrees) {
2996
+ const a = degrees % 360, q = Math.round(a / 90), d = (a - 90 * q) * DEG4, s = Math.sin(d), c = Math.cos(d);
2997
+ switch ((q % 4 + 4) % 4) {
2998
+ case 0:
2999
+ return [s, c];
3000
+ case 1:
3001
+ return [c, -s];
3002
+ case 2:
3003
+ return [-s, -c];
3004
+ default:
3005
+ return [-c, s];
3006
+ }
3007
+ }
3008
+ function dot(a, b) {
3009
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
3010
+ }
3011
+ function cross(a, b) {
3012
+ return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
3013
+ }
3014
+
3015
+ // dist/constants.js
3016
+ var WGS84_RADIUS_X = 6378137;
3017
+ var WGS84_RADIUS_Y = 6378137;
3018
+ var WGS84_RADIUS_Z = 6356752314245179e-9;
3019
+ var WGS84_CONSTANTS = {
3020
+ radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],
3021
+ radiiSquared: [
3022
+ WGS84_RADIUS_X * WGS84_RADIUS_X,
3023
+ WGS84_RADIUS_Y * WGS84_RADIUS_Y,
3024
+ WGS84_RADIUS_Z * WGS84_RADIUS_Z
3025
+ ],
3026
+ oneOverRadii: [1 / WGS84_RADIUS_X, 1 / WGS84_RADIUS_Y, 1 / WGS84_RADIUS_Z],
3027
+ oneOverRadiiSquared: [
3028
+ 1 / (WGS84_RADIUS_X * WGS84_RADIUS_X),
3029
+ 1 / (WGS84_RADIUS_Y * WGS84_RADIUS_Y),
3030
+ 1 / (WGS84_RADIUS_Z * WGS84_RADIUS_Z)
3031
+ ],
3032
+ maximumRadius: Math.max(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z),
3033
+ centerToleranceSquared: 0.1
3034
+ // EPSILON1;
3035
+ };
3036
+
3037
+ // dist/geodesic-path.js
3038
+ var wgs84;
3039
+ var GeodesicPath = class {
3040
+ constructor(start, end, options = {}) {
3041
+ validateGeographicPosition(start);
3042
+ validateGeographicPosition(end);
3043
+ if (start.length !== end.length)
3044
+ throw new RangeError("Geodesic endpoint dimensions must match");
3045
+ const solver = options.geodesic || getDefaultGeodesic();
3046
+ const inverse = solver.inverse(start[1], start[0], end[1], end[0], { unrollLongitude: true });
3047
+ if (!Number.isFinite(inverse.s12) || inverse.s12 < 0 || !Number.isFinite(inverse.azi1) || !Number.isFinite(inverse.lon2)) {
3048
+ throw new RangeError("Unresolved geodesic path");
3049
+ }
3050
+ this.size = start.length;
3051
+ this.length = inverse.s12;
3052
+ this.first = Object.freeze(Array.from(start));
3053
+ const last = Array.from(end);
3054
+ last[0] = inverse.lon2;
3055
+ if (this.length === 0) {
3056
+ last[0] = start[0];
3057
+ last[1] = start[1];
3058
+ }
3059
+ this.last = Object.freeze(last);
3060
+ this.line = solver.line(start[1], start[0], inverse.azi1, { unrollLongitude: true });
3061
+ }
3062
+ get start() {
3063
+ return this.first.slice();
3064
+ }
3065
+ get end() {
3066
+ return this.last.slice();
3067
+ }
3068
+ sample(fraction, result = new Array(this.size)) {
3069
+ if (!Number.isFinite(fraction) || fraction < 0 || fraction > 1) {
3070
+ throw new RangeError("Geodesic fraction must be in [0, 1]");
3071
+ }
3072
+ if (result.length !== this.size)
3073
+ throw new RangeError("Invalid geodesic sample output length");
3074
+ let longitude;
3075
+ let latitude;
3076
+ if (fraction === 0 || this.length === 0) {
3077
+ longitude = this.first[0];
3078
+ latitude = this.first[1];
3079
+ } else if (fraction === 1) {
3080
+ longitude = this.last[0];
3081
+ latitude = this.last[1];
3082
+ } else {
3083
+ const value2 = this.line.position(this.length * fraction);
3084
+ longitude = value2.lon2;
3085
+ latitude = value2.lat2;
3086
+ }
3087
+ const height = this.size === 3 ? this.first[2] * (1 - fraction) + this.last[2] * fraction : 0;
3088
+ if (![longitude, latitude, height].every(Number.isFinite) || result instanceof Float32Array && ![longitude, latitude, height].every((value2) => Number.isFinite(Math.fround(value2)))) {
3089
+ throw new RangeError("Unrepresentable geodesic sample");
3090
+ }
3091
+ result[0] = longitude;
3092
+ result[1] = latitude;
3093
+ if (this.size === 3)
3094
+ result[2] = height;
3095
+ return result;
3096
+ }
3097
+ sampleByDistance(distance, result = new Array(this.size)) {
3098
+ if (!Number.isFinite(distance) || distance < 0 || distance > this.length) {
3099
+ throw new RangeError("Distance must be within the geodesic path");
3100
+ }
3101
+ return this.sample(this.length === 0 ? 0 : distance / this.length, result);
3102
+ }
3103
+ };
3104
+ function validateGeographicPosition(point2) {
3105
+ if (point2.length !== 2 && point2.length !== 3 || !Array.from(point2).every(Number.isFinite) || Math.abs(point2[1]) > 90) {
3106
+ throw new RangeError("Expected finite longitude/latitude[/height], latitude in [-90, 90]");
3107
+ }
3108
+ }
3109
+ function getDefaultGeodesic() {
3110
+ if (!wgs84) {
3111
+ wgs84 = new EllipsoidGeodesic({ semiMajorAxis: WGS84_RADIUS_X, semiMinorAxis: WGS84_RADIUS_Z });
3112
+ }
3113
+ return wgs84;
3114
+ }
3115
+
3116
+ // dist/rhumb-path.js
3117
+ var wgs842;
3118
+ function getDefaultRhumb() {
3119
+ if (!wgs842)
3120
+ wgs842 = new EllipsoidRhumb({ semiMajorAxis: WGS84_RADIUS_X, semiMinorAxis: WGS84_RADIUS_Z });
3121
+ return wgs842;
3122
+ }
3123
+ var RhumbPath = class {
3124
+ constructor(start, end, options = {}) {
3125
+ validateGeographicPosition(start);
3126
+ validateGeographicPosition(end);
3127
+ if (start.length !== end.length)
3128
+ throw new RangeError("Rhumb endpoint dimensions must match");
3129
+ const solver = options.rhumb || getDefaultRhumb();
3130
+ if (options.longitudeMode !== void 0 && !["shortest", "unrolled"].includes(options.longitudeMode) || options.longitudeMode === "unrolled" && options.longitudeTurns !== void 0)
3131
+ throw new RangeError("Choose explicit turns or unrolled endpoint longitudes");
3132
+ let inverse = solver.inverse(start[1], start[0], end[1], end[0], {
3133
+ longitudeTurns: options.longitudeTurns,
3134
+ unrollLongitude: true
3135
+ });
3136
+ if (options.longitudeMode === "unrolled") {
3137
+ const turns2 = Math.round((end[0] - inverse.lon2) / 360);
3138
+ if (turns2 !== 0)
3139
+ inverse = solver.inverse(start[1], start[0], end[1], end[0], {
3140
+ longitudeTurns: turns2,
3141
+ unrollLongitude: true
3142
+ });
3143
+ }
3144
+ if (![inverse.s12, inverse.azi12, inverse.lon2].every(Number.isFinite) || inverse.s12 < 0)
3145
+ throw new RangeError("Unresolved rhumb path");
3146
+ this.size = start.length;
3147
+ this.length = inverse.s12;
3148
+ this.first = Object.freeze(Array.from(start));
3149
+ const last = Array.from(end);
3150
+ const turns = Math.round((inverse.lon2 - end[0]) / 360);
3151
+ const endpoint = end[0] + 360 * turns;
3152
+ const retainsPhase = Number.isSafeInteger(turns) && Number.isFinite(endpoint) && Math.abs(endpoint - inverse.lon2) <= 4 * Number.EPSILON * Math.max(360, Math.abs(inverse.lon2));
3153
+ last[0] = inverse.s12 === 0 ? start[0] : retainsPhase ? endpoint : inverse.lon2;
3154
+ if (inverse.s12 === 0)
3155
+ last[1] = start[1];
3156
+ this.last = Object.freeze(last);
3157
+ this.line = solver.line(start[1], start[0], inverse.azi12, { unrollLongitude: true });
3158
+ }
3159
+ get start() {
3160
+ return this.first.slice();
3161
+ }
3162
+ get end() {
3163
+ return this.last.slice();
3164
+ }
3165
+ sample(fraction, result = new Array(this.size)) {
3166
+ if (!Number.isFinite(fraction) || fraction < 0 || fraction > 1)
3167
+ throw new RangeError("Rhumb fraction must be in [0, 1]");
3168
+ if (result.length !== this.size || ArrayBuffer.isView(result) && !(result instanceof Float32Array) && !(result instanceof Float64Array))
3169
+ throw new RangeError("Expected a floating rhumb output with matching dimensions");
3170
+ let longitude = this.first[0], latitude = this.first[1];
3171
+ if (fraction === 1) {
3172
+ longitude = this.last[0];
3173
+ latitude = this.last[1];
3174
+ } else if (fraction !== 0 && this.length !== 0) {
3175
+ const p = this.line.position(this.length * fraction);
3176
+ longitude = p.lon2;
3177
+ latitude = p.lat2;
3178
+ }
3179
+ const height = this.size === 3 ? this.first[2] * (1 - fraction) + this.last[2] * fraction : 0;
3180
+ const values = [longitude, latitude, height];
3181
+ if (!values.every(Number.isFinite) || result instanceof Float32Array && !values.every((x) => Number.isFinite(Math.fround(x))))
3182
+ throw new RangeError("Unrepresentable rhumb sample");
3183
+ result[0] = longitude;
3184
+ result[1] = latitude;
3185
+ if (this.size === 3)
3186
+ result[2] = height;
3187
+ return result;
3188
+ }
3189
+ sampleByDistance(distance, result = new Array(this.size)) {
3190
+ if (!Number.isFinite(distance) || distance < 0 || distance > this.length)
3191
+ throw new RangeError("Distance must be within the rhumb path");
3192
+ return this.sample(this.length === 0 ? 0 : distance / this.length, result);
3193
+ }
3194
+ };
3195
+ //# sourceMappingURL=geodesics.cjs.map