@math.gl/geospatial 5.0.0-rc.2 → 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,4160 @@
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 key2 of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key2) && key2 !== except)
13
+ __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // dist/geographic-cuts.js
20
+ var geographic_cuts_exports = {};
21
+ __export(geographic_cuts_exports, {
22
+ GeographicCutAtlas: () => GeographicCutAtlas,
23
+ GeographicSeamError: () => import_types14.GeographicSeamError,
24
+ clipGeographicPolygon: () => clipGeographicPolygon,
25
+ clipGeographicPolyline: () => clipGeographicPolyline,
26
+ createOctahedralCutAtlas: () => createOctahedralCutAtlas,
27
+ createOctahedralCutGraph: () => createOctahedralCutGraph,
28
+ createOrthographicCutAtlas: () => createOrthographicCutAtlas,
29
+ subdivideGeographicCutRing: () => subdivideGeographicCutRing
30
+ });
31
+ module.exports = __toCommonJS(geographic_cuts_exports);
32
+
33
+ // dist/vendor/geographiclib-geodesic/runtime.js
34
+ var geodesic = {};
35
+ geodesic.Constants = {};
36
+ geodesic.Math = {};
37
+ geodesic.Accumulator = {};
38
+ (function(c) {
39
+ "use strict";
40
+ c.WGS84 = { a: 6378137, f: 1 / 298.257223563 };
41
+ c.version = {
42
+ major: 2,
43
+ minor: 2,
44
+ patch: 0
45
+ };
46
+ c.version_string = "2.2.0";
47
+ })(geodesic.Constants);
48
+ (function(m) {
49
+ "use strict";
50
+ m.digits = 53;
51
+ m.epsilon = Math.pow(0.5, m.digits - 1);
52
+ m.degree = Math.PI / 180;
53
+ m.sq = function(x) {
54
+ return x * x;
55
+ };
56
+ m.hypot = function(x, y) {
57
+ return Math.sqrt(x * x + y * y);
58
+ };
59
+ m.cbrt = Math.cbrt || function(x) {
60
+ var y = Math.pow(Math.abs(x), 1 / 3);
61
+ return x > 0 ? y : x < 0 ? -y : x;
62
+ };
63
+ m.log1p = Math.log1p || function(x) {
64
+ var y = 1 + x, z = y - 1;
65
+ return z === 0 ? x : x * Math.log(y) / z;
66
+ };
67
+ m.atanh = Math.atanh || function(x) {
68
+ var y = Math.abs(x);
69
+ y = m.log1p(2 * y / (1 - y)) / 2;
70
+ return x > 0 ? y : x < 0 ? -y : x;
71
+ };
72
+ m.copysign = function(x, y) {
73
+ return Math.abs(x) * (y < 0 || y === 0 && 1 / y < 0 ? -1 : 1);
74
+ };
75
+ m.sum = function(u, v) {
76
+ var s = u + v, up = s - v, vpp = s - up, t;
77
+ up -= u;
78
+ vpp -= v;
79
+ t = s ? 0 - (up + vpp) : s;
80
+ return { s, t };
81
+ };
82
+ m.polyval = function(N, p, s, x) {
83
+ var y = N < 0 ? 0 : p[s++];
84
+ while (--N >= 0)
85
+ y = y * x + p[s++];
86
+ return y;
87
+ };
88
+ m.AngRound = function(x) {
89
+ var z = 1 / 16, y = Math.abs(x);
90
+ y = y < z ? z - (z - y) : y;
91
+ return m.copysign(y, x);
92
+ };
93
+ m.remainder = function(x, y) {
94
+ x %= y;
95
+ return x < -y / 2 ? x + y : x < y / 2 ? x : x - y;
96
+ };
97
+ m.AngNormalize = function(x) {
98
+ var y = m.remainder(x, 360);
99
+ return Math.abs(y) === 180 ? m.copysign(180, x) : y;
100
+ };
101
+ m.LatFix = function(x) {
102
+ return Math.abs(x) > 90 ? NaN : x;
103
+ };
104
+ m.AngDiff = function(x, y) {
105
+ var r = m.sum(m.remainder(-x, 360), m.remainder(y, 360)), d, e;
106
+ r = m.sum(m.remainder(r.s, 360), r.t);
107
+ d = r.s;
108
+ e = r.t;
109
+ if (d === 0 || Math.abs(d) === 180)
110
+ d = m.copysign(d, e === 0 ? y - x : -e);
111
+ return { d, e };
112
+ };
113
+ m.sincosd = function(x) {
114
+ var d, r, q, s, c, sinx, cosx;
115
+ d = x % 360;
116
+ q = Math.round(d / 90);
117
+ d -= 90 * q;
118
+ r = d * this.degree;
119
+ s = Math.sin(r);
120
+ c = Math.cos(r);
121
+ if (Math.abs(d) === 45) {
122
+ c = Math.sqrt(0.5);
123
+ s = m.copysign(c, r);
124
+ } else if (Math.abs(d) === 30) {
125
+ c = Math.sqrt(0.75);
126
+ s = m.copysign(0.5, r);
127
+ }
128
+ switch (q & 3) {
129
+ case 0:
130
+ sinx = s;
131
+ cosx = c;
132
+ break;
133
+ case 1:
134
+ sinx = c;
135
+ cosx = -s;
136
+ break;
137
+ case 2:
138
+ sinx = -s;
139
+ cosx = -c;
140
+ break;
141
+ default:
142
+ sinx = -c;
143
+ cosx = s;
144
+ break;
145
+ }
146
+ cosx += 0;
147
+ if (sinx === 0)
148
+ sinx = m.copysign(sinx, x);
149
+ return { s: sinx, c: cosx };
150
+ };
151
+ m.sincosde = function(x, t) {
152
+ var d, r, q, s, c, sinx, cosx;
153
+ d = x % 360;
154
+ q = Math.round(d / 90);
155
+ d = m.AngRound(d - 90 * q + t);
156
+ r = d * this.degree;
157
+ s = Math.sin(r);
158
+ c = Math.cos(r);
159
+ if (Math.abs(d) === 45) {
160
+ c = Math.sqrt(0.5);
161
+ s = m.copysign(c, r);
162
+ } else if (Math.abs(d) === 30) {
163
+ c = Math.sqrt(0.75);
164
+ s = m.copysign(0.5, r);
165
+ }
166
+ switch (q & 3) {
167
+ case 0:
168
+ sinx = s;
169
+ cosx = c;
170
+ break;
171
+ case 1:
172
+ sinx = c;
173
+ cosx = -s;
174
+ break;
175
+ case 2:
176
+ sinx = -s;
177
+ cosx = -c;
178
+ break;
179
+ default:
180
+ sinx = -c;
181
+ cosx = s;
182
+ break;
183
+ }
184
+ cosx += 0;
185
+ if (sinx === 0)
186
+ sinx = m.copysign(sinx, x + t);
187
+ return { s: sinx, c: cosx };
188
+ };
189
+ m.atan2d = function(y, x) {
190
+ var q = 0, ang;
191
+ if (Math.abs(y) > Math.abs(x)) {
192
+ [y, x] = [x, y];
193
+ q = 2;
194
+ }
195
+ if (m.copysign(1, x) < 0) {
196
+ x = -x;
197
+ ++q;
198
+ }
199
+ ang = Math.atan2(y, x) / this.degree;
200
+ switch (q) {
201
+ // Note that atan2d(-0.0, 1.0) will return -0. However, we expect that
202
+ // atan2d will not be called with y = -0. If need be, include
203
+ //
204
+ // case 0: ang = 0 + ang; break;
205
+ //
206
+ // and handle mpfr as in AngRound.
207
+ case 1:
208
+ ang = m.copysign(180, y) - ang;
209
+ break;
210
+ case 2:
211
+ ang = 90 - ang;
212
+ break;
213
+ case 3:
214
+ ang = -90 + ang;
215
+ break;
216
+ default:
217
+ break;
218
+ }
219
+ return ang;
220
+ };
221
+ })(geodesic.Math);
222
+ (function(a, m) {
223
+ "use strict";
224
+ a.Accumulator = function(y) {
225
+ this.Set(y);
226
+ };
227
+ a.Accumulator.prototype.Set = function(y) {
228
+ if (!y)
229
+ y = 0;
230
+ if (y.constructor === a.Accumulator) {
231
+ this._s = y._s;
232
+ this._t = y._t;
233
+ } else {
234
+ this._s = y;
235
+ this._t = 0;
236
+ }
237
+ };
238
+ a.Accumulator.prototype.Add = function(y) {
239
+ var u = m.sum(y, this._t), v = m.sum(u.s, this._s);
240
+ u = u.t;
241
+ this._s = v.s;
242
+ this._t = v.t;
243
+ if (this._s === 0)
244
+ this._s = u;
245
+ else
246
+ this._t += u;
247
+ };
248
+ a.Accumulator.prototype.Sum = function(y) {
249
+ var b;
250
+ if (!y)
251
+ return this._s;
252
+ else {
253
+ b = new a.Accumulator(this);
254
+ b.Add(y);
255
+ return b._s;
256
+ }
257
+ };
258
+ a.Accumulator.prototype.Negate = function() {
259
+ this._s *= -1;
260
+ this._t *= -1;
261
+ };
262
+ a.Accumulator.prototype.Remainder = function(y) {
263
+ this._s = m.remainder(this._s, y);
264
+ this.Add(0);
265
+ };
266
+ })(geodesic.Accumulator, geodesic.Math);
267
+ geodesic.Geodesic = {};
268
+ geodesic.GeodesicLine = {};
269
+ geodesic.PolygonArea = {};
270
+ (function(g, l, p, m, c) {
271
+ "use strict";
272
+ 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;
273
+ g.tiny_ = Math.sqrt(Number.MIN_VALUE / Number.EPSILON);
274
+ g.nC1_ = GEOGRAPHICLIB_GEODESIC_ORDER;
275
+ g.nC1p_ = GEOGRAPHICLIB_GEODESIC_ORDER;
276
+ g.nC2_ = GEOGRAPHICLIB_GEODESIC_ORDER;
277
+ g.nC3_ = GEOGRAPHICLIB_GEODESIC_ORDER;
278
+ g.nC4_ = GEOGRAPHICLIB_GEODESIC_ORDER;
279
+ nC3x_ = g.nC3_ * (g.nC3_ - 1) / 2;
280
+ nC4x_ = g.nC4_ * (g.nC4_ + 1) / 2;
281
+ g.CAP_C1 = 1 << 0;
282
+ g.CAP_C1p = 1 << 1;
283
+ g.CAP_C2 = 1 << 2;
284
+ g.CAP_C3 = 1 << 3;
285
+ g.CAP_C4 = 1 << 4;
286
+ g.NONE = 0;
287
+ g.ARC = 1 << 6;
288
+ g.LATITUDE = 1 << 7 | CAP_NONE;
289
+ g.LONGITUDE = 1 << 8 | g.CAP_C3;
290
+ g.AZIMUTH = 1 << 9 | CAP_NONE;
291
+ g.DISTANCE = 1 << 10 | g.CAP_C1;
292
+ g.STANDARD = g.LATITUDE | g.LONGITUDE | g.AZIMUTH | g.DISTANCE;
293
+ g.DISTANCE_IN = 1 << 11 | g.CAP_C1 | g.CAP_C1p;
294
+ g.REDUCEDLENGTH = 1 << 12 | g.CAP_C1 | g.CAP_C2;
295
+ g.GEODESICSCALE = 1 << 13 | g.CAP_C1 | g.CAP_C2;
296
+ g.AREA = 1 << 14 | g.CAP_C4;
297
+ g.ALL = OUT_ALL | CAP_ALL;
298
+ g.LONG_UNROLL = 1 << 15;
299
+ g.OUT_MASK = OUT_ALL | g.LONG_UNROLL;
300
+ g.SinCosSeries = function(sinp, sinx, cosx, c2, delta) {
301
+ if (delta !== void 0) {
302
+ var h = delta / 2, sh = Math.sin(h), ch = Math.cos(h);
303
+ return -2 * g.SinCosSeries(false, cosx * ch - sinx * sh, sinx * ch + cosx * sh, c2.map(function(v, i) {
304
+ return (i % 2 ? -v : v) * Math.sin((2 * i + 1) * h);
305
+ }));
306
+ }
307
+ var k = c2.length, n = k - (sinp ? 1 : 0), ar = 2 * (cosx - sinx) * (cosx + sinx), y0 = n & 1 ? c2[--k] : 0, y1 = 0;
308
+ n = Math.floor(n / 2);
309
+ while (n--) {
310
+ y1 = ar * y0 - y1 + c2[--k];
311
+ y0 = ar * y1 - y0 + c2[--k];
312
+ }
313
+ return sinp ? 2 * sinx * cosx * y0 : (
314
+ // sin(2 * x) * y0
315
+ cosx * (y0 - y1)
316
+ );
317
+ };
318
+ astroid = function(x, y) {
319
+ 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;
320
+ if (!(q === 0 && r <= 0)) {
321
+ S = p2 * q / 4;
322
+ r2 = m.sq(r);
323
+ r3 = r * r2;
324
+ disc = S * (S + 2 * r3);
325
+ u = r;
326
+ if (disc >= 0) {
327
+ T3 = S + r3;
328
+ T3 += T3 < 0 ? -Math.sqrt(disc) : Math.sqrt(disc);
329
+ T = m.cbrt(T3);
330
+ u += T + (T !== 0 ? r2 / T : 0);
331
+ } else {
332
+ ang = Math.atan2(Math.sqrt(-disc), -(S + r3));
333
+ u += 2 * r * Math.cos(ang / 3);
334
+ }
335
+ v = Math.sqrt(m.sq(u) + q);
336
+ uv = u < 0 ? q / (v - u) : u + v;
337
+ w = (uv - q) / (2 * v);
338
+ k = uv / (Math.sqrt(uv + m.sq(w)) + w);
339
+ } else {
340
+ k = 0;
341
+ }
342
+ return k;
343
+ };
344
+ A1m1f_coeff = [
345
+ // (1-eps)*A1-1, polynomial in eps2 of order 3
346
+ 1,
347
+ 4,
348
+ 64,
349
+ 0,
350
+ 256
351
+ ];
352
+ g.A1m1f = function(eps) {
353
+ var p2 = Math.floor(nA1_ / 2), t = m.polyval(p2, A1m1f_coeff, 0, m.sq(eps)) / A1m1f_coeff[p2 + 1];
354
+ return (t + eps) / (1 - eps);
355
+ };
356
+ C1f_coeff = [
357
+ // C1[1]/eps^1, polynomial in eps2 of order 2
358
+ -1,
359
+ 6,
360
+ -16,
361
+ 32,
362
+ // C1[2]/eps^2, polynomial in eps2 of order 2
363
+ -9,
364
+ 64,
365
+ -128,
366
+ 2048,
367
+ // C1[3]/eps^3, polynomial in eps2 of order 1
368
+ 9,
369
+ -16,
370
+ 768,
371
+ // C1[4]/eps^4, polynomial in eps2 of order 1
372
+ 3,
373
+ -5,
374
+ 512,
375
+ // C1[5]/eps^5, polynomial in eps2 of order 0
376
+ -7,
377
+ 1280,
378
+ // C1[6]/eps^6, polynomial in eps2 of order 0
379
+ -7,
380
+ 2048
381
+ ];
382
+ g.C1f = function(eps, c2) {
383
+ var eps2 = m.sq(eps), d = eps, o = 0, l2, p2;
384
+ for (l2 = 1; l2 <= g.nC1_; ++l2) {
385
+ p2 = Math.floor((g.nC1_ - l2) / 2);
386
+ c2[l2] = d * m.polyval(p2, C1f_coeff, o, eps2) / C1f_coeff[o + p2 + 1];
387
+ o += p2 + 2;
388
+ d *= eps;
389
+ }
390
+ };
391
+ C1pf_coeff = [
392
+ // C1p[1]/eps^1, polynomial in eps2 of order 2
393
+ 205,
394
+ -432,
395
+ 768,
396
+ 1536,
397
+ // C1p[2]/eps^2, polynomial in eps2 of order 2
398
+ 4005,
399
+ -4736,
400
+ 3840,
401
+ 12288,
402
+ // C1p[3]/eps^3, polynomial in eps2 of order 1
403
+ -225,
404
+ 116,
405
+ 384,
406
+ // C1p[4]/eps^4, polynomial in eps2 of order 1
407
+ -7173,
408
+ 2695,
409
+ 7680,
410
+ // C1p[5]/eps^5, polynomial in eps2 of order 0
411
+ 3467,
412
+ 7680,
413
+ // C1p[6]/eps^6, polynomial in eps2 of order 0
414
+ 38081,
415
+ 61440
416
+ ];
417
+ g.C1pf = function(eps, c2) {
418
+ var eps2 = m.sq(eps), d = eps, o = 0, l2, p2;
419
+ for (l2 = 1; l2 <= g.nC1p_; ++l2) {
420
+ p2 = Math.floor((g.nC1p_ - l2) / 2);
421
+ c2[l2] = d * m.polyval(p2, C1pf_coeff, o, eps2) / C1pf_coeff[o + p2 + 1];
422
+ o += p2 + 2;
423
+ d *= eps;
424
+ }
425
+ };
426
+ A2m1f_coeff = [
427
+ // (eps+1)*A2-1, polynomial in eps2 of order 3
428
+ -11,
429
+ -28,
430
+ -192,
431
+ 0,
432
+ 256
433
+ ];
434
+ g.A2m1f = function(eps) {
435
+ var p2 = Math.floor(nA2_ / 2), t = m.polyval(p2, A2m1f_coeff, 0, m.sq(eps)) / A2m1f_coeff[p2 + 1];
436
+ return (t - eps) / (1 + eps);
437
+ };
438
+ C2f_coeff = [
439
+ // C2[1]/eps^1, polynomial in eps2 of order 2
440
+ 1,
441
+ 2,
442
+ 16,
443
+ 32,
444
+ // C2[2]/eps^2, polynomial in eps2 of order 2
445
+ 35,
446
+ 64,
447
+ 384,
448
+ 2048,
449
+ // C2[3]/eps^3, polynomial in eps2 of order 1
450
+ 15,
451
+ 80,
452
+ 768,
453
+ // C2[4]/eps^4, polynomial in eps2 of order 1
454
+ 7,
455
+ 35,
456
+ 512,
457
+ // C2[5]/eps^5, polynomial in eps2 of order 0
458
+ 63,
459
+ 1280,
460
+ // C2[6]/eps^6, polynomial in eps2 of order 0
461
+ 77,
462
+ 2048
463
+ ];
464
+ g.C2f = function(eps, c2) {
465
+ var eps2 = m.sq(eps), d = eps, o = 0, l2, p2;
466
+ for (l2 = 1; l2 <= g.nC2_; ++l2) {
467
+ p2 = Math.floor((g.nC2_ - l2) / 2);
468
+ c2[l2] = d * m.polyval(p2, C2f_coeff, o, eps2) / C2f_coeff[o + p2 + 1];
469
+ o += p2 + 2;
470
+ d *= eps;
471
+ }
472
+ };
473
+ g.Geodesic = function(a, f) {
474
+ this.a = a;
475
+ this.f = f;
476
+ this._f1 = 1 - this.f;
477
+ this._e2 = this.f * (2 - this.f);
478
+ this._ep2 = this._e2 / m.sq(this._f1);
479
+ this._n = this.f / (2 - this.f);
480
+ this._b = this.a * this._f1;
481
+ 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;
482
+ this._etol2 = 0.1 * tol2_ / Math.sqrt(Math.max(1e-3, Math.abs(this.f)) * Math.min(1, 1 - this.f / 2) / 2);
483
+ if (!(isFinite(this.a) && this.a > 0))
484
+ throw new Error("Equatorial radius is not positive");
485
+ if (!(isFinite(this._b) && this._b > 0))
486
+ throw new Error("Polar semi-axis is not positive");
487
+ this._A3x = new Array(nA3x_);
488
+ this._C3x = new Array(nC3x_);
489
+ this._C4x = new Array(nC4x_);
490
+ this.A3coeff();
491
+ this.C3coeff();
492
+ this.C4coeff();
493
+ };
494
+ A3_coeff = [
495
+ // A3, coeff of eps^5, polynomial in n of order 0
496
+ -3,
497
+ 128,
498
+ // A3, coeff of eps^4, polynomial in n of order 1
499
+ -2,
500
+ -3,
501
+ 64,
502
+ // A3, coeff of eps^3, polynomial in n of order 2
503
+ -1,
504
+ -3,
505
+ -1,
506
+ 16,
507
+ // A3, coeff of eps^2, polynomial in n of order 2
508
+ 3,
509
+ -1,
510
+ -2,
511
+ 8,
512
+ // A3, coeff of eps^1, polynomial in n of order 1
513
+ 1,
514
+ -1,
515
+ 2,
516
+ // A3, coeff of eps^0, polynomial in n of order 0
517
+ 1,
518
+ 1
519
+ ];
520
+ g.Geodesic.prototype.A3coeff = function() {
521
+ var o = 0, k = 0, j, p2;
522
+ for (j = nA3_ - 1; j >= 0; --j) {
523
+ p2 = Math.min(nA3_ - j - 1, j);
524
+ this._A3x[k++] = m.polyval(p2, A3_coeff, o, this._n) / A3_coeff[o + p2 + 1];
525
+ o += p2 + 2;
526
+ }
527
+ };
528
+ C3_coeff = [
529
+ // C3[1], coeff of eps^5, polynomial in n of order 0
530
+ 3,
531
+ 128,
532
+ // C3[1], coeff of eps^4, polynomial in n of order 1
533
+ 2,
534
+ 5,
535
+ 128,
536
+ // C3[1], coeff of eps^3, polynomial in n of order 2
537
+ -1,
538
+ 3,
539
+ 3,
540
+ 64,
541
+ // C3[1], coeff of eps^2, polynomial in n of order 2
542
+ -1,
543
+ 0,
544
+ 1,
545
+ 8,
546
+ // C3[1], coeff of eps^1, polynomial in n of order 1
547
+ -1,
548
+ 1,
549
+ 4,
550
+ // C3[2], coeff of eps^5, polynomial in n of order 0
551
+ 5,
552
+ 256,
553
+ // C3[2], coeff of eps^4, polynomial in n of order 1
554
+ 1,
555
+ 3,
556
+ 128,
557
+ // C3[2], coeff of eps^3, polynomial in n of order 2
558
+ -3,
559
+ -2,
560
+ 3,
561
+ 64,
562
+ // C3[2], coeff of eps^2, polynomial in n of order 2
563
+ 1,
564
+ -3,
565
+ 2,
566
+ 32,
567
+ // C3[3], coeff of eps^5, polynomial in n of order 0
568
+ 7,
569
+ 512,
570
+ // C3[3], coeff of eps^4, polynomial in n of order 1
571
+ -10,
572
+ 9,
573
+ 384,
574
+ // C3[3], coeff of eps^3, polynomial in n of order 2
575
+ 5,
576
+ -9,
577
+ 5,
578
+ 192,
579
+ // C3[4], coeff of eps^5, polynomial in n of order 0
580
+ 7,
581
+ 512,
582
+ // C3[4], coeff of eps^4, polynomial in n of order 1
583
+ -14,
584
+ 7,
585
+ 512,
586
+ // C3[5], coeff of eps^5, polynomial in n of order 0
587
+ 21,
588
+ 2560
589
+ ];
590
+ g.Geodesic.prototype.C3coeff = function() {
591
+ var o = 0, k = 0, l2, j, p2;
592
+ for (l2 = 1; l2 < g.nC3_; ++l2) {
593
+ for (j = g.nC3_ - 1; j >= l2; --j) {
594
+ p2 = Math.min(g.nC3_ - j - 1, j);
595
+ this._C3x[k++] = m.polyval(p2, C3_coeff, o, this._n) / C3_coeff[o + p2 + 1];
596
+ o += p2 + 2;
597
+ }
598
+ }
599
+ };
600
+ C4_coeff = [
601
+ // C4[0], coeff of eps^5, polynomial in n of order 0
602
+ 97,
603
+ 15015,
604
+ // C4[0], coeff of eps^4, polynomial in n of order 1
605
+ 1088,
606
+ 156,
607
+ 45045,
608
+ // C4[0], coeff of eps^3, polynomial in n of order 2
609
+ -224,
610
+ -4784,
611
+ 1573,
612
+ 45045,
613
+ // C4[0], coeff of eps^2, polynomial in n of order 3
614
+ -10656,
615
+ 14144,
616
+ -4576,
617
+ -858,
618
+ 45045,
619
+ // C4[0], coeff of eps^1, polynomial in n of order 4
620
+ 64,
621
+ 624,
622
+ -4576,
623
+ 6864,
624
+ -3003,
625
+ 15015,
626
+ // C4[0], coeff of eps^0, polynomial in n of order 5
627
+ 100,
628
+ 208,
629
+ 572,
630
+ 3432,
631
+ -12012,
632
+ 30030,
633
+ 45045,
634
+ // C4[1], coeff of eps^5, polynomial in n of order 0
635
+ 1,
636
+ 9009,
637
+ // C4[1], coeff of eps^4, polynomial in n of order 1
638
+ -2944,
639
+ 468,
640
+ 135135,
641
+ // C4[1], coeff of eps^3, polynomial in n of order 2
642
+ 5792,
643
+ 1040,
644
+ -1287,
645
+ 135135,
646
+ // C4[1], coeff of eps^2, polynomial in n of order 3
647
+ 5952,
648
+ -11648,
649
+ 9152,
650
+ -2574,
651
+ 135135,
652
+ // C4[1], coeff of eps^1, polynomial in n of order 4
653
+ -64,
654
+ -624,
655
+ 4576,
656
+ -6864,
657
+ 3003,
658
+ 135135,
659
+ // C4[2], coeff of eps^5, polynomial in n of order 0
660
+ 8,
661
+ 10725,
662
+ // C4[2], coeff of eps^4, polynomial in n of order 1
663
+ 1856,
664
+ -936,
665
+ 225225,
666
+ // C4[2], coeff of eps^3, polynomial in n of order 2
667
+ -8448,
668
+ 4992,
669
+ -1144,
670
+ 225225,
671
+ // C4[2], coeff of eps^2, polynomial in n of order 3
672
+ -1440,
673
+ 4160,
674
+ -4576,
675
+ 1716,
676
+ 225225,
677
+ // C4[3], coeff of eps^5, polynomial in n of order 0
678
+ -136,
679
+ 63063,
680
+ // C4[3], coeff of eps^4, polynomial in n of order 1
681
+ 1024,
682
+ -208,
683
+ 105105,
684
+ // C4[3], coeff of eps^3, polynomial in n of order 2
685
+ 3584,
686
+ -3328,
687
+ 1144,
688
+ 315315,
689
+ // C4[4], coeff of eps^5, polynomial in n of order 0
690
+ -128,
691
+ 135135,
692
+ // C4[4], coeff of eps^4, polynomial in n of order 1
693
+ -2560,
694
+ 832,
695
+ 405405,
696
+ // C4[5], coeff of eps^5, polynomial in n of order 0
697
+ 128,
698
+ 99099
699
+ ];
700
+ g.Geodesic.prototype.C4coeff = function() {
701
+ var o = 0, k = 0, l2, j, p2;
702
+ for (l2 = 0; l2 < g.nC4_; ++l2) {
703
+ for (j = g.nC4_ - 1; j >= l2; --j) {
704
+ p2 = g.nC4_ - j - 1;
705
+ this._C4x[k++] = m.polyval(p2, C4_coeff, o, this._n) / C4_coeff[o + p2 + 1];
706
+ o += p2 + 2;
707
+ }
708
+ }
709
+ };
710
+ g.Geodesic.prototype.A3f = function(eps) {
711
+ return m.polyval(nA3x_ - 1, this._A3x, 0, eps);
712
+ };
713
+ g.Geodesic.prototype.C3f = function(eps, c2) {
714
+ var mult = 1, o = 0, l2, p2;
715
+ for (l2 = 1; l2 < g.nC3_; ++l2) {
716
+ p2 = g.nC3_ - l2 - 1;
717
+ mult *= eps;
718
+ c2[l2] = mult * m.polyval(p2, this._C3x, o, eps);
719
+ o += p2 + 1;
720
+ }
721
+ };
722
+ g.Geodesic.prototype.C4f = function(eps, c2) {
723
+ var mult = 1, o = 0, l2, p2;
724
+ for (l2 = 0; l2 < g.nC4_; ++l2) {
725
+ p2 = g.nC4_ - l2 - 1;
726
+ c2[l2] = mult * m.polyval(p2, this._C4x, o, eps);
727
+ o += p2 + 1;
728
+ mult *= eps;
729
+ }
730
+ };
731
+ g.Geodesic.prototype.Lengths = function(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, outmask, C1a, C2a) {
732
+ outmask &= g.OUT_MASK;
733
+ var vals = {}, m0x = 0, J12 = 0, A1 = 0, A2 = 0, B1, B2, l2, csig12, t;
734
+ if (outmask & (g.DISTANCE | g.REDUCEDLENGTH | g.GEODESICSCALE)) {
735
+ A1 = g.A1m1f(eps);
736
+ g.C1f(eps, C1a);
737
+ if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
738
+ A2 = g.A2m1f(eps);
739
+ g.C2f(eps, C2a);
740
+ m0x = A1 - A2;
741
+ A2 = 1 + A2;
742
+ }
743
+ A1 = 1 + A1;
744
+ }
745
+ if (outmask & g.DISTANCE) {
746
+ B1 = g.SinCosSeries(true, ssig2, csig2, C1a) - g.SinCosSeries(true, ssig1, csig1, C1a);
747
+ vals.s12b = A1 * (sig12 + B1);
748
+ if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
749
+ B2 = g.SinCosSeries(true, ssig2, csig2, C2a) - g.SinCosSeries(true, ssig1, csig1, C2a);
750
+ J12 = m0x * sig12 + (A1 * B1 - A2 * B2);
751
+ }
752
+ } else if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
753
+ for (l2 = 1; l2 <= g.nC2_; ++l2)
754
+ C2a[l2] = A1 * C1a[l2] - A2 * C2a[l2];
755
+ J12 = m0x * sig12 + (g.SinCosSeries(true, ssig2, csig2, C2a) - g.SinCosSeries(true, ssig1, csig1, C2a));
756
+ }
757
+ if (outmask & g.REDUCEDLENGTH) {
758
+ vals.m0 = m0x;
759
+ vals.m12b = dn2 * (csig1 * ssig2) - dn1 * (ssig1 * csig2) - csig1 * csig2 * J12;
760
+ } else
761
+ vals.m12b = NaN;
762
+ if (outmask & g.GEODESICSCALE) {
763
+ csig12 = csig1 * csig2 + ssig1 * ssig2;
764
+ t = this._ep2 * (cbet1 - cbet2) * (cbet1 + cbet2) / (dn1 + dn2);
765
+ vals.M12 = csig12 + (t * ssig2 - csig2 * J12) * ssig1 / dn1;
766
+ vals.M21 = csig12 - (t * ssig1 - csig1 * J12) * ssig2 / dn2;
767
+ }
768
+ return vals;
769
+ };
770
+ g.Geodesic.prototype.InverseStart = function(sbet1, cbet1, dn1, sbet2, cbet2, dn2, lam12, slam12, clam12, C1a, C2a) {
771
+ 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;
772
+ vals.sig12 = -1;
773
+ sbet12a = sbet2 * cbet1;
774
+ sbet12a += cbet2 * sbet1;
775
+ shortline = cbet12 >= 0 && sbet12 < 0.5 && cbet2 * lam12 < 0.5;
776
+ if (shortline) {
777
+ sbetm2 = m.sq(sbet1 + sbet2);
778
+ sbetm2 /= sbetm2 + m.sq(cbet1 + cbet2);
779
+ vals.dnm = Math.sqrt(1 + this._ep2 * sbetm2);
780
+ omg12 = lam12 / (this._f1 * vals.dnm);
781
+ somg12 = Math.sin(omg12);
782
+ comg12 = Math.cos(omg12);
783
+ } else {
784
+ somg12 = slam12;
785
+ comg12 = clam12;
786
+ }
787
+ vals.salp1 = cbet2 * somg12;
788
+ vals.calp1 = comg12 >= 0 ? sbet12 + cbet2 * sbet1 * m.sq(somg12) / (1 + comg12) : sbet12a - cbet2 * sbet1 * m.sq(somg12) / (1 - comg12);
789
+ ssig12 = m.hypot(vals.salp1, vals.calp1);
790
+ csig12 = sbet1 * sbet2 + cbet1 * cbet2 * comg12;
791
+ if (shortline && ssig12 < this._etol2) {
792
+ vals.salp2 = cbet1 * somg12;
793
+ vals.calp2 = sbet12 - cbet1 * sbet2 * (comg12 >= 0 ? m.sq(somg12) / (1 + comg12) : 1 - comg12);
794
+ t = m.hypot(vals.salp2, vals.calp2);
795
+ vals.salp2 /= t;
796
+ vals.calp2 /= t;
797
+ vals.sig12 = Math.atan2(ssig12, csig12);
798
+ } else if (Math.abs(this._n) > 0.1 || // Skip astroid calc if too eccentric
799
+ csig12 >= 0 || ssig12 >= 6 * Math.abs(this._n) * Math.PI * m.sq(cbet1)) {
800
+ } else {
801
+ lam12x = Math.atan2(-slam12, -clam12);
802
+ if (this.f >= 0) {
803
+ k2 = m.sq(sbet1) * this._ep2;
804
+ eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
805
+ lamscale = this.f * cbet1 * this.A3f(eps) * Math.PI;
806
+ betscale = lamscale * cbet1;
807
+ x = lam12x / lamscale;
808
+ y = sbet12a / betscale;
809
+ } else {
810
+ cbet12a = cbet2 * cbet1 - sbet2 * sbet1;
811
+ bet12a = Math.atan2(sbet12a, cbet12a);
812
+ nvals = this.Lengths(this._n, Math.PI + bet12a, sbet1, -cbet1, dn1, sbet2, cbet2, dn2, cbet1, cbet2, g.REDUCEDLENGTH, C1a, C2a);
813
+ m12b = nvals.m12b;
814
+ m0 = nvals.m0;
815
+ x = -1 + m12b / (cbet1 * cbet2 * m0 * Math.PI);
816
+ betscale = x < -0.01 ? sbet12a / x : -this.f * m.sq(cbet1) * Math.PI;
817
+ lamscale = betscale / cbet1;
818
+ y = lam12 / lamscale;
819
+ }
820
+ if (y > -tol1_ && x > -1 - xthresh_) {
821
+ if (this.f >= 0) {
822
+ vals.salp1 = Math.min(1, -x);
823
+ vals.calp1 = -Math.sqrt(1 - m.sq(vals.salp1));
824
+ } else {
825
+ vals.calp1 = Math.max(x > -tol1_ ? 0 : -1, x);
826
+ vals.salp1 = Math.sqrt(1 - m.sq(vals.calp1));
827
+ }
828
+ } else {
829
+ k = astroid(x, y);
830
+ omg12a = lamscale * (this.f >= 0 ? -x * k / (1 + k) : -y * (1 + k) / k);
831
+ somg12 = Math.sin(omg12a);
832
+ comg12 = -Math.cos(omg12a);
833
+ vals.salp1 = cbet2 * somg12;
834
+ vals.calp1 = sbet12a - cbet2 * sbet1 * m.sq(somg12) / (1 - comg12);
835
+ }
836
+ }
837
+ if (!(vals.salp1 <= 0)) {
838
+ t = m.hypot(vals.salp1, vals.calp1);
839
+ vals.salp1 /= t;
840
+ vals.calp1 /= t;
841
+ } else {
842
+ vals.salp1 = 1;
843
+ vals.calp1 = 0;
844
+ }
845
+ return vals;
846
+ };
847
+ g.Geodesic.prototype.Lambda12 = function(sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1, slam120, clam120, diffp, C1a, C2a, C3a) {
848
+ var vals = {}, t, salp0, calp0, somg1, comg1, somg2, comg2, somg12, comg12, B312, eta, k2, nvals;
849
+ if (sbet1 === 0 && calp1 === 0)
850
+ calp1 = -g.tiny_;
851
+ salp0 = salp1 * cbet1;
852
+ calp0 = m.hypot(calp1, salp1 * sbet1);
853
+ vals.ssig1 = sbet1;
854
+ somg1 = salp0 * sbet1;
855
+ vals.csig1 = comg1 = calp1 * cbet1;
856
+ t = m.hypot(vals.ssig1, vals.csig1);
857
+ vals.ssig1 /= t;
858
+ vals.csig1 /= t;
859
+ vals.salp2 = cbet2 !== cbet1 ? salp0 / cbet2 : salp1;
860
+ 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);
861
+ vals.ssig2 = sbet2;
862
+ somg2 = salp0 * sbet2;
863
+ vals.csig2 = comg2 = vals.calp2 * cbet2;
864
+ t = m.hypot(vals.ssig2, vals.csig2);
865
+ vals.ssig2 /= t;
866
+ vals.csig2 /= t;
867
+ vals.sig12 = Math.atan2(Math.max(0, vals.csig1 * vals.ssig2 - vals.ssig1 * vals.csig2), vals.csig1 * vals.csig2 + vals.ssig1 * vals.ssig2);
868
+ somg12 = Math.max(0, comg1 * somg2 - somg1 * comg2);
869
+ comg12 = comg1 * comg2 + somg1 * somg2;
870
+ eta = Math.atan2(somg12 * clam120 - comg12 * slam120, comg12 * clam120 + somg12 * slam120);
871
+ k2 = m.sq(calp0) * this._ep2;
872
+ vals.eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
873
+ this.C3f(vals.eps, C3a);
874
+ B312 = g.SinCosSeries(true, vals.ssig2, vals.csig2, C3a) - g.SinCosSeries(true, vals.ssig1, vals.csig1, C3a);
875
+ vals.domg12 = -this.f * this.A3f(vals.eps) * salp0 * (vals.sig12 + B312);
876
+ vals.lam12 = eta + vals.domg12;
877
+ if (diffp) {
878
+ if (vals.calp2 === 0)
879
+ vals.dlam12 = -2 * this._f1 * dn1 / sbet1;
880
+ else {
881
+ nvals = this.Lengths(vals.eps, vals.sig12, vals.ssig1, vals.csig1, dn1, vals.ssig2, vals.csig2, dn2, cbet1, cbet2, g.REDUCEDLENGTH, C1a, C2a);
882
+ vals.dlam12 = nvals.m12b;
883
+ vals.dlam12 *= this._f1 / (vals.calp2 * cbet2);
884
+ }
885
+ }
886
+ return vals;
887
+ };
888
+ g.Geodesic.prototype.Inverse = function(lat1, lon1, lat2, lon2, outmask) {
889
+ var r, vals;
890
+ if (!outmask)
891
+ outmask = g.STANDARD;
892
+ if (outmask === g.LONG_UNROLL)
893
+ outmask |= g.STANDARD;
894
+ outmask &= g.OUT_MASK;
895
+ r = this.InverseInt(lat1, lon1, lat2, lon2, outmask);
896
+ vals = r.vals;
897
+ if (outmask & g.AZIMUTH) {
898
+ vals.azi1 = m.atan2d(r.salp1, r.calp1);
899
+ vals.azi2 = m.atan2d(r.salp2, r.calp2);
900
+ }
901
+ return vals;
902
+ };
903
+ g.Geodesic.prototype.InverseInt = function(lat1, lon1, lat2, lon2, outmask) {
904
+ 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;
905
+ vals.lat1 = lat1 = m.LatFix(lat1);
906
+ vals.lat2 = lat2 = m.LatFix(lat2);
907
+ lat1 = m.AngRound(lat1);
908
+ lat2 = m.AngRound(lat2);
909
+ lon12 = m.AngDiff(lon1, lon2);
910
+ lon12s = lon12.e;
911
+ lon12 = lon12.d;
912
+ if (outmask & g.LONG_UNROLL) {
913
+ vals.lon1 = lon1;
914
+ vals.lon2 = lon1 + lon12 + lon12s;
915
+ } else {
916
+ vals.lon1 = m.AngNormalize(lon1);
917
+ vals.lon2 = m.AngNormalize(lon2);
918
+ }
919
+ lonsign = m.copysign(1, lon12);
920
+ lon12 *= lonsign;
921
+ lon12s *= lonsign;
922
+ lam12 = lon12 * m.degree;
923
+ t = m.sincosde(lon12, lon12s);
924
+ slam12 = t.s;
925
+ clam12 = t.c;
926
+ lon12s = 180 - lon12 - lon12s;
927
+ swapp = Math.abs(lat1) < Math.abs(lat2) || isNaN(lat2) ? -1 : 1;
928
+ if (swapp < 0) {
929
+ lonsign *= -1;
930
+ [lat2, lat1] = [lat1, lat2];
931
+ }
932
+ latsign = m.copysign(1, -lat1);
933
+ lat1 *= latsign;
934
+ lat2 *= latsign;
935
+ t = m.sincosd(lat1);
936
+ sbet1 = this._f1 * t.s;
937
+ cbet1 = t.c;
938
+ t = m.hypot(sbet1, cbet1);
939
+ sbet1 /= t;
940
+ cbet1 /= t;
941
+ cbet1 = Math.max(g.tiny_, cbet1);
942
+ t = m.sincosd(lat2);
943
+ sbet2 = this._f1 * t.s;
944
+ cbet2 = t.c;
945
+ t = m.hypot(sbet2, cbet2);
946
+ sbet2 /= t;
947
+ cbet2 /= t;
948
+ cbet2 = Math.max(g.tiny_, cbet2);
949
+ if (cbet1 < -sbet1) {
950
+ if (cbet2 === cbet1)
951
+ sbet2 = m.copysign(sbet1, sbet2);
952
+ } else {
953
+ if (Math.abs(sbet2) === -sbet1)
954
+ cbet2 = cbet1;
955
+ }
956
+ dn1 = Math.sqrt(1 + this._ep2 * m.sq(sbet1));
957
+ dn2 = Math.sqrt(1 + this._ep2 * m.sq(sbet2));
958
+ C1a = new Array(g.nC1_ + 1);
959
+ C2a = new Array(g.nC2_ + 1);
960
+ C3a = new Array(g.nC3_);
961
+ meridian = lat1 === -90 || slam12 === 0;
962
+ if (meridian) {
963
+ calp1 = clam12;
964
+ salp1 = slam12;
965
+ calp2 = 1;
966
+ salp2 = 0;
967
+ ssig1 = sbet1;
968
+ csig1 = calp1 * cbet1;
969
+ ssig2 = sbet2;
970
+ csig2 = calp2 * cbet2;
971
+ sig12 = Math.atan2(Math.max(0, csig1 * ssig2 - ssig1 * csig2), csig1 * csig2 + ssig1 * ssig2);
972
+ nvals = this.Lengths(this._n, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, outmask | g.DISTANCE | g.REDUCEDLENGTH, C1a, C2a);
973
+ s12x = nvals.s12b;
974
+ m12x = nvals.m12b;
975
+ if (outmask & g.GEODESICSCALE) {
976
+ vals.M12 = nvals.M12;
977
+ vals.M21 = nvals.M21;
978
+ }
979
+ if (sig12 < tol2_ || m12x >= 0) {
980
+ if (sig12 < 3 * g.tiny_ || // Prevent negative s12 or m12 for short lines
981
+ sig12 < tol0_ && (s12x < 0 || m12x < 0))
982
+ sig12 = m12x = s12x = 0;
983
+ m12x *= this._b;
984
+ s12x *= this._b;
985
+ vals.a12 = sig12 / m.degree;
986
+ } else
987
+ meridian = false;
988
+ }
989
+ somg12 = 2;
990
+ if (!meridian && sbet1 === 0 && // and sbet2 == 0
991
+ (this.f <= 0 || lon12s >= this.f * 180)) {
992
+ calp1 = calp2 = 0;
993
+ salp1 = salp2 = 1;
994
+ s12x = this.a * lam12;
995
+ sig12 = omg12 = lam12 / this._f1;
996
+ m12x = this._b * Math.sin(sig12);
997
+ if (outmask & g.GEODESICSCALE)
998
+ vals.M12 = vals.M21 = Math.cos(sig12);
999
+ vals.a12 = lon12 / this._f1;
1000
+ } else if (!meridian) {
1001
+ nvals = this.InverseStart(sbet1, cbet1, dn1, sbet2, cbet2, dn2, lam12, slam12, clam12, C1a, C2a);
1002
+ sig12 = nvals.sig12;
1003
+ salp1 = nvals.salp1;
1004
+ calp1 = nvals.calp1;
1005
+ if (sig12 >= 0) {
1006
+ salp2 = nvals.salp2;
1007
+ calp2 = nvals.calp2;
1008
+ dnm = nvals.dnm;
1009
+ s12x = sig12 * this._b * dnm;
1010
+ m12x = m.sq(dnm) * this._b * Math.sin(sig12 / dnm);
1011
+ if (outmask & g.GEODESICSCALE)
1012
+ vals.M12 = vals.M21 = Math.cos(sig12 / dnm);
1013
+ vals.a12 = sig12 / m.degree;
1014
+ omg12 = lam12 / (this._f1 * dnm);
1015
+ } else {
1016
+ numit = 0;
1017
+ salp1a = g.tiny_;
1018
+ calp1a = 1;
1019
+ salp1b = g.tiny_;
1020
+ calp1b = -1;
1021
+ for (tripn = false, tripb = false; ; ++numit) {
1022
+ nvals = this.Lambda12(sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1, slam12, clam12, numit < maxit1_, C1a, C2a, C3a);
1023
+ v = nvals.lam12;
1024
+ salp2 = nvals.salp2;
1025
+ calp2 = nvals.calp2;
1026
+ sig12 = nvals.sig12;
1027
+ ssig1 = nvals.ssig1;
1028
+ csig1 = nvals.csig1;
1029
+ ssig2 = nvals.ssig2;
1030
+ csig2 = nvals.csig2;
1031
+ eps = nvals.eps;
1032
+ domg12 = nvals.domg12;
1033
+ dv = nvals.dlam12;
1034
+ if (tripb || !(Math.abs(v) >= (tripn ? 8 : 1) * tol0_) || numit == maxit2_)
1035
+ break;
1036
+ if (v > 0 && (numit < maxit1_ || calp1 / salp1 > calp1b / salp1b)) {
1037
+ salp1b = salp1;
1038
+ calp1b = calp1;
1039
+ } else if (v < 0 && (numit < maxit1_ || calp1 / salp1 < calp1a / salp1a)) {
1040
+ salp1a = salp1;
1041
+ calp1a = calp1;
1042
+ }
1043
+ if (numit < maxit1_ && dv > 0) {
1044
+ dalp1 = -v / dv;
1045
+ if (Math.abs(dalp1) < Math.PI) {
1046
+ sdalp1 = Math.sin(dalp1);
1047
+ cdalp1 = Math.cos(dalp1);
1048
+ nsalp1 = salp1 * cdalp1 + calp1 * sdalp1;
1049
+ if (nsalp1 > 0) {
1050
+ calp1 = calp1 * cdalp1 - salp1 * sdalp1;
1051
+ salp1 = nsalp1;
1052
+ t = m.hypot(salp1, calp1);
1053
+ salp1 /= t;
1054
+ calp1 /= t;
1055
+ tripn = Math.abs(v) <= 16 * tol0_;
1056
+ continue;
1057
+ }
1058
+ }
1059
+ }
1060
+ salp1 = (salp1a + salp1b) / 2;
1061
+ calp1 = (calp1a + calp1b) / 2;
1062
+ t = m.hypot(salp1, calp1);
1063
+ salp1 /= t;
1064
+ calp1 /= t;
1065
+ tripn = false;
1066
+ tripb = Math.abs(salp1a - salp1) + (calp1a - calp1) < tolb_ || Math.abs(salp1 - salp1b) + (calp1 - calp1b) < tolb_;
1067
+ }
1068
+ lengthmask = outmask | (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE) ? g.DISTANCE : g.NONE);
1069
+ nvals = this.Lengths(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, lengthmask, C1a, C2a);
1070
+ s12x = nvals.s12b;
1071
+ m12x = nvals.m12b;
1072
+ if (outmask & g.GEODESICSCALE) {
1073
+ vals.M12 = nvals.M12;
1074
+ vals.M21 = nvals.M21;
1075
+ }
1076
+ m12x *= this._b;
1077
+ s12x *= this._b;
1078
+ vals.a12 = sig12 / m.degree;
1079
+ if (outmask & g.AREA) {
1080
+ sdomg12 = Math.sin(domg12);
1081
+ cdomg12 = Math.cos(domg12);
1082
+ somg12 = slam12 * cdomg12 - clam12 * sdomg12;
1083
+ comg12 = clam12 * cdomg12 + slam12 * sdomg12;
1084
+ }
1085
+ }
1086
+ }
1087
+ if (outmask & g.DISTANCE)
1088
+ vals.s12 = 0 + s12x;
1089
+ if (outmask & g.REDUCEDLENGTH)
1090
+ vals.m12 = 0 + m12x;
1091
+ if (outmask & g.AREA) {
1092
+ salp0 = salp1 * cbet1;
1093
+ calp0 = m.hypot(calp1, salp1 * sbet1);
1094
+ if (calp0 !== 0 && salp0 !== 0) {
1095
+ ssig1 = sbet1;
1096
+ csig1 = calp1 * cbet1;
1097
+ ssig2 = sbet2;
1098
+ csig2 = calp2 * cbet2;
1099
+ k2 = m.sq(calp0) * this._ep2;
1100
+ eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
1101
+ A4 = m.sq(this.a) * calp0 * salp0 * this._e2;
1102
+ t = m.hypot(ssig1, csig1);
1103
+ ssig1 /= t;
1104
+ csig1 /= t;
1105
+ t = m.hypot(ssig2, csig2);
1106
+ ssig2 /= t;
1107
+ csig2 /= t;
1108
+ C4a = new Array(g.nC4_);
1109
+ this.C4f(eps, C4a);
1110
+ B41 = g.SinCosSeries(false, ssig1, csig1, C4a);
1111
+ B42 = g.SinCosSeries(false, ssig2, csig2, C4a);
1112
+ vals.S12 = A4 * (sig12 < 0.01 ? g.SinCosSeries(false, ssig1, csig1, C4a, sig12) : B42 - B41);
1113
+ } else
1114
+ vals.S12 = 0;
1115
+ if (!meridian && somg12 == 2) {
1116
+ somg12 = Math.sin(omg12);
1117
+ comg12 = Math.cos(omg12);
1118
+ }
1119
+ if (!meridian && comg12 > -0.7071 && // Long difference not too big
1120
+ sbet2 - sbet1 < 1.75) {
1121
+ domg12 = 1 + comg12;
1122
+ dbet1 = 1 + cbet1;
1123
+ dbet2 = 1 + cbet2;
1124
+ alp12 = 2 * Math.atan2(somg12 * (sbet1 * dbet2 + sbet2 * dbet1), domg12 * (sbet1 * sbet2 + dbet1 * dbet2));
1125
+ } else {
1126
+ salp12 = salp2 * calp1 - calp2 * salp1;
1127
+ calp12 = calp2 * calp1 + salp2 * salp1;
1128
+ if (salp12 === 0 && calp12 < 0) {
1129
+ salp12 = g.tiny_ * calp1;
1130
+ calp12 = -1;
1131
+ }
1132
+ alp12 = Math.atan2(salp12, calp12);
1133
+ }
1134
+ vals.S12 += this._c2 * alp12;
1135
+ vals.S12 *= swapp * lonsign * latsign;
1136
+ vals.S12 += 0;
1137
+ }
1138
+ if (swapp < 0) {
1139
+ [salp2, salp1] = [salp1, salp2];
1140
+ [calp2, calp1] = [calp1, calp2];
1141
+ if (outmask & g.GEODESICSCALE) {
1142
+ [vals.M21, vals.M12] = [vals.M12, vals.M21];
1143
+ }
1144
+ }
1145
+ salp1 *= swapp * lonsign;
1146
+ calp1 *= swapp * latsign;
1147
+ salp2 *= swapp * lonsign;
1148
+ calp2 *= swapp * latsign;
1149
+ return {
1150
+ vals,
1151
+ salp1,
1152
+ calp1,
1153
+ salp2,
1154
+ calp2
1155
+ };
1156
+ };
1157
+ g.Geodesic.prototype.GenDirect = function(lat1, lon1, azi1, arcmode, s12_a12, outmask) {
1158
+ var line;
1159
+ if (!outmask)
1160
+ outmask = g.STANDARD;
1161
+ else if (outmask === g.LONG_UNROLL)
1162
+ outmask |= g.STANDARD;
1163
+ if (!arcmode)
1164
+ outmask |= g.DISTANCE_IN;
1165
+ line = new l.GeodesicLine(this, lat1, lon1, azi1, outmask);
1166
+ return line.GenPosition(arcmode, s12_a12, outmask);
1167
+ };
1168
+ g.Geodesic.prototype.Direct = function(lat1, lon1, azi1, s12, outmask) {
1169
+ return this.GenDirect(lat1, lon1, azi1, false, s12, outmask);
1170
+ };
1171
+ g.Geodesic.prototype.ArcDirect = function(lat1, lon1, azi1, a12, outmask) {
1172
+ return this.GenDirect(lat1, lon1, azi1, true, a12, outmask);
1173
+ };
1174
+ g.Geodesic.prototype.Line = function(lat1, lon1, azi1, caps) {
1175
+ return new l.GeodesicLine(this, lat1, lon1, azi1, caps);
1176
+ };
1177
+ g.Geodesic.prototype.DirectLine = function(lat1, lon1, azi1, s12, caps) {
1178
+ return this.GenDirectLine(lat1, lon1, azi1, false, s12, caps);
1179
+ };
1180
+ g.Geodesic.prototype.ArcDirectLine = function(lat1, lon1, azi1, a12, caps) {
1181
+ return this.GenDirectLine(lat1, lon1, azi1, true, a12, caps);
1182
+ };
1183
+ g.Geodesic.prototype.GenDirectLine = function(lat1, lon1, azi1, arcmode, s12_a12, caps) {
1184
+ var t;
1185
+ if (!caps)
1186
+ caps = g.STANDARD | g.DISTANCE_IN;
1187
+ if (!arcmode)
1188
+ caps |= g.DISTANCE_IN;
1189
+ t = new l.GeodesicLine(this, lat1, lon1, azi1, caps);
1190
+ t.GenSetDistance(arcmode, s12_a12);
1191
+ return t;
1192
+ };
1193
+ g.Geodesic.prototype.InverseLine = function(lat1, lon1, lat2, lon2, caps) {
1194
+ var r, t, azi1;
1195
+ if (!caps)
1196
+ caps = g.STANDARD | g.DISTANCE_IN;
1197
+ r = this.InverseInt(lat1, lon1, lat2, lon2, g.ARC);
1198
+ azi1 = m.atan2d(r.salp1, r.calp1);
1199
+ if (caps & (g.OUT_MASK & g.DISTANCE_IN))
1200
+ caps |= g.DISTANCE;
1201
+ t = new l.GeodesicLine(this, lat1, lon1, azi1, caps, r.salp1, r.calp1);
1202
+ t.SetArc(r.vals.a12);
1203
+ return t;
1204
+ };
1205
+ g.Geodesic.prototype.Polygon = function(polyline) {
1206
+ return new p.PolygonArea(this, polyline);
1207
+ };
1208
+ g.WGS84 = new g.Geodesic(c.WGS84.a, c.WGS84.f);
1209
+ })(geodesic.Geodesic, geodesic.GeodesicLine, geodesic.PolygonArea, geodesic.Math, geodesic.Constants);
1210
+ (function(g, l, m) {
1211
+ "use strict";
1212
+ l.GeodesicLine = function(geod, lat1, lon1, azi1, caps, salp1, calp1) {
1213
+ var t, cbet1, sbet1, eps, s, c;
1214
+ if (!caps)
1215
+ caps = g.STANDARD | g.DISTANCE_IN;
1216
+ this.a = geod.a;
1217
+ this.f = geod.f;
1218
+ this._b = geod._b;
1219
+ this._c2 = geod._c2;
1220
+ this._f1 = geod._f1;
1221
+ this.caps = caps | g.LATITUDE | g.AZIMUTH | g.LONG_UNROLL;
1222
+ this.lat1 = m.LatFix(lat1);
1223
+ this.lon1 = lon1;
1224
+ if (typeof salp1 === "undefined" || typeof calp1 === "undefined") {
1225
+ this.azi1 = m.AngNormalize(azi1);
1226
+ t = m.sincosd(m.AngRound(this.azi1));
1227
+ this.salp1 = t.s;
1228
+ this.calp1 = t.c;
1229
+ } else {
1230
+ this.azi1 = azi1;
1231
+ this.salp1 = salp1;
1232
+ this.calp1 = calp1;
1233
+ }
1234
+ t = m.sincosd(m.AngRound(this.lat1));
1235
+ sbet1 = this._f1 * t.s;
1236
+ cbet1 = t.c;
1237
+ t = m.hypot(sbet1, cbet1);
1238
+ sbet1 /= t;
1239
+ cbet1 /= t;
1240
+ cbet1 = Math.max(g.tiny_, cbet1);
1241
+ this._dn1 = Math.sqrt(1 + geod._ep2 * m.sq(sbet1));
1242
+ this._salp0 = this.salp1 * cbet1;
1243
+ this._calp0 = m.hypot(this.calp1, this.salp1 * sbet1);
1244
+ this._ssig1 = sbet1;
1245
+ this._somg1 = this._salp0 * sbet1;
1246
+ this._csig1 = this._comg1 = sbet1 !== 0 || this.calp1 !== 0 ? cbet1 * this.calp1 : 1;
1247
+ t = m.hypot(this._ssig1, this._csig1);
1248
+ this._ssig1 /= t;
1249
+ this._csig1 /= t;
1250
+ this._k2 = m.sq(this._calp0) * geod._ep2;
1251
+ eps = this._k2 / (2 * (1 + Math.sqrt(1 + this._k2)) + this._k2);
1252
+ if (this.caps & g.CAP_C1) {
1253
+ this._A1m1 = g.A1m1f(eps);
1254
+ this._C1a = new Array(g.nC1_ + 1);
1255
+ g.C1f(eps, this._C1a);
1256
+ this._B11 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C1a);
1257
+ s = Math.sin(this._B11);
1258
+ c = Math.cos(this._B11);
1259
+ this._stau1 = this._ssig1 * c + this._csig1 * s;
1260
+ this._ctau1 = this._csig1 * c - this._ssig1 * s;
1261
+ }
1262
+ if (this.caps & g.CAP_C1p) {
1263
+ this._C1pa = new Array(g.nC1p_ + 1);
1264
+ g.C1pf(eps, this._C1pa);
1265
+ }
1266
+ if (this.caps & g.CAP_C2) {
1267
+ this._A2m1 = g.A2m1f(eps);
1268
+ this._C2a = new Array(g.nC2_ + 1);
1269
+ g.C2f(eps, this._C2a);
1270
+ this._B21 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C2a);
1271
+ }
1272
+ if (this.caps & g.CAP_C3) {
1273
+ this._C3a = new Array(g.nC3_);
1274
+ geod.C3f(eps, this._C3a);
1275
+ this._A3c = -this.f * this._salp0 * geod.A3f(eps);
1276
+ this._B31 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C3a);
1277
+ }
1278
+ if (this.caps & g.CAP_C4) {
1279
+ this._C4a = new Array(g.nC4_);
1280
+ geod.C4f(eps, this._C4a);
1281
+ this._A4 = m.sq(this.a) * this._calp0 * this._salp0 * geod._e2;
1282
+ this._B41 = g.SinCosSeries(false, this._ssig1, this._csig1, this._C4a);
1283
+ }
1284
+ this.a13 = this.s13 = NaN;
1285
+ };
1286
+ l.GeodesicLine.prototype.GenPosition = function(arcmode, s12_a12, outmask, vals = {}) {
1287
+ 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;
1288
+ if (!outmask)
1289
+ outmask = g.STANDARD;
1290
+ else if (outmask === g.LONG_UNROLL)
1291
+ outmask |= g.STANDARD;
1292
+ outmask &= this.caps & g.OUT_MASK;
1293
+ vals.lat1 = this.lat1;
1294
+ vals.azi1 = this.azi1;
1295
+ vals.lon1 = outmask & g.LONG_UNROLL ? this.lon1 : m.AngNormalize(this.lon1);
1296
+ if (arcmode)
1297
+ vals.a12 = s12_a12;
1298
+ else
1299
+ vals.s12 = s12_a12;
1300
+ if (!(arcmode || this.caps & g.DISTANCE_IN & g.OUT_MASK)) {
1301
+ vals.a12 = NaN;
1302
+ return vals;
1303
+ }
1304
+ B12 = 0;
1305
+ AB1 = 0;
1306
+ if (arcmode) {
1307
+ sig12 = s12_a12 * m.degree;
1308
+ t = m.sincosd(s12_a12);
1309
+ ssig12 = t.s;
1310
+ csig12 = t.c;
1311
+ } else {
1312
+ tau12 = s12_a12 / (this._b * (1 + this._A1m1));
1313
+ s = Math.sin(tau12);
1314
+ c = Math.cos(tau12);
1315
+ B12 = -g.SinCosSeries(true, this._stau1 * c + this._ctau1 * s, this._ctau1 * c - this._stau1 * s, this._C1pa);
1316
+ sig12 = tau12 - (B12 - this._B11);
1317
+ ssig12 = Math.sin(sig12);
1318
+ csig12 = Math.cos(sig12);
1319
+ if (Math.abs(this.f) > 0.01) {
1320
+ ssig2 = this._ssig1 * csig12 + this._csig1 * ssig12;
1321
+ csig2 = this._csig1 * csig12 - this._ssig1 * ssig12;
1322
+ B12 = g.SinCosSeries(true, ssig2, csig2, this._C1a);
1323
+ serr = (1 + this._A1m1) * (sig12 + (B12 - this._B11)) - s12_a12 / this._b;
1324
+ sig12 = sig12 - serr / Math.sqrt(1 + this._k2 * m.sq(ssig2));
1325
+ ssig12 = Math.sin(sig12);
1326
+ csig12 = Math.cos(sig12);
1327
+ }
1328
+ }
1329
+ ssig2 = this._ssig1 * csig12 + this._csig1 * ssig12;
1330
+ csig2 = this._csig1 * csig12 - this._ssig1 * ssig12;
1331
+ dn2 = Math.sqrt(1 + this._k2 * m.sq(ssig2));
1332
+ if (outmask & (g.DISTANCE | g.REDUCEDLENGTH | g.GEODESICSCALE)) {
1333
+ if (arcmode || Math.abs(this.f) > 0.01)
1334
+ B12 = g.SinCosSeries(true, ssig2, csig2, this._C1a);
1335
+ AB1 = (1 + this._A1m1) * (B12 - this._B11);
1336
+ }
1337
+ sbet2 = this._calp0 * ssig2;
1338
+ cbet2 = m.hypot(this._salp0, this._calp0 * csig2);
1339
+ if (cbet2 === 0)
1340
+ cbet2 = csig2 = g.tiny_;
1341
+ salp2 = this._salp0;
1342
+ calp2 = this._calp0 * csig2;
1343
+ if (arcmode && outmask & g.DISTANCE)
1344
+ vals.s12 = this._b * ((1 + this._A1m1) * sig12 + AB1);
1345
+ if (outmask & g.LONGITUDE) {
1346
+ somg2 = this._salp0 * ssig2;
1347
+ comg2 = csig2;
1348
+ E = m.copysign(1, this._salp0);
1349
+ 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);
1350
+ lam12 = omg12 + this._A3c * (sig12 + (g.SinCosSeries(true, ssig2, csig2, this._C3a) - this._B31));
1351
+ lon12 = lam12 / m.degree;
1352
+ vals.lon2 = outmask & g.LONG_UNROLL ? this.lon1 + lon12 : m.AngNormalize(m.AngNormalize(this.lon1) + m.AngNormalize(lon12));
1353
+ }
1354
+ if (outmask & g.LATITUDE)
1355
+ vals.lat2 = m.atan2d(sbet2, this._f1 * cbet2);
1356
+ if (outmask & g.AZIMUTH)
1357
+ vals.azi2 = m.atan2d(salp2, calp2);
1358
+ if (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE)) {
1359
+ B22 = g.SinCosSeries(true, ssig2, csig2, this._C2a);
1360
+ AB2 = (1 + this._A2m1) * (B22 - this._B21);
1361
+ J12 = (this._A1m1 - this._A2m1) * sig12 + (AB1 - AB2);
1362
+ if (outmask & g.REDUCEDLENGTH)
1363
+ vals.m12 = this._b * (dn2 * (this._csig1 * ssig2) - this._dn1 * (this._ssig1 * csig2) - this._csig1 * csig2 * J12);
1364
+ if (outmask & g.GEODESICSCALE) {
1365
+ t = this._k2 * (ssig2 - this._ssig1) * (ssig2 + this._ssig1) / (this._dn1 + dn2);
1366
+ vals.M12 = csig12 + (t * ssig2 - csig2 * J12) * this._ssig1 / this._dn1;
1367
+ vals.M21 = csig12 - (t * this._ssig1 - this._csig1 * J12) * ssig2 / dn2;
1368
+ }
1369
+ }
1370
+ if (outmask & g.AREA) {
1371
+ B42 = g.SinCosSeries(false, ssig2, csig2, this._C4a);
1372
+ if (this._calp0 === 0 || this._salp0 === 0) {
1373
+ salp12 = salp2 * this.calp1 - calp2 * this.salp1;
1374
+ calp12 = calp2 * this.calp1 + salp2 * this.salp1;
1375
+ } else {
1376
+ salp12 = this._calp0 * this._salp0 * (csig12 <= 0 ? this._csig1 * (1 - csig12) + ssig12 * this._ssig1 : ssig12 * (this._csig1 * ssig12 / (1 + csig12) + this._ssig1));
1377
+ calp12 = m.sq(this._salp0) + m.sq(this._calp0) * this._csig1 * csig2;
1378
+ }
1379
+ 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);
1380
+ }
1381
+ if (!arcmode)
1382
+ vals.a12 = sig12 / m.degree;
1383
+ return vals;
1384
+ };
1385
+ l.GeodesicLine.prototype.Position = function(s12, outmask) {
1386
+ return this.GenPosition(false, s12, outmask);
1387
+ };
1388
+ l.GeodesicLine.prototype.ArcPosition = function(a12, outmask) {
1389
+ return this.GenPosition(true, a12, outmask);
1390
+ };
1391
+ l.GeodesicLine.prototype.GenSetDistance = function(arcmode, s13_a13) {
1392
+ if (arcmode)
1393
+ this.SetArc(s13_a13);
1394
+ else
1395
+ this.SetDistance(s13_a13);
1396
+ };
1397
+ l.GeodesicLine.prototype.SetDistance = function(s13) {
1398
+ var r;
1399
+ this.s13 = s13;
1400
+ r = this.GenPosition(false, this.s13, g.ARC);
1401
+ this.a13 = 0 + r.a12;
1402
+ };
1403
+ l.GeodesicLine.prototype.SetArc = function(a13) {
1404
+ var r;
1405
+ this.a13 = a13;
1406
+ r = this.GenPosition(true, this.a13, g.DISTANCE);
1407
+ this.s13 = 0 + r.s12;
1408
+ };
1409
+ })(geodesic.Geodesic, geodesic.GeodesicLine, geodesic.Math);
1410
+
1411
+ // dist/ellipsoid-geodesic.js
1412
+ var library = geodesic.Geodesic;
1413
+ var EllipsoidGeodesic = class {
1414
+ constructor({ semiMajorAxis: a, semiMinorAxis: b }) {
1415
+ this.engine = createGeodesicEngine({ semiMajorAxis: a, semiMinorAxis: b });
1416
+ }
1417
+ /** Total area in squared axis units, with the same normalization as S12. */
1418
+ get surfaceArea() {
1419
+ return 4 * Math.PI * this.engine._c2;
1420
+ }
1421
+ inverse(lat1, lon1, lat2, lon2, options = {}) {
1422
+ validatePoint(lat1, lon1);
1423
+ validatePoint(lat2, lon2);
1424
+ return this.engine.Inverse(lat1, lon1, lat2, lon2, outputMask(options));
1425
+ }
1426
+ direct(latitude, longitude, azimuth, distance, options = {}) {
1427
+ return this.line(latitude, longitude, azimuth, options).position(distance);
1428
+ }
1429
+ arcDirect(latitude, longitude, azimuth, arc, options = {}) {
1430
+ return this.line(latitude, longitude, azimuth, options).arcPosition(arc);
1431
+ }
1432
+ line(latitude, longitude, azimuth, options = {}) {
1433
+ validatePoint(latitude, longitude);
1434
+ validateFinite(azimuth);
1435
+ const selectedMask = outputMask(options);
1436
+ const line = this.engine.Line(latitude, longitude, azimuth, selectedMask | library.DISTANCE_IN);
1437
+ return {
1438
+ // Fourth argument is an internal result request; ordinary Array.map arguments remain ignored.
1439
+ position(distance, _index, _array, output2) {
1440
+ validateFinite(distance);
1441
+ return line.GenPosition(false, distance, selectedMask, output2);
1442
+ },
1443
+ arcPosition(arc) {
1444
+ validateFinite(arc);
1445
+ return line.ArcPosition(arc, selectedMask);
1446
+ }
1447
+ };
1448
+ }
1449
+ };
1450
+ function validatePoint(latitude, longitude) {
1451
+ if (!(Number.isFinite(latitude) && Math.abs(latitude) <= 90 && Number.isFinite(longitude))) {
1452
+ throw new Error("Invalid geodesic coordinates");
1453
+ }
1454
+ }
1455
+ function outputMask(options) {
1456
+ return library.ALL & ~(options.area ? 0 : library.AREA) | (options.unrollLongitude ? library.LONG_UNROLL : 0);
1457
+ }
1458
+ function validateFinite(value2) {
1459
+ if (!Number.isFinite(value2))
1460
+ throw new Error("Nonfinite axis, azimuth, distance or arc");
1461
+ }
1462
+ var nonAreaGeodesicMask = library.ALL & ~library.AREA;
1463
+ function createGeodesicEngine({ semiMajorAxis: a, semiMinorAxis: b }) {
1464
+ validateFinite(a);
1465
+ validateFinite(b);
1466
+ return new library.Geodesic(a, (a - b) / a);
1467
+ }
1468
+
1469
+ // dist/constants.js
1470
+ var WGS84_RADIUS_X = 6378137;
1471
+ var WGS84_RADIUS_Y = 6378137;
1472
+ var WGS84_RADIUS_Z = 6356752314245179e-9;
1473
+ var WGS84_CONSTANTS = {
1474
+ radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],
1475
+ radiiSquared: [
1476
+ WGS84_RADIUS_X * WGS84_RADIUS_X,
1477
+ WGS84_RADIUS_Y * WGS84_RADIUS_Y,
1478
+ WGS84_RADIUS_Z * WGS84_RADIUS_Z
1479
+ ],
1480
+ oneOverRadii: [1 / WGS84_RADIUS_X, 1 / WGS84_RADIUS_Y, 1 / WGS84_RADIUS_Z],
1481
+ oneOverRadiiSquared: [
1482
+ 1 / (WGS84_RADIUS_X * WGS84_RADIUS_X),
1483
+ 1 / (WGS84_RADIUS_Y * WGS84_RADIUS_Y),
1484
+ 1 / (WGS84_RADIUS_Z * WGS84_RADIUS_Z)
1485
+ ],
1486
+ maximumRadius: Math.max(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z),
1487
+ centerToleranceSquared: 0.1
1488
+ // EPSILON1;
1489
+ };
1490
+
1491
+ // dist/geodesic-path.js
1492
+ var wgs84;
1493
+ var GeodesicPath = class {
1494
+ constructor(start, end, options = {}) {
1495
+ validateGeographicPosition(start);
1496
+ validateGeographicPosition(end);
1497
+ if (start.length !== end.length)
1498
+ throw new RangeError("Geodesic endpoint dimensions must match");
1499
+ const solver = options.geodesic || getDefaultGeodesic();
1500
+ const inverse = solver.inverse(start[1], start[0], end[1], end[0], { unrollLongitude: true });
1501
+ if (!Number.isFinite(inverse.s12) || inverse.s12 < 0 || !Number.isFinite(inverse.azi1) || !Number.isFinite(inverse.lon2)) {
1502
+ throw new RangeError("Unresolved geodesic path");
1503
+ }
1504
+ this.size = start.length;
1505
+ this.length = inverse.s12;
1506
+ this.first = Object.freeze(Array.from(start));
1507
+ const last = Array.from(end);
1508
+ last[0] = inverse.lon2;
1509
+ if (this.length === 0) {
1510
+ last[0] = start[0];
1511
+ last[1] = start[1];
1512
+ }
1513
+ this.last = Object.freeze(last);
1514
+ this.line = solver.line(start[1], start[0], inverse.azi1, { unrollLongitude: true });
1515
+ }
1516
+ get start() {
1517
+ return this.first.slice();
1518
+ }
1519
+ get end() {
1520
+ return this.last.slice();
1521
+ }
1522
+ sample(fraction, result = new Array(this.size)) {
1523
+ if (!Number.isFinite(fraction) || fraction < 0 || fraction > 1) {
1524
+ throw new RangeError("Geodesic fraction must be in [0, 1]");
1525
+ }
1526
+ if (result.length !== this.size)
1527
+ throw new RangeError("Invalid geodesic sample output length");
1528
+ let longitude;
1529
+ let latitude;
1530
+ if (fraction === 0 || this.length === 0) {
1531
+ longitude = this.first[0];
1532
+ latitude = this.first[1];
1533
+ } else if (fraction === 1) {
1534
+ longitude = this.last[0];
1535
+ latitude = this.last[1];
1536
+ } else {
1537
+ const value2 = this.line.position(this.length * fraction);
1538
+ longitude = value2.lon2;
1539
+ latitude = value2.lat2;
1540
+ }
1541
+ const height = this.size === 3 ? this.first[2] * (1 - fraction) + this.last[2] * fraction : 0;
1542
+ if (![longitude, latitude, height].every(Number.isFinite) || result instanceof Float32Array && ![longitude, latitude, height].every((value2) => Number.isFinite(Math.fround(value2)))) {
1543
+ throw new RangeError("Unrepresentable geodesic sample");
1544
+ }
1545
+ result[0] = longitude;
1546
+ result[1] = latitude;
1547
+ if (this.size === 3)
1548
+ result[2] = height;
1549
+ return result;
1550
+ }
1551
+ sampleByDistance(distance, result = new Array(this.size)) {
1552
+ if (!Number.isFinite(distance) || distance < 0 || distance > this.length) {
1553
+ throw new RangeError("Distance must be within the geodesic path");
1554
+ }
1555
+ return this.sample(this.length === 0 ? 0 : distance / this.length, result);
1556
+ }
1557
+ };
1558
+ function validateGeographicPosition(point) {
1559
+ if (point.length !== 2 && point.length !== 3 || !Array.from(point).every(Number.isFinite) || Math.abs(point[1]) > 90) {
1560
+ throw new RangeError("Expected finite longitude/latitude[/height], latitude in [-90, 90]");
1561
+ }
1562
+ }
1563
+ function getDefaultGeodesic() {
1564
+ if (!wgs84) {
1565
+ wgs84 = new EllipsoidGeodesic({ semiMajorAxis: WGS84_RADIUS_X, semiMinorAxis: WGS84_RADIUS_Z });
1566
+ }
1567
+ return wgs84;
1568
+ }
1569
+
1570
+ // dist/ellipsoid-helpers/rhumb-pole-distance.js
1571
+ var Q = 10n ** 48n;
1572
+ var PI = 3141592653589793238462643383279502884197169399375n;
1573
+ var mul = (x, y) => x * y / Q;
1574
+ var div = (x, y) => x * Q / y;
1575
+ function exact(x) {
1576
+ const bytes = new DataView(new ArrayBuffer(8));
1577
+ bytes.setFloat64(0, x);
1578
+ const bits = bytes.getBigUint64(0), exponent = Number(bits >> 52n & 2047n);
1579
+ const mantissa = bits & (1n << 52n) - 1n | (exponent ? 1n << 52n : 0n);
1580
+ const shift2 = exponent ? exponent - 1075 : -1074;
1581
+ const value2 = shift2 >= 0 ? mantissa * Q << BigInt(shift2) : mantissa * Q >> BigInt(-shift2);
1582
+ return bits >> 63n ? -value2 : value2;
1583
+ }
1584
+ function sc(x) {
1585
+ let s = x, c = Q, ts = x, tc = Q;
1586
+ const square = mul(x, x);
1587
+ for (let n = 1n; n < 160n; n++) {
1588
+ ts = -mul(ts, square) / (2n * n * (2n * n + 1n));
1589
+ tc = -mul(tc, square) / ((2n * n - 1n) * (2n * n));
1590
+ s += ts;
1591
+ c += tc;
1592
+ if (ts === 0n && tc === 0n)
1593
+ break;
1594
+ }
1595
+ return [s, c];
1596
+ }
1597
+ function remainingPoleDistance(a, b, latitude, azimuth, distance, sign) {
1598
+ const unit2 = 2 ** Math.floor(Math.log2(a));
1599
+ a /= unit2;
1600
+ b /= unit2;
1601
+ distance /= unit2;
1602
+ const ratio = div(exact(b), exact(a));
1603
+ const theta = mul(90n * Q - BigInt(sign) * exact(latitude), PI) / 180n;
1604
+ const [s, c] = sc(theta), prolate = ratio > Q;
1605
+ const square = mul(ratio, ratio);
1606
+ const k = prolate ? Q - div(Q, square) : Q - square;
1607
+ const z = prolate ? s : c, other = prolate ? c : s;
1608
+ const zz = mul(z, z);
1609
+ let integral = theta, total = theta, coefficient = Q, power = z;
1610
+ for (let n = 1n; n < 480n; n++) {
1611
+ integral = ((2n * n - 1n) * integral + (prolate ? -1n : 1n) * mul(power, other)) / (2n * n);
1612
+ coefficient = mul(coefficient, k) * (2n * n + 1n) / (2n * n);
1613
+ const term = mul(coefficient, integral);
1614
+ total += term;
1615
+ power = mul(power, zz);
1616
+ if (term === 0n)
1617
+ break;
1618
+ }
1619
+ const gap = prolate ? div(total, ratio) : mul(total, square);
1620
+ const angle3 = mul(exact(azimuth % 360), PI) / 180n;
1621
+ const north = mul(div(exact(distance), exact(a)), sc(angle3)[1]);
1622
+ return Number(gap - BigInt(sign) * north) / Number(Q);
1623
+ }
1624
+
1625
+ // dist/ellipsoid-metrics.js
1626
+ var DEG = Math.PI / 180;
1627
+ var NODES = [
1628
+ 0.09501250983763744,
1629
+ 0.2816035507792589,
1630
+ 0.4580167776572274,
1631
+ 0.6178762444026438,
1632
+ 0.755404408355003,
1633
+ 0.8656312023878318,
1634
+ 0.9445750230732326,
1635
+ 0.9894009349916499
1636
+ ];
1637
+ var WEIGHTS = [
1638
+ 0.1894506104550685,
1639
+ 0.1826034150449236,
1640
+ 0.16915651939500254,
1641
+ 0.14959598881657674,
1642
+ 0.12462897125553388,
1643
+ 0.09515851168249279,
1644
+ 0.06225352393864789,
1645
+ 0.027152459411754096
1646
+ ];
1647
+ var KINDS = [
1648
+ "geocentric",
1649
+ "parametric",
1650
+ "rectifying",
1651
+ "authalic",
1652
+ "conformal",
1653
+ "isometric"
1654
+ ];
1655
+ var EllipsoidMetrics = class {
1656
+ constructor({ semiMajorAxis: a, semiMinorAxis: b }) {
1657
+ const r = b / a;
1658
+ if (!(Number.isFinite(a) && Number.isFinite(b) && a > 0 && b > 0 && r >= 0.5 && r <= 2)) {
1659
+ throw new Error("Ellipsoid metrics require finite positive axes with 0.5 <= b/a <= 2");
1660
+ }
1661
+ this.semiMajorAxis = a;
1662
+ this.semiMinorAxis = b;
1663
+ this.ratio = r;
1664
+ this.e2 = (1 - r) * (1 + r);
1665
+ this.qPole = 1 + r * r * this.eccentricIntegral(1);
1666
+ this.quarter = integrate((t) => this.meridianIntegrand(t), 0, Math.PI / 2);
1667
+ this.quarterMeridian = a * this.quarter;
1668
+ this.surfaceArea = 2 * Math.PI * a * a * this.qPole;
1669
+ this.volume = 4 * Math.PI / 3 * a * b * a;
1670
+ if (![this.quarterMeridian, this.surfaceArea, this.volume].every((v) => Number.isFinite(v) && v > 0)) {
1671
+ throw new Error("Ellipsoid metrics exceed representable length/area/volume range");
1672
+ }
1673
+ Object.freeze(this);
1674
+ }
1675
+ meridianDistance(latitude) {
1676
+ validateLatitude(latitude);
1677
+ return Math.sign(latitude) * this.semiMajorAxis * this.meridian(Math.abs(latitude));
1678
+ }
1679
+ meridionalCurvatureRadius(latitude) {
1680
+ validateLatitude(latitude);
1681
+ return this.semiMajorAxis * this.meridianIntegrand(latitude * DEG);
1682
+ }
1683
+ transverseCurvatureRadius(latitude) {
1684
+ validateLatitude(latitude);
1685
+ const [s, c] = sincos(latitude);
1686
+ return this.semiMajorAxis / Math.hypot(c, this.ratio * s);
1687
+ }
1688
+ normalCurvatureRadius(latitude, azimuth) {
1689
+ if (!Number.isFinite(azimuth))
1690
+ throw new Error("Azimuth must be finite");
1691
+ const [s, c] = sincos(azimuth % 180);
1692
+ return 1 / (c * c / this.meridionalCurvatureRadius(latitude) + s * s / this.transverseCurvatureRadius(latitude));
1693
+ }
1694
+ latitudeToAuxiliary(latitude, kind) {
1695
+ validateKind(kind);
1696
+ validateLatitude(latitude);
1697
+ if (latitude === 0)
1698
+ return latitude;
1699
+ if (Math.abs(latitude) === 90)
1700
+ return kind === "isometric" ? Math.sign(latitude) * Infinity : latitude;
1701
+ if (this.ratio === 1 && kind !== "isometric")
1702
+ return latitude;
1703
+ const sign = Math.sign(latitude);
1704
+ const phi = Math.abs(latitude);
1705
+ const [s, c] = sincos(phi);
1706
+ switch (kind) {
1707
+ case "geocentric":
1708
+ return sign * angle(this.ratio * this.ratio * s, c);
1709
+ case "parametric":
1710
+ return sign * angle(this.ratio * s, c);
1711
+ case "rectifying":
1712
+ return sign * (phi <= 45 ? this.meridian(phi) / this.quarter * 90 : 90 - integrate((t) => this.meridianIntegrand(Math.PI / 2 - t), 0, (90 - phi) * DEG) / this.quarter * 90);
1713
+ case "authalic": {
1714
+ if (phi <= 45) {
1715
+ const q = this.ratio ** 2 * (s / (c * c + (this.ratio * s) ** 2) + this.eccentricIntegral(s));
1716
+ return sign * Math.asin(q / this.qPole) / DEG;
1717
+ }
1718
+ const cap = integrate((t) => {
1719
+ const st = Math.sin(t), ct = Math.cos(t);
1720
+ const d = st * st + (this.ratio * ct) ** 2;
1721
+ return 2 * this.ratio ** 2 * st / (d * d);
1722
+ }, 0, (90 - phi) * DEG);
1723
+ return sign * (90 - 2 * Math.asin(Math.sqrt(cap / (2 * this.qPole))) / DEG);
1724
+ }
1725
+ default: {
1726
+ const psi = Math.asinh(s / c) - this.e2 * this.eccentricIntegral(s);
1727
+ return sign * (kind === "isometric" ? psi / DEG : psi < 1 ? Math.atan(Math.sinh(psi)) / DEG : 90 - 2 * Math.atan(Math.exp(-psi)) / DEG);
1728
+ }
1729
+ }
1730
+ }
1731
+ latitudeFromAuxiliary(latitude, kind) {
1732
+ validateKind(kind);
1733
+ if (kind === "isometric" && Math.abs(latitude) === Infinity)
1734
+ return Math.sign(latitude) * 90;
1735
+ if (kind !== "isometric")
1736
+ validateLatitude(latitude);
1737
+ else if (!Number.isFinite(latitude))
1738
+ throw new Error("Isometric latitude must be finite or a pole infinity");
1739
+ if (latitude === 0)
1740
+ return latitude;
1741
+ if (kind !== "isometric" && Math.abs(latitude) === 90)
1742
+ return latitude;
1743
+ if (this.ratio === 1 && kind !== "isometric")
1744
+ return latitude;
1745
+ const sign = Math.sign(latitude), target = Math.abs(latitude);
1746
+ if (kind === "geocentric" || kind === "parametric") {
1747
+ const [s, c] = sincos(target);
1748
+ return sign * angle(s, c * (kind === "geocentric" ? this.ratio ** 2 : this.ratio));
1749
+ }
1750
+ let lo = 0, hi = 90;
1751
+ for (let i = 0; i < 64; ++i) {
1752
+ const mid = (lo + hi) / 2;
1753
+ if (mid === lo || mid === hi)
1754
+ break;
1755
+ if (this.latitudeToAuxiliary(mid, kind) < target)
1756
+ lo = mid;
1757
+ else
1758
+ hi = mid;
1759
+ }
1760
+ return sign * ((lo + hi) / 2);
1761
+ }
1762
+ eccentricIntegral(s) {
1763
+ const e = Math.sqrt(Math.abs(this.e2));
1764
+ return e === 0 ? s : (this.e2 > 0 ? Math.atanh(e * s) : Math.atan(e * s)) / e;
1765
+ }
1766
+ meridianIntegrand(t) {
1767
+ return this.ratio ** 2 / Math.hypot(Math.cos(t), this.ratio * Math.sin(t)) ** 3;
1768
+ }
1769
+ meridian(phi) {
1770
+ return phi <= 45 ? integrate((t) => this.meridianIntegrand(t), 0, phi * DEG) : this.quarter - integrate((t) => this.meridianIntegrand(Math.PI / 2 - t), 0, (90 - phi) * DEG);
1771
+ }
1772
+ };
1773
+ function validateLatitude(value2) {
1774
+ if (!(Number.isFinite(value2) && Math.abs(value2) <= 90))
1775
+ throw new Error("Latitude must be in [-90, 90] degrees");
1776
+ }
1777
+ function validateKind(kind) {
1778
+ if (!KINDS.includes(kind))
1779
+ throw new Error("Unknown auxiliary latitude");
1780
+ }
1781
+ function sincos(degrees) {
1782
+ const a = Math.abs(degrees);
1783
+ if (a <= 45)
1784
+ return [Math.sin(degrees * DEG), Math.cos(degrees * DEG)];
1785
+ return [Math.sign(degrees) * Math.cos((90 - a) * DEG), Math.sin((90 - a) * DEG)];
1786
+ }
1787
+ function angle(s, c) {
1788
+ return s > c ? 90 - Math.atan2(c, s) / DEG : Math.atan2(s, c) / DEG;
1789
+ }
1790
+ function integrate(f, lo, hi) {
1791
+ let sum = 0;
1792
+ for (let j = 0; j < 8; ++j) {
1793
+ const h = (hi - lo) / 16, mid = lo + (2 * j + 1) * h;
1794
+ let part = 0;
1795
+ for (let i = 0; i < 8; ++i)
1796
+ part += WEIGHTS[i] * (f(mid - h * NODES[i]) + f(mid + h * NODES[i]));
1797
+ sum += h * part;
1798
+ }
1799
+ return sum;
1800
+ }
1801
+
1802
+ // dist/ellipsoid-rhumb.js
1803
+ var RhumbDomainError = class extends RangeError {
1804
+ constructor(reason) {
1805
+ super(reason === "pole" ? "Rhumb longitude/bearing is undefined at an exact pole" : "Rhumb crosses a pole; continuation longitude is undefined");
1806
+ this.reason = reason;
1807
+ this.name = "RhumbDomainError";
1808
+ }
1809
+ };
1810
+ var DEG2 = Math.PI / 180;
1811
+ var EllipsoidRhumb = class {
1812
+ constructor({ semiMajorAxis: a, semiMinorAxis: b }) {
1813
+ if (!(Number.isFinite(a) && Number.isFinite(b) && a > 0 && b > 0))
1814
+ throw new RangeError("Rhumbs require finite positive axes");
1815
+ this.a = a;
1816
+ this.b = b;
1817
+ this.r = b / a;
1818
+ this.metrics = new EllipsoidMetrics({ semiMajorAxis: 1, semiMinorAxis: this.r });
1819
+ this.surfaceArea = a * this.metrics.surfaceArea * a;
1820
+ if (!(Number.isFinite(this.surfaceArea) && this.surfaceArea > 0))
1821
+ throw new RangeError("Rhumb surface area is unrepresentable");
1822
+ Object.freeze(this);
1823
+ }
1824
+ inverse(lat1, lon1, lat2, lon2, options = {}) {
1825
+ validateRhumbPoint(lat1, lon1);
1826
+ validateRhumbPoint(lat2, lon2);
1827
+ const turns = options.longitudeTurns ?? 0;
1828
+ if (!Number.isSafeInteger(turns))
1829
+ throw new RangeError("Rhumb longitudeTurns must be a safe integer");
1830
+ const longitude = angleDifference(lon1, lon2) + 360 * turns;
1831
+ if (!Number.isFinite(longitude))
1832
+ throw new RangeError("Unrepresentable rhumb winding");
1833
+ const dphi = (lat2 - lat1) * DEG2;
1834
+ const [meanM, meanP] = this.means(lat1, lat2);
1835
+ const dx = longitude * DEG2 * meanM / meanP;
1836
+ const distance = this.a * Math.hypot(dphi * meanM, dx);
1837
+ const azi = Math.atan2(longitude * DEG2, dphi * meanP) / DEG2;
1838
+ const result = {
1839
+ lat1,
1840
+ lon1,
1841
+ lat2,
1842
+ lon2: options.unrollLongitude ? lon1 + longitude : normalize(lon2),
1843
+ azi12: azi,
1844
+ s12: distance
1845
+ };
1846
+ if (options.area)
1847
+ result.S12 = this.area(lat1, lat2, longitude * DEG2);
1848
+ if (!Number.isFinite(distance))
1849
+ throw new RangeError("Unrepresentable rhumb distance");
1850
+ return result;
1851
+ }
1852
+ direct(latitude, longitude, azimuth, distance, options = {}) {
1853
+ return this.line(latitude, longitude, azimuth, options).position(distance);
1854
+ }
1855
+ line(latitude, longitude, azimuth, options = {}) {
1856
+ validateRhumbPoint(latitude, longitude);
1857
+ if (!Number.isFinite(azimuth))
1858
+ throw new RangeError("Rhumb azimuth must be finite");
1859
+ const [sa, ca] = sincosDegrees(azimuth);
1860
+ const area = Boolean(options.area), unroll = Boolean(options.unrollLongitude);
1861
+ const azi = normalize(azimuth);
1862
+ const evaluate = (distance, _index, _array, output2) => {
1863
+ if (!Number.isFinite(distance))
1864
+ throw new RangeError("Rhumb distance must be finite");
1865
+ const delta = distance / this.a;
1866
+ if (!Number.isFinite(delta))
1867
+ throw new RangeError("Unrepresentable rhumb distance");
1868
+ const north = delta * ca;
1869
+ let poleDistance;
1870
+ if (north !== 0) {
1871
+ const gap = north > 0 ? this.meridianDelta(latitude, 90) : this.meridianDelta(-90, latitude);
1872
+ poleDistance = gap - Math.abs(north);
1873
+ if (Math.abs(poleDistance) < 1e-4 * gap)
1874
+ poleDistance = remainingPoleDistance(this.a, this.b, latitude, azimuth, distance, Math.sign(north));
1875
+ if (poleDistance < 0)
1876
+ throw new RhumbDomainError("pole-crossing");
1877
+ if (poleDistance === 0)
1878
+ throw new RhumbDomainError("pole");
1879
+ }
1880
+ const polar = north === 0 ? void 0 : this.polarEndpoint(latitude, north, poleDistance);
1881
+ const lat2 = north === 0 ? latitude : (polar == null ? void 0 : polar.latitude) ?? this.inverseMeridian(latitude, north);
1882
+ if (Math.abs(lat2) === 90)
1883
+ throw new RhumbDomainError("pole");
1884
+ const [meanM, meanP] = (polar == null ? void 0 : polar.means) ?? this.means(latitude, lat2);
1885
+ const dlon = delta * sa * meanP / meanM / DEG2;
1886
+ const lon2 = unroll ? longitude + dlon : normalize(normalize(longitude) + dlon);
1887
+ if (!Number.isFinite(lon2))
1888
+ throw new RangeError("Unrepresentable rhumb longitude");
1889
+ const result = output2 ?? {};
1890
+ result.lat1 = latitude;
1891
+ result.lon1 = longitude;
1892
+ result.lat2 = lat2;
1893
+ result.lon2 = lon2;
1894
+ result.azi12 = azi;
1895
+ result.s12 = distance;
1896
+ if (!area)
1897
+ delete result.S12;
1898
+ if (area)
1899
+ result.S12 = this.area(latitude, lat2, dlon * DEG2, polar == null ? void 0 : polar.psi);
1900
+ return result;
1901
+ };
1902
+ return { position: evaluate };
1903
+ }
1904
+ means(lat1, lat2) {
1905
+ const d = (lat2 - lat1) * DEG2;
1906
+ const mid = (lat1 + lat2) / 2;
1907
+ const meanM = this.meridianMean(lat1, lat2);
1908
+ const cmin = Math.min(latitudeSinCos(lat1)[1], latitudeSinCos(lat2)[1]);
1909
+ const meanP = Math.abs(d) < 0.25 * cmin ? integrate((t) => {
1910
+ const [s, c] = latitudeSinCos(mid + t * (lat2 - lat1) / 2);
1911
+ return this.r ** 2 / (c * (c * c + (this.r * s) ** 2));
1912
+ }, -1, 1) / 2 : (this.psi(lat2) - this.psi(lat1)) / d;
1913
+ return [meanM, meanP];
1914
+ }
1915
+ psi(latitude) {
1916
+ return this.metrics.latitudeToAuxiliary(latitude, "isometric") * DEG2;
1917
+ }
1918
+ polarEndpoint(latitude, north, poleDistance) {
1919
+ 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) * DEG2, limit = 10 * DEG2;
1920
+ const density = (theta2) => this.r ** 2 / Math.hypot(Math.sin(theta2), this.r * Math.cos(theta2)) ** 3;
1921
+ const gap = (theta2) => integrate(density, 0, theta2);
1922
+ const target = sign === Math.sign(north) ? poleDistance : this.meridianDelta(sign > 0 ? latitude : -90, sign > 0 ? 90 : latitude) - sign * north;
1923
+ if (!(target > 0 && target < gap(limit)))
1924
+ return void 0;
1925
+ let lo = 0, hi = limit, theta = target * this.r;
1926
+ if (!(theta > lo && theta < hi))
1927
+ theta = theta1;
1928
+ for (let i = 0; i < 64; i++) {
1929
+ const residual = gap(theta) - target;
1930
+ if (residual === 0)
1931
+ break;
1932
+ if (residual < 0)
1933
+ lo = theta;
1934
+ else
1935
+ hi = theta;
1936
+ const next = theta - residual / density(theta);
1937
+ if (next === theta)
1938
+ break;
1939
+ theta = next > lo && next < hi ? next : (lo + hi) / 2;
1940
+ if (theta === lo || theta === hi)
1941
+ break;
1942
+ if (i === 63)
1943
+ throw new Error("Rhumb polar meridian inversion did not converge");
1944
+ }
1945
+ const span = theta - theta1, mid = (theta + theta1) / 2;
1946
+ const meanM = integrate((t) => density(mid + t * span / 2), -1, 1) / 2;
1947
+ const meanP = Math.abs(span) < 0.25 * Math.min(Math.sin(theta), Math.sin(theta1)) ? integrate((t) => {
1948
+ const x = mid + t * span / 2, c = Math.sin(x), s = Math.cos(x);
1949
+ return this.r ** 2 / (c * (c * c + (this.r * s) ** 2));
1950
+ }, -1, 1) / 2 : -(this.polarPsi(theta) - this.polarPsi(theta1)) / span;
1951
+ return {
1952
+ latitude: sign * (90 - theta / DEG2),
1953
+ means: [meanM, meanP],
1954
+ psi: sign * this.polarPsi(theta)
1955
+ };
1956
+ }
1957
+ polarPsi(theta) {
1958
+ const s = Math.cos(theta), c = Math.sin(theta), e2 = (1 - this.r) * (1 + this.r), e = Math.sqrt(Math.abs(e2));
1959
+ const I = e === 0 ? s : (e2 > 0 ? Math.atanh(e * s) : Math.atan(e * s)) / e;
1960
+ return Math.asinh(s / c) - e2 * I;
1961
+ }
1962
+ meridianMean(lat1, lat2) {
1963
+ const mid = (lat1 + lat2) / 2;
1964
+ return integrate((t) => {
1965
+ const [s, c] = latitudeSinCos(mid + t * (lat2 - lat1) / 2);
1966
+ return this.r ** 2 / Math.hypot(c, this.r * s) ** 3;
1967
+ }, -1, 1) / 2;
1968
+ }
1969
+ meridianDelta(lat1, lat2) {
1970
+ return (lat2 - lat1) * DEG2 * this.meridianMean(lat1, lat2);
1971
+ }
1972
+ inverseMeridian(start, displacement) {
1973
+ let lo = -90, hi = 90;
1974
+ let phi = start + displacement / this.metrics.meridionalCurvatureRadius(start) / DEG2;
1975
+ if (!(phi > lo && phi < hi))
1976
+ phi = (start + Math.sign(displacement) * 90) / 2;
1977
+ for (let i = 0; i < 64; i++) {
1978
+ const residual = this.meridianDelta(start, phi) - displacement;
1979
+ if (residual === 0)
1980
+ return phi;
1981
+ if (residual < 0)
1982
+ lo = phi;
1983
+ else
1984
+ hi = phi;
1985
+ const next = phi - residual / this.metrics.meridionalCurvatureRadius(phi) / DEG2;
1986
+ if (next === phi)
1987
+ return phi;
1988
+ phi = next > lo && next < hi ? next : (lo + hi) / 2;
1989
+ if (phi === lo || phi === hi) {
1990
+ const candidates = [lo, hi].filter((v) => Math.abs(v) < 90);
1991
+ return candidates.reduce((best, v) => Math.abs(this.meridianDelta(start, v) - displacement) < Math.abs(this.meridianDelta(start, best) - displacement) ? v : best);
1992
+ }
1993
+ }
1994
+ throw new Error("Rhumb meridian inversion did not converge");
1995
+ }
1996
+ inversePsi(psi) {
1997
+ let lo = -90, hi = 90, phi = Math.atan(Math.sinh(psi)) / DEG2;
1998
+ if (Math.abs(phi) === 90)
1999
+ phi = Math.sign(psi) * (90 - 2 ** -46);
2000
+ for (let i = 0; i < 32; i++) {
2001
+ const value2 = this.psi(phi) - psi;
2002
+ if (value2 === 0)
2003
+ return phi;
2004
+ if (value2 < 0)
2005
+ lo = phi;
2006
+ else
2007
+ hi = phi;
2008
+ const [s, c] = latitudeSinCos(phi);
2009
+ const next = phi - value2 * c * (c * c + (this.r * s) ** 2) / this.r ** 2 / DEG2;
2010
+ if (next === phi)
2011
+ return phi;
2012
+ phi = next > lo && next < hi ? next : (lo + hi) / 2;
2013
+ if (phi === lo || phi === hi)
2014
+ return phi;
2015
+ }
2016
+ throw new Error("Rhumb isometric inversion did not converge");
2017
+ }
2018
+ potential(latitude) {
2019
+ const [s, c] = latitudeSinCos(latitude), e2 = (1 - this.r) * (1 + this.r), e = Math.sqrt(Math.abs(e2));
2020
+ const I = e === 0 ? s : (e2 > 0 ? Math.atanh(e * s) : Math.atan(e * s)) / e;
2021
+ return this.r ** 2 * (s / (c * c + (this.r * s) ** 2) + I) / 2;
2022
+ }
2023
+ area(lat1, lat2, dlon, endpointPsi) {
2024
+ if (dlon === 0 || lat1 === -lat2)
2025
+ return 0;
2026
+ if (lat1 === lat2) {
2027
+ const value3 = this.a * dlon * (this.a * this.potential(lat1));
2028
+ if (!Number.isFinite(value3))
2029
+ throw new RangeError("Unrepresentable rhumb area");
2030
+ return value3;
2031
+ }
2032
+ const p1 = this.psi(lat1), p2 = endpointPsi ?? this.psi(lat2), mid = (p1 + p2) / 2, half = (p2 - p1) / 2;
2033
+ const pieces = Math.max(1, Math.ceil(Math.abs(p2 - p1) / 2));
2034
+ let sum = 0;
2035
+ for (let j = 0; j < pieces; j++)
2036
+ sum += integrate((t) => this.potential(this.inversePsi(mid + half * t)), -1 + 2 * j / pieces, -1 + 2 * (j + 1) / pieces);
2037
+ const value2 = this.a * dlon * (this.a * (sum / 2));
2038
+ if (!Number.isFinite(value2))
2039
+ throw new RangeError("Unrepresentable rhumb area");
2040
+ return value2;
2041
+ }
2042
+ };
2043
+ function validateRhumbPoint(latitude, longitude) {
2044
+ if (!(Number.isFinite(latitude) && Math.abs(latitude) <= 90 && Number.isFinite(longitude)))
2045
+ throw new RangeError("Rhumb coordinates require finite longitude and latitude in [-90,90]");
2046
+ if (Math.abs(latitude) === 90)
2047
+ throw new RhumbDomainError("pole");
2048
+ }
2049
+ function latitudeSinCos(phi) {
2050
+ const p = Math.abs(phi);
2051
+ return p <= 45 ? [Math.sin(phi * DEG2), Math.cos(phi * DEG2)] : [Math.sign(phi) * Math.cos((90 - p) * DEG2), Math.sin((90 - p) * DEG2)];
2052
+ }
2053
+ function sincosDegrees(angle3) {
2054
+ const reduced = angle3 % 360, q = Math.round(reduced / 90), d = reduced - 90 * q, x = d * DEG2;
2055
+ const s = Math.sin(x), c = Math.cos(x);
2056
+ switch ((q % 4 + 4) % 4) {
2057
+ case 0:
2058
+ return [s, c];
2059
+ case 1:
2060
+ return [c, -s];
2061
+ case 2:
2062
+ return [-s, -c];
2063
+ default:
2064
+ return [-c, s];
2065
+ }
2066
+ }
2067
+ function normalize(angle3) {
2068
+ let a = angle3 % 360;
2069
+ if (a > 180)
2070
+ a -= 360;
2071
+ if (a < -180)
2072
+ a += 360;
2073
+ return a;
2074
+ }
2075
+ function angleDifference(a, b) {
2076
+ let [d, e] = twoSum(-normalize(a), normalize(b));
2077
+ [d, e] = twoSum(normalize(d), e);
2078
+ if (Math.abs(d) === 180)
2079
+ return (e === 0 ? b < a : e > 0) ? -180 : 180;
2080
+ return d === 0 ? b < a ? -0 : 0 : d;
2081
+ }
2082
+ function twoSum(a, b) {
2083
+ const s = a + b, v = s - a;
2084
+ return [s, a - (s - v) + (b - v)];
2085
+ }
2086
+
2087
+ // dist/rhumb-path.js
2088
+ var wgs842;
2089
+ function getDefaultRhumb() {
2090
+ if (!wgs842)
2091
+ wgs842 = new EllipsoidRhumb({ semiMajorAxis: WGS84_RADIUS_X, semiMinorAxis: WGS84_RADIUS_Z });
2092
+ return wgs842;
2093
+ }
2094
+ var RhumbPath = class {
2095
+ constructor(start, end, options = {}) {
2096
+ validateGeographicPosition(start);
2097
+ validateGeographicPosition(end);
2098
+ if (start.length !== end.length)
2099
+ throw new RangeError("Rhumb endpoint dimensions must match");
2100
+ const solver = options.rhumb || getDefaultRhumb();
2101
+ if (options.longitudeMode !== void 0 && !["shortest", "unrolled"].includes(options.longitudeMode) || options.longitudeMode === "unrolled" && options.longitudeTurns !== void 0)
2102
+ throw new RangeError("Choose explicit turns or unrolled endpoint longitudes");
2103
+ let inverse = solver.inverse(start[1], start[0], end[1], end[0], {
2104
+ longitudeTurns: options.longitudeTurns,
2105
+ unrollLongitude: true
2106
+ });
2107
+ if (options.longitudeMode === "unrolled") {
2108
+ const turns2 = Math.round((end[0] - inverse.lon2) / 360);
2109
+ if (turns2 !== 0)
2110
+ inverse = solver.inverse(start[1], start[0], end[1], end[0], {
2111
+ longitudeTurns: turns2,
2112
+ unrollLongitude: true
2113
+ });
2114
+ }
2115
+ if (![inverse.s12, inverse.azi12, inverse.lon2].every(Number.isFinite) || inverse.s12 < 0)
2116
+ throw new RangeError("Unresolved rhumb path");
2117
+ this.size = start.length;
2118
+ this.length = inverse.s12;
2119
+ this.first = Object.freeze(Array.from(start));
2120
+ const last = Array.from(end);
2121
+ const turns = Math.round((inverse.lon2 - end[0]) / 360);
2122
+ const endpoint = end[0] + 360 * turns;
2123
+ const retainsPhase = Number.isSafeInteger(turns) && Number.isFinite(endpoint) && Math.abs(endpoint - inverse.lon2) <= 4 * Number.EPSILON * Math.max(360, Math.abs(inverse.lon2));
2124
+ last[0] = inverse.s12 === 0 ? start[0] : retainsPhase ? endpoint : inverse.lon2;
2125
+ if (inverse.s12 === 0)
2126
+ last[1] = start[1];
2127
+ this.last = Object.freeze(last);
2128
+ this.line = solver.line(start[1], start[0], inverse.azi12, { unrollLongitude: true });
2129
+ }
2130
+ get start() {
2131
+ return this.first.slice();
2132
+ }
2133
+ get end() {
2134
+ return this.last.slice();
2135
+ }
2136
+ sample(fraction, result = new Array(this.size)) {
2137
+ if (!Number.isFinite(fraction) || fraction < 0 || fraction > 1)
2138
+ throw new RangeError("Rhumb fraction must be in [0, 1]");
2139
+ if (result.length !== this.size || ArrayBuffer.isView(result) && !(result instanceof Float32Array) && !(result instanceof Float64Array))
2140
+ throw new RangeError("Expected a floating rhumb output with matching dimensions");
2141
+ let longitude = this.first[0], latitude = this.first[1];
2142
+ if (fraction === 1) {
2143
+ longitude = this.last[0];
2144
+ latitude = this.last[1];
2145
+ } else if (fraction !== 0 && this.length !== 0) {
2146
+ const p = this.line.position(this.length * fraction);
2147
+ longitude = p.lon2;
2148
+ latitude = p.lat2;
2149
+ }
2150
+ const height = this.size === 3 ? this.first[2] * (1 - fraction) + this.last[2] * fraction : 0;
2151
+ const values = [longitude, latitude, height];
2152
+ if (!values.every(Number.isFinite) || result instanceof Float32Array && !values.every((x) => Number.isFinite(Math.fround(x))))
2153
+ throw new RangeError("Unrepresentable rhumb sample");
2154
+ result[0] = longitude;
2155
+ result[1] = latitude;
2156
+ if (this.size === 3)
2157
+ result[2] = height;
2158
+ return result;
2159
+ }
2160
+ sampleByDistance(distance, result = new Array(this.size)) {
2161
+ if (!Number.isFinite(distance) || distance < 0 || distance > this.length)
2162
+ throw new RangeError("Distance must be within the rhumb path");
2163
+ return this.sample(this.length === 0 ? 0 : distance / this.length, result);
2164
+ }
2165
+ };
2166
+
2167
+ // dist/geographic-seams/edge.js
2168
+ var import_types = require("./geographic-seams/types.shared.cjs");
2169
+ var ANGULAR_TOLERANCE = 1e-10;
2170
+ var MAX_LONGITUDE = 65536;
2171
+ var wgs843;
2172
+ function getDefaultGeodesic2() {
2173
+ if (!wgs843)
2174
+ wgs843 = new EllipsoidGeodesic({ semiMajorAxis: WGS84_RADIUS_X, semiMinorAxis: WGS84_RADIUS_Z });
2175
+ return wgs843;
2176
+ }
2177
+ var Context = class {
2178
+ constructor(options) {
2179
+ this.options = options;
2180
+ this.work = 0;
2181
+ this.vertices = 0;
2182
+ this.longitudeAliases = /* @__PURE__ */ new Map();
2183
+ this.options = { ...options };
2184
+ this.size = this.options.size ?? 2;
2185
+ this.right = this.options.seamLongitude ?? 180;
2186
+ this.left = this.right - 360;
2187
+ this.iterations = this.options.maxIterations ?? 64;
2188
+ this.maxVertices = this.options.maxVertices ?? 65536;
2189
+ this.maxWork = this.options.maxWork ?? 1e6;
2190
+ if (!["linear", "geodesic", "rhumb"].includes(this.options.edgeModel) || this.options.linearLongitude !== void 0 && !["supplied", "shortest"].includes(this.options.linearLongitude) || !Number.isSafeInteger(this.size) || this.size < 2 || this.size > 64 || !Number.isFinite(this.right) || Math.abs(this.right) > MAX_LONGITUDE || !Number.isSafeInteger(this.maxVertices) || this.maxVertices < 1 || this.maxVertices > 4294967295 || !Number.isSafeInteger(this.maxWork) || this.maxWork < 1 || this.maxWork > 1e8 || !Number.isInteger(this.iterations) || this.iterations < 1 || this.iterations > 128)
2191
+ throw new import_types.GeographicSeamError("input", "Invalid seam model, dimensions or limits");
2192
+ }
2193
+ tick(n = 1) {
2194
+ this.work += n;
2195
+ if (this.work > this.maxWork)
2196
+ throw new import_types.GeographicSeamError("limit", "Exceeded maxWork");
2197
+ }
2198
+ canonicalLongitude(longitude) {
2199
+ while (this.longitudeAliases.has(longitude)) {
2200
+ this.tick();
2201
+ longitude = this.longitudeAliases.get(longitude);
2202
+ }
2203
+ return longitude;
2204
+ }
2205
+ aliasLongitude(from, to) {
2206
+ const a = this.canonicalLongitude(from), b = this.canonicalLongitude(to);
2207
+ if (a !== b)
2208
+ this.longitudeAliases.set(a, b);
2209
+ }
2210
+ projectLongitude(longitude, shift2) {
2211
+ const world = Math.round((longitude - this.right) / 360);
2212
+ const translated = longitude === this.right + 360 * world ? this.right + 360 * (world + shift2 / 360) : longitude + shift2;
2213
+ return this.canonicalLongitude(translated);
2214
+ }
2215
+ addVertices(n) {
2216
+ this.vertices += n;
2217
+ if (this.vertices > this.maxVertices)
2218
+ throw new import_types.GeographicSeamError("limit", "Exceeded maxVertices");
2219
+ }
2220
+ read(input) {
2221
+ if (!Number.isSafeInteger(input.length) || input.length < 0 || input.length % this.size)
2222
+ throw new import_types.GeographicSeamError("input", "Invalid packed geographic positions or vertex limit");
2223
+ this.addVertices(input.length / this.size);
2224
+ const result = [];
2225
+ for (let i = 0; i < input.length; i += this.size) {
2226
+ this.tick();
2227
+ const p = Array.from({ length: this.size }, (_, k) => input[i + k]);
2228
+ if (!p.every(Number.isFinite) || Math.abs(p[0]) > MAX_LONGITUDE || Math.abs(p[1]) > 90)
2229
+ throw new import_types.GeographicSeamError("input", "Expected finite positions, latitude in [-90,90], |longitude| <= 65536");
2230
+ result.push(p);
2231
+ }
2232
+ return result;
2233
+ }
2234
+ };
2235
+ function same(a, b) {
2236
+ return a.length === b.length && a.every((x, i) => x === b[i]);
2237
+ }
2238
+ function shortDifference(delta) {
2239
+ const value2 = delta % 360;
2240
+ return value2 > 180 ? value2 - 360 : value2 < -180 ? value2 + 360 : value2;
2241
+ }
2242
+ function shortLongitudeTurns(a, b) {
2243
+ const delta = b - a, virtual = delta - b;
2244
+ const low = b - (delta - virtual) + (-a - virtual);
2245
+ const remainder = delta % 360;
2246
+ let turns = -Math.trunc(delta / 360);
2247
+ if (remainder > 180 || remainder === 180 && low > 0)
2248
+ turns--;
2249
+ if (remainder < -180 || remainder === -180 && low < 0)
2250
+ turns++;
2251
+ return turns;
2252
+ }
2253
+ function oppositeMeridians(a, b) {
2254
+ const x = shortDifference(b), y = -shortDifference(a), sum = x + y, virtual = sum - x;
2255
+ return Math.abs(sum) === 180 && x - (sum - virtual) + (y - virtual) === 0;
2256
+ }
2257
+ function worldAt(x, context) {
2258
+ let world = Math.floor((x - context.right) / 360) + 1;
2259
+ while (x < context.right + 360 * (world - 1))
2260
+ world--;
2261
+ while (x >= context.right + 360 * world)
2262
+ world++;
2263
+ return world;
2264
+ }
2265
+ function chartPoint(point, world, context) {
2266
+ const p = point.slice();
2267
+ p[0] -= 360 * world;
2268
+ const onLeft = point[0] === context.right + 360 * (world - 1);
2269
+ const onRight = point[0] === context.right + 360 * world;
2270
+ if (onLeft)
2271
+ p[0] = context.left;
2272
+ if (onRight)
2273
+ p[0] = context.right;
2274
+ if (!onLeft && p[0] === context.left || !onRight && p[0] === context.right)
2275
+ throw new import_types.GeographicSeamError("precision", "Longitude displacement cannot be represented in this chart");
2276
+ return p;
2277
+ }
2278
+ function straight(a, b) {
2279
+ return { a, b, source: null, sample: (t) => a.map((x, i) => x * (1 - t) + b[i] * t) };
2280
+ }
2281
+ function slice(edge, lo, hi) {
2282
+ const a = lo === 0 ? edge.a : lo === 1 ? edge.b : edge.sample(lo);
2283
+ const b = hi === 0 ? edge.a : hi === 1 ? edge.b : edge.sample(hi);
2284
+ const source = edge.source && {
2285
+ ...edge.source,
2286
+ startFraction: edge.source.startFraction + (edge.source.endFraction - edge.source.startFraction) * lo,
2287
+ endFraction: edge.source.startFraction + (edge.source.endFraction - edge.source.startFraction) * hi
2288
+ };
2289
+ return {
2290
+ a,
2291
+ b,
2292
+ source,
2293
+ sample: (t) => t === 0 ? a.slice() : t === 1 ? b.slice() : edge.sample(lo + (hi - lo) * t)
2294
+ };
2295
+ }
2296
+ function shift(edge, delta) {
2297
+ const move = (p) => [p[0] + delta, ...p.slice(1)];
2298
+ return {
2299
+ a: move(edge.a),
2300
+ b: move(edge.b),
2301
+ source: edge.source && { ...edge.source, longitudeShift: edge.source.longitudeShift + delta },
2302
+ sample: (t) => move(edge.sample(t))
2303
+ };
2304
+ }
2305
+ function createEdges(start, end, originalStart, edgeIndex, ringIndex, turns, context, splitLatitude = true) {
2306
+ context.tick();
2307
+ const { edgeModel, linearLongitude = "supplied" } = context.options;
2308
+ if (!Number.isSafeInteger(turns) || Math.abs(turns) > 128 || turns !== 0 && edgeModel !== "rhumb")
2309
+ throw new import_types.GeographicSeamError("input", "Turns require rhumb edges and |turns| <= 128");
2310
+ let offset = 360 * Math.round((start[0] - originalStart[0]) / 360);
2311
+ const source = {
2312
+ ringIndex,
2313
+ edgeIndex,
2314
+ startFraction: 0,
2315
+ endFraction: 1,
2316
+ longitudeShift: offset
2317
+ };
2318
+ const first = start.slice(), last = end.slice();
2319
+ let horizontal;
2320
+ let critical;
2321
+ let pole;
2322
+ if (edgeModel === "linear") {
2323
+ last[0] = end[0] + (offset + (linearLongitude === "shortest" ? 360 * shortLongitudeTurns(originalStart[0], end[0]) : 0));
2324
+ horizontal = (t) => [first[0] * (1 - t) + last[0] * t, first[1] * (1 - t) + last[1] * t];
2325
+ } else if (edgeModel === "rhumb") {
2326
+ context.tick(2);
2327
+ const path = new RhumbPath(originalStart.slice(0, 2), last.slice(0, 2), {
2328
+ rhumb: context.options.rhumb,
2329
+ longitudeTurns: turns
2330
+ });
2331
+ last[0] = end[0] + (360 * Math.round((path.end[0] - end[0]) / 360) + offset);
2332
+ horizontal = (t) => {
2333
+ const p = path.sample(t);
2334
+ p[0] += offset;
2335
+ return p;
2336
+ };
2337
+ } else {
2338
+ context.tick(3);
2339
+ const solver = context.options.geodesic || getDefaultGeodesic2();
2340
+ const path = new GeodesicPath(originalStart.slice(0, 2), last.slice(0, 2), { geodesic: solver });
2341
+ if (Math.abs(first[1]) === 90) {
2342
+ context.tick(2);
2343
+ const incomingChart = new GeodesicPath(first.slice(0, 2), last.slice(0, 2), {
2344
+ geodesic: solver
2345
+ });
2346
+ offset = 360 * Math.round((incomingChart.end[0] - path.end[0]) / 360);
2347
+ source.longitudeShift = offset;
2348
+ }
2349
+ last[0] = end[0] + (360 * Math.round((path.end[0] - end[0]) / 360) + offset);
2350
+ horizontal = (t) => {
2351
+ const p = path.sample(t);
2352
+ p[0] += offset;
2353
+ return p;
2354
+ };
2355
+ if (Math.abs(first[1]) === 90)
2356
+ first[0] = last[0];
2357
+ if (Math.abs(last[1]) === 90)
2358
+ last[0] = first[0];
2359
+ const inverse = solver.inverse(originalStart[1], originalStart[0], end[1], end[0]);
2360
+ if (first[0] === last[0] && (inverse.azi1 === 0 || Math.abs(inverse.azi1) === 180)) {
2361
+ const meridianSample = horizontal;
2362
+ horizontal = (t) => {
2363
+ const p = meridianSample(t);
2364
+ p[0] = first[0];
2365
+ return p;
2366
+ };
2367
+ }
2368
+ const c1 = Math.cos(inverse.azi1 * Math.PI / 180), c2 = Math.cos(inverse.azi2 * Math.PI / 180);
2369
+ if (path.length > 0 && oppositeMeridians(originalStart[0], end[0]) && (inverse.azi1 === 0 || Math.abs(inverse.azi1) === 180) && Math.abs(first[1]) !== 90 && Math.abs(last[1]) !== 90) {
2370
+ const latitude = c1 > 0 ? 90 : -90;
2371
+ context.tick(2);
2372
+ const fraction = solver.inverse(start[1], start[0], latitude, start[0]).s12 / path.length;
2373
+ if (fraction > 0 && fraction < 1 && Math.abs(path.sample(fraction)[1] - latitude) < ANGULAR_TOLERANCE)
2374
+ pole = { fraction, latitude };
2375
+ } else if (splitLatitude && c1 * c2 < 0 && path.length > 0) {
2376
+ context.tick();
2377
+ const line = solver.line(originalStart[1], originalStart[0], inverse.azi1, {
2378
+ unrollLongitude: true
2379
+ });
2380
+ let lo = 0, hi = 1;
2381
+ for (let i = 0; i < 64; i++) {
2382
+ context.tick();
2383
+ const mid = (lo + hi) / 2;
2384
+ const c = Math.cos(line.position(path.length * mid).azi2 * Math.PI / 180);
2385
+ if (c > 0 === c1 > 0)
2386
+ lo = mid;
2387
+ else
2388
+ hi = mid;
2389
+ }
2390
+ critical = (lo + hi) / 2;
2391
+ }
2392
+ }
2393
+ if (Math.abs(last[0]) > MAX_LONGITUDE)
2394
+ throw new import_types.GeographicSeamError("input", "Unrolled longitude exceeds the declared seam profile");
2395
+ const sample = (t) => {
2396
+ context.tick();
2397
+ const p = t === 0 ? first.slice(0, 2) : t === 1 ? last.slice(0, 2) : horizontal(t);
2398
+ for (let i = 2; i < first.length; i++)
2399
+ p[i] = first[i] * (1 - t) + last[i] * t;
2400
+ if (!p.every(Number.isFinite))
2401
+ throw new import_types.GeographicSeamError("precision", "Nonfinite edge sample");
2402
+ return p;
2403
+ };
2404
+ const edge = { a: first, b: last, source, sample };
2405
+ if (pole) {
2406
+ const incoming = slice(edge, 0, pole.fraction), outgoing = slice(edge, pole.fraction, 1);
2407
+ incoming.b = [first[0], pole.latitude, ...sample(pole.fraction).slice(2)];
2408
+ outgoing.a = [last[0], pole.latitude, ...incoming.b.slice(2)];
2409
+ const incomingSample = incoming.sample, outgoingSample = outgoing.sample;
2410
+ incoming.sample = (t) => t === 1 ? incoming.b.slice() : incomingSample(t);
2411
+ outgoing.sample = (t) => t === 0 ? outgoing.a.slice() : outgoingSample(t);
2412
+ return [incoming, straight(incoming.b, outgoing.a), outgoing];
2413
+ }
2414
+ return critical !== void 0 && critical > 0 && critical < 1 ? [slice(edge, 0, critical), slice(edge, critical, 1)] : [edge];
2415
+ }
2416
+ function root(edge, axis, value2, context) {
2417
+ if (edge.a[axis] === value2)
2418
+ return 0;
2419
+ if (edge.b[axis] === value2)
2420
+ return 1;
2421
+ if (!(value2 > Math.min(edge.a[axis], edge.b[axis]) && value2 < Math.max(edge.a[axis], edge.b[axis])))
2422
+ throw new import_types.GeographicSeamError("precision", "Unbracketed seam root");
2423
+ let lo = 0, hi = 1, a = edge.a, b = edge.b;
2424
+ for (let i = 0; i < context.iterations; i++) {
2425
+ context.tick();
2426
+ const t = (lo + hi) / 2, p = edge.sample(t);
2427
+ if (p[axis] === value2)
2428
+ return t;
2429
+ if (hi - lo <= 4 * Number.EPSILON && Math.abs(a[0] - b[0]) * Math.max(Math.abs(Math.cos(a[1] * Math.PI / 180)), Math.abs(Math.cos(b[1] * Math.PI / 180))) <= ANGULAR_TOLERANCE && Math.abs(a[1] - b[1]) <= ANGULAR_TOLERANCE)
2430
+ return t;
2431
+ if (t === lo || t === hi)
2432
+ break;
2433
+ if (p[axis] < value2 === edge.a[axis] < edge.b[axis]) {
2434
+ lo = t;
2435
+ a = p;
2436
+ } else {
2437
+ hi = t;
2438
+ b = p;
2439
+ }
2440
+ }
2441
+ throw new import_types.GeographicSeamError("precision", "Seam root exhausted its precision/iteration budget");
2442
+ }
2443
+ function cut(edge, context) {
2444
+ const low = Math.min(edge.a[0], edge.b[0]), high = Math.max(edge.a[0], edge.b[0]);
2445
+ const fractions = [0, 1];
2446
+ for (let k = worldAt(low, context); context.right + 360 * k < high; k++) {
2447
+ context.tick();
2448
+ fractions.push(root(edge, 0, context.right + 360 * k, context));
2449
+ if (fractions.length > context.maxVertices)
2450
+ throw new import_types.GeographicSeamError("limit", "Too many seam crossings");
2451
+ }
2452
+ fractions.sort((a, b) => a - b);
2453
+ const result = [];
2454
+ for (let i = 1; i < fractions.length; i++) {
2455
+ context.tick();
2456
+ context.addVertices(2);
2457
+ const piece = slice(edge, fractions[i - 1], fractions[i]);
2458
+ for (const p of [piece.a, piece.b]) {
2459
+ const k = Math.round((p[0] - context.right) / 360), boundary = context.right + 360 * k;
2460
+ if (fractions[i - 1] !== 0 && p === piece.a || fractions[i] !== 1 && p === piece.b)
2461
+ p[0] = boundary;
2462
+ }
2463
+ const onBoundary = (x) => x === context.right + 360 * Math.round((x - context.right) / 360);
2464
+ const reference = !onBoundary(piece.a[0]) ? piece.a[0] : !onBoundary(piece.b[0]) ? piece.b[0] : (piece.a[0] + piece.b[0]) / 2;
2465
+ const world = worldAt(reference, context);
2466
+ const shifted = shift(piece, -360 * world);
2467
+ shifted.a = chartPoint(piece.a, world, context);
2468
+ shifted.b = chartPoint(piece.b, world, context);
2469
+ const previousSample = shifted.sample;
2470
+ shifted.sample = (t) => t === 0 ? shifted.a.slice() : t === 1 ? shifted.b.slice() : previousSample(t);
2471
+ result.push({ edge: shifted, world });
2472
+ }
2473
+ return result;
2474
+ }
2475
+
2476
+ // dist/geographic-seams/latitude.js
2477
+ var import_types2 = require("./geographic-seams/types.shared.cjs");
2478
+ function readLatitudeRange(value2) {
2479
+ if (!Array.isArray(value2) || value2.length !== 2 || !value2.every(Number.isFinite) || value2[0] < -90 || value2[1] > 90 || value2[0] >= value2[1])
2480
+ throw new import_types2.GeographicSeamError("input", "Expected -90 <= south < north <= 90");
2481
+ return [value2[0], value2[1]];
2482
+ }
2483
+ function clipLatitudeEdge(edge, range, context) {
2484
+ const fractions = [0, 1], events = /* @__PURE__ */ new Map();
2485
+ for (const latitude of range)
2486
+ if (latitude > Math.min(edge.a[1], edge.b[1]) && latitude < Math.max(edge.a[1], edge.b[1])) {
2487
+ const t = root(edge, 1, latitude, context);
2488
+ if (events.has(t) && events.get(t) !== latitude)
2489
+ throw new import_types2.GeographicSeamError("precision", "Unresolvable latitude events");
2490
+ fractions.push(t);
2491
+ events.set(t, latitude);
2492
+ }
2493
+ fractions.sort((a, b) => a - b);
2494
+ const result = [];
2495
+ for (let i = 1; i < fractions.length; i++) {
2496
+ context.tick();
2497
+ const part = slice(edge, fractions[i - 1], fractions[i]);
2498
+ const middle = (part.a[1] + part.b[1]) / 2;
2499
+ if (middle < range[0] || middle > range[1])
2500
+ continue;
2501
+ if (events.has(fractions[i - 1]))
2502
+ part.a[1] = events.get(fractions[i - 1]);
2503
+ if (events.has(fractions[i]))
2504
+ part.b[1] = events.get(fractions[i]);
2505
+ const sample = part.sample;
2506
+ part.sample = (t) => t === 0 ? part.a.slice() : t === 1 ? part.b.slice() : sample(t);
2507
+ context.addVertices(2);
2508
+ result.push(part);
2509
+ }
2510
+ return result;
2511
+ }
2512
+
2513
+ // dist/geographic-seams/cut-options.js
2514
+ var import_types3 = require("./geographic-seams/types.shared.cjs");
2515
+ function cutOptions(options) {
2516
+ const range = readLatitudeRange(options.latitudeRange), axes = {
2517
+ ...options.ellipsoid ?? { semiMajorAxis: WGS84_RADIUS_X, semiMinorAxis: WGS84_RADIUS_Z }
2518
+ };
2519
+ const a = axes.semiMajorAxis, b = axes.semiMinorAxis, r = b / a;
2520
+ if (!Number.isFinite(a) || !Number.isFinite(b) || a < 1e-60 || a > 1e60 || b < 1e-60 || b > 1e60 || options.edgeModel === "geodesic" && (r < 0.99 || r > 1.01) || options.edgeModel === "rhumb" && (r < 0.5 || r > 2))
2521
+ throw new import_types3.GeographicSeamError("input", "Ellipsoid outside the qualified cut profile");
2522
+ return {
2523
+ range,
2524
+ axes,
2525
+ options: {
2526
+ ...options,
2527
+ geodesic: void 0,
2528
+ rhumb: void 0,
2529
+ ...options.edgeModel === "geodesic" ? { geodesic: new EllipsoidGeodesic(axes) } : options.edgeModel === "rhumb" ? { rhumb: new EllipsoidRhumb(axes) } : {}
2530
+ }
2531
+ };
2532
+ }
2533
+
2534
+ // dist/geographic-seams/polygon.js
2535
+ var import_types4 = require("./geographic-seams/types.shared.cjs");
2536
+ function winding(edges, point, context, side, generatedBoundary = true, longitudeShift = 0, verticalSide) {
2537
+ let value2 = 0, boundary = false;
2538
+ for (const edge of edges) {
2539
+ context.tick();
2540
+ const a = edge.a, b = edge.b;
2541
+ if (a[1] === b[1]) {
2542
+ if ((generatedBoundary || edge.source) && point[1] === a[1] && point[0] >= Math.min(context.projectLongitude(a[0], longitudeShift), context.projectLongitude(b[0], longitudeShift)) && point[0] <= Math.max(context.projectLongitude(a[0], longitudeShift), context.projectLongitude(b[0], longitudeShift)))
2543
+ boundary = true;
2544
+ continue;
2545
+ }
2546
+ if (point[1] >= Math.min(a[1], b[1]) && point[1] <= Math.max(a[1], b[1])) {
2547
+ const t = root(edge, 1, point[1], context), x = context.projectLongitude(edge.sample(t)[0], longitudeShift);
2548
+ if ((generatedBoundary || edge.source) && Math.abs(x - point[0]) <= ANGULAR_TOLERANCE)
2549
+ boundary = true;
2550
+ if ((verticalSide === "south" ? a[1] >= point[1] : a[1] > point[1]) !== (verticalSide === "south" ? b[1] >= point[1] : b[1] > point[1]) && (side === "left" ? x >= point[0] : x > point[0]))
2551
+ value2 += b[1] > a[1] ? 1 : -1;
2552
+ }
2553
+ }
2554
+ return { value: value2, boundary };
2555
+ }
2556
+ function contains(ring, p, context, side, verticalSide) {
2557
+ context.tick();
2558
+ for (let k = Math.ceil((ring.min - p[0]) / 360) - 1; k <= Math.floor((ring.max - p[0]) / 360) + 1; k++) {
2559
+ context.tick();
2560
+ if (winding(ring.membership, p, context, side, false, -360 * k, verticalSide).value !== 0)
2561
+ return true;
2562
+ }
2563
+ return false;
2564
+ }
2565
+ function filled(rings, p, context, side, verticalSide) {
2566
+ return contains(rings[0], p, context, side, verticalSide) && !rings.slice(1).some((r) => contains(r, p, context, side, verticalSide));
2567
+ }
2568
+ function prepare(input, index, context) {
2569
+ const positions = context.read(input.positions);
2570
+ if (positions.length > 1 && positions[0][0] === positions[positions.length - 1][0] && positions[0][1] === positions[positions.length - 1][1]) {
2571
+ if (!same(positions[0], positions[positions.length - 1]))
2572
+ throw new import_types4.GeographicSeamError("input", "Closing polygon attributes must match");
2573
+ positions.pop();
2574
+ }
2575
+ if (new Set(positions.map((p) => `${p[0]},${p[1]}`)).size < 3)
2576
+ throw new import_types4.GeographicSeamError("topology", "Polygon ring needs three distinct positions");
2577
+ const turns = input.longitudeTurns ? Array.from(input.longitudeTurns) : new Array(positions.length).fill(0);
2578
+ if (turns.length !== positions.length)
2579
+ throw new import_types4.GeographicSeamError("input", "Expected a turn count per ring edge");
2580
+ const edges = [];
2581
+ let cursor = positions[0];
2582
+ for (let i = 0; i < positions.length; i++) {
2583
+ const end = positions[(i + 1) % positions.length];
2584
+ const pieces = createEdges(cursor, end, positions[i], i, index, turns[i], context);
2585
+ if (edges.length && !same(cursor, pieces[0].a)) {
2586
+ if (Math.abs(cursor[1]) !== 90 || cursor[1] !== pieces[0].a[1])
2587
+ throw new import_types4.GeographicSeamError("precision", "Discontinuous ring edge");
2588
+ edges.push(straight(cursor, pieces[0].a));
2589
+ }
2590
+ for (const edge of pieces) {
2591
+ if (edge.a[0] === edge.b[0] && edge.a[1] === edge.b[1]) {
2592
+ if (!same(edge.a, edge.b))
2593
+ throw new import_types4.GeographicSeamError("topology", "Zero-length polygon edge changes attributes");
2594
+ } else
2595
+ edges.push(edge);
2596
+ }
2597
+ cursor = pieces[pieces.length - 1].b;
2598
+ }
2599
+ if (!edges.length)
2600
+ throw new import_types4.GeographicSeamError("topology", "Empty polygon boundary");
2601
+ const first = edges[0].a;
2602
+ if (Math.abs(first[1]) === 90) {
2603
+ const closing = first.slice();
2604
+ closing[0] += 360 * Math.round((cursor[0] - first[0]) / 360);
2605
+ if (!same(cursor, closing))
2606
+ edges.push(straight(cursor, closing));
2607
+ cursor = closing;
2608
+ }
2609
+ const turnsAround = Math.round((cursor[0] - first[0]) / 360);
2610
+ if (Math.abs(cursor[0] - first[0] - 360 * turnsAround) > ANGULAR_TOLERANCE || cursor[1] !== first[1] || Math.abs(turnsAround) > 1)
2611
+ throw new import_types4.GeographicSeamError("topology", "Unsupported ring winding");
2612
+ let min = Infinity, max = -Infinity;
2613
+ for (const e of edges) {
2614
+ min = Math.min(min, e.a[0], e.b[0]);
2615
+ max = Math.max(max, e.a[0], e.b[0]);
2616
+ }
2617
+ if (max - min > 360 + ANGULAR_TOLERANCE)
2618
+ throw new import_types4.GeographicSeamError("topology", "Ring exceeds a single longitude chart");
2619
+ const membership = edges.slice();
2620
+ const poleAttributes = input.poleAttributes ? Array.from(input.poleAttributes) : [];
2621
+ if (turnsAround !== 0) {
2622
+ if (!["north", "south"].includes(input.pole) || edges.some((e) => Math.abs(e.a[1]) === 90 || (e.b[0] - e.a[0]) * turnsAround < 0))
2623
+ throw new import_types4.GeographicSeamError("topology", "Polar rings require an explicit pole and monotone longitude winding");
2624
+ if (poleAttributes.length !== context.size - 2 || !poleAttributes.every(Number.isFinite))
2625
+ throw new import_types4.GeographicSeamError("input", "Explicit poleAttributes are required for polar attributes");
2626
+ const latitude = input.pole === "north" ? 90 : -90;
2627
+ const a = [cursor[0], latitude, ...poleAttributes], b = [first[0], latitude, ...poleAttributes];
2628
+ membership.push(straight(cursor, a), straight(a, b), straight(b, first));
2629
+ } else if (input.pole !== void 0 || poleAttributes.length) {
2630
+ throw new import_types4.GeographicSeamError("input", "Pole selection applies only to once-winding polar rings");
2631
+ }
2632
+ return { edges, membership, min, max, pole: input.pole, poleAttributes };
2633
+ }
2634
+ function reverse(edge) {
2635
+ return {
2636
+ a: edge.b,
2637
+ b: edge.a,
2638
+ sample: (t) => edge.sample(1 - t),
2639
+ source: edge.source && {
2640
+ ...edge.source,
2641
+ startFraction: edge.source.endFraction,
2642
+ endFraction: edge.source.startFraction
2643
+ }
2644
+ };
2645
+ }
2646
+ function canonicalAlias(edge, context) {
2647
+ const move = (p) => {
2648
+ const longitude = context.canonicalLongitude(p[0]);
2649
+ return longitude === p[0] ? p : [longitude, ...p.slice(1)];
2650
+ };
2651
+ return { ...edge, a: move(edge.a), b: move(edge.b), sample: (t) => move(edge.sample(t)) };
2652
+ }
2653
+ function interior(edges, context) {
2654
+ const ys = Array.from(new Set(edges.flatMap((e) => [e.a[1], e.b[1]]))).sort((a, b) => a - b);
2655
+ let index = 1;
2656
+ for (let i = 2; i < ys.length; i++)
2657
+ if (ys[i] - ys[i - 1] > ys[index] - ys[index - 1])
2658
+ index = i;
2659
+ if (ys.length < 2 || ys[index] - ys[index - 1] < 8 * ANGULAR_TOLERANCE)
2660
+ throw new import_types4.GeographicSeamError("precision", "Polygon height below the topology budget");
2661
+ const y = (ys[index] + ys[index - 1]) / 2, xs = [];
2662
+ for (const edge of edges) {
2663
+ context.tick();
2664
+ if (edge.a[1] > y !== edge.b[1] > y)
2665
+ xs.push(edge.sample(root(edge, 1, y, context))[0]);
2666
+ }
2667
+ xs.sort((a, b) => a - b);
2668
+ for (let i = 1; i < xs.length; i++) {
2669
+ context.tick();
2670
+ if (xs[i] - xs[i - 1] < 8 * ANGULAR_TOLERANCE)
2671
+ continue;
2672
+ const point = [(xs[i] + xs[i - 1]) / 2, y], w = winding(edges, point, context);
2673
+ if (w.value && !w.boundary) {
2674
+ if (Math.abs(w.value) !== 1)
2675
+ throw new import_types4.GeographicSeamError("topology", "Non-simple polygon winding");
2676
+ return { point, sign: Math.sign(w.value) };
2677
+ }
2678
+ }
2679
+ throw new import_types4.GeographicSeamError("topology", "No resolvable polygon interior");
2680
+ }
2681
+ function output(edges, sign, context) {
2682
+ if (interior(edges, context).sign !== sign)
2683
+ edges = edges.slice().reverse().map(reverse);
2684
+ context.addVertices(edges.length + 1);
2685
+ return {
2686
+ positions: new Float64Array([...edges.flatMap((e) => e.a), ...edges[0].a]),
2687
+ edges: edges.map((e) => e.source && { ...e.source })
2688
+ };
2689
+ }
2690
+ function clipLatitudePolygon(inputs, options, latitudeRange) {
2691
+ return processPolygon(inputs, options, latitudeRange);
2692
+ }
2693
+ function processPolygon(inputs, options, latitudeRange) {
2694
+ const context = new Context(options);
2695
+ if (!inputs.length)
2696
+ return [];
2697
+ context.tick(inputs.length);
2698
+ const rings = inputs.map((ring, i) => prepare(ring, i, context));
2699
+ const graph = [], nodes = /* @__PURE__ */ new Map();
2700
+ const key2 = (p) => `${p[0]},${p[1]}`;
2701
+ const add2 = (edge) => {
2702
+ context.tick();
2703
+ if (edge.a[0] === edge.b[0] && edge.a[1] === edge.b[1])
2704
+ return;
2705
+ const id = graph.length;
2706
+ graph.push(edge);
2707
+ for (const p of [edge.a, edge.b]) {
2708
+ const k = key2(p), node = nodes.get(k);
2709
+ if (node) {
2710
+ if (!same(node.p, p))
2711
+ throw new import_types4.GeographicSeamError("topology", "Touching boundaries have inconsistent attributes");
2712
+ node.edges.push(id);
2713
+ } else
2714
+ nodes.set(k, { p, edges: [id] });
2715
+ }
2716
+ };
2717
+ const pieces = [];
2718
+ const meridians = /* @__PURE__ */ new Map();
2719
+ for (const ring of rings) {
2720
+ if (ring.max - ring.min === 360) {
2721
+ const low = chartPoint([ring.min, 0], worldAt(ring.min, context), context)[0];
2722
+ const high = chartPoint([ring.max, 0], worldAt(ring.max, context), context)[0];
2723
+ const roundoff = 4 * Number.EPSILON * Math.max(360, Math.abs(ring.min), Math.abs(ring.max), Math.abs(context.left), Math.abs(context.right));
2724
+ if (Math.abs(high - low) > Math.min(roundoff, ANGULAR_TOLERANCE))
2725
+ throw new import_types4.GeographicSeamError("precision", "Unresolvable full-width longitude alias");
2726
+ if (high === context.left)
2727
+ context.aliasLongitude(low, high);
2728
+ else
2729
+ context.aliasLongitude(high, low);
2730
+ }
2731
+ }
2732
+ for (const ring of rings) {
2733
+ for (const original of ring.edges)
2734
+ for (const { edge: part } of cut(original, context)) {
2735
+ const edge = canonicalAlias(part, context);
2736
+ pieces.push(edge);
2737
+ if (edge.a[0] === edge.b[0]) {
2738
+ const events = meridians.get(edge.a[0]) || /* @__PURE__ */ new Set();
2739
+ events.add(edge.a[1]);
2740
+ events.add(edge.b[1]);
2741
+ meridians.set(edge.a[0], events);
2742
+ }
2743
+ }
2744
+ }
2745
+ for (const edge of pieces) {
2746
+ if (edge.a[0] !== edge.b[0]) {
2747
+ add2(edge);
2748
+ continue;
2749
+ }
2750
+ const fractions = [0, 1];
2751
+ const latitudes = /* @__PURE__ */ new Map();
2752
+ for (const y of meridians.get(edge.a[0])) {
2753
+ context.tick();
2754
+ if (y > Math.min(edge.a[1], edge.b[1]) && y < Math.max(edge.a[1], edge.b[1])) {
2755
+ const fraction = root(edge, 1, y, context);
2756
+ if (latitudes.has(fraction) && latitudes.get(fraction) !== y)
2757
+ throw new import_types4.GeographicSeamError("precision", "Unresolvable meridian event separation");
2758
+ fractions.push(fraction);
2759
+ latitudes.set(fraction, y);
2760
+ }
2761
+ }
2762
+ fractions.sort((a, b) => a - b);
2763
+ for (let i = 1; i < fractions.length; i++) {
2764
+ context.tick();
2765
+ const piece = slice(edge, fractions[i - 1], fractions[i]);
2766
+ if (latitudes.has(fractions[i - 1]))
2767
+ piece.a[1] = latitudes.get(fractions[i - 1]);
2768
+ if (latitudes.has(fractions[i]))
2769
+ piece.b[1] = latitudes.get(fractions[i]);
2770
+ if (fractions.length > 2)
2771
+ context.addVertices(2);
2772
+ const x = piece.a[0], latitude = (piece.a[1] + piece.b[1]) / 2;
2773
+ const seam = x === context.left;
2774
+ const ring = piece.source && rings[piece.source.ringIndex];
2775
+ if (ring && ring.max - ring.min >= 360 - ANGULAR_TOLERANCE && contains(ring, [x, latitude], context, seam ? "right" : "left") && contains(ring, [seam ? context.right : x, latitude], context, seam ? "left" : "right"))
2776
+ continue;
2777
+ const left = filled(rings, [x, latitude], context, seam ? "right" : "left");
2778
+ const right = filled(rings, [seam ? context.right : x, latitude], context, seam ? "left" : "right");
2779
+ if (left && right)
2780
+ continue;
2781
+ if (!left && !right)
2782
+ throw new import_types4.GeographicSeamError("topology", "Unresolvable meridian-coincident boundary");
2783
+ if (seam && !left) {
2784
+ const assigned = shift(piece, 360), sample = assigned.sample;
2785
+ assigned.a[0] = assigned.b[0] = context.right;
2786
+ assigned.sample = (t) => {
2787
+ const p = sample(t);
2788
+ p[0] = context.right;
2789
+ return p;
2790
+ };
2791
+ add2(assigned);
2792
+ } else
2793
+ add2(piece);
2794
+ }
2795
+ }
2796
+ const pole = rings[0].pole;
2797
+ if (pole && !rings.slice(1).some((r) => r.pole === pole)) {
2798
+ const latitude = pole === "north" ? 90 : -90;
2799
+ add2(straight([context.left, latitude, ...rings[0].poleAttributes], [context.right, latitude, ...rings[0].poleAttributes]));
2800
+ }
2801
+ for (const boundary of [context.left, context.right]) {
2802
+ const boundaryNodes = Array.from(nodes.values()).filter((n) => n.p[0] === boundary).sort((a, b) => a.p[1] - b.p[1]);
2803
+ const aligned = graph.filter((e) => e.a[0] === boundary && e.b[0] === boundary);
2804
+ for (let i = 1; i < boundaryNodes.length; i++) {
2805
+ context.tick();
2806
+ const a = boundaryNodes[i - 1].p, b = boundaryNodes[i].p, latitude = (a[1] + b[1]) / 2;
2807
+ if (latitude === a[1] || latitude === b[1])
2808
+ throw new import_types4.GeographicSeamError("precision", "Unresolvable seam event separation");
2809
+ if (filled(rings, [boundary, latitude], context, boundary === context.left ? "right" : "left") && !aligned.some((e) => {
2810
+ context.tick();
2811
+ return latitude > Math.min(e.a[1], e.b[1]) && latitude < Math.max(e.a[1], e.b[1]);
2812
+ }))
2813
+ add2(straight(a, b));
2814
+ }
2815
+ }
2816
+ if (latitudeRange) {
2817
+ const sourceGraph = graph.slice();
2818
+ graph.length = 0;
2819
+ nodes.clear();
2820
+ for (const edge of sourceGraph)
2821
+ for (const part of clipLatitudeEdge(edge, latitudeRange, context)) {
2822
+ const boundary = part.a[1] === part.b[1] && latitudeRange.includes(part.a[1]);
2823
+ if (boundary && !filled(rings, [(part.a[0] + part.b[0]) / 2, part.a[1]], context, void 0, part.a[1] === latitudeRange[0] ? "north" : "south"))
2824
+ continue;
2825
+ add2(part);
2826
+ }
2827
+ for (const boundary of latitudeRange) {
2828
+ const events = Array.from(nodes.values()).filter((n) => n.p[1] === boundary).sort((a, b) => a.p[0] - b.p[0]);
2829
+ const aligned = graph.filter((e) => e.a[1] === boundary && e.b[1] === boundary);
2830
+ for (let i = 1; i < events.length; i++) {
2831
+ context.tick();
2832
+ const a = events[i - 1].p, b = events[i].p, longitude = (a[0] + b[0]) / 2;
2833
+ if (longitude === a[0] || longitude === b[0])
2834
+ throw new import_types4.GeographicSeamError("precision", "Unresolvable latitude event separation");
2835
+ if (filled(rings, [longitude, boundary], context, void 0, boundary === latitudeRange[0] ? "north" : "south") && !aligned.some((e) => {
2836
+ context.tick();
2837
+ return longitude > Math.min(e.a[0], e.b[0]) && longitude < Math.max(e.a[0], e.b[0]);
2838
+ }))
2839
+ add2(straight(a, b));
2840
+ }
2841
+ }
2842
+ }
2843
+ for (const node of nodes.values())
2844
+ if (node.edges.length !== 2)
2845
+ throw new import_types4.GeographicSeamError("topology", "Touching, coincident or unresolved polygon boundaries");
2846
+ const used = /* @__PURE__ */ new Set(), cycles = [];
2847
+ for (let seed = 0; seed < graph.length; seed++) {
2848
+ if (used.has(seed))
2849
+ continue;
2850
+ const cycle = [], start = key2(graph[seed].a);
2851
+ let id = seed, current = start;
2852
+ do {
2853
+ context.tick();
2854
+ if (used.has(id))
2855
+ throw new import_types4.GeographicSeamError("topology", "Non-simple boundary graph");
2856
+ used.add(id);
2857
+ const edge = key2(graph[id].a) === current ? graph[id] : reverse(graph[id]);
2858
+ cycle.push(edge);
2859
+ current = key2(edge.b);
2860
+ const adjacent = nodes.get(current).edges;
2861
+ id = adjacent[0] === id ? adjacent[1] : adjacent[0];
2862
+ } while (current !== start);
2863
+ if (cycle.length < 3)
2864
+ throw new import_types4.GeographicSeamError("topology", "Degenerate polygon component");
2865
+ cycles.push(cycle);
2866
+ }
2867
+ const parents = cycles.map((cycle, i) => {
2868
+ const containers = [];
2869
+ for (let j = 0; j < cycles.length; j++)
2870
+ if (j !== i) {
2871
+ const w = winding(cycles[j], cycle[0].a, context);
2872
+ if (w.boundary)
2873
+ throw new import_types4.GeographicSeamError("topology", "Polygon components touch");
2874
+ if (w.value)
2875
+ containers.push(j);
2876
+ }
2877
+ if (containers.length > 1)
2878
+ throw new import_types4.GeographicSeamError("topology", "Nested holes or overlapping polygon components");
2879
+ return containers[0];
2880
+ });
2881
+ const sign = interior(rings[0].membership, context).sign;
2882
+ const result = [], groups = /* @__PURE__ */ new Map();
2883
+ for (let i = 0; i < cycles.length; i++)
2884
+ if (parents[i] === void 0) {
2885
+ if (cycles[i].every((e) => e.source && e.source.ringIndex !== 0))
2886
+ throw new import_types4.GeographicSeamError("topology", "Hole is outside the outer ring");
2887
+ const polygon = { rings: [output(cycles[i], sign, context)] };
2888
+ result.push(polygon);
2889
+ groups.set(i, polygon);
2890
+ }
2891
+ for (let i = 0; i < cycles.length; i++)
2892
+ if (parents[i] !== void 0) {
2893
+ const group = groups.get(parents[i]);
2894
+ if (!group)
2895
+ throw new import_types4.GeographicSeamError("topology", "Nested polygon rings");
2896
+ group.rings.push(output(cycles[i], -sign, context));
2897
+ }
2898
+ return result;
2899
+ }
2900
+
2901
+ // dist/geographic-cuts.js
2902
+ var import_types13 = require("./geographic-seams/types.shared.cjs");
2903
+ var import_types14 = require("./geographic-seams/types.shared.cjs");
2904
+
2905
+ // dist/geographic-seams/subdivide-cut.js
2906
+ var import_polygon = require("@math.gl/geometry/polygon");
2907
+ var import_types5 = require("./geographic-seams/types.shared.cjs");
2908
+ function subdivideGeographicCutRing(inputs, ring, options) {
2909
+ const settings = { ...options };
2910
+ const turns = inputs.map((r) => r.longitudeTurns ? Array.from(r.longitudeTurns) : void 0);
2911
+ const config = cutOptions(settings), context = new Context(config.options), size = settings.size ?? 2;
2912
+ if (size !== 2 && size !== 3)
2913
+ throw new import_types5.GeographicSeamError("input", "Cut subdivision supports coordinate sizes 2 or 3");
2914
+ const points = inputs.map((r) => {
2915
+ const p = context.read(r.positions);
2916
+ if (p.length > 1 && same(p[0], p[p.length - 1]))
2917
+ p.pop();
2918
+ return p;
2919
+ });
2920
+ const positions = context.read(ring.positions);
2921
+ if (!positions.length || ring.edges.length !== positions.length - 1 || !same(positions[0], positions[positions.length - 1]))
2922
+ throw new import_types5.GeographicSeamError("input", "Expected a closed cut ring with one descriptor per edge");
2923
+ const descriptors = ring.edges.map((e) => e.kind === "source" ? { kind: "source", source: { ...e.source } } : { ...e });
2924
+ const sources = /* @__PURE__ */ new Map();
2925
+ let geodesic2 = config.options.geodesic;
2926
+ const getGeodesic = () => geodesic2 ?? (geodesic2 = new EllipsoidGeodesic(config.axes));
2927
+ let rhumb = config.options.rhumb;
2928
+ const getRhumb = () => rhumb ?? (rhumb = new EllipsoidRhumb(config.axes));
2929
+ const result = (0, import_polygon.subdividePolyline)(new Float64Array(positions.flat()), {
2930
+ ...settings,
2931
+ transform: (p) => {
2932
+ context.tick();
2933
+ return settings.transform(p);
2934
+ },
2935
+ size,
2936
+ createEdgeSampler: (a, b, index) => {
2937
+ var _a;
2938
+ const descriptor = descriptors[index];
2939
+ const endpoint = (sample, t) => t === 0 ? a.slice() : t === 1 ? b.slice() : sample(t);
2940
+ if (descriptor.kind === "source") {
2941
+ const s = descriptor.source, p = points[s.ringIndex];
2942
+ if (!Number.isInteger(s.ringIndex) || !p || !Number.isInteger(s.edgeIndex) || s.edgeIndex < 0 || s.edgeIndex >= p.length || ![s.startFraction, s.endFraction, s.longitudeShift].every(Number.isFinite) || Math.min(s.startFraction, s.endFraction) < 0 || Math.max(s.startFraction, s.endFraction) > 1 || !Number.isSafeInteger(s.longitudeShift / 360))
2943
+ throw new import_types5.GeographicSeamError("input", "Invalid cut source interval");
2944
+ const key2 = s.ringIndex + ":" + s.edgeIndex;
2945
+ let path = sources.get(key2);
2946
+ if (!path) {
2947
+ const first = p[s.edgeIndex], last = p[(s.edgeIndex + 1) % p.length], edgeTurns = ((_a = turns[s.ringIndex]) == null ? void 0 : _a[s.edgeIndex]) ?? 0;
2948
+ if (settings.edgeModel === "geodesic")
2949
+ path = new GeodesicPath(first, last, { geodesic: getGeodesic() });
2950
+ else if (settings.edgeModel === "rhumb")
2951
+ path = new RhumbPath(first, last, { rhumb: getRhumb(), longitudeTurns: edgeTurns });
2952
+ else {
2953
+ const edge = createEdges(first, last, first, s.edgeIndex, s.ringIndex, edgeTurns, context)[0];
2954
+ path = {
2955
+ length: Math.hypot(...edge.b.map((v, i) => v - edge.a[i])),
2956
+ sample: edge.sample
2957
+ };
2958
+ }
2959
+ sources.set(key2, path);
2960
+ }
2961
+ const curve = path;
2962
+ return {
2963
+ length: curve.length * Math.abs(s.endFraction - s.startFraction),
2964
+ sample: (t) => endpoint((u) => {
2965
+ const f = s.startFraction + (s.endFraction - s.startFraction) * u, p2 = Array.from(curve.sample(f));
2966
+ p2[0] += s.longitudeShift;
2967
+ return p2;
2968
+ }, t)
2969
+ };
2970
+ }
2971
+ if (descriptor.kind === "pole") {
2972
+ if (Math.abs(descriptor.latitude) !== 90 || a[1] !== descriptor.latitude || b[1] !== descriptor.latitude)
2973
+ throw new import_types5.GeographicSeamError("input", "Invalid pole connector");
2974
+ return { length: 0, sample: (t) => a.map((v, i) => v * (1 - t) + b[i] * t) };
2975
+ }
2976
+ if (descriptor.kind === "parallel" ? a[1] !== descriptor.latitude || b[1] !== descriptor.latitude : descriptor.kind !== "meridian" || a[0] !== descriptor.longitude || b[0] !== descriptor.longitude)
2977
+ throw new import_types5.GeographicSeamError("input", "Boundary descriptor does not match its endpoints");
2978
+ if (settings.edgeModel === "linear")
2979
+ return {
2980
+ length: Math.hypot(...a.map((v, i) => v - b[i])),
2981
+ sample: (t) => a.map((v, i) => v * (1 - t) + b[i] * t)
2982
+ };
2983
+ if (descriptor.kind === "parallel") {
2984
+ const path = new RhumbPath(a, b, { rhumb: getRhumb(), longitudeMode: "unrolled" });
2985
+ return {
2986
+ length: path.length,
2987
+ sample: (t) => endpoint((u) => {
2988
+ const p = path.sample(u);
2989
+ p[1] = descriptor.latitude;
2990
+ return p;
2991
+ }, t)
2992
+ };
2993
+ }
2994
+ const metrics = new EllipsoidMetrics(config.axes), m0 = metrics.meridianDistance(a[1]), m1 = metrics.meridianDistance(b[1]);
2995
+ return {
2996
+ length: Math.abs(m1 - m0),
2997
+ sample: (t) => endpoint((u) => {
2998
+ const p = a.map((v, i) => v * (1 - u) + b[i] * u);
2999
+ p[0] = descriptor.longitude;
3000
+ p[1] = metrics.latitudeFromAuxiliary((m0 * (1 - u) + m1 * u) / metrics.quarterMeridian * 90, "rectifying");
3001
+ return p;
3002
+ }, t)
3003
+ };
3004
+ }
3005
+ });
3006
+ const edges = [];
3007
+ for (let i = 1; i < result.segmentIndices.length; i++) {
3008
+ const index = result.segmentIndices[i], edge = descriptors[index], lo = result.segmentIndices[i - 1] === index ? result.segmentFractions[i - 1] : 0, hi = result.segmentFractions[i];
3009
+ edges.push(edge.kind === "source" ? {
3010
+ kind: "source",
3011
+ source: {
3012
+ ...edge.source,
3013
+ startFraction: edge.source.startFraction + (edge.source.endFraction - edge.source.startFraction) * lo,
3014
+ endFraction: edge.source.startFraction + (edge.source.endFraction - edge.source.startFraction) * hi
3015
+ }
3016
+ } : { ...edge });
3017
+ }
3018
+ return { ...result, edges };
3019
+ }
3020
+
3021
+ // dist/geographic-atlas/atlas.js
3022
+ var import_types10 = require("./geographic-seams/types.shared.cjs");
3023
+
3024
+ // dist/geographic-atlas/curves.js
3025
+ var import_types7 = require("./geographic-seams/types.shared.cjs");
3026
+
3027
+ // dist/geographic-atlas/math.js
3028
+ var import_types6 = require("./geographic-seams/types.shared.cjs");
3029
+ var TAU = 2 * Math.PI;
3030
+ var ANGULAR = 1e-12;
3031
+ var ROUND = 64 * Number.EPSILON;
3032
+ var dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
3033
+ var cross = (a, b) => [
3034
+ a[1] * b[2] - a[2] * b[1],
3035
+ a[2] * b[0] - a[0] * b[2],
3036
+ a[0] * b[1] - a[1] * b[0]
3037
+ ];
3038
+ var scale = (a, s) => a.map((x) => x * s);
3039
+ var add = (a, b) => a.map((x, i) => x + b[i]);
3040
+ function unit(a) {
3041
+ if (a.length !== 3 || !a.every(Number.isFinite))
3042
+ throw new import_types6.GeographicSeamError("input", "Expected a finite three-component direction");
3043
+ const m = Math.max(...a.map(Math.abs));
3044
+ if (!m)
3045
+ throw new import_types6.GeographicSeamError("input", "Zero direction");
3046
+ const v = a.map((x) => x / m);
3047
+ return scale(v, 1 / Math.hypot(...v));
3048
+ }
3049
+ function sincos2(degrees) {
3050
+ const q = Math.round(degrees / 90), r = (degrees - 90 * q) * Math.PI / 180, s = Math.sin(r), c = Math.cos(r);
3051
+ switch ((q % 4 + 4) % 4) {
3052
+ case 0:
3053
+ return [s, c];
3054
+ case 1:
3055
+ return [c, -s];
3056
+ case 2:
3057
+ return [-s, -c];
3058
+ default:
3059
+ return [-c, s];
3060
+ }
3061
+ }
3062
+ function normal(p) {
3063
+ const [sp, cp] = sincos2(p[1]), [sl, cl] = sincos2((p[0] % 360 + 540) % 360 - 180);
3064
+ return [cp * cl, cp * sl, sp];
3065
+ }
3066
+ function position(n, attributes = []) {
3067
+ return [
3068
+ Math.atan2(n[1], n[0]) * 180 / Math.PI,
3069
+ Math.atan2(n[2], Math.hypot(n[0], n[1])) * 180 / Math.PI,
3070
+ ...attributes
3071
+ ];
3072
+ }
3073
+ function basis(n) {
3074
+ const axis = Math.abs(n[2]) < 0.8 ? [0, 0, 1] : [0, 1, 0];
3075
+ const u = unit(cross(axis, n));
3076
+ return [u, cross(n, u)];
3077
+ }
3078
+ function circle(id, n, c) {
3079
+ const [u, v] = basis(n);
3080
+ return { id, normal: n, offset: c, radius: Math.sqrt((1 - c) * (1 + c)), u, v };
3081
+ }
3082
+ function onCircle(c, t) {
3083
+ const [s, k] = sincos2(t * 180 / Math.PI);
3084
+ return add(scale(c.normal, c.offset), scale(add(scale(c.u, k), scale(c.v, s)), c.radius));
3085
+ }
3086
+ var angle2 = (c, n) => (Math.atan2(dot(c.v, n), dot(c.u, n)) + TAU) % TAU;
3087
+ function project(c, n) {
3088
+ const tangent = add(n, scale(c.normal, -dot(c.normal, n)));
3089
+ return add(scale(c.normal, c.offset), scale(unit(tangent), c.radius));
3090
+ }
3091
+ function value(c, n) {
3092
+ if (c.offset > 0.5)
3093
+ return 1 - c.offset - 0.5 * n.reduce((sum, x, i) => sum + (x - c.normal[i]) ** 2, 0);
3094
+ if (c.offset < -0.5)
3095
+ return -1 - c.offset + 0.5 * n.reduce((sum, x, i) => sum + (x + c.normal[i]) ** 2, 0);
3096
+ return dot(c.normal, n) - c.offset;
3097
+ }
3098
+ function valueError(c, n) {
3099
+ if (Math.abs(c.offset) > 0.5) {
3100
+ const sign = c.offset > 0 ? 1 : -1;
3101
+ return ROUND * (1 - Math.abs(c.offset) + Math.hypot(...n.map((x, i) => x - sign * c.normal[i])));
3102
+ }
3103
+ return ROUND * (Math.abs(c.offset) + n.reduce((sum, x, i) => sum + Math.abs(x * c.normal[i]), 0));
3104
+ }
3105
+ function slope(c, n, tangent) {
3106
+ if (c.offset > 0.5)
3107
+ return -n.reduce((sum, x, i) => sum + (x - c.normal[i]) * tangent[i], 0);
3108
+ if (c.offset < -0.5)
3109
+ return n.reduce((sum, x, i) => sum + (x + c.normal[i]) * tangent[i], 0);
3110
+ return dot(c.normal, tangent);
3111
+ }
3112
+ function intersections(a, b) {
3113
+ const d = dot(a.normal, b.normal), w = cross(a.normal, b.normal), w2 = dot(w, w);
3114
+ if (w2 === 0)
3115
+ return [];
3116
+ if (w2 < ROUND * ROUND)
3117
+ throw new import_types6.GeographicSeamError("precision", "Unresolved nearly parallel cut circles");
3118
+ const x = add(scale(a.normal, (a.offset - d * b.offset) / w2), scale(b.normal, (b.offset - d * a.offset) / w2));
3119
+ const h2 = 1 - dot(x, x);
3120
+ if (h2 < -ROUND)
3121
+ return [];
3122
+ if (Math.abs(h2) <= ROUND)
3123
+ throw new import_types6.GeographicSeamError("precision", "Tangent or unresolved cut-circle junction");
3124
+ const z = scale(w, Math.sqrt(h2 / w2));
3125
+ return [unit(add(x, z)), unit(add(x, scale(z, -1)))];
3126
+ }
3127
+ function chartPoint2(f, n) {
3128
+ const d = 1 + dot(f.center, n);
3129
+ if (d < 0.5)
3130
+ throw new import_types6.GeographicSeamError("precision", "Point outside the chart hemisphere");
3131
+ return [dot(f.u, n) / d, dot(f.v, n) / d];
3132
+ }
3133
+ function chartNormal(f, x, y) {
3134
+ const r = x * x + y * y;
3135
+ return add(scale(f.center, (1 - r) / (1 + r)), scale(add(scale(f.u, x), scale(f.v, y)), 2 / (1 + r)));
3136
+ }
3137
+
3138
+ // dist/geographic-atlas/curves.js
3139
+ function sourceCurve(edge, context, a, b, original) {
3140
+ const model = context.options.edgeModel, r = b / a, qmax = Math.max(1, 1 / (r * r)), wmin = Math.min(1, 1 / r), K = qmax / wmin;
3141
+ let initialAzimuth = 0;
3142
+ let length = 0, azimuth = (t) => ({ azi: 0, longitude: edge.a[0] });
3143
+ if (model === "geodesic") {
3144
+ const g = context.options.geodesic;
3145
+ context.tick(2);
3146
+ const first = (original == null ? void 0 : original[0]) ?? edge.a, last = (original == null ? void 0 : original[1]) ?? edge.b;
3147
+ const inv = g.inverse(first[1], first[0], last[1], last[0]);
3148
+ initialAzimuth = inv.azi1;
3149
+ length = inv.s12 / a;
3150
+ const line = g.line(first[1], first[0], inv.azi1);
3151
+ azimuth = (t) => {
3152
+ context.tick();
3153
+ const p = line.position(inv.s12 * t);
3154
+ return { azi: p.azi2, longitude: p.lon2 };
3155
+ };
3156
+ } else if (model === "rhumb") {
3157
+ const rh = context.options.rhumb;
3158
+ context.tick(2);
3159
+ const first = rh.inverse(edge.a[1], edge.a[0], edge.b[1], edge.b[0], { unrollLongitude: true });
3160
+ const turns = Math.round((edge.b[0] - first.lon2) / 360);
3161
+ const inv = turns ? rh.inverse(edge.a[1], edge.a[0], edge.b[1], edge.b[0], { longitudeTurns: turns }) : first;
3162
+ length = inv.s12 / a;
3163
+ azimuth = () => ({ azi: inv.azi12, longitude: edge.a[0] });
3164
+ }
3165
+ const dp = (edge.b[1] - edge.a[1]) * Math.PI / 180, dl = (edge.b[0] - edge.a[0]) * Math.PI / 180;
3166
+ const speed = model === "linear" ? Math.abs(dp) + Math.abs(dl) : length * K;
3167
+ const minCos = Math.min(...[edge.a[1], edge.b[1]].map((x) => Math.abs(sincos2(x)[1])));
3168
+ const second = model === "linear" ? speed * speed : model === "geodesic" ? 4 * speed * speed : 100 * K * K * speed * speed / (minCos * minCos);
3169
+ const curve = {
3170
+ sample: edge.sample,
3171
+ speed,
3172
+ second,
3173
+ derivative: (t) => {
3174
+ const p = edge.sample(t), heading = model === "linear" ? void 0 : azimuth(t), longitude = model === "geodesic" && Math.abs(p[1]) === 90 ? heading.longitude : p[0], [sp, cp] = sincos2(p[1]), [sl, cl] = sincos2(longitude);
3175
+ const north = [-sp * cl, -sp * sl, cp], east = [-sl, cl, 0];
3176
+ if (model === "linear")
3177
+ return add(scale(north, dp), scale(east, cp * dl));
3178
+ const [sa, ca] = sincos2(heading.azi), w = Math.sqrt(cp * cp + r * r * sp * sp), M = r * r / (w * w * w), N = 1 / w;
3179
+ return scale(add(scale(north, ca / M), scale(east, sa / N)), length);
3180
+ }
3181
+ };
3182
+ const axis = (coordinate, theta) => {
3183
+ const target = theta * 180 / Math.PI;
3184
+ if (Math.abs(target - edge.a[coordinate]) < 1e-13)
3185
+ return 0;
3186
+ if (Math.abs(target - edge.b[coordinate]) < 1e-13)
3187
+ return 1;
3188
+ return root(edge, coordinate, target, context);
3189
+ };
3190
+ if (edge.a[1] === edge.b[1] && (model !== "geodesic" || edge.a[1] === 0 && Math.abs(initialAzimuth) === 90)) {
3191
+ curve.circular = {
3192
+ normal: [0, 0, 1],
3193
+ offset: sincos2(edge.a[1])[0],
3194
+ u: [1, 0, 0],
3195
+ v: [0, 1, 0],
3196
+ start: edge.a[0] * Math.PI / 180,
3197
+ end: edge.b[0] * Math.PI / 180,
3198
+ fraction: (t) => axis(0, t)
3199
+ };
3200
+ } else if (edge.a[0] === edge.b[0]) {
3201
+ const [s, c] = sincos2(edge.a[0]);
3202
+ curve.circular = {
3203
+ normal: [s, -c, 0],
3204
+ offset: 0,
3205
+ u: [c, s, 0],
3206
+ v: [0, 0, 1],
3207
+ start: edge.a[1] * Math.PI / 180,
3208
+ end: edge.b[1] * Math.PI / 180,
3209
+ fraction: (t) => axis(1, t)
3210
+ };
3211
+ } else if (model === "geodesic" && a === b && length > 0) {
3212
+ const u = normal(edge.a), v = unit(curve.derivative(0));
3213
+ curve.circular = {
3214
+ normal: unit(cross(u, v)),
3215
+ offset: 0,
3216
+ u,
3217
+ v,
3218
+ start: 0,
3219
+ end: length,
3220
+ fraction: (t) => t / length
3221
+ };
3222
+ }
3223
+ if (curve.circular && Math.abs(curve.circular.offset) === 1) {
3224
+ curve.speed = 0;
3225
+ curve.second = 0;
3226
+ }
3227
+ return curve;
3228
+ }
3229
+ function sliceCurve(c, lo, hi) {
3230
+ const d = hi - lo, z = c.circular;
3231
+ const theta = (t) => {
3232
+ const n = normal(c.sample(t)), raw = Math.atan2(dot(z.v, n), dot(z.u, n)), expected = z.start + (z.end - z.start) * t;
3233
+ return raw + TAU * Math.round((expected - raw) / TAU);
3234
+ };
3235
+ return {
3236
+ sample: (t) => c.sample(lo + d * t),
3237
+ derivative: (t) => scale(c.derivative(lo + d * t), d),
3238
+ speed: c.speed * Math.abs(d),
3239
+ second: c.second * d * d,
3240
+ circular: z && {
3241
+ ...z,
3242
+ start: theta(lo),
3243
+ end: theta(hi),
3244
+ fraction: (angle3) => (z.fraction(angle3) - lo) / d
3245
+ }
3246
+ };
3247
+ }
3248
+ function circleCurve(c, start, end, attributesA, attributesB) {
3249
+ const delta = end - start;
3250
+ const sample = (t) => {
3251
+ const theta = start + delta * t, n = add(scale(c.normal, c.offset), scale(add(scale(c.u, Math.cos(theta)), scale(c.v, Math.sin(theta))), c.radius));
3252
+ return position(n, attributesA.map((x, i) => x * (1 - t) + attributesB[i] * t));
3253
+ };
3254
+ return {
3255
+ sample,
3256
+ derivative: (t) => {
3257
+ const theta = start + delta * t;
3258
+ return scale(add(scale(c.u, -Math.sin(theta)), scale(c.v, Math.cos(theta))), c.radius * delta);
3259
+ },
3260
+ speed: c.radius * Math.abs(delta),
3261
+ second: c.radius * delta * delta,
3262
+ circular: {
3263
+ normal: c.normal,
3264
+ offset: c.offset,
3265
+ u: c.u,
3266
+ v: c.v,
3267
+ start,
3268
+ end,
3269
+ fraction: (theta) => (theta - start) / delta
3270
+ }
3271
+ };
3272
+ }
3273
+ function roots(c, b, context) {
3274
+ const result = [];
3275
+ const put = (t) => {
3276
+ if (t >= 0 && t <= 1 && !result.includes(t)) {
3277
+ result.push(t);
3278
+ context.addVertices(1);
3279
+ }
3280
+ };
3281
+ const f = (t) => {
3282
+ context.tick();
3283
+ return value(b, normal(c.sample(t)));
3284
+ };
3285
+ if (c.circular) {
3286
+ const z = c.circular, radius = Math.sqrt((1 - z.offset) * (1 + z.offset)), A = radius * dot(b.normal, z.u), B = radius * dot(b.normal, z.v), direct = dot(b.normal, z.normal), d = direct >= 0 ? 1 - 0.5 * b.normal.reduce((sum, x, i) => sum + (x - z.normal[i]) ** 2, 0) : -1 + 0.5 * b.normal.reduce((sum, x, i) => sum + (x + z.normal[i]) ** 2, 0), C = d >= 0 ? b.offset - z.offset + z.offset * 0.5 * b.normal.reduce((sum, x, i) => sum + (x - z.normal[i]) ** 2, 0) : b.offset + z.offset - z.offset * 0.5 * b.normal.reduce((sum, x, i) => sum + (x + z.normal[i]) ** 2, 0), R = Math.hypot(A, B);
3287
+ if (Math.hypot(...cross(b.normal, z.normal)) <= ROUND && Math.abs(b.offset - z.offset * (d >= 0 ? 1 : -1)) / radius <= ROUND)
3288
+ return { fractions: [], coincident: true };
3289
+ if (R === 0)
3290
+ return { fractions: [], coincident: false };
3291
+ const phase = Math.atan2(B, A), low = Math.min(z.start, z.end), high = Math.max(z.start, z.end);
3292
+ const evaluate = (theta) => A * Math.cos(theta) + B * Math.sin(theta) - C;
3293
+ let minimum = Math.min(evaluate(low), evaluate(high)), maximum = Math.max(evaluate(low), evaluate(high));
3294
+ for (let k = Math.ceil((low - phase) / Math.PI); phase + k * Math.PI <= high; k++) {
3295
+ context.tick();
3296
+ const value2 = (k % 2 === 0 ? R : -R) - C;
3297
+ minimum = Math.min(minimum, value2);
3298
+ maximum = Math.max(maximum, value2);
3299
+ }
3300
+ const enclosureError = ROUND * (1 + Math.abs(A) + Math.abs(B) + Math.abs(C) + R * Math.max(Math.abs(low), Math.abs(high)));
3301
+ if (minimum > enclosureError || maximum < -enclosureError)
3302
+ return { fractions: [], coincident: false };
3303
+ const sine = Math.hypot(...cross(b.normal, z.normal));
3304
+ const left = Math.abs(d) > 0.5 ? radius * radius * sine * sine : (1 - b.offset) * (1 + b.offset) * (1 - z.offset) * (1 + z.offset), right = Math.abs(d) > 0.5 ? C * C : (d - b.offset * z.offset) ** 2, D = left - right, error = ROUND * (Math.abs(left) + Math.abs(right));
3305
+ if (D < -error)
3306
+ return { fractions: [], coincident: false };
3307
+ if (D <= error)
3308
+ throw new import_types7.GeographicSeamError("precision", "Unresolved circle tangency");
3309
+ if (sine < Math.sqrt(ROUND))
3310
+ throw new import_types7.GeographicSeamError("precision", "Unresolved nearly coincident source/cut circles");
3311
+ const delta = Math.atan2(Math.sqrt(D), C);
3312
+ for (const base of [phase - delta, phase + delta])
3313
+ for (let k = Math.ceil((low - base) / TAU); base + TAU * k <= high; k++) {
3314
+ context.tick();
3315
+ const theta = base + TAU * k;
3316
+ const t = theta === z.start ? 0 : theta === z.end ? 1 : z.fraction(theta);
3317
+ put(t);
3318
+ }
3319
+ return { fractions: result.sort((x, y) => x - y), coincident: false };
3320
+ }
3321
+ const bisect = (a, b1, fa) => {
3322
+ let lo = a, hi = b1;
3323
+ for (let i = 0; i < context.iterations; i++) {
3324
+ context.tick();
3325
+ const mid = (lo + hi) / 2, fm = f(mid);
3326
+ if (fm === 0) {
3327
+ put(mid);
3328
+ return;
3329
+ }
3330
+ if (hi - lo <= 4 * Number.EPSILON && c.speed * (hi - lo) <= ANGULAR) {
3331
+ put(mid);
3332
+ return;
3333
+ }
3334
+ if (mid === lo || mid === hi)
3335
+ break;
3336
+ if (fm < 0 === fa < 0) {
3337
+ lo = mid;
3338
+ fa = fm;
3339
+ } else
3340
+ hi = mid;
3341
+ }
3342
+ throw new import_types7.GeographicSeamError("precision", "Atlas intersection exhausted its root budget");
3343
+ };
3344
+ const visit = (lo, hi, fl, fh, depth) => {
3345
+ context.tick();
3346
+ const mid = (lo + hi) / 2, h = (hi - lo) / 2, fm = f(mid);
3347
+ const n = normal(c.sample(mid)), d = slope(b, n, c.derivative(mid)), derivativeError = ROUND * Math.max(1, c.speed);
3348
+ const excursion = Math.min(c.speed * h, (Math.abs(d) + derivativeError) * h + 0.5 * c.second * h * h);
3349
+ if (Math.abs(fm) > excursion + valueError(b, n))
3350
+ return;
3351
+ if (Math.abs(d) > c.second * h + ROUND * Math.max(1, c.speed)) {
3352
+ if (fl === 0)
3353
+ put(lo);
3354
+ if (fh === 0)
3355
+ put(hi);
3356
+ if (fl * fh < 0)
3357
+ bisect(lo, hi, fl);
3358
+ return;
3359
+ }
3360
+ if (depth >= context.iterations || mid === lo || mid === hi)
3361
+ throw new import_types7.GeographicSeamError("precision", "Unresolved tangent or coincident source/cut");
3362
+ visit(lo, mid, fl, fm, depth + 1);
3363
+ visit(mid, hi, fm, fh, depth + 1);
3364
+ };
3365
+ visit(0, 1, f(0), f(1), 0);
3366
+ return { fractions: result.sort((x, y) => x - y), coincident: false };
3367
+ }
3368
+
3369
+ // dist/geographic-atlas/topology.js
3370
+ var import_types8 = require("./geographic-seams/types.shared.cjs");
3371
+ function reverseArc(e) {
3372
+ const d = e.descriptor;
3373
+ return {
3374
+ coincident: e.coincident,
3375
+ a: e.b,
3376
+ b: e.a,
3377
+ curve: sliceCurve(e.curve, 1, 0),
3378
+ descriptor: d.kind === "source" ? {
3379
+ kind: "source",
3380
+ source: {
3381
+ ...d.source,
3382
+ startFraction: d.source.endFraction,
3383
+ endFraction: d.source.startFraction
3384
+ }
3385
+ } : { ...d, startAngle: d.endAngle, endAngle: d.startAngle }
3386
+ };
3387
+ }
3388
+ function crossings(edges, y, frame, context) {
3389
+ const direction = frame.v.map((x, i) => x - y * frame.center[i]), m = Math.hypot(...direction), query = circle("ray", unit(direction), y / m), result = [];
3390
+ for (const edge of edges) {
3391
+ const hits = roots(edge.curve, query, context);
3392
+ if (hits.coincident)
3393
+ throw new import_types8.GeographicSeamError("precision", "Interior ray coincides with a boundary");
3394
+ for (const t of hits.fractions) {
3395
+ const n = edge.curve.sample(t), v = dot(direction, edge.curve.derivative(t));
3396
+ if (v === 0 || t === 0 && v < 0 || t === 1 && v > 0)
3397
+ continue;
3398
+ result.push({ x: chartPoint2(frame, normal(n))[0], sign: Math.sign(v) });
3399
+ }
3400
+ }
3401
+ return result.sort((a, b) => a.x - b.x);
3402
+ }
3403
+ function winding2(edges, n, frame, context) {
3404
+ const [x, y] = chartPoint2(frame, n);
3405
+ return crossings(edges, y, frame, context).reduce((s, p) => s + (p.x > x ? p.sign : 0), 0);
3406
+ }
3407
+ function orientation(edges, frame, context) {
3408
+ const ys = Array.from(new Set(edges.map((e) => chartPoint2(frame, e.a.n)[1]))).sort((a, b) => a - b);
3409
+ const bands = ys.slice(1).map((y, i) => [ys[i], y]).sort((a, b) => b[1] - b[0] - (a[1] - a[0]));
3410
+ for (const [lo, hi] of bands) {
3411
+ if (hi - lo < 1e-11)
3412
+ continue;
3413
+ const hits = crossings(edges, (lo + hi) / 2, frame, context);
3414
+ for (let i = 1; i < hits.length; i++)
3415
+ if (hits[i].x - hits[i - 1].x > 1e-11) {
3416
+ const n = chartNormal(frame, (hits[i].x + hits[i - 1].x) / 2, (lo + hi) / 2), w = winding2(edges, n, frame, context);
3417
+ if (w)
3418
+ return Math.sign(w);
3419
+ }
3420
+ }
3421
+ for (const edge of edges)
3422
+ for (const t of [0.371, 0.613, 0.5]) {
3423
+ context.tick();
3424
+ const n = normal(edge.curve.sample(t)), left = cross(n, edge.curve.derivative(t));
3425
+ if (Math.hypot(...left) === 0)
3426
+ continue;
3427
+ const direction = unit(left);
3428
+ for (let epsilon = 0.0625; epsilon >= ANGULAR; epsilon /= 4)
3429
+ for (const side of [1, -1]) {
3430
+ context.tick();
3431
+ const probe = unit(add(n, scale(direction, side * epsilon)));
3432
+ try {
3433
+ const w = winding2(edges, probe, frame, context);
3434
+ if (w)
3435
+ return Math.sign(w);
3436
+ } catch (error) {
3437
+ if (!(error instanceof import_types8.GeographicSeamError) || error.reason !== "precision")
3438
+ throw error;
3439
+ }
3440
+ }
3441
+ }
3442
+ throw new import_types8.GeographicSeamError("precision", "No resolvable chart-ring interior");
3443
+ }
3444
+ function polygons(arcs, frame, chart, sign, context) {
3445
+ const outgoing = /* @__PURE__ */ new Map(), incoming = /* @__PURE__ */ new Map();
3446
+ for (let i = 0; i < arcs.length; i++) {
3447
+ context.tick();
3448
+ const e = arcs[i];
3449
+ if (e.a.id === e.b.id)
3450
+ throw new import_types8.GeographicSeamError("topology", "Collapsed atlas arc");
3451
+ if (outgoing.has(e.a.id) || incoming.has(e.b.id))
3452
+ throw new import_types8.GeographicSeamError("topology", "Touching or unresolved atlas boundaries");
3453
+ outgoing.set(e.a.id, i);
3454
+ incoming.set(e.b.id, i);
3455
+ }
3456
+ for (const key2 of outgoing.keys())
3457
+ if (!incoming.has(key2))
3458
+ throw new import_types8.GeographicSeamError("topology", "Open atlas boundary");
3459
+ const cycles = [], used = /* @__PURE__ */ new Set();
3460
+ for (let i = 0; i < arcs.length; i++)
3461
+ if (!used.has(i)) {
3462
+ const cycle = [];
3463
+ let k = i;
3464
+ do {
3465
+ context.tick();
3466
+ if (used.has(k) || k === void 0)
3467
+ throw new import_types8.GeographicSeamError("topology", "Invalid atlas cycle");
3468
+ used.add(k);
3469
+ const e = arcs[k];
3470
+ cycle.push(e);
3471
+ k = outgoing.get(e.b.id);
3472
+ } while (k !== i);
3473
+ cycles.push(cycle);
3474
+ }
3475
+ const parents = cycles.map((c, i) => {
3476
+ const containers = [];
3477
+ for (let j = 0; j < cycles.length; j++)
3478
+ if (i !== j && winding2(cycles[j], normal(c[0].curve.sample(0.371)), frame, context))
3479
+ containers.push(j);
3480
+ return containers;
3481
+ });
3482
+ const result = [], groups = /* @__PURE__ */ new Map();
3483
+ const output2 = (c, wanted) => {
3484
+ if (orientation(c, frame, context) !== wanted)
3485
+ c = c.slice().reverse().map(reverseArc);
3486
+ const vertices = [...c.map((e) => e.a), c[0].a];
3487
+ context.addVertices(vertices.length);
3488
+ return {
3489
+ positions: new Float64Array(vertices.flatMap((n) => n.p)),
3490
+ normals: new Float64Array(vertices.flatMap((n) => n.n)),
3491
+ vertexIds: vertices.map((n) => n.id),
3492
+ edges: c.map((e) => e.descriptor)
3493
+ };
3494
+ };
3495
+ const depths = parents.map((p) => p.length);
3496
+ for (let i = 0; i < cycles.length; i++) {
3497
+ const expected = depths[i] % 2 === 0 ? 1 : -1;
3498
+ if (orientation(cycles[i], frame, context) !== expected)
3499
+ throw new import_types8.GeographicSeamError("topology", "Inconsistent nested atlas winding");
3500
+ if (expected === 1) {
3501
+ const p = { chart, rings: [output2(cycles[i], sign)] };
3502
+ result.push(p);
3503
+ groups.set(i, p);
3504
+ }
3505
+ }
3506
+ for (let i = 0; i < cycles.length; i++)
3507
+ if (depths[i] % 2 === 1) {
3508
+ const immediate = parents[i].filter((j) => depths[j] === depths[i] - 1);
3509
+ if (immediate.length !== 1 || !groups.has(immediate[0]))
3510
+ throw new import_types8.GeographicSeamError("topology", "Unresolved atlas ring hierarchy");
3511
+ groups.get(immediate[0]).rings.push(output2(cycles[i], -sign));
3512
+ }
3513
+ return result;
3514
+ }
3515
+
3516
+ // dist/geographic-atlas/sampling.js
3517
+ var import_polygon2 = require("@math.gl/geometry/polygon");
3518
+ var import_types9 = require("./geographic-seams/types.shared.cjs");
3519
+ function subdivideAtlasRing(sources, boundaries, ring, options, context, axes, closed = true) {
3520
+ const settings = { ...options }, size = context.size, points = context.read(ring.positions), descriptors = ring.edges.map((e) => e.kind === "source" ? { ...e, source: { ...e.source } } : { ...e });
3521
+ if (size !== 2 && size !== 3 || points.length < (closed ? 2 : 1) || descriptors.length !== points.length - 1 || closed && !same(points[0], points[points.length - 1]))
3522
+ throw new import_types9.GeographicSeamError("input", "Invalid atlas path dimensions, closure or descriptor count");
3523
+ const ratio = axes.semiMinorAxis / axes.semiMajorAxis, Rmax = axes.semiMajorAxis * Math.max(1, ratio * ratio, 1 / ratio);
3524
+ const curves = descriptors.map((e, i) => {
3525
+ let curve;
3526
+ if (e.kind === "source") {
3527
+ const s = e.source;
3528
+ if (![s.startFraction, s.endFraction].every(Number.isFinite) || Math.min(s.startFraction, s.endFraction) < 0 || Math.max(s.startFraction, s.endFraction) > 1)
3529
+ throw new import_types9.GeographicSeamError("input", "Invalid atlas source interval");
3530
+ const source = sources.find((p) => {
3531
+ var _a;
3532
+ return ((_a = p.edge.source) == null ? void 0 : _a.ringIndex) === s.ringIndex && p.edge.source.edgeIndex === s.edgeIndex && Math.min(s.startFraction, s.endFraction) >= p.edge.source.startFraction && Math.max(s.startFraction, s.endFraction) <= p.edge.source.endFraction;
3533
+ });
3534
+ if (!source)
3535
+ throw new import_types9.GeographicSeamError("input", "Atlas source interval is not in the original rings");
3536
+ const original = source.edge.source, delta = original.endFraction - original.startFraction;
3537
+ curve = sliceCurve(source.curve, (s.startFraction - original.startFraction) / delta, (s.endFraction - original.startFraction) / delta);
3538
+ } else {
3539
+ const boundary = boundaries.find((b) => b.id === e.boundary);
3540
+ if (!boundary || ![e.startAngle, e.endAngle].every(Number.isFinite) || Math.abs(e.endAngle - e.startAngle) > 2 * Math.PI)
3541
+ throw new import_types9.GeographicSeamError("input", "Invalid atlas boundary interval");
3542
+ curve = circleCurve(boundary, e.startAngle, e.endAngle, points[i].slice(2), points[i + 1].slice(2));
3543
+ }
3544
+ for (const t of [0, 1])
3545
+ if (Math.hypot(...normal(curve.sample(t)).map((x, j) => x - normal(points[i + t])[j])) > ANGULAR)
3546
+ throw new import_types9.GeographicSeamError("input", "Atlas descriptor does not match its endpoints");
3547
+ return curve;
3548
+ });
3549
+ const result = (0, import_polygon2.subdividePolyline)(new Float64Array(points.flat()), {
3550
+ ...settings,
3551
+ size,
3552
+ transform: (p) => {
3553
+ context.tick();
3554
+ return settings.transform(p);
3555
+ },
3556
+ createEdgeSampler: (a, b, index) => {
3557
+ const curve = curves[index];
3558
+ return {
3559
+ length: curve.speed * Rmax,
3560
+ sample: (t) => {
3561
+ context.tick();
3562
+ if (t === 0)
3563
+ return a.slice();
3564
+ if (t === 1)
3565
+ return b.slice();
3566
+ const p = curve.sample(t);
3567
+ return position(normal(p), p.slice(2));
3568
+ }
3569
+ };
3570
+ }
3571
+ });
3572
+ const edges = [];
3573
+ for (let i = 1; i < result.segmentIndices.length; i++) {
3574
+ const index = result.segmentIndices[i], edge = descriptors[index], lo = result.segmentIndices[i - 1] === index ? result.segmentFractions[i - 1] : 0, hi = result.segmentFractions[i];
3575
+ if (edge.kind === "source") {
3576
+ const s = edge.source, d = s.endFraction - s.startFraction;
3577
+ edges.push({
3578
+ kind: "source",
3579
+ source: {
3580
+ ...s,
3581
+ startFraction: s.startFraction + d * lo,
3582
+ endFraction: s.startFraction + d * hi
3583
+ }
3584
+ });
3585
+ } else {
3586
+ const d = edge.endAngle - edge.startAngle;
3587
+ edges.push({
3588
+ ...edge,
3589
+ startAngle: edge.startAngle + d * lo,
3590
+ endAngle: edge.startAngle + d * hi
3591
+ });
3592
+ }
3593
+ }
3594
+ return { ...result, edges };
3595
+ }
3596
+
3597
+ // dist/geographic-atlas/atlas.js
3598
+ var key = (n) => n.map((x) => x === 0 ? 0 : x).join(",");
3599
+ function fail(message) {
3600
+ throw new import_types10.GeographicSeamError("input", message);
3601
+ }
3602
+ function mergeEdges(edges) {
3603
+ const groups = /* @__PURE__ */ new Map();
3604
+ for (const e of edges)
3605
+ if (e.source) {
3606
+ const k = e.source.ringIndex + ":" + e.source.edgeIndex;
3607
+ const list = groups.get(k) ?? [];
3608
+ list.push(e);
3609
+ groups.set(k, list);
3610
+ }
3611
+ return Array.from(groups.values(), (pieces) => {
3612
+ const first = pieces[0], last = pieces[pieces.length - 1];
3613
+ if (pieces.length === 1)
3614
+ return first;
3615
+ return {
3616
+ a: first.a,
3617
+ b: last.b,
3618
+ source: { ...first.source, startFraction: 0, endFraction: 1 },
3619
+ sample: (t) => {
3620
+ const part = pieces.find((p) => t >= p.source.startFraction && t <= p.source.endFraction);
3621
+ if (!part)
3622
+ throw new import_types10.GeographicSeamError("precision", "Missing source curve interval");
3623
+ return part.sample((t - part.source.startFraction) / (part.source.endFraction - part.source.startFraction));
3624
+ }
3625
+ };
3626
+ });
3627
+ }
3628
+ var GeographicCutAtlas = class {
3629
+ constructor(graph, options) {
3630
+ this.boundaries = [];
3631
+ this.cells = [];
3632
+ this.declaredIds = /* @__PURE__ */ new Set();
3633
+ this.config = cutOptions({ ...options, latitudeRange: [-90, 90] });
3634
+ new Context(this.config.options);
3635
+ this.attributes = options.boundaryAttributes ? Array.from(options.boundaryAttributes) : [];
3636
+ if (this.attributes.length !== (options.size ?? 2) - 2 || !this.attributes.every(Number.isFinite))
3637
+ fail("Supply boundaryAttributes for every extra coordinate");
3638
+ if (!Array.isArray(graph.boundaries) || !Array.isArray(graph.charts) || graph.boundaries.length > 64 || graph.charts.length < 1 || graph.charts.length > 64)
3639
+ fail("Expected 1\u201364 charts and at most 64 declared cuts");
3640
+ const byId = /* @__PURE__ */ new Map();
3641
+ const id = (s) => typeof s === "string" && s.length > 0 && s.length <= 128 && !s.startsWith("@");
3642
+ for (const input of graph.boundaries) {
3643
+ if (!id(input.id) || byId.has(input.id))
3644
+ fail("Cut IDs must be unique nonempty names without @");
3645
+ const n = unit(input.normal), c = input.offset ?? 0;
3646
+ if (!Number.isFinite(c) || Math.abs(c) >= 1 || Math.sqrt((1 - c) * (1 + c)) < 1e-6)
3647
+ fail("Cut circle outside the resolved radius profile");
3648
+ for (const prior of this.boundaries)
3649
+ if (Math.hypot(...cross(n, prior.normal)) === 0 && c === dot(n, prior.normal) * prior.offset)
3650
+ fail("Coincident boundaries must share one ID");
3651
+ const cut2 = circle(input.id, n, c);
3652
+ this.declaredIds.add(cut2.id);
3653
+ byId.set(cut2.id, cut2);
3654
+ this.boundaries.push(cut2);
3655
+ }
3656
+ const chartIds = /* @__PURE__ */ new Set();
3657
+ for (const input of graph.charts) {
3658
+ if (!id(input.id) || chartIds.has(input.id) || !Array.isArray(input.cuts) || input.cuts.length > 64)
3659
+ fail("Invalid chart ID or cut list");
3660
+ chartIds.add(input.id);
3661
+ const center = unit(input.center), [u, v] = basis(center), cuts = [], seen = /* @__PURE__ */ new Set();
3662
+ for (const ref of input.cuts) {
3663
+ const cut2 = byId.get(ref.boundary);
3664
+ if (!cut2 || seen.has(cut2.id) || ref.side !== 1 && ref.side !== -1)
3665
+ fail("Invalid chart boundary reference");
3666
+ seen.add(cut2.id);
3667
+ cuts.push({ circle: cut2, side: ref.side });
3668
+ }
3669
+ let cap = this.boundaries.find((b) => b.offset === 0 && Math.hypot(...cross(b.normal, center)) === 0);
3670
+ if (!cap) {
3671
+ cap = circle("@hemisphere:" + input.id, center, 0);
3672
+ this.boundaries.push(cap);
3673
+ byId.set(cap.id, cap);
3674
+ }
3675
+ const side = dot(cap.normal, center) > 0 ? 1 : -1;
3676
+ if (seen.has(cap.id)) {
3677
+ if (cuts.find((c) => c.circle === cap).side !== side)
3678
+ fail("Chart cuts exclude its center hemisphere");
3679
+ } else
3680
+ cuts.push({ circle: cap, side });
3681
+ this.cells.push({ id: input.id, center, u, v, cuts });
3682
+ }
3683
+ for (let i = 0; i < this.cells.length; i++)
3684
+ for (let j = 0; j < i; j++) {
3685
+ if (!this.cells[i].cuts.some((a) => this.cells[j].cuts.some((b) => a.circle === b.circle && a.side !== b.side)))
3686
+ fail("Atlas cells need an oppositely oriented shared separator; overlapping interiors are unsupported");
3687
+ }
3688
+ }
3689
+ /** Reconstructible snapshot of the declared graph. */
3690
+ get graph() {
3691
+ return {
3692
+ boundaries: this.boundaries.filter((b) => this.declaredIds.has(b.id)).map((b) => ({
3693
+ id: b.id,
3694
+ normal: [...b.normal],
3695
+ offset: b.offset
3696
+ })),
3697
+ charts: this.cells.map((c) => ({
3698
+ id: c.id,
3699
+ center: [...c.center],
3700
+ cuts: c.cuts.filter((r) => this.declaredIds.has(r.circle.id)).map((r) => ({ boundary: r.circle.id, side: r.side }))
3701
+ }))
3702
+ };
3703
+ }
3704
+ /** Includes implicit hemispheres used by generated boundary descriptors. */
3705
+ get boundaryDefinitions() {
3706
+ return this.boundaries.map((b) => ({ id: b.id, normal: [...b.normal], offset: b.offset }));
3707
+ }
3708
+ /** Candidate adjacency across shared cuts; disjoint arc extents are still chart-specific. */
3709
+ get adjacency() {
3710
+ return this.boundaries.filter((b) => this.declaredIds.has(b.id)).map((b) => ({
3711
+ boundary: b.id,
3712
+ positive: this.cells.filter((c) => c.cuts.some((r) => r.circle === b && r.side === 1)).map((c) => c.id),
3713
+ negative: this.cells.filter((c) => c.cuts.some((r) => r.circle === b && r.side === -1)).map((c) => c.id)
3714
+ })).filter((r) => r.positive.length && r.negative.length);
3715
+ }
3716
+ sources(inputs, context) {
3717
+ const originals = inputs.map((r) => context.read(r.positions));
3718
+ const snapshots = inputs.map((r, i) => ({
3719
+ ...r,
3720
+ positions: originals[i].flat(),
3721
+ longitudeTurns: r.longitudeTurns ? Array.from(r.longitudeTurns) : void 0,
3722
+ poleAttributes: r.poleAttributes ? Array.from(r.poleAttributes) : void 0
3723
+ }));
3724
+ const rings = snapshots.map((r, i) => prepare(r, i, context));
3725
+ if (!rings.length)
3726
+ return { sources: [], rings, sign: 1 };
3727
+ const sign = interior(rings[0].membership, context).sign, sources = [];
3728
+ for (let i = 0; i < rings.length; i++) {
3729
+ const orientation2 = interior(rings[i].membership, context).sign, reversed = orientation2 !== (i ? -1 : 1), points = originals[i];
3730
+ if (points.length > 1 && points[0][0] === points[points.length - 1][0] && points[0][1] === points[points.length - 1][1])
3731
+ points.pop();
3732
+ for (const edge of mergeEdges(rings[i].edges)) {
3733
+ const index = edge.source.edgeIndex;
3734
+ sources.push({
3735
+ edge,
3736
+ curve: sourceCurve(edge, context, this.config.axes.semiMajorAxis, this.config.axes.semiMinorAxis, [points[index], points[(index + 1) % points.length]]),
3737
+ reversed
3738
+ });
3739
+ }
3740
+ }
3741
+ return { sources, rings, sign };
3742
+ }
3743
+ /** Clip simple original outer+hole rings to every chart. Shared events are computed once. */
3744
+ clipPolygon(inputs) {
3745
+ const context = new Context(this.config.options), { sources, rings, sign } = this.sources(inputs, context);
3746
+ if (!rings.length)
3747
+ return [];
3748
+ return this.clip(sources, context, (n) => filled(rings, position(n), context), sign);
3749
+ }
3750
+ clipPolyline(input, options = {}) {
3751
+ const context = new Context(this.config.options), points = context.read(input), turns = options.longitudeTurns ? Array.from(options.longitudeTurns) : new Array(Math.max(0, points.length - 1)).fill(0);
3752
+ if (turns.length !== Math.max(0, points.length - 1))
3753
+ fail("Expected one turn count per line edge");
3754
+ if (!points.length)
3755
+ return [];
3756
+ if (points.length === 1) {
3757
+ const n = normal(points[0]), cell = this.cells.find((c) => c.cuts.every((r) => r.side * value(r.circle, n) >= -valueError(r.circle, n)));
3758
+ return cell ? [
3759
+ {
3760
+ chart: cell.id,
3761
+ positions: new Float64Array(position(n, points[0].slice(2))),
3762
+ normals: new Float64Array(n),
3763
+ vertexIds: ["v0"],
3764
+ edges: []
3765
+ }
3766
+ ] : [];
3767
+ }
3768
+ const sources = [];
3769
+ let cursor = points[0];
3770
+ for (let i = 1; i < points.length; i++) {
3771
+ const pieces = createEdges(cursor, points[i], points[i - 1], i - 1, 0, turns[i - 1], context);
3772
+ for (const edge of mergeEdges(pieces))
3773
+ sources.push({
3774
+ edge,
3775
+ curve: sourceCurve(edge, context, this.config.axes.semiMajorAxis, this.config.axes.semiMinorAxis, [points[i - 1], points[i]]),
3776
+ reversed: false
3777
+ });
3778
+ cursor = pieces[pieces.length - 1].b;
3779
+ }
3780
+ return this.clip(sources, context);
3781
+ }
3782
+ clip(sources, context, contains2, sign = 1) {
3783
+ const registry = /* @__PURE__ */ new Map(), events = new Map(this.boundaries.map((c) => [c.id, /* @__PURE__ */ new Set()]));
3784
+ let serial = 0;
3785
+ const node = (n, attributes, source = false) => {
3786
+ const k = key(n) + (!contains2 && source ? "|" + attributes.join(",") : ""), previous = registry.get(k);
3787
+ if (previous) {
3788
+ if (source && previous.source && attributes.some((x, i) => x !== previous.p[i + 2]))
3789
+ throw new import_types10.GeographicSeamError("topology", "Shared source vertex attributes disagree");
3790
+ if (source && !previous.source) {
3791
+ previous.p = position(n, attributes);
3792
+ previous.source = true;
3793
+ }
3794
+ return previous;
3795
+ }
3796
+ context.addVertices(1);
3797
+ const p = {
3798
+ id: "v" + serial++,
3799
+ n,
3800
+ p: position(n, attributes),
3801
+ cuts: /* @__PURE__ */ new Set(),
3802
+ source
3803
+ };
3804
+ registry.set(k, p);
3805
+ return p;
3806
+ };
3807
+ const on = (n, b) => {
3808
+ n.cuts.add(b.id);
3809
+ events.get(b.id).add(n);
3810
+ };
3811
+ const relevant = (ids, n) => this.cells.some((c) => {
3812
+ context.tick();
3813
+ return ids.every((id) => c.cuts.some((r) => r.circle.id === id)) && c.cuts.every((r) => {
3814
+ context.tick();
3815
+ return r.side * value(r.circle, n) >= -valueError(r.circle, n);
3816
+ });
3817
+ });
3818
+ for (let i = 0; i < this.boundaries.length; i++)
3819
+ for (let j = 0; j < i; j++) {
3820
+ context.tick();
3821
+ if (!this.cells.some((c) => c.cuts.some((r) => r.circle === this.boundaries[i]) && c.cuts.some((r) => r.circle === this.boundaries[j])))
3822
+ continue;
3823
+ for (const n of intersections(this.boundaries[i], this.boundaries[j])) {
3824
+ if (!relevant([this.boundaries[i].id, this.boundaries[j].id], n))
3825
+ continue;
3826
+ const v = node(n, this.attributes);
3827
+ on(v, this.boundaries[i]);
3828
+ on(v, this.boundaries[j]);
3829
+ }
3830
+ }
3831
+ const sourceArcs = [];
3832
+ for (const { edge, curve, reversed } of sources) {
3833
+ const endpoints = [
3834
+ node(normal(edge.a), edge.a.slice(2), true),
3835
+ node(normal(edge.b), edge.b.slice(2), true)
3836
+ ], at = /* @__PURE__ */ new Map([
3837
+ [0, endpoints[0]],
3838
+ [1, endpoints[1]]
3839
+ ]), coincident = /* @__PURE__ */ new Set();
3840
+ for (const b of this.boundaries) {
3841
+ const hit = roots(curve, b, context);
3842
+ if (hit.coincident) {
3843
+ coincident.add(b.id);
3844
+ on(endpoints[0], b);
3845
+ on(endpoints[1], b);
3846
+ continue;
3847
+ }
3848
+ for (const t of hit.fractions) {
3849
+ const p = curve.sample(t), n = project(b, normal(p));
3850
+ if (!relevant([b.id], n))
3851
+ continue;
3852
+ let v = at.get(t);
3853
+ if (!v) {
3854
+ v = node(n, p.slice(2), true);
3855
+ at.set(t, v);
3856
+ }
3857
+ on(v, b);
3858
+ }
3859
+ for (const v of endpoints)
3860
+ if (value(b, v.n) === 0)
3861
+ on(v, b);
3862
+ }
3863
+ if (!contains2 && Math.hypot(...endpoints[0].n.map((x, i) => x - endpoints[1].n[i])) === 0 && curve.speed > ANGULAR) {
3864
+ const steps = Math.max(4, Math.ceil(curve.speed / (Math.PI / 2)));
3865
+ if (steps > context.maxVertices)
3866
+ throw new import_types10.GeographicSeamError("limit", "Too many closed-line samples");
3867
+ for (let i = 1; i < steps; i++) {
3868
+ context.tick();
3869
+ const t = i / steps, p = curve.sample(t);
3870
+ if (!at.has(t))
3871
+ at.set(t, node(normal(p), p.slice(2), true));
3872
+ }
3873
+ }
3874
+ const fractions = Array.from(at.keys()).sort((a, b) => a - b);
3875
+ for (let i = 1; i < fractions.length; i++) {
3876
+ const lo = fractions[i - 1], hi = fractions[i], a = at.get(lo), b = at.get(hi);
3877
+ if (a.id === b.id) {
3878
+ if (lo !== hi && curve.speed * (hi - lo) > ANGULAR)
3879
+ throw new import_types10.GeographicSeamError("precision", "Unresolved source loop");
3880
+ continue;
3881
+ }
3882
+ const descriptor = {
3883
+ kind: "source",
3884
+ source: {
3885
+ ringIndex: edge.source.ringIndex,
3886
+ edgeIndex: edge.source.edgeIndex,
3887
+ startFraction: edge.source.startFraction + (edge.source.endFraction - edge.source.startFraction) * lo,
3888
+ endFraction: edge.source.startFraction + (edge.source.endFraction - edge.source.startFraction) * hi
3889
+ }
3890
+ };
3891
+ let arc = { a, b, curve: sliceCurve(curve, lo, hi), descriptor, coincident };
3892
+ if (reversed)
3893
+ arc = reverseArc(arc);
3894
+ for (const id of coincident) {
3895
+ arc.a.cuts.add(id);
3896
+ arc.b.cuts.add(id);
3897
+ }
3898
+ sourceArcs.push(arc);
3899
+ }
3900
+ }
3901
+ for (const b of this.boundaries)
3902
+ for (let i = 0; i < 4; i++) {
3903
+ const n = onCircle(b, i * TAU / 4);
3904
+ if (Array.from(events.get(b.id)).some((v2) => Math.hypot(...v2.n.map((x, j) => x - n[j])) < ANGULAR))
3905
+ continue;
3906
+ const v = node(n, this.attributes);
3907
+ on(v, b);
3908
+ }
3909
+ const accepts = (cell, n, known) => {
3910
+ const values = cell.cuts.filter((r) => !(known == null ? void 0 : known.has(r.circle.id))).map((r) => {
3911
+ context.tick();
3912
+ return { f: r.side * value(r.circle, n), error: valueError(r.circle, n) };
3913
+ });
3914
+ if (values.some((v) => v.f < -v.error))
3915
+ return false;
3916
+ if (values.some((v) => Math.abs(v.f) <= v.error))
3917
+ throw new import_types10.GeographicSeamError("precision", "Unresolved chart-side classification");
3918
+ return true;
3919
+ };
3920
+ const result = [];
3921
+ for (const cell of this.cells) {
3922
+ const arcs = [];
3923
+ for (const arc of sourceArcs) {
3924
+ context.tick();
3925
+ const n = normal(arc.curve.sample(0.5));
3926
+ if (!accepts(cell, n, arc.coincident))
3927
+ continue;
3928
+ if (contains2 && cell.cuts.some((r) => {
3929
+ var _a;
3930
+ return ((_a = arc.coincident) == null ? void 0 : _a.has(r.circle.id)) && r.side * dot(r.circle.normal, cross(n, arc.curve.derivative(0.5))) < 0;
3931
+ }))
3932
+ continue;
3933
+ if (!contains2) {
3934
+ const coincident = cell.cuts.filter((r) => {
3935
+ var _a;
3936
+ return (_a = arc.coincident) == null ? void 0 : _a.has(r.circle.id);
3937
+ });
3938
+ if (coincident.length) {
3939
+ const owner = this.cells.find((c) => accepts(c, n, arc.coincident));
3940
+ if (owner !== cell)
3941
+ continue;
3942
+ }
3943
+ }
3944
+ arcs.push(arc);
3945
+ }
3946
+ if (!contains2) {
3947
+ const parts = [];
3948
+ for (const e of arcs) {
3949
+ context.tick();
3950
+ const previous = parts[parts.length - 1], s = e.descriptor;
3951
+ if (s.kind !== "source")
3952
+ continue;
3953
+ if (previous && previous.vertices[previous.vertices.length - 1].id === e.a.id) {
3954
+ previous.vertices.push(e.b);
3955
+ previous.edges.push({ ...s.source });
3956
+ } else
3957
+ parts.push({ vertices: [e.a, e.b], edges: [{ ...s.source }] });
3958
+ }
3959
+ result.push(...parts.map((p) => ({
3960
+ chart: cell.id,
3961
+ positions: new Float64Array(p.vertices.flatMap((n) => n.p)),
3962
+ normals: new Float64Array(p.vertices.flatMap((n) => n.n)),
3963
+ vertexIds: p.vertices.map((n) => n.id),
3964
+ edges: p.edges
3965
+ })));
3966
+ continue;
3967
+ }
3968
+ for (const ref of cell.cuts) {
3969
+ const b = ref.circle, list = Array.from(events.get(b.id)).map((n) => ({ n, angle: angle2(b, n.n) })).sort((a, b2) => a.angle - b2.angle);
3970
+ for (let i = 0; i < list.length; i++) {
3971
+ context.tick();
3972
+ const a = list[i], end = list[(i + 1) % list.length], hi = end.angle + (i === list.length - 1 ? TAU : 0), delta = hi - a.angle;
3973
+ if (delta * b.radius < ANGULAR) {
3974
+ if (a.n.id !== end.n.id)
3975
+ throw new import_types10.GeographicSeamError("precision", "Unresolved cut-graph event separation");
3976
+ continue;
3977
+ }
3978
+ const midpoint = onCircle(b, (a.angle + hi) / 2), known = /* @__PURE__ */ new Set([b.id]);
3979
+ if (!accepts(cell, midpoint, known) || !contains2(midpoint))
3980
+ continue;
3981
+ if (sourceArcs.some((e) => {
3982
+ var _a;
3983
+ if (!((_a = e.coincident) == null ? void 0 : _a.has(b.id)))
3984
+ return false;
3985
+ const z = e.curve.circular;
3986
+ const raw = Math.atan2(dot(z.v, midpoint), dot(z.u, midpoint));
3987
+ const low = Math.min(z.start, z.end), high = Math.max(z.start, z.end);
3988
+ const theta = raw + TAU * Math.ceil((low - raw) / TAU);
3989
+ return theta > low && theta < high;
3990
+ }))
3991
+ continue;
3992
+ let arc = {
3993
+ a: a.n,
3994
+ b: end.n,
3995
+ curve: circleCurve(b, a.angle, hi, a.n.p.slice(2), end.n.p.slice(2)),
3996
+ descriptor: { kind: "boundary", boundary: b.id, startAngle: a.angle, endAngle: hi }
3997
+ };
3998
+ if (ref.side === -1)
3999
+ arc = reverseArc(arc);
4000
+ arcs.push(arc);
4001
+ }
4002
+ }
4003
+ result.push(...polygons(arcs, cell, cell.id, sign, context));
4004
+ }
4005
+ return result;
4006
+ }
4007
+ subdividePolyline(input, part, options) {
4008
+ const context = new Context(this.config.options), points = context.read(input), turns = options.longitudeTurns ? Array.from(options.longitudeTurns) : new Array(Math.max(0, points.length - 1)).fill(0), sources = [];
4009
+ if (turns.length !== Math.max(0, points.length - 1))
4010
+ fail("Expected one turn count per line edge");
4011
+ let cursor = points[0];
4012
+ for (let i = 1; i < points.length; i++) {
4013
+ const pieces = createEdges(cursor, points[i], points[i - 1], i - 1, 0, turns[i - 1], context);
4014
+ for (const edge of mergeEdges(pieces))
4015
+ sources.push({
4016
+ edge,
4017
+ curve: sourceCurve(edge, context, this.config.axes.semiMajorAxis, this.config.axes.semiMinorAxis, [points[i - 1], points[i]])
4018
+ });
4019
+ cursor = pieces[pieces.length - 1].b;
4020
+ }
4021
+ const result = subdivideAtlasRing(sources, this.boundaries, { ...part, edges: part.edges.map((source) => ({ kind: "source", source })) }, options, context, this.config.axes, false);
4022
+ return {
4023
+ ...result,
4024
+ edges: result.edges.map((e) => {
4025
+ if (e.kind !== "source")
4026
+ throw new import_types10.GeographicSeamError("input", "Unexpected generated line edge");
4027
+ return e.source;
4028
+ })
4029
+ };
4030
+ }
4031
+ subdivideRing(inputs, ring, options) {
4032
+ const context = new Context(this.config.options), { sources } = this.sources(inputs, context);
4033
+ return subdivideAtlasRing(sources.map((s) => ({ edge: s.edge, curve: s.curve })), this.boundaries, ring, options, context, this.config.axes);
4034
+ }
4035
+ };
4036
+
4037
+ // dist/geographic-atlas.js
4038
+ var import_types11 = require("./geographic-seams/types.shared.cjs");
4039
+ var import_types12 = require("./geographic-seams/types.shared.cjs");
4040
+ function createOrthographicCutAtlas(options) {
4041
+ const direction = unit(options.viewDirection), [u, v] = basis(direction), config = cutOptions({ ...options, latitudeRange: [-90, 90] }), a = config.axes.semiMajorAxis, r = config.axes.semiMinorAxis / a;
4042
+ const atlas = new GeographicCutAtlas({
4043
+ boundaries: [{ id: "horizon", normal: direction }],
4044
+ charts: [{ id: "visible", center: direction, cuts: [{ boundary: "horizon", side: 1 }] }]
4045
+ }, options);
4046
+ const project2 = (p) => {
4047
+ if (p.length < 2 || ![p[0], p[1]].every(Number.isFinite) || Math.abs(p[1]) > 90)
4048
+ throw new import_types12.GeographicSeamError("input", "Invalid orthographic position");
4049
+ const n = normal(p), w = Math.hypot(n[0], n[1], r * n[2]), x = [a * n[0] / w, a * n[1] / w, a * r * r * n[2] / w];
4050
+ return [dot(u, x), dot(v, x)];
4051
+ };
4052
+ return { atlas, project: project2, viewDirection: scale(direction, 1), right: scale(u, 1), up: scale(v, 1) };
4053
+ }
4054
+ function createOctahedralCutGraph() {
4055
+ const boundaries = [
4056
+ { id: "x", normal: [1, 0, 0] },
4057
+ { id: "y", normal: [0, 1, 0] },
4058
+ { id: "z", normal: [0, 0, 1] }
4059
+ ], charts = [];
4060
+ for (const x of [-1, 1])
4061
+ for (const y of [-1, 1])
4062
+ for (const z of [-1, 1])
4063
+ charts.push({
4064
+ id: `${x}/${y}/${z}`,
4065
+ center: [x, y, z],
4066
+ cuts: [
4067
+ { boundary: "x", side: x },
4068
+ { boundary: "y", side: y },
4069
+ { boundary: "z", side: z }
4070
+ ]
4071
+ });
4072
+ return { boundaries, charts };
4073
+ }
4074
+ function createOctahedralCutAtlas(options) {
4075
+ const graph = createOctahedralCutGraph(), atlas = new GeographicCutAtlas(graph, options), frames = new Map(graph.charts.map((c) => {
4076
+ const center = unit(c.center), [right, up] = basis(center);
4077
+ return [c.id, { center, right, up }];
4078
+ }));
4079
+ const project2 = (chart, p) => {
4080
+ const frame = frames.get(chart);
4081
+ if (!frame || p.length < 2 || ![p[0], p[1]].every(Number.isFinite) || Math.abs(p[1]) > 90)
4082
+ throw new import_types12.GeographicSeamError("input", "Invalid octahedral projection input");
4083
+ const n = normal(p), d = dot(frame.center, n);
4084
+ if (d < 0.5 || frame.center.some((x, i) => x * n[i] < -ROUND))
4085
+ throw new import_types12.GeographicSeamError("input", "Point outside the selected face projection domain");
4086
+ return [dot(frame.right, n) / d, dot(frame.up, n) / d];
4087
+ };
4088
+ return {
4089
+ atlas,
4090
+ project: project2,
4091
+ frames: Array.from(frames, ([id, f]) => ({
4092
+ id,
4093
+ center: scale(f.center, 1),
4094
+ right: scale(f.right, 1),
4095
+ up: scale(f.up, 1)
4096
+ }))
4097
+ };
4098
+ }
4099
+
4100
+ // dist/geographic-cuts.js
4101
+ function clipGeographicPolyline(input, options) {
4102
+ const config = cutOptions(options), range = config.range, context = new Context(config.options), points = context.read(input);
4103
+ const turns = options.longitudeTurns ? Array.from(options.longitudeTurns) : new Array(Math.max(0, points.length - 1)).fill(0);
4104
+ if (turns.length !== Math.max(0, points.length - 1))
4105
+ throw new import_types13.GeographicSeamError("input", "Expected one turn count per line edge");
4106
+ if (!points.length)
4107
+ return [];
4108
+ if (points.length === 1) {
4109
+ const p = points[0];
4110
+ if (p[1] < range[0] || p[1] > range[1])
4111
+ return [];
4112
+ const world = worldAt(p[0], context);
4113
+ return [{ positions: new Float64Array(chartPoint(p, world, context)), edges: [], world }];
4114
+ }
4115
+ const parts = [];
4116
+ let cursor = points[0];
4117
+ for (let i = 1; i < points.length; i++) {
4118
+ const originals = createEdges(cursor, points[i], points[i - 1], i - 1, 0, turns[i - 1], context);
4119
+ for (const original of originals) {
4120
+ if (!original.source)
4121
+ continue;
4122
+ for (const retained of clipLatitudeEdge(original, range, context))
4123
+ for (const { edge, world } of cut(retained, context)) {
4124
+ const previous = parts[parts.length - 1];
4125
+ if (previous && previous.world === world && same(previous.points[previous.points.length - 1], edge.a)) {
4126
+ previous.points.push(edge.b);
4127
+ previous.edges.push(edge.source);
4128
+ } else
4129
+ parts.push({ points: [edge.a, edge.b], edges: [edge.source], world });
4130
+ }
4131
+ }
4132
+ cursor = originals[originals.length - 1].b;
4133
+ }
4134
+ return parts.map((p) => ({
4135
+ positions: new Float64Array(p.points.flat()),
4136
+ edges: p.edges,
4137
+ world: p.world
4138
+ }));
4139
+ }
4140
+ function clipGeographicPolygon(inputs, options) {
4141
+ const config = cutOptions(options), range = config.range, size = options.size ?? 2;
4142
+ return clipLatitudePolygon(inputs, config.options, range).map((p) => ({
4143
+ rings: p.rings.map((r) => ({
4144
+ positions: r.positions,
4145
+ edges: r.edges.map((source, i) => {
4146
+ if (source)
4147
+ return { kind: "source", source };
4148
+ const a = r.positions.subarray(i * size, (i + 1) * size), b = r.positions.subarray((i + 1) * size, (i + 2) * size);
4149
+ if (a[1] === b[1] && Math.abs(a[1]) === 90)
4150
+ return { kind: "pole", latitude: a[1] };
4151
+ if (a[1] === b[1] && range.includes(a[1]))
4152
+ return { kind: "parallel", latitude: a[1] };
4153
+ if (a[0] === b[0])
4154
+ return { kind: "meridian", longitude: a[0] };
4155
+ throw new import_types13.GeographicSeamError("precision", "Unclassified generated cut boundary");
4156
+ })
4157
+ }))
4158
+ }));
4159
+ }
4160
+ //# sourceMappingURL=geographic-cuts.cjs.map