@math.gl/geospatial 5.0.0-rc.2 → 5.0.1

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