@math.gl/geospatial 5.0.0-beta.10 → 5.0.0-beta.12

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 (360) hide show
  1. package/README.md +3 -3
  2. package/dist/crs/index.cjs +54 -0
  3. package/dist/crs/index.cjs.map +2 -2
  4. package/dist/crs/index.d.ts +1 -0
  5. package/dist/crs/index.d.ts.map +1 -1
  6. package/dist/crs/index.js +1 -0
  7. package/dist/crs/index.js.map +1 -1
  8. package/dist/crs/spatial-reference-metadata.d.ts +20 -0
  9. package/dist/crs/spatial-reference-metadata.d.ts.map +1 -0
  10. package/dist/crs/spatial-reference-metadata.js +86 -0
  11. package/dist/crs/spatial-reference-metadata.js.map +1 -0
  12. package/dist/expressions.d.ts +1 -1
  13. package/dist/expressions.d.ts.map +1 -1
  14. package/dist/index.cjs +1738 -316
  15. package/dist/index.cjs.map +3 -3
  16. package/dist/index.d.ts +14 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +12 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/projection/experimental/core.cjs.map +1 -1
  21. package/dist/projection/experimental/crs/spatial-reference.d.ts.map +1 -1
  22. package/dist/projection/experimental/crs/spatial-reference.js.map +1 -1
  23. package/dist/projection/experimental/crs/types.d.ts.map +1 -1
  24. package/dist/projection/experimental/lazy-projections/aea.cjs +4 -1
  25. package/dist/projection/experimental/lazy-projections/aea.cjs.map +1 -1
  26. package/dist/projection/experimental/lazy-projections/aea.d.ts.map +1 -1
  27. package/dist/projection/experimental/lazy-projections/aea.js +4 -1
  28. package/dist/projection/experimental/lazy-projections/aea.js.map +1 -1
  29. package/dist/projection/experimental/lazy-projections/bonne.cjs +4 -1
  30. package/dist/projection/experimental/lazy-projections/bonne.cjs.map +1 -1
  31. package/dist/projection/experimental/lazy-projections/bonne.d.ts.map +1 -1
  32. package/dist/projection/experimental/lazy-projections/bonne.js +4 -1
  33. package/dist/projection/experimental/lazy-projections/bonne.js.map +1 -1
  34. package/dist/projection/experimental/lazy-projections/cass.cjs +4 -1
  35. package/dist/projection/experimental/lazy-projections/cass.cjs.map +1 -1
  36. package/dist/projection/experimental/lazy-projections/cass.d.ts.map +1 -1
  37. package/dist/projection/experimental/lazy-projections/cass.js +4 -1
  38. package/dist/projection/experimental/lazy-projections/cass.js.map +1 -1
  39. package/dist/projection/experimental/lazy-projections/eck6.cjs +4 -1
  40. package/dist/projection/experimental/lazy-projections/eck6.cjs.map +1 -1
  41. package/dist/projection/experimental/lazy-projections/eck6.d.ts.map +1 -1
  42. package/dist/projection/experimental/lazy-projections/eck6.js +4 -1
  43. package/dist/projection/experimental/lazy-projections/eck6.js.map +1 -1
  44. package/dist/projection/experimental/lazy-projections/eqdc.cjs +4 -1
  45. package/dist/projection/experimental/lazy-projections/eqdc.cjs.map +1 -1
  46. package/dist/projection/experimental/lazy-projections/eqdc.d.ts.map +1 -1
  47. package/dist/projection/experimental/lazy-projections/eqdc.js +4 -1
  48. package/dist/projection/experimental/lazy-projections/eqdc.js.map +1 -1
  49. package/dist/projection/experimental/lazy-projections/eqearth.cjs +4 -1
  50. package/dist/projection/experimental/lazy-projections/eqearth.cjs.map +1 -1
  51. package/dist/projection/experimental/lazy-projections/eqearth.d.ts.map +1 -1
  52. package/dist/projection/experimental/lazy-projections/eqearth.js +4 -1
  53. package/dist/projection/experimental/lazy-projections/eqearth.js.map +1 -1
  54. package/dist/projection/experimental/lazy-projections/equi.cjs +4 -1
  55. package/dist/projection/experimental/lazy-projections/equi.cjs.map +1 -1
  56. package/dist/projection/experimental/lazy-projections/equi.d.ts.map +1 -1
  57. package/dist/projection/experimental/lazy-projections/equi.js +4 -1
  58. package/dist/projection/experimental/lazy-projections/equi.js.map +1 -1
  59. package/dist/projection/experimental/lazy-projections/geocent.cjs +4 -1
  60. package/dist/projection/experimental/lazy-projections/geocent.cjs.map +1 -1
  61. package/dist/projection/experimental/lazy-projections/geocent.d.ts.map +1 -1
  62. package/dist/projection/experimental/lazy-projections/geocent.js +4 -1
  63. package/dist/projection/experimental/lazy-projections/geocent.js.map +1 -1
  64. package/dist/projection/experimental/lazy-projections/geos.cjs +4 -1
  65. package/dist/projection/experimental/lazy-projections/geos.cjs.map +1 -1
  66. package/dist/projection/experimental/lazy-projections/geos.d.ts.map +1 -1
  67. package/dist/projection/experimental/lazy-projections/geos.js +4 -1
  68. package/dist/projection/experimental/lazy-projections/geos.js.map +1 -1
  69. package/dist/projection/experimental/lazy-projections/gnom.cjs +4 -1
  70. package/dist/projection/experimental/lazy-projections/gnom.cjs.map +1 -1
  71. package/dist/projection/experimental/lazy-projections/gnom.d.ts.map +1 -1
  72. package/dist/projection/experimental/lazy-projections/gnom.js +4 -1
  73. package/dist/projection/experimental/lazy-projections/gnom.js.map +1 -1
  74. package/dist/projection/experimental/lazy-projections/index.cjs +92 -23
  75. package/dist/projection/experimental/lazy-projections/index.cjs.map +1 -1
  76. package/dist/projection/experimental/lazy-projections/krovak.cjs +4 -1
  77. package/dist/projection/experimental/lazy-projections/krovak.cjs.map +1 -1
  78. package/dist/projection/experimental/lazy-projections/krovak.d.ts.map +1 -1
  79. package/dist/projection/experimental/lazy-projections/krovak.js +4 -1
  80. package/dist/projection/experimental/lazy-projections/krovak.js.map +1 -1
  81. package/dist/projection/experimental/lazy-projections/merc.cjs +4 -1
  82. package/dist/projection/experimental/lazy-projections/merc.cjs.map +1 -1
  83. package/dist/projection/experimental/lazy-projections/merc.d.ts.map +1 -1
  84. package/dist/projection/experimental/lazy-projections/merc.js +4 -1
  85. package/dist/projection/experimental/lazy-projections/merc.js.map +1 -1
  86. package/dist/projection/experimental/lazy-projections/mill.cjs +4 -1
  87. package/dist/projection/experimental/lazy-projections/mill.cjs.map +1 -1
  88. package/dist/projection/experimental/lazy-projections/mill.d.ts.map +1 -1
  89. package/dist/projection/experimental/lazy-projections/mill.js +4 -1
  90. package/dist/projection/experimental/lazy-projections/mill.js.map +1 -1
  91. package/dist/projection/experimental/lazy-projections/moll.cjs +4 -1
  92. package/dist/projection/experimental/lazy-projections/moll.cjs.map +1 -1
  93. package/dist/projection/experimental/lazy-projections/moll.d.ts.map +1 -1
  94. package/dist/projection/experimental/lazy-projections/moll.js +4 -1
  95. package/dist/projection/experimental/lazy-projections/moll.js.map +1 -1
  96. package/dist/projection/experimental/lazy-projections/nzmg.cjs +4 -1
  97. package/dist/projection/experimental/lazy-projections/nzmg.cjs.map +1 -1
  98. package/dist/projection/experimental/lazy-projections/nzmg.d.ts.map +1 -1
  99. package/dist/projection/experimental/lazy-projections/nzmg.js +4 -1
  100. package/dist/projection/experimental/lazy-projections/nzmg.js.map +1 -1
  101. package/dist/projection/experimental/lazy-projections/omerc.cjs +4 -1
  102. package/dist/projection/experimental/lazy-projections/omerc.cjs.map +1 -1
  103. package/dist/projection/experimental/lazy-projections/omerc.d.ts.map +1 -1
  104. package/dist/projection/experimental/lazy-projections/omerc.js +4 -1
  105. package/dist/projection/experimental/lazy-projections/omerc.js.map +1 -1
  106. package/dist/projection/experimental/lazy-projections/ortho.cjs +4 -1
  107. package/dist/projection/experimental/lazy-projections/ortho.cjs.map +1 -1
  108. package/dist/projection/experimental/lazy-projections/ortho.d.ts.map +1 -1
  109. package/dist/projection/experimental/lazy-projections/ortho.js +4 -1
  110. package/dist/projection/experimental/lazy-projections/ortho.js.map +1 -1
  111. package/dist/projection/experimental/lazy-projections/poly.cjs +4 -1
  112. package/dist/projection/experimental/lazy-projections/poly.cjs.map +1 -1
  113. package/dist/projection/experimental/lazy-projections/poly.d.ts.map +1 -1
  114. package/dist/projection/experimental/lazy-projections/poly.js +4 -1
  115. package/dist/projection/experimental/lazy-projections/poly.js.map +1 -1
  116. package/dist/projection/experimental/lazy-projections/robin.cjs +4 -1
  117. package/dist/projection/experimental/lazy-projections/robin.cjs.map +1 -1
  118. package/dist/projection/experimental/lazy-projections/robin.d.ts.map +1 -1
  119. package/dist/projection/experimental/lazy-projections/robin.js +4 -1
  120. package/dist/projection/experimental/lazy-projections/robin.js.map +1 -1
  121. package/dist/projection/experimental/lazy-projections/sinu.cjs +4 -1
  122. package/dist/projection/experimental/lazy-projections/sinu.cjs.map +1 -1
  123. package/dist/projection/experimental/lazy-projections/sinu.d.ts.map +1 -1
  124. package/dist/projection/experimental/lazy-projections/sinu.js +4 -1
  125. package/dist/projection/experimental/lazy-projections/sinu.js.map +1 -1
  126. package/dist/projection/experimental/lazy-projections/stere.cjs +4 -1
  127. package/dist/projection/experimental/lazy-projections/stere.cjs.map +1 -1
  128. package/dist/projection/experimental/lazy-projections/stere.d.ts.map +1 -1
  129. package/dist/projection/experimental/lazy-projections/stere.js +4 -1
  130. package/dist/projection/experimental/lazy-projections/stere.js.map +1 -1
  131. package/dist/projection/experimental/lazy-projections/tpers.cjs +4 -1
  132. package/dist/projection/experimental/lazy-projections/tpers.cjs.map +1 -1
  133. package/dist/projection/experimental/lazy-projections/tpers.d.ts.map +1 -1
  134. package/dist/projection/experimental/lazy-projections/tpers.js +4 -1
  135. package/dist/projection/experimental/lazy-projections/tpers.js.map +1 -1
  136. package/dist/projection/experimental/lazy-projections/vandg.cjs +4 -1
  137. package/dist/projection/experimental/lazy-projections/vandg.cjs.map +1 -1
  138. package/dist/projection/experimental/lazy-projections/vandg.d.ts.map +1 -1
  139. package/dist/projection/experimental/lazy-projections/vandg.js +4 -1
  140. package/dist/projection/experimental/lazy-projections/vandg.js.map +1 -1
  141. package/dist/projection/index.cjs.map +1 -1
  142. package/dist/projection/index.d.ts.map +1 -1
  143. package/dist/projection/index.js.map +1 -1
  144. package/dist/projection/lib/projection.js.map +1 -1
  145. package/dist/projection/pipeline.cjs.map +1 -1
  146. package/dist/projection/transform-analysis.cjs.map +1 -1
  147. package/dist/tasks/index.cjs +181 -84
  148. package/dist/tasks/index.cjs.map +2 -2
  149. package/dist/tasks/terrain-residency.d.ts.map +1 -1
  150. package/dist/tasks/terrain-residency.js +80 -18
  151. package/dist/tasks/terrain-residency.js.map +1 -1
  152. package/dist/terrain/cutout-polygons.d.ts +21 -0
  153. package/dist/terrain/cutout-polygons.d.ts.map +1 -0
  154. package/dist/terrain/cutout-polygons.js +172 -0
  155. package/dist/terrain/cutout-polygons.js.map +1 -0
  156. package/dist/terrain/cutout-region.d.ts +34 -0
  157. package/dist/terrain/cutout-region.d.ts.map +1 -0
  158. package/dist/terrain/cutout-region.js +33 -0
  159. package/dist/terrain/cutout-region.js.map +1 -0
  160. package/dist/terrain/cutout-skirts.d.ts +34 -0
  161. package/dist/terrain/cutout-skirts.d.ts.map +1 -0
  162. package/dist/terrain/cutout-skirts.js +29 -0
  163. package/dist/terrain/cutout-skirts.js.map +1 -0
  164. package/dist/terrain/depression-fill.d.ts +25 -0
  165. package/dist/terrain/depression-fill.d.ts.map +1 -0
  166. package/dist/terrain/depression-fill.js +106 -0
  167. package/dist/terrain/depression-fill.js.map +1 -0
  168. package/dist/terrain/geographic-cutout.d.ts +38 -0
  169. package/dist/terrain/geographic-cutout.d.ts.map +1 -0
  170. package/dist/terrain/geographic-cutout.js +120 -0
  171. package/dist/terrain/geographic-cutout.js.map +1 -0
  172. package/dist/terrain/hydrology.d.ts +42 -0
  173. package/dist/terrain/hydrology.d.ts.map +1 -0
  174. package/dist/terrain/hydrology.js +112 -0
  175. package/dist/terrain/hydrology.js.map +1 -0
  176. package/dist/terrain/index.cjs +1529 -107
  177. package/dist/terrain/index.cjs.map +3 -3
  178. package/dist/terrain/index.d.ts +15 -1
  179. package/dist/terrain/index.d.ts.map +1 -1
  180. package/dist/terrain/index.js +13 -0
  181. package/dist/terrain/index.js.map +1 -1
  182. package/dist/terrain/lod-screen-error.d.ts +28 -0
  183. package/dist/terrain/lod-screen-error.d.ts.map +1 -0
  184. package/dist/terrain/lod-screen-error.js +95 -0
  185. package/dist/terrain/lod-screen-error.js.map +1 -0
  186. package/dist/terrain/lod-select.d.ts +26 -10
  187. package/dist/terrain/lod-select.d.ts.map +1 -1
  188. package/dist/terrain/lod-select.js +27 -14
  189. package/dist/terrain/lod-select.js.map +1 -1
  190. package/dist/terrain/mesh-cutout.d.ts +45 -0
  191. package/dist/terrain/mesh-cutout.d.ts.map +1 -0
  192. package/dist/terrain/mesh-cutout.js +336 -0
  193. package/dist/terrain/mesh-cutout.js.map +1 -0
  194. package/dist/terrain/mesh-skirts.d.ts +8 -2
  195. package/dist/terrain/mesh-skirts.d.ts.map +1 -1
  196. package/dist/terrain/mesh-skirts.js +5 -4
  197. package/dist/terrain/mesh-skirts.js.map +1 -1
  198. package/dist/terrain/mixed-halo-update.d.ts.map +1 -1
  199. package/dist/terrain/mixed-halo-update.js +58 -23
  200. package/dist/terrain/mixed-halo-update.js.map +1 -1
  201. package/dist/terrain/mixed-vertex-halos.d.ts +24 -1
  202. package/dist/terrain/mixed-vertex-halos.d.ts.map +1 -1
  203. package/dist/terrain/mixed-vertex-halos.js +75 -58
  204. package/dist/terrain/mixed-vertex-halos.js.map +1 -1
  205. package/dist/terrain/regional-viewshed.d.ts +55 -0
  206. package/dist/terrain/regional-viewshed.d.ts.map +1 -0
  207. package/dist/terrain/regional-viewshed.js +119 -0
  208. package/dist/terrain/regional-viewshed.js.map +1 -0
  209. package/dist/terrain/sweep-polytope.d.ts +4 -0
  210. package/dist/terrain/sweep-polytope.d.ts.map +1 -1
  211. package/dist/terrain/sweep-polytope.js +15 -5
  212. package/dist/terrain/sweep-polytope.js.map +1 -1
  213. package/dist/terrain/sweep-rotating-capsule.d.ts +17 -0
  214. package/dist/terrain/sweep-rotating-capsule.d.ts.map +1 -0
  215. package/dist/terrain/sweep-rotating-capsule.js +118 -0
  216. package/dist/terrain/sweep-rotating-capsule.js.map +1 -0
  217. package/dist/terrain/sweep-rotation.d.ts +35 -0
  218. package/dist/terrain/sweep-rotation.d.ts.map +1 -0
  219. package/dist/terrain/sweep-rotation.js +114 -0
  220. package/dist/terrain/sweep-rotation.js.map +1 -0
  221. package/dist/terrain/tile-cutout-update.d.ts +73 -0
  222. package/dist/terrain/tile-cutout-update.d.ts.map +1 -0
  223. package/dist/terrain/tile-cutout-update.js +181 -0
  224. package/dist/terrain/tile-cutout-update.js.map +1 -0
  225. package/dist/terrain/tile-cutout.d.ts +33 -0
  226. package/dist/terrain/tile-cutout.d.ts.map +1 -0
  227. package/dist/terrain/tile-cutout.js +93 -0
  228. package/dist/terrain/tile-cutout.js.map +1 -0
  229. package/dist/terrain/watershed-accumulation.d.ts +20 -0
  230. package/dist/terrain/watershed-accumulation.d.ts.map +1 -0
  231. package/dist/terrain/watershed-accumulation.js +53 -0
  232. package/dist/terrain/watershed-accumulation.js.map +1 -0
  233. package/dist/turf/expressions.cjs +4 -4
  234. package/dist/turf/expressions.cjs.map +2 -2
  235. package/dist/turf/expressions.d.ts +2 -2
  236. package/dist/turf/expressions.d.ts.map +1 -1
  237. package/dist/turf/expressions.js +2 -2
  238. package/dist/turf/expressions.js.map +1 -1
  239. package/dist/turf.cjs +25 -25
  240. package/dist/turf.cjs.map +2 -2
  241. package/dist/turf.d.ts +1 -1
  242. package/dist/turf.d.ts.map +1 -1
  243. package/dist/turf.js +2 -2
  244. package/dist/turf.js.map +1 -1
  245. package/dist/web-mercator/assert.d.ts +2 -0
  246. package/dist/web-mercator/assert.d.ts.map +1 -0
  247. package/dist/web-mercator/assert.js +12 -0
  248. package/dist/web-mercator/assert.js.map +1 -0
  249. package/dist/web-mercator/fit-bounds.d.ts +52 -0
  250. package/dist/web-mercator/fit-bounds.d.ts.map +1 -0
  251. package/dist/web-mercator/fit-bounds.js +70 -0
  252. package/dist/web-mercator/fit-bounds.js.map +1 -0
  253. package/dist/web-mercator/fly-to-viewport.d.ts +19 -0
  254. package/dist/web-mercator/fly-to-viewport.d.ts.map +1 -0
  255. package/dist/web-mercator/fly-to-viewport.js +94 -0
  256. package/dist/web-mercator/fly-to-viewport.js.map +1 -0
  257. package/dist/web-mercator/get-bounds.d.ts +3 -0
  258. package/dist/web-mercator/get-bounds.d.ts.map +1 -0
  259. package/dist/web-mercator/get-bounds.js +56 -0
  260. package/dist/web-mercator/get-bounds.js.map +1 -0
  261. package/dist/web-mercator/index.cjs +705 -0
  262. package/dist/web-mercator/index.cjs.map +6 -0
  263. package/dist/web-mercator/index.d.ts +14 -0
  264. package/dist/web-mercator/index.d.ts.map +1 -0
  265. package/dist/web-mercator/index.js +14 -0
  266. package/dist/web-mercator/index.js.map +1 -0
  267. package/dist/web-mercator/math-utils.d.ts +7 -0
  268. package/dist/web-mercator/math-utils.d.ts.map +1 -0
  269. package/dist/web-mercator/math-utils.js +30 -0
  270. package/dist/web-mercator/math-utils.js.map +1 -0
  271. package/dist/web-mercator/mercator-meters.d.ts +29 -0
  272. package/dist/web-mercator/mercator-meters.d.ts.map +1 -0
  273. package/dist/web-mercator/mercator-meters.js +61 -0
  274. package/dist/web-mercator/mercator-meters.js.map +1 -0
  275. package/dist/web-mercator/normalize-viewport-props.d.ts +16 -0
  276. package/dist/web-mercator/normalize-viewport-props.d.ts.map +1 -0
  277. package/dist/web-mercator/normalize-viewport-props.js +45 -0
  278. package/dist/web-mercator/normalize-viewport-props.js.map +1 -0
  279. package/dist/web-mercator/web-mercator-utils.d.ts +192 -0
  280. package/dist/web-mercator/web-mercator-utils.d.ts.map +1 -0
  281. package/dist/web-mercator/web-mercator-utils.js +321 -0
  282. package/dist/web-mercator/web-mercator-utils.js.map +1 -0
  283. package/dist/web-mercator/web-mercator-viewport.d.ts +177 -0
  284. package/dist/web-mercator/web-mercator-viewport.d.ts.map +1 -0
  285. package/dist/web-mercator/web-mercator-viewport.js +276 -0
  286. package/dist/web-mercator/web-mercator-viewport.js.map +1 -0
  287. package/dist/web-mercator.d.ts +1 -1
  288. package/dist/web-mercator.d.ts.map +1 -1
  289. package/dist/web-mercator.js +1 -1
  290. package/dist/web-mercator.js.map +1 -1
  291. package/package.json +19 -458
  292. package/src/crs/index.ts +7 -0
  293. package/src/crs/spatial-reference-metadata.ts +118 -0
  294. package/src/expressions.ts +1 -1
  295. package/src/index.ts +92 -4
  296. package/src/projection/experimental/crs/spatial-reference.ts +1 -6
  297. package/src/projection/experimental/crs/types.ts +1 -1
  298. package/src/projection/experimental/crs/wkt.ts +1 -1
  299. package/src/projection/experimental/crs-descriptor.ts +1 -1
  300. package/src/projection/experimental/lazy-projections/aea.ts +4 -1
  301. package/src/projection/experimental/lazy-projections/bonne.ts +4 -1
  302. package/src/projection/experimental/lazy-projections/cass.ts +4 -1
  303. package/src/projection/experimental/lazy-projections/eck6.ts +4 -1
  304. package/src/projection/experimental/lazy-projections/eqdc.ts +4 -1
  305. package/src/projection/experimental/lazy-projections/eqearth.ts +4 -1
  306. package/src/projection/experimental/lazy-projections/equi.ts +4 -1
  307. package/src/projection/experimental/lazy-projections/geocent.ts +4 -1
  308. package/src/projection/experimental/lazy-projections/geos.ts +4 -1
  309. package/src/projection/experimental/lazy-projections/gnom.ts +4 -1
  310. package/src/projection/experimental/lazy-projections/krovak.ts +4 -1
  311. package/src/projection/experimental/lazy-projections/merc.ts +4 -1
  312. package/src/projection/experimental/lazy-projections/mill.ts +4 -1
  313. package/src/projection/experimental/lazy-projections/moll.ts +4 -1
  314. package/src/projection/experimental/lazy-projections/nzmg.ts +4 -1
  315. package/src/projection/experimental/lazy-projections/omerc.ts +4 -1
  316. package/src/projection/experimental/lazy-projections/ortho.ts +4 -1
  317. package/src/projection/experimental/lazy-projections/poly.ts +4 -1
  318. package/src/projection/experimental/lazy-projections/robin.ts +4 -1
  319. package/src/projection/experimental/lazy-projections/sinu.ts +4 -1
  320. package/src/projection/experimental/lazy-projections/stere.ts +4 -1
  321. package/src/projection/experimental/lazy-projections/tpers.ts +4 -1
  322. package/src/projection/experimental/lazy-projections/vandg.ts +4 -1
  323. package/src/projection/index.ts +1 -1
  324. package/src/projection/lib/projection.ts +1 -1
  325. package/src/tasks/terrain-residency.ts +86 -21
  326. package/src/terrain/cutout-polygons.ts +202 -0
  327. package/src/terrain/cutout-region.ts +54 -0
  328. package/src/terrain/cutout-skirts.ts +52 -0
  329. package/src/terrain/depression-fill.ts +125 -0
  330. package/src/terrain/geographic-cutout.ts +154 -0
  331. package/src/terrain/hydrology.ts +149 -0
  332. package/src/terrain/index.ts +85 -1
  333. package/src/terrain/lod-screen-error.ts +128 -0
  334. package/src/terrain/lod-select.ts +65 -31
  335. package/src/terrain/mesh-cutout.ts +420 -0
  336. package/src/terrain/mesh-skirts.ts +10 -7
  337. package/src/terrain/mixed-halo-update.ts +54 -20
  338. package/src/terrain/mixed-vertex-halos.ts +94 -78
  339. package/src/terrain/regional-viewshed.ts +177 -0
  340. package/src/terrain/sweep-polytope.ts +49 -25
  341. package/src/terrain/sweep-rotating-capsule.ts +139 -0
  342. package/src/terrain/sweep-rotation.ts +149 -0
  343. package/src/terrain/tile-cutout-update.ts +293 -0
  344. package/src/terrain/tile-cutout.ts +123 -0
  345. package/src/terrain/watershed-accumulation.ts +67 -0
  346. package/src/turf/expressions.ts +3 -3
  347. package/src/turf.ts +3 -7
  348. package/src/web-mercator/assert.ts +11 -0
  349. package/src/web-mercator/fit-bounds.ts +132 -0
  350. package/src/web-mercator/fly-to-viewport.ts +157 -0
  351. package/src/web-mercator/get-bounds.ts +62 -0
  352. package/src/web-mercator/index.ts +49 -0
  353. package/src/web-mercator/math-utils.ts +35 -0
  354. package/src/web-mercator/mercator-meters.ts +83 -0
  355. package/src/web-mercator/normalize-viewport-props.ts +58 -0
  356. package/src/web-mercator/web-mercator-utils.ts +468 -0
  357. package/src/web-mercator/web-mercator-viewport.ts +406 -0
  358. package/src/web-mercator.ts +1 -1
  359. package/dist/projection/experimental/index.cjs +0 -11707
  360. package/dist/projection/experimental/index.cjs.map +0 -6
package/dist/index.cjs CHANGED
@@ -73,6 +73,7 @@ __export(index_exports, {
73
73
  TerrainContourBoundaryAxis: () => TerrainContourBoundaryAxis,
74
74
  TerrainMorphStatus: () => TerrainMorphStatus,
75
75
  TerrainProfileViewStatus: () => TerrainProfileViewStatus,
76
+ TerrainRegionalViewStatus: () => TerrainRegionalViewStatus,
76
77
  TerrainSampleStatus: () => TerrainSampleStatus,
77
78
  TerrainSurface: () => TerrainSurface,
78
79
  TerrainVertexHaloStatus: () => TerrainVertexHaloStatus,
@@ -81,8 +82,10 @@ __export(index_exports, {
81
82
  WKTCRSSyntaxError: () => WKTCRSSyntaxError,
82
83
  WKTCRSValidationError: () => WKTCRSValidationError,
83
84
  WebMercatorViewport: () => web_mercator_exports.WebMercatorViewport,
85
+ accumulateTerrainWatersheds: () => accumulateTerrainWatersheds,
84
86
  addMetersToLngLat: () => web_mercator_exports.addMetersToLngLat,
85
87
  altitudeToFovy: () => web_mercator_exports.altitudeToFovy,
88
+ boundTerrainLodScreenError: () => boundTerrainLodScreenError,
86
89
  boundTerrainMeshError: () => boundTerrainMeshError,
87
90
  certifyTerrainMeshCoverage: () => certifyTerrainMeshCoverage,
88
91
  clipGeographicPolygon: () => clipGeographicPolygon,
@@ -95,12 +98,15 @@ __export(index_exports, {
95
98
  createCRSProjectionDomain: () => createCRSProjectionDomain,
96
99
  createCRSResolver: () => createCRSResolver,
97
100
  createDelatinTerrainMesh: () => createDelatinTerrainMesh,
101
+ createGeographicTerrainCutoutFrame: () => createGeographicTerrainCutoutFrame,
98
102
  createMartiniTerrainMesh: () => createMartiniTerrainMesh,
99
103
  createOctahedralCutAtlas: () => createOctahedralCutAtlas,
100
104
  createOctahedralCutGraph: () => createOctahedralCutGraph,
101
105
  createOrthographicCutAtlas: () => createOrthographicCutAtlas,
102
106
  createSpatialReference: () => createSpatialReference,
103
107
  createTerrainContours: () => createTerrainContours,
108
+ createTerrainCutoutSkirts: () => createTerrainCutoutSkirts,
109
+ createTerrainDrainage: () => createTerrainDrainage,
104
110
  createTerrainFilteredPyramid: () => createTerrainFilteredPyramid,
105
111
  createTerrainGradientGrid: () => createTerrainGradientGrid,
106
112
  createTerrainGradientPyramid: () => createTerrainGradientPyramid,
@@ -109,6 +115,7 @@ __export(index_exports, {
109
115
  createTerrainMesh: () => createTerrainMesh,
110
116
  createTerrainMixedIsobands: () => createTerrainMixedIsobands,
111
117
  createTerrainMixedVertexTileHalos: () => createTerrainMixedVertexTileHalos,
118
+ createTerrainRegionalViewshed: () => createTerrainRegionalViewshed,
112
119
  createTerrainSkirt: () => createTerrainSkirt,
113
120
  createTerrainSlopeAspectGrid: () => createTerrainSlopeAspectGrid,
114
121
  createTerrainSurface: () => createTerrainSurface,
@@ -121,6 +128,7 @@ __export(index_exports, {
121
128
  encodePROJString: () => encodePROJString,
122
129
  encodeWKTCRS: () => encodeWKTCRS,
123
130
  evaluateTerrainLodMorph: () => evaluateTerrainLodMorph,
131
+ fillTerrainDepressions: () => fillTerrainDepressions,
124
132
  fitBounds: () => web_mercator_exports.fitBounds,
125
133
  flyToViewport: () => web_mercator_exports.flyToViewport,
126
134
  formatAngle: () => formatAngle,
@@ -141,6 +149,7 @@ __export(index_exports, {
141
149
  getMeterZoom: () => web_mercator_exports.getMeterZoom,
142
150
  getProjectionMatrix: () => web_mercator_exports.getProjectionMatrix,
143
151
  getProjectionParameters: () => web_mercator_exports.getProjectionParameters,
152
+ getTerrainCellMetrics: () => getTerrainCellMetrics,
144
153
  getTerrainHierarchyNode: () => getTerrainHierarchyNode,
145
154
  getTerrainMeshEdge: () => getTerrainMeshEdge,
146
155
  getTerrainProfileHorizon: () => getTerrainProfileHorizon,
@@ -174,6 +183,8 @@ __export(index_exports, {
174
183
  parsePROJString: () => parsePROJString,
175
184
  parseWKTCRS: () => parseWKTCRS,
176
185
  pixelsToWorld: () => web_mercator_exports.pixelsToWorld,
186
+ prepareTerrainCutoutPolygons: () => prepareTerrainCutoutPolygons,
187
+ projectGeographicTerrainCutout: () => projectGeographicTerrainCutout,
177
188
  projectGrid: () => projectGrid,
178
189
  reconcileTerrainVertexTiles: () => reconcileTerrainVertexTiles,
179
190
  resolveTileIndex: () => resolveTileIndex,
@@ -187,6 +198,8 @@ __export(index_exports, {
187
198
  splitGeographicPolyline: () => splitGeographicPolyline,
188
199
  splitGlobeBounds: () => splitGlobeBounds,
189
200
  splitTerrainBreaklines: () => splitTerrainBreaklines,
201
+ splitTerrainMesh: () => splitTerrainMesh,
202
+ splitTerrainMeshTiles: () => splitTerrainMeshTiles,
190
203
  standardGridZone: () => standardGridZone,
191
204
  stitchTerrainContourTiles: () => stitchTerrainContourTiles,
192
205
  stitchTerrainContours: () => stitchTerrainContours,
@@ -201,12 +214,17 @@ __export(index_exports, {
201
214
  sweepTerrainCylinder: () => sweepTerrainCylinder,
202
215
  sweepTerrainPlane: () => sweepTerrainPlane,
203
216
  sweepTerrainPolytope: () => sweepTerrainPolytope,
217
+ sweepTerrainRotatingBox: () => sweepTerrainRotatingBox,
218
+ sweepTerrainRotatingCapsule: () => sweepTerrainRotatingCapsule,
219
+ sweepTerrainRotatingPolytope: () => sweepTerrainRotatingPolytope,
220
+ sweepTerrainRotatingSphere: () => sweepTerrainRotatingSphere,
204
221
  sweepTerrainSphere: () => sweepTerrainSphere,
205
222
  sweepTerrainTaperedCapsule: () => sweepTerrainTaperedCapsule,
206
223
  sweepTerrainTriangleMesh: () => sweepTerrainTriangleMesh,
207
224
  transferGrid: () => transferGrid,
208
225
  unitsPerMeter: () => web_mercator_exports.unitsPerMeter,
209
226
  unpackTerrainHeightField: () => unpackTerrainHeightField,
227
+ unprojectGeographicTerrainCutout: () => unprojectGeographicTerrainCutout,
210
228
  unprojectGrid: () => unprojectGrid,
211
229
  updateTerrainBounds: () => updateTerrainBounds,
212
230
  updateTerrainBoundsRegions: () => updateTerrainBoundsRegions,
@@ -220,6 +238,7 @@ __export(index_exports, {
220
238
  updateTerrainMixedVertexTileHalos: () => updateTerrainMixedVertexTileHalos,
221
239
  updateTerrainPersistentBounds: () => updateTerrainPersistentBounds,
222
240
  updateTerrainPersistentGradients: () => updateTerrainPersistentGradients,
241
+ updateTerrainTileCutouts: () => updateTerrainTileCutouts,
223
242
  updateTerrainValidDomainMeshRegions: () => updateTerrainValidDomainMeshRegions,
224
243
  updateTerrainVertexTileHalos: () => updateTerrainVertexTileHalos,
225
244
  validateTileMatrix: () => validateTileMatrix,
@@ -286,9 +305,9 @@ function fromCartographic(cartographic, result = [], map = identity) {
286
305
  function fromCartographicToRadians(cartographic, vector2 = []) {
287
306
  return fromCartographic(cartographic, vector2, import_core.config._cartographicRadians ? identity : import_core.toRadians);
288
307
  }
289
- function toCartographicFromRadiansComponents(longitude, latitude, height, cartographic) {
308
+ function toCartographicFromRadiansComponents(longitude, latitude2, height, cartographic) {
290
309
  const map = import_core.config._cartographicRadians ? identity : import_core.toDegrees;
291
- const mappedLongitude = map(longitude), mappedLatitude = map(latitude);
310
+ const mappedLongitude = map(longitude), mappedLatitude = map(latitude2);
292
311
  if ("longitude" in cartographic) {
293
312
  cartographic.longitude = mappedLongitude;
294
313
  cartographic.latitude = mappedLatitude;
@@ -606,12 +625,12 @@ var Ellipsoid = class _Ellipsoid {
606
625
  }
607
626
  cartographicToCartesian(cartographic, result = [0, 0, 0]) {
608
627
  const llh = fromCartographicToRadians(cartographic, scratchCartesian);
609
- const longitude = llh[0], latitude = llh[1], height = llh[2];
610
- if (!Number.isFinite(longitude) || !Number.isFinite(latitude) || !Number.isFinite(height) || !(this.minimumRadius > 0) || !Number.isFinite(this.maximumRadius * this.maximumRadius))
628
+ const longitude = llh[0], latitude2 = llh[1], height = llh[2];
629
+ if (!Number.isFinite(longitude) || !Number.isFinite(latitude2) || !Number.isFinite(height) || !(this.minimumRadius > 0) || !Number.isFinite(this.maximumRadius * this.maximumRadius))
611
630
  return void 0;
612
- if (this.spheroidGeometry && (import_core3.config._cartographicRadians || Math.abs(latitude) <= Math.PI / 4)) {
631
+ if (this.spheroidGeometry && (import_core3.config._cartographicRadians || Math.abs(latitude2) <= Math.PI / 4)) {
613
632
  spheroidScratch.x = longitude;
614
- spheroidScratch.y = latitude;
633
+ spheroidScratch.y = latitude2;
615
634
  spheroidScratch.z = height;
616
635
  if (!(0, import_core4.spheroidToCartesian)(spheroidScratch, this.spheroidGeometry))
617
636
  return void 0;
@@ -662,9 +681,9 @@ var Ellipsoid = class _Ellipsoid {
662
681
  return void 0;
663
682
  const nx = gx / length, ny = gy / length, nz = gz / length;
664
683
  const longitude = Math.atan2(ny, nx);
665
- const latitude = Math.atan2(nz, Math.hypot(nx, ny));
684
+ const latitude2 = Math.atan2(nz, Math.hypot(nx, ny));
666
685
  const height = (x - point2[0]) * nx + (y - point2[1]) * ny + (z - point2[2]) * nz;
667
- return toCartographicFromRadiansComponents(longitude, latitude, height, result);
686
+ return toCartographicFromRadiansComponents(longitude, latitude2, height, result);
668
687
  }
669
688
  geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {
670
689
  fromCartographic(cartesian, scratchVector2);
@@ -674,11 +693,11 @@ var Ellipsoid = class _Ellipsoid {
674
693
  geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {
675
694
  const point2 = fromCartographic(cartographic, scratchCartesian);
676
695
  const longitude = import_core3.config._cartographicRadians ? point2[0] : point2[0] * Math.PI / 180;
677
- const latitude = import_core3.config._cartographicRadians ? point2[1] : point2[1] * Math.PI / 180;
696
+ const latitude2 = import_core3.config._cartographicRadians ? point2[1] : point2[1] * Math.PI / 180;
678
697
  const polarDegrees = !import_core3.config._cartographicRadians && Math.abs(point2[1]) > 45;
679
698
  const complement = (90 - Math.abs(point2[1])) * Math.PI / 180;
680
- const cosLatitude = polarDegrees ? Math.sin(complement) : Math.abs(latitude) === Math.PI / 2 ? 0 : Math.cos(latitude);
681
- const sinLatitude = polarDegrees ? Math.sign(point2[1]) * Math.cos(complement) : Math.sin(latitude);
699
+ const cosLatitude = polarDegrees ? Math.sin(complement) : Math.abs(latitude2) === Math.PI / 2 ? 0 : Math.cos(latitude2);
700
+ const sinLatitude = polarDegrees ? Math.sign(point2[1]) * Math.cos(complement) : Math.sin(latitude2);
682
701
  return normalResult(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), sinLatitude, result);
683
702
  }
684
703
  geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {
@@ -1082,10 +1101,10 @@ geodesic.Accumulator = {};
1082
1101
  return Math.abs(x) * (y < 0 || y === 0 && 1 / y < 0 ? -1 : 1);
1083
1102
  };
1084
1103
  m.sum = function(u, v) {
1085
- var s = u + v, up = s - v, vpp = s - up, t;
1086
- up -= u;
1104
+ var s = u + v, up2 = s - v, vpp = s - up2, t;
1105
+ up2 -= u;
1087
1106
  vpp -= v;
1088
- t = s ? 0 - (up + vpp) : s;
1107
+ t = s ? 0 - (up2 + vpp) : s;
1089
1108
  return { s, t };
1090
1109
  };
1091
1110
  m.polyval = function(N, p, s, x) {
@@ -2432,17 +2451,17 @@ var EllipsoidGeodesic = class {
2432
2451
  validatePoint(lat2, lon2);
2433
2452
  return this.engine.Inverse(lat1, lon1, lat2, lon2, outputMask(options));
2434
2453
  }
2435
- direct(latitude, longitude, azimuth, distance, options = {}) {
2436
- return this.line(latitude, longitude, azimuth, options).position(distance);
2454
+ direct(latitude2, longitude, azimuth, distance, options = {}) {
2455
+ return this.line(latitude2, longitude, azimuth, options).position(distance);
2437
2456
  }
2438
- arcDirect(latitude, longitude, azimuth, arc, options = {}) {
2439
- return this.line(latitude, longitude, azimuth, options).arcPosition(arc);
2457
+ arcDirect(latitude2, longitude, azimuth, arc, options = {}) {
2458
+ return this.line(latitude2, longitude, azimuth, options).arcPosition(arc);
2440
2459
  }
2441
- line(latitude, longitude, azimuth, options = {}) {
2442
- validatePoint(latitude, longitude);
2460
+ line(latitude2, longitude, azimuth, options = {}) {
2461
+ validatePoint(latitude2, longitude);
2443
2462
  validateFinite(azimuth);
2444
2463
  const selectedMask = outputMask(options);
2445
- const line = this.engine.Line(latitude, longitude, azimuth, selectedMask | library.DISTANCE_IN);
2464
+ const line = this.engine.Line(latitude2, longitude, azimuth, selectedMask | library.DISTANCE_IN);
2446
2465
  return {
2447
2466
  // Fourth argument is an internal result request; ordinary Array.map arguments remain ignored.
2448
2467
  position(distance, _index, _array, output2) {
@@ -2456,8 +2475,8 @@ var EllipsoidGeodesic = class {
2456
2475
  };
2457
2476
  }
2458
2477
  };
2459
- function validatePoint(latitude, longitude) {
2460
- if (!(Number.isFinite(latitude) && Math.abs(latitude) <= 90 && Number.isFinite(longitude))) {
2478
+ function validatePoint(latitude2, longitude) {
2479
+ if (!(Number.isFinite(latitude2) && Math.abs(latitude2) <= 90 && Number.isFinite(longitude))) {
2461
2480
  throw new Error("Invalid geodesic coordinates");
2462
2481
  }
2463
2482
  }
@@ -2715,36 +2734,36 @@ var EllipsoidMetrics = class {
2715
2734
  }
2716
2735
  Object.freeze(this);
2717
2736
  }
2718
- meridianDistance(latitude) {
2719
- validateLatitude(latitude);
2720
- return Math.sign(latitude) * this.semiMajorAxis * this.meridian(Math.abs(latitude));
2737
+ meridianDistance(latitude2) {
2738
+ validateLatitude(latitude2);
2739
+ return Math.sign(latitude2) * this.semiMajorAxis * this.meridian(Math.abs(latitude2));
2721
2740
  }
2722
- meridionalCurvatureRadius(latitude) {
2723
- validateLatitude(latitude);
2724
- return this.semiMajorAxis * this.meridianIntegrand(latitude * DEG);
2741
+ meridionalCurvatureRadius(latitude2) {
2742
+ validateLatitude(latitude2);
2743
+ return this.semiMajorAxis * this.meridianIntegrand(latitude2 * DEG);
2725
2744
  }
2726
- transverseCurvatureRadius(latitude) {
2727
- validateLatitude(latitude);
2728
- const [s, c] = sincos(latitude);
2745
+ transverseCurvatureRadius(latitude2) {
2746
+ validateLatitude(latitude2);
2747
+ const [s, c] = sincos(latitude2);
2729
2748
  return this.semiMajorAxis / Math.hypot(c, this.ratio * s);
2730
2749
  }
2731
- normalCurvatureRadius(latitude, azimuth) {
2750
+ normalCurvatureRadius(latitude2, azimuth) {
2732
2751
  if (!Number.isFinite(azimuth))
2733
2752
  throw new Error("Azimuth must be finite");
2734
2753
  const [s, c] = sincos(azimuth % 180);
2735
- return 1 / (c * c / this.meridionalCurvatureRadius(latitude) + s * s / this.transverseCurvatureRadius(latitude));
2754
+ return 1 / (c * c / this.meridionalCurvatureRadius(latitude2) + s * s / this.transverseCurvatureRadius(latitude2));
2736
2755
  }
2737
- latitudeToAuxiliary(latitude, kind) {
2756
+ latitudeToAuxiliary(latitude2, kind) {
2738
2757
  validateKind(kind);
2739
- validateLatitude(latitude);
2740
- if (latitude === 0)
2741
- return latitude;
2742
- if (Math.abs(latitude) === 90)
2743
- return kind === "isometric" ? Math.sign(latitude) * Infinity : latitude;
2758
+ validateLatitude(latitude2);
2759
+ if (latitude2 === 0)
2760
+ return latitude2;
2761
+ if (Math.abs(latitude2) === 90)
2762
+ return kind === "isometric" ? Math.sign(latitude2) * Infinity : latitude2;
2744
2763
  if (this.ratio === 1 && kind !== "isometric")
2745
- return latitude;
2746
- const sign2 = Math.sign(latitude);
2747
- const phi = Math.abs(latitude);
2764
+ return latitude2;
2765
+ const sign2 = Math.sign(latitude2);
2766
+ const phi = Math.abs(latitude2);
2748
2767
  const [s, c] = sincos(phi);
2749
2768
  switch (kind) {
2750
2769
  case "geocentric":
@@ -2771,21 +2790,21 @@ var EllipsoidMetrics = class {
2771
2790
  }
2772
2791
  }
2773
2792
  }
2774
- latitudeFromAuxiliary(latitude, kind) {
2793
+ latitudeFromAuxiliary(latitude2, kind) {
2775
2794
  validateKind(kind);
2776
- if (kind === "isometric" && Math.abs(latitude) === Infinity)
2777
- return Math.sign(latitude) * 90;
2795
+ if (kind === "isometric" && Math.abs(latitude2) === Infinity)
2796
+ return Math.sign(latitude2) * 90;
2778
2797
  if (kind !== "isometric")
2779
- validateLatitude(latitude);
2780
- else if (!Number.isFinite(latitude))
2798
+ validateLatitude(latitude2);
2799
+ else if (!Number.isFinite(latitude2))
2781
2800
  throw new Error("Isometric latitude must be finite or a pole infinity");
2782
- if (latitude === 0)
2783
- return latitude;
2784
- if (kind !== "isometric" && Math.abs(latitude) === 90)
2785
- return latitude;
2801
+ if (latitude2 === 0)
2802
+ return latitude2;
2803
+ if (kind !== "isometric" && Math.abs(latitude2) === 90)
2804
+ return latitude2;
2786
2805
  if (this.ratio === 1 && kind !== "isometric")
2787
- return latitude;
2788
- const sign2 = Math.sign(latitude), target = Math.abs(latitude);
2806
+ return latitude2;
2807
+ const sign2 = Math.sign(latitude2), target = Math.abs(latitude2);
2789
2808
  if (kind === "geocentric" || kind === "parametric") {
2790
2809
  const [s, c] = sincos(target);
2791
2810
  return sign2 * angle(s, c * (kind === "geocentric" ? this.ratio ** 2 : this.ratio));
@@ -2872,12 +2891,12 @@ var SurfacePolygon = class {
2872
2891
  this.area = new Accumulator();
2873
2892
  return this;
2874
2893
  }
2875
- addPoint(latitude, longitude, options = {}) {
2876
- if (!(Number.isFinite(latitude) && Math.abs(latitude) <= 90 && Number.isFinite(longitude))) {
2894
+ addPoint(latitude2, longitude, options = {}) {
2895
+ if (!(Number.isFinite(latitude2) && Math.abs(latitude2) <= 90 && Number.isFinite(longitude))) {
2877
2896
  throw new Error("Polygon point requires finite longitude and latitude in [-90, 90]");
2878
2897
  }
2879
2898
  if (this.count) {
2880
- const edge2 = this.geodesic.inverse(this.lastLat, this.lastLon, latitude, longitude, {
2899
+ const edge2 = this.geodesic.inverse(this.lastLat, this.lastLon, latitude2, longitude, {
2881
2900
  area: !this.polyline,
2882
2901
  longitudeTurns: options.longitudeTurns,
2883
2902
  unrollLongitude: Boolean(options.longitudeTurns)
@@ -2887,10 +2906,10 @@ var SurfacePolygon = class {
2887
2906
  this.crossings = (this.crossings + (options.longitudeTurns ? transitDirect(this.lastLon, edge2.lon2) : transit(this.lastLon, longitude))) % 2;
2888
2907
  }
2889
2908
  } else {
2890
- this.firstLat = latitude;
2909
+ this.firstLat = latitude2;
2891
2910
  this.firstLon = longitude;
2892
2911
  }
2893
- this.lastLat = latitude;
2912
+ this.lastLat = latitude2;
2894
2913
  this.lastLon = longitude;
2895
2914
  ++this.count;
2896
2915
  return this;
@@ -2944,8 +2963,8 @@ var SurfacePolygon = class {
2944
2963
  return { number: this.count, perimeter: this.perimeter.Sum(edge2.s12), area: 0 + total.Sum() };
2945
2964
  }
2946
2965
  /** Nonmutating preview, with the same compensated arithmetic as insertion. */
2947
- testPoint(latitude, longitude, options = {}) {
2948
- return this.copy().addPoint(latitude, longitude, options).compute(options);
2966
+ testPoint(latitude2, longitude, options = {}) {
2967
+ return this.copy().addPoint(latitude2, longitude, options).compute(options);
2949
2968
  }
2950
2969
  testEdge(azimuth, distance, options = {}) {
2951
2970
  return this.copy().addEdge(azimuth, distance).compute(options);
@@ -2983,8 +3002,8 @@ var GeodesicPolygon = class extends SurfacePolygon {
2983
3002
  constructor(parameters, options = {}) {
2984
3003
  super(new EllipsoidGeodesic(parameters), options);
2985
3004
  }
2986
- addPoint(latitude, longitude) {
2987
- return super.addPoint(latitude, longitude);
3005
+ addPoint(latitude2, longitude) {
3006
+ return super.addPoint(latitude2, longitude);
2988
3007
  }
2989
3008
  };
2990
3009
 
@@ -3015,13 +3034,13 @@ function sc(x) {
3015
3034
  }
3016
3035
  return [s, c];
3017
3036
  }
3018
- function remainingPoleDistance(a, b, latitude, azimuth, distance, sign2) {
3037
+ function remainingPoleDistance(a, b, latitude2, azimuth, distance, sign2) {
3019
3038
  const unit3 = 2 ** Math.floor(Math.log2(a));
3020
3039
  a /= unit3;
3021
3040
  b /= unit3;
3022
3041
  distance /= unit3;
3023
3042
  const ratio2 = div(exact(b), exact(a));
3024
- const theta = mul(90n * Q - BigInt(sign2) * exact(latitude), PI) / 180n;
3043
+ const theta = mul(90n * Q - BigInt(sign2) * exact(latitude2), PI) / 180n;
3025
3044
  const [s, c] = sc(theta), prolate = ratio2 > Q;
3026
3045
  const square = mul(ratio2, ratio2);
3027
3046
  const k = prolate ? Q - div(Q, square) : Q - square;
@@ -3093,11 +3112,11 @@ var EllipsoidRhumb = class {
3093
3112
  throw new RangeError("Unrepresentable rhumb distance");
3094
3113
  return result;
3095
3114
  }
3096
- direct(latitude, longitude, azimuth, distance, options = {}) {
3097
- return this.line(latitude, longitude, azimuth, options).position(distance);
3115
+ direct(latitude2, longitude, azimuth, distance, options = {}) {
3116
+ return this.line(latitude2, longitude, azimuth, options).position(distance);
3098
3117
  }
3099
- line(latitude, longitude, azimuth, options = {}) {
3100
- validateRhumbPoint(latitude, longitude);
3118
+ line(latitude2, longitude, azimuth, options = {}) {
3119
+ validateRhumbPoint(latitude2, longitude);
3101
3120
  if (!Number.isFinite(azimuth))
3102
3121
  throw new RangeError("Rhumb azimuth must be finite");
3103
3122
  const [sa, ca] = sincosDegrees(azimuth);
@@ -3112,26 +3131,26 @@ var EllipsoidRhumb = class {
3112
3131
  const north = delta * ca;
3113
3132
  let poleDistance;
3114
3133
  if (north !== 0) {
3115
- const gap = north > 0 ? this.meridianDelta(latitude, 90) : this.meridianDelta(-90, latitude);
3134
+ const gap = north > 0 ? this.meridianDelta(latitude2, 90) : this.meridianDelta(-90, latitude2);
3116
3135
  poleDistance = gap - Math.abs(north);
3117
3136
  if (Math.abs(poleDistance) < 1e-4 * gap)
3118
- poleDistance = remainingPoleDistance(this.a, this.b, latitude, azimuth, distance, Math.sign(north));
3137
+ poleDistance = remainingPoleDistance(this.a, this.b, latitude2, azimuth, distance, Math.sign(north));
3119
3138
  if (poleDistance < 0)
3120
3139
  throw new RhumbDomainError("pole-crossing");
3121
3140
  if (poleDistance === 0)
3122
3141
  throw new RhumbDomainError("pole");
3123
3142
  }
3124
- const polar = north === 0 ? void 0 : this.polarEndpoint(latitude, north, poleDistance);
3125
- const lat2 = north === 0 ? latitude : (polar == null ? void 0 : polar.latitude) ?? this.inverseMeridian(latitude, north);
3143
+ const polar = north === 0 ? void 0 : this.polarEndpoint(latitude2, north, poleDistance);
3144
+ const lat2 = north === 0 ? latitude2 : (polar == null ? void 0 : polar.latitude) ?? this.inverseMeridian(latitude2, north);
3126
3145
  if (Math.abs(lat2) === 90)
3127
3146
  throw new RhumbDomainError("pole");
3128
- const [meanM, meanP] = (polar == null ? void 0 : polar.means) ?? this.means(latitude, lat2);
3147
+ const [meanM, meanP] = (polar == null ? void 0 : polar.means) ?? this.means(latitude2, lat2);
3129
3148
  const dlon = delta * sa * meanP / meanM / DEG2;
3130
3149
  const lon2 = unroll ? longitude + dlon : normalize(normalize(longitude) + dlon);
3131
3150
  if (!Number.isFinite(lon2))
3132
3151
  throw new RangeError("Unrepresentable rhumb longitude");
3133
3152
  const result = output2 ?? {};
3134
- result.lat1 = latitude;
3153
+ result.lat1 = latitude2;
3135
3154
  result.lon1 = longitude;
3136
3155
  result.lat2 = lat2;
3137
3156
  result.lon2 = lon2;
@@ -3140,7 +3159,7 @@ var EllipsoidRhumb = class {
3140
3159
  if (!area)
3141
3160
  delete result.S12;
3142
3161
  if (area)
3143
- result.S12 = this.area(latitude, lat2, dlon * DEG2, polar == null ? void 0 : polar.psi);
3162
+ result.S12 = this.area(latitude2, lat2, dlon * DEG2, polar == null ? void 0 : polar.psi);
3144
3163
  return result;
3145
3164
  };
3146
3165
  return { position: evaluate2 };
@@ -3156,14 +3175,14 @@ var EllipsoidRhumb = class {
3156
3175
  }, -1, 1) / 2 : (this.psi(lat2) - this.psi(lat1)) / d;
3157
3176
  return [meanM, meanP];
3158
3177
  }
3159
- psi(latitude) {
3160
- return this.metrics.latitudeToAuxiliary(latitude, "isometric") * DEG2;
3178
+ psi(latitude2) {
3179
+ return this.metrics.latitudeToAuxiliary(latitude2, "isometric") * DEG2;
3161
3180
  }
3162
- polarEndpoint(latitude, north, poleDistance) {
3163
- const sign2 = Math.abs(latitude) > 80 && Math.abs(north) < Math.abs(this.meridianDelta(0, latitude)) ? Math.sign(latitude) : Math.sign(north), theta1 = (90 - sign2 * latitude) * DEG2, limit = 10 * DEG2;
3181
+ polarEndpoint(latitude2, north, poleDistance) {
3182
+ const sign2 = Math.abs(latitude2) > 80 && Math.abs(north) < Math.abs(this.meridianDelta(0, latitude2)) ? Math.sign(latitude2) : Math.sign(north), theta1 = (90 - sign2 * latitude2) * DEG2, limit = 10 * DEG2;
3164
3183
  const density = (theta2) => this.r ** 2 / Math.hypot(Math.sin(theta2), this.r * Math.cos(theta2)) ** 3;
3165
3184
  const gap = (theta2) => integrate(density, 0, theta2);
3166
- const target = sign2 === Math.sign(north) ? poleDistance : this.meridianDelta(sign2 > 0 ? latitude : -90, sign2 > 0 ? 90 : latitude) - sign2 * north;
3185
+ const target = sign2 === Math.sign(north) ? poleDistance : this.meridianDelta(sign2 > 0 ? latitude2 : -90, sign2 > 0 ? 90 : latitude2) - sign2 * north;
3167
3186
  if (!(target > 0 && target < gap(limit)))
3168
3187
  return void 0;
3169
3188
  let lo = 0, hi = limit, theta = target * this.r;
@@ -3259,8 +3278,8 @@ var EllipsoidRhumb = class {
3259
3278
  }
3260
3279
  throw new Error("Rhumb isometric inversion did not converge");
3261
3280
  }
3262
- potential(latitude) {
3263
- const [s, c] = latitudeSinCos(latitude), e2 = (1 - this.r) * (1 + this.r), e = Math.sqrt(Math.abs(e2));
3281
+ potential(latitude2) {
3282
+ const [s, c] = latitudeSinCos(latitude2), e2 = (1 - this.r) * (1 + this.r), e = Math.sqrt(Math.abs(e2));
3264
3283
  const I = e === 0 ? s : (e2 > 0 ? Math.atanh(e * s) : Math.atan(e * s)) / e;
3265
3284
  return this.r ** 2 * (s / (c * c + (this.r * s) ** 2) + I) / 2;
3266
3285
  }
@@ -3284,10 +3303,10 @@ var EllipsoidRhumb = class {
3284
3303
  return value3;
3285
3304
  }
3286
3305
  };
3287
- function validateRhumbPoint(latitude, longitude) {
3288
- if (!(Number.isFinite(latitude) && Math.abs(latitude) <= 90 && Number.isFinite(longitude)))
3306
+ function validateRhumbPoint(latitude2, longitude) {
3307
+ if (!(Number.isFinite(latitude2) && Math.abs(latitude2) <= 90 && Number.isFinite(longitude)))
3289
3308
  throw new RangeError("Rhumb coordinates require finite longitude and latitude in [-90,90]");
3290
- if (Math.abs(latitude) === 90)
3309
+ if (Math.abs(latitude2) === 90)
3291
3310
  throw new RhumbDomainError("pole");
3292
3311
  }
3293
3312
  function latitudeSinCos(phi) {
@@ -3333,11 +3352,11 @@ var RhumbPolygon = class extends SurfacePolygon {
3333
3352
  constructor(parameters, options = {}) {
3334
3353
  super(new EllipsoidRhumb(parameters), options);
3335
3354
  }
3336
- addPoint(latitude, longitude, options = {}) {
3337
- validateRhumbPoint(latitude, longitude);
3355
+ addPoint(latitude2, longitude, options = {}) {
3356
+ validateRhumbPoint(latitude2, longitude);
3338
3357
  if (!Number.isSafeInteger(options.longitudeTurns ?? 0))
3339
3358
  throw new RangeError("Rhumb longitudeTurns must be a safe integer");
3340
- return super.addPoint(latitude, longitude, options);
3359
+ return super.addPoint(latitude2, longitude, options);
3341
3360
  }
3342
3361
  };
3343
3362
 
@@ -3370,8 +3389,8 @@ var IntersectionBounds = class {
3370
3389
  }
3371
3390
  throw new Error("Conjugate distance did not converge");
3372
3391
  }
3373
- polarDistance(latitude, ratio2) {
3374
- return this.conjugate(this.solver.line(latitude, 0, 0), (1 + (1 - ratio2) / 2) * Math.PI / 2, true);
3392
+ polarDistance(latitude2, ratio2) {
3393
+ return this.conjugate(this.solver.line(latitude2, 0, 0), (1 + (1 - ratio2) / 2) * Math.PI / 2, true);
3375
3394
  }
3376
3395
  polarMinimum(ratio2) {
3377
3396
  let lat0 = 63, lat1 = 65, lat2 = 64;
@@ -3438,7 +3457,7 @@ var GeodesicIntersections = class {
3438
3457
  seeds.push([x + spacing * (i + j) / 2, y + spacing * (i - j) / 2, spacing, 0]);
3439
3458
  let failed = 0, unresolved = 0;
3440
3459
  const isolated = [], lines = [];
3441
- const equal = (p, q) => Math.abs(p.x - q.x) + Math.abs(p.y - q.y) <= this.bounds.margin;
3460
+ const equal2 = (p, q) => Math.abs(p.x - q.x) + Math.abs(p.y - q.y) <= this.bounds.margin;
3442
3461
  const canonical = (p, c) => {
3443
3462
  const shift2 = (x + c * y - (p.x + c * p.y)) / 2;
3444
3463
  return { ...p, x: p.x + shift2, y: p.y + c * shift2, c };
@@ -3470,14 +3489,14 @@ var GeodesicIntersections = class {
3470
3489
  retry(seed);
3471
3490
  continue;
3472
3491
  }
3473
- if (!lines.some((p) => p.c === q.c && equal(p, q)))
3492
+ if (!lines.some((p) => p.c === q.c && equal2(p, q)))
3474
3493
  lines.push(q);
3475
- } else if (!isolated.some((p) => equal(p, root2)))
3494
+ } else if (!isolated.some((p) => equal2(p, root2)))
3476
3495
  isolated.push(root2);
3477
3496
  }
3478
3497
  const roots2 = [], coincidences = [];
3479
3498
  for (const p of isolated) {
3480
- if (lines.some((q) => equal(canonical(p, q.c), q)))
3499
+ if (lines.some((q) => equal2(canonical(p, q.c), q)))
3481
3500
  continue;
3482
3501
  if (Math.abs(p.x - x) + Math.abs(p.y - y) > d + this.tolerance)
3483
3502
  continue;
@@ -3533,13 +3552,13 @@ var GeodesicIntersections = class {
3533
3552
  /** Global next crossing, excluding the shared parameter origin. For a
3534
3553
  * coincident continuum use GeographicLib's nearest-conjugate convention.
3535
3554
  */
3536
- next(latitude, longitude, azimuthA, azimuthB, maxDistance) {
3537
- const a = { latitude, longitude, azimuth: azimuthA }, b = { latitude, longitude, azimuth: azimuthB };
3555
+ next(latitude2, longitude, azimuthA, azimuthB, maxDistance) {
3556
+ const a = { latitude: latitude2, longitude, azimuth: azimuthA }, b = { latitude: latitude2, longitude, azimuth: azimuthB };
3538
3557
  const bound = maxDistance === void 0 ? 4 * this.bounds.halfCircumference : maxDistance / this.a;
3539
3558
  const search = this.search(a, b, { maxDistance: maxDistance ?? bound }, maxDistance === void 0);
3540
3559
  search.intersections = search.intersections.filter((p) => Math.abs(p.s / this.a) + Math.abs(p.t / this.a) > this.bounds.margin);
3541
3560
  const candidates = [...search.intersections];
3542
- const A3 = this.solver.line(latitude, longitude, azimuthA);
3561
+ const A3 = this.solver.line(latitude2, longitude, azimuthA);
3543
3562
  for (const c of search.coincidences) {
3544
3563
  if (Math.abs(c.s / this.a) + Math.abs(c.t / this.a) > this.bounds.margin) {
3545
3564
  const point2 = this.coincidencePoint(a, b, c);
@@ -3835,24 +3854,24 @@ var GeodesicPath = class {
3835
3854
  if (result.length !== this.size)
3836
3855
  throw new RangeError("Invalid geodesic sample output length");
3837
3856
  let longitude;
3838
- let latitude;
3857
+ let latitude2;
3839
3858
  if (fraction === 0 || this.length === 0) {
3840
3859
  longitude = this.first[0];
3841
- latitude = this.first[1];
3860
+ latitude2 = this.first[1];
3842
3861
  } else if (fraction === 1) {
3843
3862
  longitude = this.last[0];
3844
- latitude = this.last[1];
3863
+ latitude2 = this.last[1];
3845
3864
  } else {
3846
3865
  const value3 = this.line.position(this.length * fraction);
3847
3866
  longitude = value3.lon2;
3848
- latitude = value3.lat2;
3867
+ latitude2 = value3.lat2;
3849
3868
  }
3850
3869
  const height = this.size === 3 ? this.first[2] * (1 - fraction) + this.last[2] * fraction : 0;
3851
- if (![longitude, latitude, height].every(Number.isFinite) || result instanceof Float32Array && ![longitude, latitude, height].every((value3) => Number.isFinite(Math.fround(value3)))) {
3870
+ if (![longitude, latitude2, height].every(Number.isFinite) || result instanceof Float32Array && ![longitude, latitude2, height].every((value3) => Number.isFinite(Math.fround(value3)))) {
3852
3871
  throw new RangeError("Unrepresentable geodesic sample");
3853
3872
  }
3854
3873
  result[0] = longitude;
3855
- result[1] = latitude;
3874
+ result[1] = latitude2;
3856
3875
  if (this.size === 3)
3857
3876
  result[2] = height;
3858
3877
  return result;
@@ -3930,21 +3949,21 @@ var RhumbPath = class {
3930
3949
  throw new RangeError("Rhumb fraction must be in [0, 1]");
3931
3950
  if (result.length !== this.size || ArrayBuffer.isView(result) && !(result instanceof Float32Array) && !(result instanceof Float64Array))
3932
3951
  throw new RangeError("Expected a floating rhumb output with matching dimensions");
3933
- let longitude = this.first[0], latitude = this.first[1];
3952
+ let longitude = this.first[0], latitude2 = this.first[1];
3934
3953
  if (fraction === 1) {
3935
3954
  longitude = this.last[0];
3936
- latitude = this.last[1];
3955
+ latitude2 = this.last[1];
3937
3956
  } else if (fraction !== 0 && this.length !== 0) {
3938
3957
  const p = this.line.position(this.length * fraction);
3939
3958
  longitude = p.lon2;
3940
- latitude = p.lat2;
3959
+ latitude2 = p.lat2;
3941
3960
  }
3942
3961
  const height = this.size === 3 ? this.first[2] * (1 - fraction) + this.last[2] * fraction : 0;
3943
- const values = [longitude, latitude, height];
3962
+ const values = [longitude, latitude2, height];
3944
3963
  if (!values.every(Number.isFinite) || result instanceof Float32Array && !values.every((x) => Number.isFinite(Math.fround(x))))
3945
3964
  throw new RangeError("Unrepresentable rhumb sample");
3946
3965
  result[0] = longitude;
3947
- result[1] = latitude;
3966
+ result[1] = latitude2;
3948
3967
  if (this.size === 3)
3949
3968
  result[2] = height;
3950
3969
  return result;
@@ -4035,16 +4054,16 @@ function localFrameToFixedFrame(ellipsoid, firstAxis, secondAxis, thirdAxis, car
4035
4054
  const atPole = Math.abs(origin.x) <= poleTolerance && Math.abs(origin.y) <= poleTolerance;
4036
4055
  const radii = ellipsoid.radii;
4037
4056
  if (radii.x === radii.y && radii.x > 0 && radii.z > 0 && radii.z <= radii.x && (!atPole || origin.z !== 0)) {
4038
- const { east, up } = scratchAxisVectors;
4057
+ const { east, up: up2 } = scratchAxisVectors;
4039
4058
  if (atPole) {
4040
4059
  east.set(0, 1, 0);
4041
- up.set(0, 0, Math.sign(origin.z));
4060
+ up2.set(0, 0, Math.sign(origin.z));
4042
4061
  } else {
4043
4062
  const scale3 = Math.max(Math.abs(origin.x), Math.abs(origin.y));
4044
4063
  east.set(-origin.y / scale3, origin.x / scale3, 0).normalize();
4045
- ellipsoid.geodeticSurfaceNormal(origin, up);
4064
+ ellipsoid.geodeticSurfaceNormal(origin, up2);
4046
4065
  }
4047
- if (!(0, import_core9.eastNorthUpBasisFromDirections)(east, up, scratchBasis) || !(0, import_core9.localFrameToMatrix)(scratchBasis, origin, firstAxis, secondAxis, thirdAxis, result))
4066
+ if (!(0, import_core9.eastNorthUpBasisFromDirections)(east, up2, scratchBasis) || !(0, import_core9.localFrameToMatrix)(scratchBasis, origin, firstAxis, secondAxis, thirdAxis, result))
4048
4067
  throw new Error("Unsupported local frame");
4049
4068
  return result;
4050
4069
  }
@@ -4063,13 +4082,13 @@ function localFrameToFixedFrame(ellipsoid, firstAxis, secondAxis, thirdAxis, car
4063
4082
  thirdAxisVector.scale(sign2);
4064
4083
  }
4065
4084
  } else {
4066
- const { up, east, north } = scratchAxisVectors;
4085
+ const { up: up2, east, north } = scratchAxisVectors;
4067
4086
  const scale3 = Math.max(Math.abs(origin.x), Math.abs(origin.y));
4068
4087
  east.set(-origin.y / scale3, origin.x / scale3, 0).normalize();
4069
- ellipsoid.geodeticSurfaceNormal(origin, up);
4070
- north.copy(up).cross(east);
4071
- const { down, west, south } = scratchAxisVectors;
4072
- down.copy(up).scale(-1);
4088
+ ellipsoid.geodeticSurfaceNormal(origin, up2);
4089
+ north.copy(up2).cross(east);
4090
+ const { down: down2, west, south } = scratchAxisVectors;
4091
+ down2.copy(up2).scale(-1);
4073
4092
  west.copy(east).scale(-1);
4074
4093
  south.copy(north).scale(-1);
4075
4094
  firstAxisVector = scratchAxisVectors[firstAxis];
@@ -4140,9 +4159,9 @@ var LngLatRectangle = class {
4140
4159
  east += import_core11._MathUtils.TWO_PI;
4141
4160
  }
4142
4161
  const longitude = (0, import_core11.normalizeAngle)((west + east) * 0.5, "negative-pi-to-pi");
4143
- const latitude = (rectangle.south + rectangle.north) * 0.5;
4162
+ const latitude2 = (rectangle.south + rectangle.north) * 0.5;
4144
4163
  result.x = longitude;
4145
- result.y = latitude;
4164
+ result.y = latitude2;
4146
4165
  result.z = 0;
4147
4166
  return result;
4148
4167
  }
@@ -4335,10 +4354,10 @@ function applyTransform(obb, transform) {
4335
4354
  obb.halfAxes = new import_core12.Matrix3().set(halfSize.x, 0, 0, 0, halfSize.y, 0, 0, 0, halfSize.z);
4336
4355
  return obb;
4337
4356
  }
4338
- function latitudeZExtent(ellipsoid, latitude, height, maximum) {
4357
+ function latitudeZExtent(ellipsoid, latitude2, height, maximum) {
4339
4358
  let extent = maximum ? -Infinity : Infinity;
4340
4359
  for (const longitude of [0, 90, 180, 270]) {
4341
- const z = ellipsoid.cartographicToCartesian([longitude, latitude, height], scratchMaxY).z;
4360
+ const z = ellipsoid.cartographicToCartesian([longitude, latitude2, height], scratchMaxY).z;
4342
4361
  extent = maximum ? Math.max(extent, z) : Math.min(extent, z);
4343
4362
  }
4344
4363
  return extent;
@@ -4479,16 +4498,16 @@ function getGlobeHorizonBounds(camera, radius) {
4479
4498
  throw new RangeError("Camera magnitude must be finite");
4480
4499
  if (distance <= radius)
4481
4500
  return void 0;
4482
- const latitude = Math.atan2(camera[2], Math.hypot(camera[0], camera[1]));
4501
+ const latitude2 = Math.atan2(camera[2], Math.hypot(camera[0], camera[1]));
4483
4502
  const longitude = Math.atan2(camera[1], camera[0]);
4484
4503
  const angle3 = Math.acos(radius / distance);
4485
4504
  const degrees2 = 180 / Math.PI;
4486
4505
  const padding = 1e-10;
4487
- const south = Math.max(-90, (latitude - angle3) * degrees2 - padding);
4488
- const north = Math.min(90, (latitude + angle3) * degrees2 + padding);
4489
- if (Math.abs(latitude) + angle3 >= Math.PI / 2 - 1e-12)
4506
+ const south = Math.max(-90, (latitude2 - angle3) * degrees2 - padding);
4507
+ const north = Math.min(90, (latitude2 + angle3) * degrees2 + padding);
4508
+ if (Math.abs(latitude2) + angle3 >= Math.PI / 2 - 1e-12)
4490
4509
  return [-180, south, 180, north];
4491
- const extent = Math.asin(Math.min(1, Math.sin(angle3) / Math.cos(latitude))) * degrees2 + padding;
4510
+ const extent = Math.asin(Math.min(1, Math.sin(angle3) / Math.cos(latitude2))) * degrees2 + padding;
4492
4511
  return [wrap(longitude * degrees2 - extent), south, wrap(longitude * degrees2 + extent), north];
4493
4512
  }
4494
4513
  function splitGlobeBounds(bounds2) {
@@ -4845,11 +4864,11 @@ function createEdges(start, end, originalStart, edgeIndex, ringIndex, turns, con
4845
4864
  }
4846
4865
  const c1 = Math.cos(inverse4.azi1 * Math.PI / 180), c2 = Math.cos(inverse4.azi2 * Math.PI / 180);
4847
4866
  if (path.length > 0 && oppositeMeridians(originalStart[0], end[0]) && (inverse4.azi1 === 0 || Math.abs(inverse4.azi1) === 180) && Math.abs(first[1]) !== 90 && Math.abs(last[1]) !== 90) {
4848
- const latitude = c1 > 0 ? 90 : -90;
4867
+ const latitude2 = c1 > 0 ? 90 : -90;
4849
4868
  context.tick(2);
4850
- const fraction = solver.inverse(start[1], start[0], latitude, start[0]).s12 / path.length;
4851
- if (fraction > 0 && fraction < 1 && Math.abs(path.sample(fraction)[1] - latitude) < ANGULAR_TOLERANCE)
4852
- pole = { fraction, latitude };
4869
+ const fraction = solver.inverse(start[1], start[0], latitude2, start[0]).s12 / path.length;
4870
+ if (fraction > 0 && fraction < 1 && Math.abs(path.sample(fraction)[1] - latitude2) < ANGULAR_TOLERANCE)
4871
+ pole = { fraction, latitude: latitude2 };
4853
4872
  } else if (splitLatitude && c1 * c2 < 0 && path.length > 0) {
4854
4873
  context.tick();
4855
4874
  const line = solver.line(originalStart[1], originalStart[0], inverse4.azi1, {
@@ -4959,13 +4978,13 @@ function readLatitudeRange(value3) {
4959
4978
  }
4960
4979
  function clipLatitudeEdge(edge2, range, context) {
4961
4980
  const fractions = [0, 1], events = /* @__PURE__ */ new Map();
4962
- for (const latitude of range)
4963
- if (latitude > Math.min(edge2.a[1], edge2.b[1]) && latitude < Math.max(edge2.a[1], edge2.b[1])) {
4964
- const t = root(edge2, 1, latitude, context);
4965
- if (events.has(t) && events.get(t) !== latitude)
4981
+ for (const latitude2 of range)
4982
+ if (latitude2 > Math.min(edge2.a[1], edge2.b[1]) && latitude2 < Math.max(edge2.a[1], edge2.b[1])) {
4983
+ const t = root(edge2, 1, latitude2, context);
4984
+ if (events.has(t) && events.get(t) !== latitude2)
4966
4985
  throw new GeographicSeamError("precision", "Unresolvable latitude events");
4967
4986
  fractions.push(t);
4968
- events.set(t, latitude);
4987
+ events.set(t, latitude2);
4969
4988
  }
4970
4989
  fractions.sort((a, b) => a - b);
4971
4990
  const result = [];
@@ -5078,8 +5097,8 @@ function prepare(input, index, context) {
5078
5097
  throw new GeographicSeamError("topology", "Polar rings require an explicit pole and monotone longitude winding");
5079
5098
  if (poleAttributes.length !== context.size - 2 || !poleAttributes.every(Number.isFinite))
5080
5099
  throw new GeographicSeamError("input", "Explicit poleAttributes are required for polar attributes");
5081
- const latitude = input.pole === "north" ? 90 : -90;
5082
- const a = [cursor[0], latitude, ...poleAttributes], b = [first[0], latitude, ...poleAttributes];
5100
+ const latitude2 = input.pole === "north" ? 90 : -90;
5101
+ const a = [cursor[0], latitude2, ...poleAttributes], b = [first[0], latitude2, ...poleAttributes];
5083
5102
  membership.push(straight(cursor, a), straight(a, b), straight(b, first));
5084
5103
  } else if (input.pole !== void 0 || poleAttributes.length) {
5085
5104
  throw new GeographicSeamError("input", "Pole selection applies only to once-winding polar rings");
@@ -5227,13 +5246,13 @@ function processPolygon(inputs, options, latitudeRange) {
5227
5246
  piece.b[1] = latitudes.get(fractions[i]);
5228
5247
  if (fractions.length > 2)
5229
5248
  context.addVertices(2);
5230
- const x = piece.a[0], latitude = (piece.a[1] + piece.b[1]) / 2;
5249
+ const x = piece.a[0], latitude2 = (piece.a[1] + piece.b[1]) / 2;
5231
5250
  const seam = x === context.left;
5232
5251
  const ring = piece.source && rings[piece.source.ringIndex];
5233
- 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"))
5252
+ if (ring && ring.max - ring.min >= 360 - ANGULAR_TOLERANCE && contains(ring, [x, latitude2], context, seam ? "right" : "left") && contains(ring, [seam ? context.right : x, latitude2], context, seam ? "left" : "right"))
5234
5253
  continue;
5235
- const left = filled(rings, [x, latitude], context, seam ? "right" : "left");
5236
- const right = filled(rings, [seam ? context.right : x, latitude], context, seam ? "left" : "right");
5254
+ const left = filled(rings, [x, latitude2], context, seam ? "right" : "left");
5255
+ const right = filled(rings, [seam ? context.right : x, latitude2], context, seam ? "left" : "right");
5237
5256
  if (left && right)
5238
5257
  continue;
5239
5258
  if (!left && !right)
@@ -5253,20 +5272,20 @@ function processPolygon(inputs, options, latitudeRange) {
5253
5272
  }
5254
5273
  const pole = rings[0].pole;
5255
5274
  if (pole && !rings.slice(1).some((r) => r.pole === pole)) {
5256
- const latitude = pole === "north" ? 90 : -90;
5257
- add4(straight([context.left, latitude, ...rings[0].poleAttributes], [context.right, latitude, ...rings[0].poleAttributes]));
5275
+ const latitude2 = pole === "north" ? 90 : -90;
5276
+ add4(straight([context.left, latitude2, ...rings[0].poleAttributes], [context.right, latitude2, ...rings[0].poleAttributes]));
5258
5277
  }
5259
5278
  for (const boundary of [context.left, context.right]) {
5260
5279
  const boundaryNodes = Array.from(nodes.values()).filter((n) => n.p[0] === boundary).sort((a, b) => a.p[1] - b.p[1]);
5261
5280
  const aligned = graph.filter((e) => e.a[0] === boundary && e.b[0] === boundary);
5262
5281
  for (let i = 1; i < boundaryNodes.length; i++) {
5263
5282
  context.tick();
5264
- const a = boundaryNodes[i - 1].p, b = boundaryNodes[i].p, latitude = (a[1] + b[1]) / 2;
5265
- if (latitude === a[1] || latitude === b[1])
5283
+ const a = boundaryNodes[i - 1].p, b = boundaryNodes[i].p, latitude2 = (a[1] + b[1]) / 2;
5284
+ if (latitude2 === a[1] || latitude2 === b[1])
5266
5285
  throw new GeographicSeamError("precision", "Unresolvable seam event separation");
5267
- if (filled(rings, [boundary, latitude], context, boundary === context.left ? "right" : "left") && !aligned.some((e) => {
5286
+ if (filled(rings, [boundary, latitude2], context, boundary === context.left ? "right" : "left") && !aligned.some((e) => {
5268
5287
  context.tick();
5269
- return latitude > Math.min(e.a[1], e.b[1]) && latitude < Math.max(e.a[1], e.b[1]);
5288
+ return latitude2 > Math.min(e.a[1], e.b[1]) && latitude2 < Math.max(e.a[1], e.b[1]);
5270
5289
  }))
5271
5290
  add4(straight(a, b));
5272
5291
  }
@@ -5406,13 +5425,13 @@ function getGeographicTileBounds(tile) {
5406
5425
  90 - 180 * tile.y / size
5407
5426
  ];
5408
5427
  }
5409
- function getGeographicTile(longitude, latitude, level) {
5428
+ function getGeographicTile(longitude, latitude2, level) {
5410
5429
  const size = gridSize(level);
5411
- if (!Number.isFinite(longitude) || longitude < -180 || longitude > 180 || !Number.isFinite(latitude) || latitude < -90 || latitude > 90)
5430
+ if (!Number.isFinite(longitude) || longitude < -180 || longitude > 180 || !Number.isFinite(latitude2) || latitude2 < -90 || latitude2 > 90)
5412
5431
  throw new RangeError("Expected longitude in [-180, 180] and latitude in [-90, 90]");
5413
5432
  return {
5414
5433
  x: Math.min(size - 1, Math.floor((longitude + 180) / 360 * size)),
5415
- y: Math.min(size - 1, Math.floor((90 - latitude) / 180 * size)),
5434
+ y: Math.min(size - 1, Math.floor((90 - latitude2) / 180 * size)),
5416
5435
  level
5417
5436
  };
5418
5437
  }
@@ -6956,7 +6975,7 @@ function requireValue(condition, field) {
6956
6975
 
6957
6976
  // dist/web-mercator.js
6958
6977
  var web_mercator_exports = {};
6959
- __reExport(web_mercator_exports, require("@math.gl/web-mercator"));
6978
+ __reExport(web_mercator_exports, require("@math.gl/geospatial/web-mercator"));
6960
6979
 
6961
6980
  // dist/expressions.js
6962
6981
  var import_core14 = require("@math.gl/core");
@@ -7747,11 +7766,11 @@ var GeographicCutAtlas = class {
7747
7766
  }
7748
7767
  return this.clip(sources, context);
7749
7768
  }
7750
- clip(sources, context, contains2, sign2 = 1) {
7769
+ clip(sources, context, contains3, sign2 = 1) {
7751
7770
  const registry = /* @__PURE__ */ new Map(), events = new Map(this.boundaries.map((c) => [c.id, /* @__PURE__ */ new Set()]));
7752
7771
  let serial = 0;
7753
7772
  const node = (n, attributes, source = false) => {
7754
- const k = key(n) + (!contains2 && source ? "|" + attributes.join(",") : ""), previous = registry.get(k);
7773
+ const k = key(n) + (!contains3 && source ? "|" + attributes.join(",") : ""), previous = registry.get(k);
7755
7774
  if (previous) {
7756
7775
  if (source && previous.source && attributes.some((x, i) => x !== previous.p[i + 2]))
7757
7776
  throw new GeographicSeamError("topology", "Shared source vertex attributes disagree");
@@ -7828,7 +7847,7 @@ var GeographicCutAtlas = class {
7828
7847
  if (value(b, v.n) === 0)
7829
7848
  on2(v, b);
7830
7849
  }
7831
- if (!contains2 && Math.hypot(...endpoints[0].n.map((x, i) => x - endpoints[1].n[i])) === 0 && curve.speed > ANGULAR) {
7850
+ if (!contains3 && Math.hypot(...endpoints[0].n.map((x, i) => x - endpoints[1].n[i])) === 0 && curve.speed > ANGULAR) {
7832
7851
  const steps = Math.max(4, Math.ceil(curve.speed / (Math.PI / 2)));
7833
7852
  if (steps > context.maxVertices)
7834
7853
  throw new GeographicSeamError("limit", "Too many closed-line samples");
@@ -7893,12 +7912,12 @@ var GeographicCutAtlas = class {
7893
7912
  const n = normal(arc.curve.sample(0.5));
7894
7913
  if (!accepts(cell, n, arc.coincident))
7895
7914
  continue;
7896
- if (contains2 && cell.cuts.some((r) => {
7915
+ if (contains3 && cell.cuts.some((r) => {
7897
7916
  var _a;
7898
7917
  return ((_a = arc.coincident) == null ? void 0 : _a.has(r.circle.id)) && r.side * dot2(r.circle.normal, cross3(n, arc.curve.derivative(0.5))) < 0;
7899
7918
  }))
7900
7919
  continue;
7901
- if (!contains2) {
7920
+ if (!contains3) {
7902
7921
  const coincident = cell.cuts.filter((r) => {
7903
7922
  var _a;
7904
7923
  return (_a = arc.coincident) == null ? void 0 : _a.has(r.circle.id);
@@ -7911,7 +7930,7 @@ var GeographicCutAtlas = class {
7911
7930
  }
7912
7931
  arcs.push(arc);
7913
7932
  }
7914
- if (!contains2) {
7933
+ if (!contains3) {
7915
7934
  const parts = [];
7916
7935
  for (const e of arcs) {
7917
7936
  context.tick();
@@ -7944,7 +7963,7 @@ var GeographicCutAtlas = class {
7944
7963
  continue;
7945
7964
  }
7946
7965
  const midpoint = onCircle(b, (a.angle + hi) / 2), known = /* @__PURE__ */ new Set([b.id]);
7947
- if (!accepts(cell, midpoint, known) || !contains2(midpoint))
7966
+ if (!accepts(cell, midpoint, known) || !contains3(midpoint))
7948
7967
  continue;
7949
7968
  if (sourceArcs.some((e) => {
7950
7969
  var _a;
@@ -8039,8 +8058,8 @@ function createOctahedralCutGraph() {
8039
8058
  }
8040
8059
  function createOctahedralCutAtlas(options) {
8041
8060
  const graph = createOctahedralCutGraph(), atlas = new GeographicCutAtlas(graph, options), frames = new Map(graph.charts.map((c) => {
8042
- const center = unit(c.center), [right, up] = basis(center);
8043
- return [c.id, { center, right, up }];
8061
+ const center = unit(c.center), [right, up2] = basis(center);
8062
+ return [c.id, { center, right, up: up2 }];
8044
8063
  }));
8045
8064
  const project2 = (chart, p) => {
8046
8065
  const frame2 = frames.get(chart);
@@ -8228,12 +8247,12 @@ var GeodesicPolygonExact = class extends SurfacePolygon {
8228
8247
  direct: (a, b, c, d, opts) => solver.direct(a, b % 720, c, d, opts)
8229
8248
  }, options);
8230
8249
  }
8231
- addPoint(latitude, longitude, options = {}) {
8250
+ addPoint(latitude2, longitude, options = {}) {
8232
8251
  if (Math.abs(longitude) > 1e6)
8233
8252
  throw new RangeError("Exact polygon longitude exceeds input profile");
8234
8253
  if (options.longitudeTurns !== void 0 && options.longitudeTurns !== 0)
8235
8254
  throw new RangeError("Exact geodesic point insertion does not select winding routes; use addEdge");
8236
- return super.addPoint(latitude, longitude);
8255
+ return super.addPoint(latitude2, longitude);
8237
8256
  }
8238
8257
  };
8239
8258
 
@@ -8519,11 +8538,11 @@ var TriaxialEllipsoid = class {
8519
8538
  }
8520
8539
  throw new RangeError("Surface sampling work limit exceeded");
8521
8540
  }
8522
- toCartesian(latitude, longitude, coordinates = "geodetic") {
8541
+ toCartesian(latitude2, longitude, coordinates = "geodetic") {
8523
8542
  system(coordinates);
8524
- if (!Number.isFinite(latitude) || Math.abs(latitude) > 90 || !Number.isFinite(longitude))
8543
+ if (!Number.isFinite(latitude2) || Math.abs(latitude2) > 90 || !Number.isFinite(longitude))
8525
8544
  throw new RangeError("Invalid triaxial latitude/longitude");
8526
- const p = trig(latitude), l = trig(longitude), n = [p.c * l.c, p.c * l.s, p.s], r = this.axes;
8545
+ const p = trig(latitude2), l = trig(longitude), n = [p.c * l.c, p.c * l.s, p.s], r = this.axes;
8527
8546
  if (coordinates === "parametric")
8528
8547
  return n.map((x, i) => x * this.radii[i]);
8529
8548
  const denominator = coordinates === "geodetic" ? Math.hypot(...n.map((x, i) => x * r[i])) : Math.hypot(...n.map((x, i) => x / r[i]));
@@ -8562,12 +8581,12 @@ var TriaxialEllipsoid = class {
8562
8581
  basis(position2) {
8563
8582
  const p = this.surface(position2), normal2 = unit2(p.map((x, i) => x / this.axes[i] ** 2));
8564
8583
  const horizontal = Math.hypot(p[0], p[1]), meridian = horizontal ? [-p[1] / horizontal, p[0] / horizontal, 0] : [0, 1, 0];
8565
- const cross6 = (a, b) => [
8584
+ const cross7 = (a, b) => [
8566
8585
  a[1] * b[2] - a[2] * b[1],
8567
8586
  a[2] * b[0] - a[0] * b[2],
8568
8587
  a[0] * b[1] - a[1] * b[0]
8569
8588
  ];
8570
- const north = unit2(cross6(normal2, meridian)), east = unit2(cross6(north, normal2));
8589
+ const north = unit2(cross7(normal2, meridian)), east = unit2(cross7(north, normal2));
8571
8590
  return { north, east, normal: normal2 };
8572
8591
  }
8573
8592
  /** Cartesian initial-value geodesic. No global triaxial inverse is implied. */
@@ -8673,8 +8692,8 @@ function parseGeographicCoordinates(text, options = {}) {
8673
8692
  longitude: parseAngle(lon, "longitude")
8674
8693
  };
8675
8694
  }
8676
- function formatGeographicCoordinates(latitude, longitude, options = {}) {
8677
- const lat = formatAngle(latitude, { ...options, axis: "latitude" }), lon = formatAngle(longitude, { ...options, axis: "longitude" });
8695
+ function formatGeographicCoordinates(latitude2, longitude, options = {}) {
8696
+ const lat = formatAngle(latitude2, { ...options, axis: "latitude" }), lon = formatAngle(longitude, { ...options, axis: "longitude" });
8678
8697
  return (options.longitudeFirst ? [lon, lat] : [lat, lon]).join(", ");
8679
8698
  }
8680
8699
 
@@ -8817,13 +8836,13 @@ function intersectGeographicBounds(a, b) {
8817
8836
  }
8818
8837
  function clampGeographicPoint(bounds2, point2) {
8819
8838
  let longitude = normalizeLongitude2(point2[0]);
8820
- const latitude = Math.max(bounds2[1], Math.min(bounds2[3], point2[1]));
8821
- if (!containsGeographicPoint(bounds2, [longitude, latitude])) {
8839
+ const latitude2 = Math.max(bounds2[1], Math.min(bounds2[3], point2[1]));
8840
+ if (!containsGeographicPoint(bounds2, [longitude, latitude2])) {
8822
8841
  const westDistance = Math.abs(normalizeLongitude2(longitude - bounds2[0]));
8823
8842
  const eastDistance = Math.abs(normalizeLongitude2(longitude - bounds2[2]));
8824
8843
  longitude = westDistance <= eastDistance ? bounds2[0] : bounds2[2];
8825
8844
  }
8826
- return [longitude, latitude];
8845
+ return [longitude, latitude2];
8827
8846
  }
8828
8847
  function getAngularRanges(bounds2, primeMeridian = 0, origin = 0) {
8829
8848
  const width = getLongitudeSpan(bounds2);
@@ -9083,10 +9102,10 @@ function bindKernel(name, state, forward4, inverse4, adapt = createProjection) {
9083
9102
  function guardAzimuthalDomain(base, implementation) {
9084
9103
  const forward4 = projectionOperation(implementation, false);
9085
9104
  return createProjection((point2) => {
9086
- const longitude = point2.x, latitude = point2.y;
9105
+ const longitude = point2.x, latitude2 = point2.y;
9087
9106
  const delta = Math.atan2(Math.sin(longitude - base.long0), Math.cos(longitude - base.long0));
9088
9107
  const polar = Math.abs(Math.abs(base.lat0) - Math.PI / 2) < 1e-10;
9089
- if (Math.abs(latitude + base.lat0) < 1e-10 && (polar || Math.abs(Math.abs(delta) - Math.PI) < 1e-10))
9108
+ if (Math.abs(latitude2 + base.lat0) < 1e-10 && (polar || Math.abs(Math.abs(delta) - Math.PI) < 1e-10))
9090
9109
  throw new Error("Azimuthal projection is undefined at the antipode");
9091
9110
  forward4(point2);
9092
9111
  }, projectionOperation(implementation, true));
@@ -9615,11 +9634,11 @@ var universalTransverseMercator = {
9615
9634
  };
9616
9635
 
9617
9636
  // dist/projection/experimental/rendering-profile/spherical-rendering-domain.js
9618
- function geographicVector(longitude, latitude) {
9637
+ function geographicVector(longitude, latitude2) {
9619
9638
  return [
9620
- Math.cos(latitude) * Math.cos(longitude),
9621
- Math.cos(latitude) * Math.sin(longitude),
9622
- Math.sin(latitude)
9639
+ Math.cos(latitude2) * Math.cos(longitude),
9640
+ Math.cos(latitude2) * Math.sin(longitude),
9641
+ Math.sin(latitude2)
9623
9642
  ];
9624
9643
  }
9625
9644
  var dot3 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
@@ -9644,38 +9663,38 @@ function sphericalExtremum(vector2, parameters, domain, maximize = true) {
9644
9663
  const limit = domain ? Math.cos(domain.distance) : -1;
9645
9664
  let best = maximize ? -Infinity : Infinity;
9646
9665
  let point2 = [NaN, NaN];
9647
- const consider = (longitude, latitude) => {
9666
+ const consider = (longitude, latitude2) => {
9648
9667
  longitude = center + wrapLongitude(longitude - center);
9649
- if (longitude < west - 1e-12 || longitude > east + 1e-12 || latitude < south - 1e-12 || latitude > north + 1e-12)
9668
+ if (longitude < west - 1e-12 || longitude > east + 1e-12 || latitude2 < south - 1e-12 || latitude2 > north + 1e-12)
9650
9669
  return;
9651
- const position2 = geographicVector(longitude, latitude);
9670
+ const position2 = geographicVector(longitude, latitude2);
9652
9671
  if (domain && dot3(axis, position2) < limit - 1e-13)
9653
9672
  return;
9654
9673
  const value3 = dot3(vector2, position2);
9655
9674
  if (maximize ? value3 > best : value3 < best) {
9656
9675
  best = value3;
9657
- point2 = [longitude, latitude];
9676
+ point2 = [longitude, latitude2];
9658
9677
  }
9659
9678
  };
9660
9679
  const longitudes = [west, east, ...trigonometricRoots(-vector2[1], vector2[0], 0, west, east)];
9661
9680
  for (const longitude of longitudes) {
9662
9681
  const coefficient = vector2[0] * Math.cos(longitude) + vector2[1] * Math.sin(longitude);
9663
- for (const latitude of [
9682
+ for (const latitude2 of [
9664
9683
  south,
9665
9684
  north,
9666
9685
  ...trigonometricRoots(vector2[2], -coefficient, 0, south, north)
9667
9686
  ])
9668
- consider(longitude, latitude);
9687
+ consider(longitude, latitude2);
9669
9688
  }
9670
9689
  if (domain) {
9671
9690
  const [a, , c] = axis;
9672
- for (const latitude of [south, north]) {
9673
- for (const longitude of trigonometricRoots(a * Math.cos(latitude), 0, limit - c * Math.sin(latitude), west, east))
9674
- consider(longitude, latitude);
9691
+ for (const latitude2 of [south, north]) {
9692
+ for (const longitude of trigonometricRoots(a * Math.cos(latitude2), 0, limit - c * Math.sin(latitude2), west, east))
9693
+ consider(longitude, latitude2);
9675
9694
  }
9676
9695
  for (const longitude of [west, east]) {
9677
- for (const latitude of trigonometricRoots(a * Math.cos(longitude), c, limit, south, north))
9678
- consider(longitude, latitude);
9696
+ for (const latitude2 of trigonometricRoots(a * Math.cos(longitude), c, limit, south, north))
9697
+ consider(longitude, latitude2);
9679
9698
  }
9680
9699
  const parallel = dot3(vector2, axis);
9681
9700
  let tangent = vector2.map((value3, index) => value3 - parallel * axis[index]);
@@ -9743,10 +9762,10 @@ function createAngularRenderingProfile(base, maximumDistance, resolveBounds2, ho
9743
9762
  const angle3 = base.lat0 + domain.distance;
9744
9763
  const center = (local[0][0] + local[1][0]) / 2;
9745
9764
  const longitude = center + wrapLongitude((Math.cos(angle3) < 0 ? Math.PI : 0) - center);
9746
- const latitude = Math.atan2(Math.sin(angle3), Math.abs(Math.cos(angle3)));
9747
- if (longitude >= local[0][0] && longitude <= local[1][0] && latitude >= local[0][1] && latitude <= local[1][1]) {
9765
+ const latitude2 = Math.atan2(Math.sin(angle3), Math.abs(Math.cos(angle3)));
9766
+ if (longitude >= local[0][0] && longitude <= local[1][0] && latitude2 >= local[0][1] && latitude2 <= local[1][1]) {
9748
9767
  point2.x = longitude + base.long0;
9749
- point2.y = latitude;
9768
+ point2.y = latitude2;
9750
9769
  return;
9751
9770
  }
9752
9771
  }
@@ -10006,7 +10025,7 @@ var stereographic = {
10006
10025
  const base = kernelParameters(context);
10007
10026
  const state = createState3(base);
10008
10027
  const projection2 = guardAzimuthalDomain(base, bindKernel("stere", state, forward3, inverse3));
10009
- return withAngularRenderingProfile(projection2, base, 150 * Math.PI / 180, (region, domain) => state.sphere ? sphericalAzimuthalBounds(state, region, domain, "stere") : ellipsoidalStereographicBounds(state, (latitude) => 2 * Math.atan(Math.tan(Math.PI / 4 + latitude / 2) * Math.pow((1 - state.e * Math.sin(latitude)) / (1 + state.e * Math.sin(latitude)), state.e / 2)) - Math.PI / 2, state.X0, 2 * state.a * state.k0 * (Math.abs(state.coslat0) < 1e-10 ? 1 / state.cons : state.ms1 / state.cosX0), region, domain));
10028
+ return withAngularRenderingProfile(projection2, base, 150 * Math.PI / 180, (region, domain) => state.sphere ? sphericalAzimuthalBounds(state, region, domain, "stere") : ellipsoidalStereographicBounds(state, (latitude2) => 2 * Math.atan(Math.tan(Math.PI / 4 + latitude2 / 2) * Math.pow((1 - state.e * Math.sin(latitude2)) / (1 + state.e * Math.sin(latitude2)), state.e / 2)) - Math.PI / 2, state.X0, 2 * state.a * state.k0 * (Math.abs(state.coslat0) < 1e-10 ? 1 / state.cons : state.ms1 / state.cosX0), region, domain));
10010
10029
  }
10011
10030
  };
10012
10031
 
@@ -10014,16 +10033,16 @@ var stereographic = {
10014
10033
  var DEG5 = Math.PI / 180;
10015
10034
  var A2 = 6378137;
10016
10035
  var F = 1 / 298.257223563;
10017
- function standardGridZone(latitude, longitude) {
10018
- if (!Number.isFinite(latitude) || Math.abs(latitude) > 90 || !Number.isFinite(longitude) || Math.abs(longitude) > 180)
10036
+ function standardGridZone(latitude2, longitude) {
10037
+ if (!Number.isFinite(latitude2) || Math.abs(latitude2) > 90 || !Number.isFinite(longitude) || Math.abs(longitude) > 180)
10019
10038
  throw new RangeError("Expected latitude/longitude degrees in [-90,90]/[-180,180]");
10020
- if (latitude < -80 || latitude >= 84)
10039
+ if (latitude2 < -80 || latitude2 >= 84)
10021
10040
  return 0;
10022
10041
  const lon = longitude === 180 ? -180 : longitude;
10023
10042
  let zone = Math.floor((Math.floor(lon) + 186) / 6);
10024
- if (latitude >= 56 && latitude < 64 && lon >= 3 && lon < 12)
10043
+ if (latitude2 >= 56 && latitude2 < 64 && lon >= 3 && lon < 12)
10025
10044
  zone = 32;
10026
- if (latitude >= 72 && lon >= 0 && lon < 42)
10045
+ if (latitude2 >= 72 && lon >= 0 && lon < 42)
10027
10046
  zone = 2 * Math.floor((Math.floor(lon) + 183) / 12) + 1;
10028
10047
  return zone;
10029
10048
  }
@@ -10048,16 +10067,16 @@ function projection(zone, north) {
10048
10067
  prepared.set(key3, result);
10049
10068
  return result;
10050
10069
  }
10051
- function projectGrid(latitude, longitude, options = {}) {
10052
- const standard = standardGridZone(latitude, longitude), zone = options.zone ?? standard, naturalNorth = !(latitude < 0 || Object.is(latitude, -0)), north = options.north ?? naturalNorth;
10070
+ function projectGrid(latitude2, longitude, options = {}) {
10071
+ const standard = standardGridZone(latitude2, longitude), zone = options.zone ?? standard, naturalNorth = !(latitude2 < 0 || Object.is(latitude2, -0)), north = options.north ?? naturalNorth;
10053
10072
  validateZone(zone, north);
10054
- if (zone === 0 && (Math.abs(latitude) < 70 || north !== naturalNorth))
10073
+ if (zone === 0 && (Math.abs(latitude2) < 70 || north !== naturalNorth))
10055
10074
  throw new RangeError("UPS requires its matching polar hemisphere");
10056
10075
  if (zone && Math.abs((longitude - (6 * zone - 183) + 540) % 360 - 180) > 60)
10057
10076
  throw new RangeError("Longitude too far from UTM central meridian");
10058
- if (zone === 0 && Math.abs(latitude) === 90)
10077
+ if (zone === 0 && Math.abs(latitude2) === 90)
10059
10078
  return { zone, north, easting: 2e6, northing: 2e6 };
10060
- const p = projection(zone, north).forward(longitude * DEG5, latitude * DEG5);
10079
+ const p = projection(zone, north).forward(longitude * DEG5, latitude2 * DEG5);
10061
10080
  if (zone === 0) {
10062
10081
  if (longitude % 180 === 0)
10063
10082
  p[0] = 2e6;
@@ -10122,17 +10141,17 @@ function utmRow(band, column, row) {
10122
10141
  }
10123
10142
  return row;
10124
10143
  }
10125
- function formatMGRS(latitude, longitude, precision = 5, options = {}) {
10144
+ function formatMGRS(latitude2, longitude, precision = 5, options = {}) {
10126
10145
  if (!Number.isInteger(precision) || precision < 0 || precision > 11)
10127
10146
  throw new RangeError("MGRS precision must be in [0,11]");
10128
- const grid = projectGrid(latitude, longitude, options), { zone, north, easting: x } = grid;
10147
+ const grid = projectGrid(latitude2, longitude, options), { zone, north, easting: x } = grid;
10129
10148
  let y = grid.northing;
10130
10149
  if (zone && !north && y === 1e7)
10131
10150
  y -= 2 ** -28;
10132
10151
  const column = Math.floor(x / TILE), row = Math.floor(y / TILE);
10133
10152
  let prefix;
10134
10153
  if (zone) {
10135
- const band = Math.abs(latitude) < 2 ** -46 ? north ? 0 : -1 : Math.max(-10, Math.min(9, Math.floor((Math.floor(latitude) + 80) / 8) - 10));
10154
+ const band = Math.abs(latitude2) < 2 ** -46 ? north ? 0 : -1 : Math.max(-10, Math.min(9, Math.floor((Math.floor(latitude2) + 80) / 8) - 10));
10136
10155
  if (column < 1 || column > 8 || utmRow(band, column - 1, row % 20) !== row - (north ? 0 : 100))
10137
10156
  throw new RangeError("Grid outside MGRS domain");
10138
10157
  prefix = String(zone).padStart(2, "0") + BANDS[band + 10] + COLUMNS[(zone - 1) % 3][column - 1] + ROWS[(row + ((zone - 1) % 2 ? 5 : 0)) % 20];
@@ -10204,8 +10223,8 @@ function parseMGRSZone(text) {
10204
10223
  band
10205
10224
  };
10206
10225
  }
10207
- function formatMGRSZone(latitude, longitude, options = {}) {
10208
- const cell = formatMGRS(latitude, longitude, 0, options);
10226
+ function formatMGRSZone(latitude2, longitude, options = {}) {
10227
+ const cell = formatMGRS(latitude2, longitude, 0, options);
10209
10228
  return cell.slice(0, cell.length - 2);
10210
10229
  }
10211
10230
 
@@ -10774,9 +10793,9 @@ function validateBatch(positions, output2) {
10774
10793
 
10775
10794
  // dist/terrain/mesh-skirts.js
10776
10795
  function createTerrainSkirt(mesh, options) {
10777
- const { positions, indices } = mesh, { height, edges: edges2 } = options;
10796
+ const { positions, indices } = mesh, { height, baseZ, edges: edges2 } = options;
10778
10797
  const maxVertices = options.maxVertices ?? 2e6, maxTriangles = options.maxTriangles ?? 4e6;
10779
- if (!Number.isFinite(height) || height <= 0 || !Number.isSafeInteger(maxVertices) || maxVertices < 0 || maxVertices > 4294967295 || !Number.isSafeInteger(maxTriangles) || maxTriangles < 0 || maxTriangles > 4294967295)
10798
+ if ((baseZ === void 0 ? !(Number.isFinite(height) && height > 0) : height !== void 0 || !Number.isFinite(baseZ)) || !Number.isSafeInteger(maxVertices) || maxVertices < 0 || maxVertices > 4294967295 || !Number.isSafeInteger(maxTriangles) || maxTriangles < 0 || maxTriangles > 4294967295)
10780
10799
  throw new Error("Invalid terrain skirt height or capacity");
10781
10800
  if (!(positions instanceof Float32Array || positions instanceof Float64Array) || positions.length < 3 || positions.length % 3 || !positions.every(Number.isFinite) || !(indices instanceof Uint16Array || indices instanceof Uint32Array) || indices.length % 3 || positions.length / 3 > maxVertices || indices.length / 3 > maxTriangles)
10782
10801
  throw new Error("Invalid terrain skirt mesh or capacity");
@@ -10832,7 +10851,7 @@ function createTerrainSkirt(mesh, options) {
10832
10851
  [b, lowerB]
10833
10852
  ]) {
10834
10853
  resultPositions.set(positions.subarray(3 * source, 3 * source + 3), 3 * target);
10835
- resultPositions[3 * target + 2] = positions[3 * source + 2] - height;
10854
+ resultPositions[3 * target + 2] = baseZ ?? positions[3 * source + 2] - height;
10836
10855
  if (!Number.isFinite(resultPositions[3 * target + 2]) || resultPositions[3 * target + 2] >= positions[3 * source + 2])
10837
10856
  throw new Error("Terrain skirt height cannot be represented in position precision");
10838
10857
  sourceVertexIndices[target - vertexCount] = source;
@@ -10993,17 +11012,17 @@ var GeographicHeightField = class {
10993
11012
  });
10994
11013
  }
10995
11014
  /** Longitude must use the bounds' unwrapped interval; no implicit wrapping or clamping. */
10996
- sample(longitude, latitude, options, result) {
10997
- const valid = Number.isFinite(longitude) && Number.isFinite(latitude);
10998
- const inside = valid && longitude >= this.bounds[0] && longitude <= this.bounds[2] && latitude >= this.bounds[1] && latitude <= this.bounds[3];
10999
- const sample = this.field.sample(inside ? this.projectX(longitude) : NaN, inside ? this.projectY(latitude) : NaN, options, result);
11015
+ sample(longitude, latitude2, options, result) {
11016
+ const valid = Number.isFinite(longitude) && Number.isFinite(latitude2);
11017
+ const inside = valid && longitude >= this.bounds[0] && longitude <= this.bounds[2] && latitude2 >= this.bounds[1] && latitude2 <= this.bounds[3];
11018
+ const sample = this.field.sample(inside ? this.projectX(longitude) : NaN, inside ? this.projectY(latitude2) : NaN, options, result);
11000
11019
  if (!inside) {
11001
11020
  sample.status = sample.gradientStatus = valid ? TerrainSampleStatus.OUTSIDE_DOMAIN : TerrainSampleStatus.INVALID_INPUT;
11002
11021
  return sample;
11003
11022
  }
11004
11023
  if (sample.gradientStatus !== TerrainSampleStatus.VALID)
11005
11024
  return sample;
11006
- const phi = latitude * RADIANS2;
11025
+ const phi = latitude2 * RADIANS2;
11007
11026
  const denominator = 1 - ECCENTRICITY_SQUARED * Math.sin(phi) ** 2;
11008
11027
  const n = RADIUS / Math.sqrt(denominator);
11009
11028
  const m = RADIUS * (1 - ECCENTRICITY_SQUARED) / denominator ** 1.5;
@@ -11027,8 +11046,8 @@ var GeographicHeightField = class {
11027
11046
  projectX(longitude) {
11028
11047
  return this.projection === "web-mercator" ? RADIUS * longitude * RADIANS2 : longitude;
11029
11048
  }
11030
- projectY(latitude) {
11031
- return this.projection === "web-mercator" ? RADIUS * Math.asinh(Math.tan(latitude * RADIANS2)) : latitude;
11049
+ projectY(latitude2) {
11050
+ return this.projection === "web-mercator" ? RADIUS * Math.asinh(Math.tan(latitude2 * RADIANS2)) : latitude2;
11032
11051
  }
11033
11052
  };
11034
11053
 
@@ -14369,56 +14388,48 @@ function buildMixedVertexTileHalos(tiles, options = {}, targets, preparation) {
14369
14388
  if (![maxSamples, maxTests].every((v) => Number.isSafeInteger(v) && v >= 0))
14370
14389
  throw new Error("Invalid mixed halo capacity");
14371
14390
  let count = 0;
14372
- const addresses = /* @__PURE__ */ new Set();
14391
+ let previousKey;
14373
14392
  let frame2;
14374
14393
  const sources = [...tiles].sort((a, b) => a.spacing - b.spacing || a.column - b.column || a.row - b.row).map((tile) => {
14375
- if (![tile.column, tile.row, tile.spacing].every(Number.isSafeInteger) || tile.spacing < 1 || 2 ** Math.round(Math.log2(tile.spacing)) !== tile.spacing)
14376
- throw new Error("Invalid mixed halo lattice");
14377
- const key3 = `${tile.spacing}/${tile.column}/${tile.row}`;
14378
- if (addresses.has(key3))
14379
- throw new Error("Duplicate mixed halo tile");
14380
- addresses.add(key3);
14381
14394
  count += (tile.field.width + 2) * (tile.field.height + 2);
14382
14395
  if (!Number.isSafeInteger(count) || count > maxSamples)
14383
14396
  throw new Error("Mixed halo sample capacity exceeded");
14384
- let field = preparation == null ? void 0 : preparation.fields.get(tile);
14385
- if (!field) {
14386
- field = new HeightField(tile.field);
14387
- preparation == null ? void 0 : preparation.fields.set(tile, field);
14397
+ let prepared2 = preparation == null ? void 0 : preparation.tiles.get(tile);
14398
+ if (!prepared2) {
14399
+ prepared2 = prepareMixedHaloTile(tile);
14400
+ preparation == null ? void 0 : preparation.tiles.set(tile, prepared2);
14401
+ }
14402
+ const { key: key3, source: field, columnStep: column, rowStep: row, frameOrigin: origin, scale: scale3 } = prepared2;
14403
+ if (previousKey === key3)
14404
+ throw new Error("Duplicate mixed halo tile");
14405
+ previousKey = key3;
14406
+ if (frame2) {
14407
+ if (frame2.reference !== field.heightReference)
14408
+ throw new Error("Mixed halo frames or height references differ");
14409
+ for (let i = 0; i < 2; i++) {
14410
+ if (column[i] !== frame2.column[i] || row[i] !== frame2.row[i] || origin[i] !== frame2.origin[i] && Math.abs(origin[i] - frame2.origin[i]) > Math.min(16 * Number.EPSILON * Math.max(scale3[i], frame2.scale[i]), 1e-9 * Math.max(Math.abs(column[i]), Math.abs(row[i]))))
14411
+ throw new Error("Mixed halo frames or height references differ");
14412
+ }
14388
14413
  }
14389
- if (field.registration !== "vertex")
14390
- throw new Error("Mixed halos require vertex registration");
14391
- const column = field.columnStep.map((v) => v / tile.spacing);
14392
- const row = field.rowStep.map((v) => v / tile.spacing);
14393
- const origin = field.origin.map((v, axis) => v - tile.column * column[axis] - tile.row * row[axis]);
14394
- const scale3 = field.origin.map((v, i) => Math.max(1, Math.abs(v), Math.abs(tile.column * column[i]), Math.abs(tile.row * row[i])));
14395
- if (!origin.every(Number.isFinite))
14396
- throw new Error("Mixed halo coordinate overflow");
14397
- if (frame2 && (frame2.reference !== field.heightReference || column.some((v, i) => v !== frame2.column[i]) || row.some((v, i) => v !== frame2.row[i]) || origin.some((v, i) => Math.abs(v - frame2.origin[i]) > Math.min(16 * Number.EPSILON * Math.max(scale3[i], frame2.scale[i]), 1e-9 * Math.max(Math.abs(column[i]), Math.abs(row[i]))))))
14398
- throw new Error("Mixed halo frames or height references differ");
14399
14414
  frame2 ?? (frame2 = { origin, column, row, reference: field.heightReference, scale: scale3 });
14400
- return { ...tile, source: field };
14415
+ return prepared2;
14401
14416
  });
14402
- for (const axis of ["column", "row"]) {
14403
- let min = Infinity, max = -Infinity;
14404
- for (const tile of sources) {
14405
- const size = axis === "column" ? tile.source.width : tile.source.height;
14406
- const low = tile[axis] - tile.spacing, high = tile[axis] + size * tile.spacing;
14407
- if (![low, high].every(Number.isSafeInteger))
14408
- throw new Error("Mixed halo lattice overflow");
14409
- min = Math.min(min, low);
14410
- max = Math.max(max, high);
14411
- }
14412
- if (sources.length && !Number.isSafeInteger(max - min))
14413
- throw new Error("Mixed halo lattice span overflow");
14414
- }
14417
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
14418
+ for (let i = 0; i < sources.length; i++) {
14419
+ const { haloBounds } = sources[i];
14420
+ minX = Math.min(minX, haloBounds.minX);
14421
+ minY = Math.min(minY, haloBounds.minY);
14422
+ maxX = Math.max(maxX, haloBounds.maxX);
14423
+ maxY = Math.max(maxY, haloBounds.maxY);
14424
+ }
14425
+ if (sources.length && (!Number.isSafeInteger(maxX - minX) || !Number.isSafeInteger(maxY - minY)))
14426
+ throw new Error("Mixed halo lattice span overflow");
14415
14427
  if (targets && targets.size === 0)
14416
14428
  return { tiles: [] };
14417
14429
  let index;
14418
14430
  if (sources.length > 8) {
14419
- const keys = preparation && sources.map((tile) => `${tile.spacing}/${tile.column}/${tile.row}/${tile.source.width}/${tile.source.height}`);
14420
14431
  const cached = preparation == null ? void 0 : preparation.layout;
14421
- if (keys && cached && keys.length === cached.keys.length && keys.every((key3, i) => key3 === cached.keys[i])) {
14432
+ if (cached && sources.length === cached.keys.length && sources.every((tile, i) => tile.layoutKey === cached.keys[i])) {
14422
14433
  index = cached.query;
14423
14434
  } else {
14424
14435
  index = createTerrainBoxIndex(sources.map((tile) => ({
@@ -14427,8 +14438,8 @@ function buildMixedVertexTileHalos(tiles, options = {}, targets, preparation) {
14427
14438
  maxX: tile.column + (tile.source.width - 1) * tile.spacing,
14428
14439
  maxY: tile.row + (tile.source.height - 1) * tile.spacing
14429
14440
  })));
14430
- if (preparation && keys)
14431
- preparation.layout = { keys, query: index };
14441
+ if (preparation)
14442
+ preparation.layout = { keys: sources.map((tile) => tile.layoutKey), query: index };
14432
14443
  }
14433
14444
  }
14434
14445
  let tests = 0;
@@ -14437,21 +14448,17 @@ function buildMixedVertexTileHalos(tiles, options = {}, targets, preparation) {
14437
14448
  throw new Error("Mixed halo tile-test budget exceeded");
14438
14449
  };
14439
14450
  return {
14440
- tiles: sources.filter((tile) => !targets || targets.has(`${tile.spacing}/${tile.column}/${tile.row}`)).map((tile) => {
14451
+ tiles: sources.filter((tile) => !targets || targets.has(tile.key)).map((tile) => {
14441
14452
  const source = tile.source, width = source.width + 2, height = source.height + 2;
14442
14453
  const heights = new Float64Array(width * height), validity = new Uint8Array(heights.length), statuses = new Uint8Array(heights.length);
14443
- const candidates = (index == null ? void 0 : index({
14444
- minX: tile.column - tile.spacing,
14445
- minY: tile.row - tile.spacing,
14446
- maxX: tile.column + source.width * tile.spacing,
14447
- maxY: tile.row + source.height * tile.spacing
14448
- }, charge).map((id) => sources[id])) ?? sources;
14454
+ const candidates = (index == null ? void 0 : index(tile.haloBounds, charge).map((id) => sources[id])) ?? sources;
14449
14455
  for (let y = 0; y < height; y++)
14450
14456
  for (let x = 0; x < width; x++) {
14451
14457
  const gx = tile.column + (x - 1) * tile.spacing, gy = tile.row + (y - 1) * tile.spacing;
14452
- if (![gx, gy].every(Number.isSafeInteger))
14458
+ if (!Number.isSafeInteger(gx) || !Number.isSafeInteger(gy))
14453
14459
  throw new Error("Mixed halo lattice overflow");
14454
- for (const candidate of candidates) {
14460
+ for (let candidateIndex = 0; candidateIndex < candidates.length; candidateIndex++) {
14461
+ const candidate = candidates[candidateIndex];
14455
14462
  charge();
14456
14463
  const cx = (gx - candidate.column) / candidate.spacing, cy = (gy - candidate.row) / candidate.spacing;
14457
14464
  const f = candidate.source;
@@ -14494,6 +14501,36 @@ function buildMixedVertexTileHalos(tiles, options = {}, targets, preparation) {
14494
14501
  })
14495
14502
  };
14496
14503
  }
14504
+ function prepareMixedHaloTile(tile) {
14505
+ const { column, row, spacing } = tile;
14506
+ if (![column, row, spacing].every(Number.isSafeInteger) || spacing < 1 || 2 ** Math.round(Math.log2(spacing)) !== spacing)
14507
+ throw new Error("Invalid mixed halo lattice");
14508
+ const source = new HeightField(tile.field);
14509
+ if (source.registration !== "vertex")
14510
+ throw new Error("Mixed halos require vertex registration");
14511
+ const columnStep = source.columnStep.map((v) => v / spacing);
14512
+ const rowStep = source.rowStep.map((v) => v / spacing);
14513
+ const frameOrigin = source.origin.map((v, i) => v - column * columnStep[i] - row * rowStep[i]);
14514
+ const scale3 = source.origin.map((v, i) => Math.max(1, Math.abs(v), Math.abs(column * columnStep[i]), Math.abs(row * rowStep[i])));
14515
+ if (!frameOrigin.every(Number.isFinite))
14516
+ throw new Error("Mixed halo coordinate overflow");
14517
+ const minX = column - spacing, minY = row - spacing;
14518
+ const maxX = column + source.width * spacing, maxY = row + source.height * spacing;
14519
+ if (![minX, minY, maxX, maxY].every(Number.isSafeInteger))
14520
+ throw new Error("Mixed halo lattice overflow");
14521
+ const key3 = `${spacing}/${column}/${row}`;
14522
+ return {
14523
+ ...tile,
14524
+ source,
14525
+ columnStep,
14526
+ rowStep,
14527
+ frameOrigin,
14528
+ scale: scale3,
14529
+ key: key3,
14530
+ layoutKey: `${key3}/${source.width}/${source.height}`,
14531
+ haloBounds: { minX, minY, maxX, maxY }
14532
+ };
14533
+ }
14497
14534
 
14498
14535
  // dist/terrain/mixed-halo-update.js
14499
14536
  var key2 = (t) => `${t.spacing}/${t.column}/${t.row}`;
@@ -14539,14 +14576,21 @@ function updateTerrainMixedVertexTileHalos(previous, resident, options = {}) {
14539
14576
  const budget = options.maxDependencyTests ?? 1e7;
14540
14577
  if (!Number.isSafeInteger(budget) || budget < 0)
14541
14578
  throw new Error("Invalid mixed halo dependency budget");
14542
- const old = new Map(previous == null ? void 0 : previous.sources.map((t) => [key2(t), t]));
14543
- const current = new Map(resident.map((t) => [key2(t), t]));
14544
- const cached = new Map(previous == null ? void 0 : previous.tiles.map((t) => [key2(t), t]));
14545
- const targets = /* @__PURE__ */ new Set();
14546
14579
  const unchangedLayout = (previous == null ? void 0 : previous.sources.length) === resident.length && resident.every((tile, i) => {
14547
14580
  const prior = previous.sources[i];
14548
- return key2(prior) === key2(tile) && prior.field.width === tile.field.width && prior.field.height === tile.field.height;
14581
+ return prior === tile || prior.column === tile.column && prior.row === tile.row && prior.spacing === tile.spacing && prior.field.width === tile.field.width && prior.field.height === tile.field.height;
14549
14582
  });
14583
+ const old = unchangedLayout ? void 0 : new Map(previous == null ? void 0 : previous.sources.map((t) => [key2(t), t]));
14584
+ const targets = /* @__PURE__ */ new Set();
14585
+ const initialized = previous !== null && preparations.has(previous);
14586
+ if (!initialized) {
14587
+ const cached = new Set(previous == null ? void 0 : previous.tiles.map(key2));
14588
+ for (const tile of resident) {
14589
+ const address = key2(tile);
14590
+ if (!cached.has(address))
14591
+ targets.add(address);
14592
+ }
14593
+ }
14550
14594
  let index = unchangedLayout && previous ? targetIndexes.get(previous) : void 0;
14551
14595
  let tests = 0;
14552
14596
  const charge = () => {
@@ -14558,12 +14602,13 @@ function updateTerrainMixedVertexTileHalos(previous, resident, options = {}) {
14558
14602
  for (const id of index(box, charge))
14559
14603
  targets.add(key2(resident[id]));
14560
14604
  }
14561
- for (const tile of resident) {
14562
- const address = key2(tile);
14563
- const prior = old.get(address);
14564
- if (!cached.has(address) || prior !== tile)
14565
- targets.add(address);
14566
- if (prior === tile || !previous)
14605
+ for (let i = 0; i < resident.length; i++) {
14606
+ const tile = resident[i];
14607
+ const prior = unchangedLayout ? previous.sources[i] : old == null ? void 0 : old.get(key2(tile));
14608
+ if (prior === tile)
14609
+ continue;
14610
+ targets.add(key2(tile));
14611
+ if (!previous)
14567
14612
  continue;
14568
14613
  if (!prior) {
14569
14614
  invalidate(bounds(tile));
@@ -14576,24 +14621,44 @@ function updateTerrainMixedVertexTileHalos(previous, resident, options = {}) {
14576
14621
  invalidate(dirty);
14577
14622
  }
14578
14623
  }
14579
- for (const [address, tile] of old) {
14580
- if (!current.has(address) && resident.length)
14581
- invalidate(bounds(tile));
14624
+ const removed = [];
14625
+ if (old == null ? void 0 : old.size) {
14626
+ const current = new Set(resident.map(key2));
14627
+ for (const [address, tile] of old) {
14628
+ if (current.has(address))
14629
+ continue;
14630
+ removed.push(address);
14631
+ if (resident.length)
14632
+ invalidate(bounds(tile));
14633
+ }
14582
14634
  }
14583
14635
  const priorPreparation = previous && preparations.get(previous);
14584
14636
  const preparation = {
14585
- fields: (priorPreparation == null ? void 0 : priorPreparation.fields) ?? /* @__PURE__ */ new WeakMap(),
14637
+ tiles: (priorPreparation == null ? void 0 : priorPreparation.tiles) ?? /* @__PURE__ */ new WeakMap(),
14586
14638
  layout: priorPreparation == null ? void 0 : priorPreparation.layout
14587
14639
  };
14588
14640
  const built = buildMixedVertexTileHalos(resident, options, targets, preparation).tiles;
14589
- for (const tile of built)
14590
- cached.set(key2(tile), tile);
14591
- const tiles = resident.map((t) => cached.get(key2(t))).sort((a, b) => a.spacing - b.spacing || a.column - b.column || a.row - b.row);
14641
+ let tiles;
14642
+ if (unchangedLayout && initialized) {
14643
+ let cursor = 0;
14644
+ tiles = previous.tiles.map((tile) => {
14645
+ const replacement = built[cursor];
14646
+ if ((replacement == null ? void 0 : replacement.spacing) !== tile.spacing || replacement.column !== tile.column || replacement.row !== tile.row)
14647
+ return tile;
14648
+ cursor++;
14649
+ return replacement;
14650
+ });
14651
+ } else {
14652
+ const cached = new Map(previous == null ? void 0 : previous.tiles.map((tile) => [key2(tile), tile]));
14653
+ for (const tile of built)
14654
+ cached.set(key2(tile), tile);
14655
+ tiles = resident.map((tile) => cached.get(key2(tile))).sort((a, b) => a.spacing - b.spacing || a.column - b.column || a.row - b.row);
14656
+ }
14592
14657
  const snapshot2 = {
14593
14658
  sources: resident.slice(),
14594
14659
  tiles,
14595
14660
  rebuilt: built.map(key2),
14596
- removed: [...old.keys()].filter((k) => !current.has(k)).sort()
14661
+ removed: removed.sort()
14597
14662
  };
14598
14663
  preparations.set(snapshot2, preparation);
14599
14664
  if (index)
@@ -15905,12 +15970,12 @@ function meshValidDomain(field, options, constraints) {
15905
15970
  const { width, height, origin, heightReference } = regular;
15906
15971
  const active = new Uint8Array(count);
15907
15972
  const boundary = /* @__PURE__ */ new Map();
15908
- const edgeKey2 = (a, b) => Math.min(a, b) * count + Math.max(a, b);
15973
+ const edgeKey3 = (a, b) => Math.min(a, b) * count + Math.max(a, b);
15909
15974
  for (let i = 0; i < regular.indices.length; i += 3) {
15910
15975
  for (let j = 0; j < 3; j++) {
15911
15976
  const a = regular.indices[i + j], b = regular.indices[i + (j + 1) % 3];
15912
15977
  active[a] = 1;
15913
- const key3 = edgeKey2(a, b);
15978
+ const key3 = edgeKey3(a, b);
15914
15979
  if (!boundary.delete(key3))
15915
15980
  boundary.set(key3, [a, b]);
15916
15981
  }
@@ -16115,8 +16180,8 @@ function createBreaklineTerrainMesh(field, options) {
16115
16180
  continue;
16116
16181
  }
16117
16182
  const r = points[c], s = points[d];
16118
- const intersects2 = Math.sign(cross4(p, q, r)) * Math.sign(cross4(p, q, s)) < 0 && Math.sign(cross4(r, s, p)) * Math.sign(cross4(r, s, q)) < 0;
16119
- if (intersects2 || c !== a && c !== b && onSegment(p, q, r) || d !== a && d !== b && onSegment(p, q, s) || a !== c && a !== d && onSegment(r, s, p) || b !== c && b !== d && onSegment(r, s, q)) {
16183
+ const intersects3 = Math.sign(cross4(p, q, r)) * Math.sign(cross4(p, q, s)) < 0 && Math.sign(cross4(r, s, p)) * Math.sign(cross4(r, s, q)) < 0;
16184
+ if (intersects3 || c !== a && c !== b && onSegment(p, q, r) || d !== a && d !== b && onSegment(p, q, s) || a !== c && a !== d && onSegment(r, s, p) || b !== c && b !== d && onSegment(r, s, q)) {
16120
16185
  throw new Error("Breaklines and domain edges must meet only at shared endpoints");
16121
16186
  }
16122
16187
  }
@@ -16349,21 +16414,21 @@ function wrapTerrainLongitude(longitude, west, east) {
16349
16414
  function measureGeographicTerrainSeam(a, b, probes, options = {}) {
16350
16415
  if (a && b && a.heightReference !== b.heightReference)
16351
16416
  throw new Error("Terrain seam height references differ");
16352
- const sample = (field, longitude, latitude) => {
16417
+ const sample = (field, longitude, latitude2) => {
16353
16418
  if (!field || !Number.isFinite(longitude))
16354
- return field == null ? void 0 : field.sample(longitude, latitude, options);
16419
+ return field == null ? void 0 : field.sample(longitude, latitude2, options);
16355
16420
  const mapped = wrapTerrainLongitude(longitude, field.bounds[0], field.bounds[2]);
16356
- return field.sample(mapped ?? longitude, latitude, options);
16421
+ return field.sample(mapped ?? longitude, latitude2, options);
16357
16422
  };
16358
- return probes.map(([longitude, latitude]) => {
16359
- const left = sample(a, longitude, latitude);
16360
- const right = sample(b, longitude, latitude);
16423
+ return probes.map(([longitude, latitude2]) => {
16424
+ const left = sample(a, longitude, latitude2);
16425
+ const right = sample(b, longitude, latitude2);
16361
16426
  const valid = (left == null ? void 0 : left.status) === TerrainSampleStatus.VALID && (right == null ? void 0 : right.status) === TerrainSampleStatus.VALID;
16362
16427
  const derivatives = (left == null ? void 0 : left.gradientStatus) === TerrainSampleStatus.VALID && (right == null ? void 0 : right.gradientStatus) === TerrainSampleStatus.VALID;
16363
16428
  const normalAngle = derivatives ? Math.atan2(Math.hypot(left.normalY * right.normalZ - left.normalZ * right.normalY, left.normalZ * right.normalX - left.normalX * right.normalZ, left.normalX * right.normalY - left.normalY * right.normalX), left.normalX * right.normalX + left.normalY * right.normalY + left.normalZ * right.normalZ) : null;
16364
16429
  return {
16365
16430
  longitude,
16366
- latitude,
16431
+ latitude: latitude2,
16367
16432
  statusA: (left == null ? void 0 : left.status) ?? TerrainSampleStatus.NOT_RESIDENT,
16368
16433
  statusB: (right == null ? void 0 : right.status) ?? TerrainSampleStatus.NOT_RESIDENT,
16369
16434
  gradientStatusA: (left == null ? void 0 : left.gradientStatus) ?? TerrainSampleStatus.NOT_RESIDENT,
@@ -16374,15 +16439,75 @@ function measureGeographicTerrainSeam(a, b, probes, options = {}) {
16374
16439
  });
16375
16440
  }
16376
16441
 
16442
+ // dist/terrain/lod-screen-error.js
16443
+ function slack(value3) {
16444
+ return Math.abs(value3) * (2 * Number.EPSILON) + Number.MIN_VALUE;
16445
+ }
16446
+ function down(value3) {
16447
+ return value3 - slack(value3);
16448
+ }
16449
+ function up(value3) {
16450
+ return value3 + slack(value3);
16451
+ }
16452
+ function boundTerrainLodScreenError(bounds2, projection2) {
16453
+ if (bounds2.min.length !== 3 || bounds2.max.length !== 3 || !bounds2.min.every((value3, i) => Number.isFinite(value3) && value3 <= bounds2.max[i]) || !bounds2.max.every(Number.isFinite) || !Number.isFinite(bounds2.geometricError) || bounds2.geometricError < 0)
16454
+ throw new RangeError("Invalid terrain LOD screen-error bounds");
16455
+ return prepareTerrainLodScreenError(projection2)(bounds2);
16456
+ }
16457
+ function prepareTerrainLodScreenError(projection2) {
16458
+ const { width, height, depthRange = "negative-one-to-one", reversedDepth = false } = projection2;
16459
+ if (projection2.matrix.length !== 16)
16460
+ throw new RangeError("Invalid terrain LOD clip matrix");
16461
+ const matrix = Array.from(projection2.matrix);
16462
+ if (!matrix.every(Number.isFinite) || !Number.isFinite(width) || width <= 0 || !Number.isFinite(height) || height <= 0 || depthRange !== "negative-one-to-one" && depthRange !== "zero-to-one")
16463
+ throw new RangeError("Invalid terrain LOD projection");
16464
+ return ({ min, max, geometricError: error }) => {
16465
+ if (error === 0)
16466
+ return 0;
16467
+ function row(index) {
16468
+ let lower = matrix[12 + index];
16469
+ let upper = lower;
16470
+ let change = 0;
16471
+ for (let axis = 0; axis < 3; axis++) {
16472
+ const coefficient = matrix[4 * axis + index];
16473
+ const a = coefficient * min[axis];
16474
+ const b = coefficient * max[axis];
16475
+ lower = down(lower + down(Math.min(a, b)));
16476
+ upper = up(upper + up(Math.max(a, b)));
16477
+ change = up(change + up(Math.abs(coefficient) * error));
16478
+ }
16479
+ return { lower, upper, change };
16480
+ }
16481
+ const w = row(3);
16482
+ const z = row(2);
16483
+ const nearLow = reversedDepth ? down(w.lower - z.upper) : depthRange === "zero-to-one" ? z.lower : down(z.lower + w.lower);
16484
+ const nearHigh = reversedDepth ? up(w.upper - z.lower) : depthRange === "zero-to-one" ? z.upper : up(z.upper + w.upper);
16485
+ const nearChange = !reversedDepth && depthRange === "zero-to-one" ? z.change : up(z.change + w.change);
16486
+ if (up(nearHigh + nearChange) < 0)
16487
+ return 0;
16488
+ const denominator = down(w.lower - w.change);
16489
+ if (!(down(nearLow - nearChange) > 0 && denominator > 0))
16490
+ return Infinity;
16491
+ function pixelAxis(index, extent) {
16492
+ const coordinate = row(index);
16493
+ const magnitude2 = Math.max(Math.abs(coordinate.lower), Math.abs(coordinate.upper));
16494
+ const ndc = up(magnitude2 / denominator);
16495
+ const coupling = up(ndc * w.change);
16496
+ const numerator = up(coordinate.change + coupling);
16497
+ return up(up(numerator / denominator) * up(extent / 2));
16498
+ }
16499
+ const pixels = pixelAxis(0, width) + pixelAxis(1, height);
16500
+ return Number.isFinite(pixels) ? up(pixels) : Infinity;
16501
+ };
16502
+ }
16503
+
16377
16504
  // dist/terrain/lod-select.js
16378
16505
  function selectTerrainLod(roots2, view) {
16379
16506
  var _a;
16380
- const { position: position2, verticalFov, viewportHeight, targetPixels, hysteresis = 0.2, previouslyRefined, maxVisited = 1e5 } = view;
16381
- if (!position2.every(Number.isFinite) || !Number.isFinite(verticalFov) || verticalFov <= 0 || verticalFov >= Math.PI || !Number.isFinite(viewportHeight) || viewportHeight <= 0 || !Number.isFinite(targetPixels) || targetPixels <= 0 || !(hysteresis >= 0 && hysteresis < 1) || !Number.isSafeInteger(maxVisited) || maxVisited < 1)
16507
+ const { targetPixels, hysteresis = 0.2, previouslyRefined, maxVisited = 1e5 } = view;
16508
+ if (!Number.isFinite(targetPixels) || targetPixels <= 0 || !(hysteresis >= 0 && hysteresis < 1) || !Number.isSafeInteger(maxVisited) || maxVisited < 1)
16382
16509
  throw new Error("Invalid terrain LOD view");
16383
- const scale3 = viewportHeight / (2 * Math.tan(verticalFov / 2));
16384
- if (!Number.isFinite(scale3))
16385
- throw new Error("Terrain LOD projection scale overflow");
16510
+ const pixelError = "projection" in view ? prepareTerrainLodScreenError(view.projection) : createDistanceEstimator(view.position, view.verticalFov, view.viewportHeight);
16386
16511
  const selected = [];
16387
16512
  const refined = /* @__PURE__ */ new Set();
16388
16513
  const unavailable = [];
@@ -16395,14 +16520,13 @@ function selectTerrainLod(roots2, view) {
16395
16520
  if (seen.has(tile.id))
16396
16521
  throw new Error("Duplicate terrain LOD tile or cycle");
16397
16522
  seen.add(tile.id);
16398
- if (![...tile.min, ...tile.max, tile.geometricError].every(Number.isFinite) || tile.geometricError < 0 || tile.min.some((n, i) => n > tile.max[i]))
16523
+ if (tile.min.length !== 3 || tile.max.length !== 3 || ![...tile.min, ...tile.max, tile.geometricError].every(Number.isFinite) || tile.geometricError < 0 || tile.min.some((n, i) => n > tile.max[i]))
16399
16524
  throw new Error("Invalid terrain LOD tile bounds or error");
16400
16525
  if (!tile.resident) {
16401
16526
  unavailable.push(tile.id);
16402
16527
  continue;
16403
16528
  }
16404
- const distance = Math.hypot(...position2.map((n, i) => Math.max(tile.min[i] - n, n - tile.max[i], 0)));
16405
- const pixels = tile.geometricError === 0 ? 0 : tile.geometricError / distance * scale3;
16529
+ const pixels = pixelError(tile);
16406
16530
  const threshold = targetPixels * ((previouslyRefined == null ? void 0 : previouslyRefined.has(tile.id)) ? 1 - hysteresis : 1);
16407
16531
  if (pixels > threshold && ((_a = tile.children) == null ? void 0 : _a.length) && tile.children.every((child) => child.resident)) {
16408
16532
  if (pending.length + seen.size + tile.children.length > maxVisited)
@@ -16416,6 +16540,17 @@ function selectTerrainLod(roots2, view) {
16416
16540
  }
16417
16541
  return { selected, refined, unavailable };
16418
16542
  }
16543
+ function createDistanceEstimator(position2, verticalFov, viewportHeight) {
16544
+ if (!position2.every(Number.isFinite) || !Number.isFinite(verticalFov) || verticalFov <= 0 || verticalFov >= Math.PI || !Number.isFinite(viewportHeight) || viewportHeight <= 0)
16545
+ throw new Error("Invalid terrain LOD view");
16546
+ const scale3 = viewportHeight / (2 * Math.tan(verticalFov / 2));
16547
+ if (!Number.isFinite(scale3))
16548
+ throw new Error("Terrain LOD projection scale overflow");
16549
+ return (tile) => {
16550
+ const distance = Math.hypot(...position2.map((n, i) => Math.max(tile.min[i] - n, n - tile.max[i], 0)));
16551
+ return tile.geometricError === 0 ? 0 : tile.geometricError / distance * scale3;
16552
+ };
16553
+ }
16419
16554
 
16420
16555
  // dist/terrain/lod-stitch.js
16421
16556
  function stitchTerrainLodCut(input, seams) {
@@ -16512,14 +16647,14 @@ function splitTerrainBreaklines(input, options = {}) {
16512
16647
  throw new Error("Breakline output limit exceeded");
16513
16648
  knots.push({ t, point: point2 });
16514
16649
  };
16515
- const cross6 = (ax, ay, bx, by) => ax * by - ay * bx;
16650
+ const cross7 = (ax, ay, bx, by) => ax * by - ay * bx;
16516
16651
  for (let i = 0; i < lines.length; i++) {
16517
16652
  const a = lines[i];
16518
16653
  for (let j = i + 1; j < lines.length; j++) {
16519
16654
  const b = lines[j];
16520
16655
  const x = b.p[0] - a.p[0], y = b.p[1] - a.p[1];
16521
- const det = cross6(a.dx, a.dy, b.dx, b.dy);
16522
- const u = cross6(x, y, a.dx, a.dy), t = cross6(x, y, b.dx, b.dy);
16656
+ const det = cross7(a.dx, a.dy, b.dx, b.dy);
16657
+ const u = cross7(x, y, a.dx, a.dy), t = cross7(x, y, b.dx, b.dy);
16523
16658
  if (![det, u, t].every(Number.isFinite))
16524
16659
  throw new Error("Breakline intersection overflow");
16525
16660
  if (det === 0) {
@@ -16910,9 +17045,12 @@ var cross5 = (a, b) => [
16910
17045
  var dot4 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
16911
17046
  var edges = ([a, b, c]) => [sub2(b, a), sub2(c, b), sub2(a, c)];
16912
17047
  function sweepTerrainPolytope(surface2, collider, translation, { maxWork = 1e5 } = {}) {
17048
+ return queryTerrainPolytope(surface2.copyData(), surface2.origin, collider, translation, maxWork);
17049
+ }
17050
+ function queryTerrainPolytope(data, origin, collider, translation, maxWork, padding = 0) {
16913
17051
  if (!Number.isSafeInteger(maxWork) || maxWork < 0 || translation.length !== 3 || !translation.every(Number.isFinite) || collider.vertices.length < 4 || collider.faces.length < 4 || collider.vertices.some((point2) => point2.length !== 3 || !point2.every(Number.isFinite)))
16914
17052
  throw new RangeError("Invalid terrain polytope sweep");
16915
- const vertices = collider.vertices.map((point2) => sub2(point2, surface2.origin));
17053
+ const vertices = collider.vertices.map((point2) => sub2(point2, origin));
16916
17054
  const normals = [];
16917
17055
  const directions = [];
16918
17056
  for (const face of collider.faces) {
@@ -16925,7 +17063,7 @@ function sweepTerrainPolytope(surface2, collider, translation, { maxWork = 1e5 }
16925
17063
  normals.push(normal2);
16926
17064
  directions.push(...side);
16927
17065
  }
16928
- return sweepTriangles(surface2.copyData(), vertices, normals, directions, translation, maxWork);
17066
+ return sweepTriangles(data, vertices, normals, directions, translation, maxWork, void 0, padding);
16929
17067
  }
16930
17068
  function sweepTerrainTriangleMesh(surface2, collider, translation, { maxWork = 1e5 } = {}) {
16931
17069
  if (!Number.isSafeInteger(maxWork) || maxWork < 0 || translation.length !== 3 || !translation.every(Number.isFinite))
@@ -16955,7 +17093,7 @@ function sweepTerrainTriangleMesh(surface2, collider, translation, { maxWork = 1
16955
17093
  }
16956
17094
  return best ? { ...best, work } : { status: "miss", work };
16957
17095
  }
16958
- function sweepTriangles(data, vertices, normals, directions, translation, maxWork, movingTriangleNormal) {
17096
+ function sweepTriangles(data, vertices, normals, directions, translation, maxWork, movingTriangleNormal, padding = 0) {
16959
17097
  let work = 0;
16960
17098
  let best;
16961
17099
  const vertex = (index) => {
@@ -17001,6 +17139,8 @@ function sweepTriangles(data, vertices, normals, directions, translation, maxWor
17001
17139
  min = Math.min(min, projection2);
17002
17140
  max = Math.max(max, projection2);
17003
17141
  }
17142
+ min -= padding;
17143
+ max += padding;
17004
17144
  const speed = dot4(translation, unit3);
17005
17145
  if (![low, high, min, max, speed, length].every(Number.isFinite))
17006
17146
  throw new RangeError("Terrain polytope projection overflow");
@@ -17029,6 +17169,9 @@ function sweepTriangles(data, vertices, normals, directions, translation, maxWor
17029
17169
  return best ? { ...best, work } : { status: "miss", work };
17030
17170
  }
17031
17171
  function sweepTerrainBox(surface2, center, halfExtents, translation, options) {
17172
+ return sweepTerrainPolytope(surface2, createSweepBox(center, halfExtents), translation, options);
17173
+ }
17174
+ function createSweepBox(center, halfExtents) {
17032
17175
  if (halfExtents.length !== 3 || halfExtents.some((value3) => !(value3 > 0)))
17033
17176
  throw new RangeError("Terrain box half extents must be positive");
17034
17177
  const vertices = Array.from({ length: 8 }, (_, i) => [
@@ -17036,7 +17179,7 @@ function sweepTerrainBox(surface2, center, halfExtents, translation, options) {
17036
17179
  center[1] + (i & 2 ? 1 : -1) * halfExtents[1],
17037
17180
  center[2] + (i & 4 ? 1 : -1) * halfExtents[2]
17038
17181
  ]);
17039
- return sweepTerrainPolytope(surface2, {
17182
+ return {
17040
17183
  vertices,
17041
17184
  faces: [
17042
17185
  [0, 1, 3],
@@ -17052,7 +17195,102 @@ function sweepTerrainBox(surface2, center, halfExtents, translation, options) {
17052
17195
  [1, 5, 7],
17053
17196
  [1, 7, 3]
17054
17197
  ]
17055
- }, translation, options);
17198
+ };
17199
+ }
17200
+
17201
+ // dist/terrain/sweep-rotating-capsule.js
17202
+ function sweepTerrainRotatingCapsule(surface2, start, end, radius, { pivot, translation, rotation }, { maxWork = 1e5, fractionTolerance = 1e-5 } = {}) {
17203
+ var _a;
17204
+ const norm = Math.hypot(...rotation);
17205
+ if (![start, end, pivot, translation].every((p) => p.length === 3 && p.every(Number.isFinite)) || rotation.length !== 4 || !(norm > 0 && Number.isFinite(norm)) || !Number.isFinite(radius) || radius < 0 || !Number.isSafeInteger(maxWork) || maxWork < 0 || !(fractionTolerance >= Number.EPSILON && fractionTolerance <= 1))
17206
+ throw new RangeError("Invalid terrain capsule rigid motion");
17207
+ const sign2 = rotation[3] < 0 ? -1 : 1;
17208
+ const axisLength = Math.hypot(rotation[0], rotation[1], rotation[2]);
17209
+ const angle3 = 2 * Math.atan2(axisLength, Math.abs(rotation[3]));
17210
+ if (angle3 === 0) {
17211
+ return sweepTerrainCapsule(surface2, start, end, translation, radius, {
17212
+ maxWork,
17213
+ fractionTolerance
17214
+ });
17215
+ }
17216
+ const x = rotation[0] / axisLength * sign2;
17217
+ const y = rotation[1] / axisLength * sign2;
17218
+ const z = rotation[2] / axisLength * sign2;
17219
+ const offsets = [start, end].map((p) => p.map((v, i) => v - pivot[i]));
17220
+ const reach = Math.max(...offsets.map((p) => Math.hypot(...p)));
17221
+ const speed = Math.hypot(...translation) + angle3 * reach;
17222
+ const scale3 = Math.max(Math.hypot(...pivot), reach, speed, radius);
17223
+ if (!Number.isFinite(scale3))
17224
+ throw new RangeError("Terrain capsule rigid motion overflow");
17225
+ let work = 0;
17226
+ function probe(t) {
17227
+ if (work >= maxWork)
17228
+ return null;
17229
+ work++;
17230
+ const sin = Math.sin(angle3 * t);
17231
+ const cos = Math.cos(angle3 * t);
17232
+ const [a, b] = t === 0 ? [start, end] : offsets.map(([u, v, w]) => {
17233
+ const d = (x * u + y * v + z * w) * (1 - cos);
17234
+ const pos = [
17235
+ pivot[0] + (translation[0] * t + u * cos + (y * w - z * v) * sin + x * d),
17236
+ pivot[1] + (translation[1] * t + v * cos + (z * u - x * w) * sin + y * d),
17237
+ pivot[2] + (translation[2] * t + w * cos + (x * v - y * u) * sin + z * d)
17238
+ ];
17239
+ if (!pos.every(Number.isFinite))
17240
+ throw new RangeError("Terrain capsule pose overflow");
17241
+ return pos;
17242
+ });
17243
+ const query = surface2.nearestSegmentQuery(a, b, { maxWork: maxWork - work });
17244
+ work += query.work;
17245
+ return query;
17246
+ }
17247
+ const initial = probe(0);
17248
+ if ((initial == null ? void 0 : initial.result) && initial.result.distance <= radius)
17249
+ return { status: "hit", fraction: 0, lowerFraction: 0, work, contact: initial.result };
17250
+ if (!(initial == null ? void 0 : initial.complete))
17251
+ return { status: "incomplete", work };
17252
+ if (!initial.result || speed === 0)
17253
+ return { status: "miss", work };
17254
+ let clearUntil = 0;
17255
+ let witness;
17256
+ const pending = [[0, 1]];
17257
+ while (pending.length) {
17258
+ if (witness && witness.fraction - clearUntil <= fractionTolerance)
17259
+ return { status: "hit", lowerFraction: clearUntil, work, ...witness };
17260
+ const [lo, hi] = pending.pop();
17261
+ const mid = lo + (hi - lo) / 2;
17262
+ const query = probe(mid);
17263
+ const contact = query == null ? void 0 : query.result;
17264
+ if (contact && contact.distance <= radius) {
17265
+ witness = { fraction: mid, contact };
17266
+ if (mid - clearUntil <= fractionTolerance)
17267
+ return { status: "hit", lowerFraction: clearUntil, work, ...witness };
17268
+ if (mid === lo || mid === hi)
17269
+ return { status: "incomplete", work };
17270
+ pending.push([lo, mid]);
17271
+ continue;
17272
+ }
17273
+ if (!(query == null ? void 0 : query.complete))
17274
+ return { status: "incomplete", work };
17275
+ const travel = speed * Math.max(mid - lo, hi - mid);
17276
+ const allowance = 16 * Number.EPSILON * Math.max(scale3, (contact == null ? void 0 : contact.distance) ?? 0);
17277
+ if (!contact || contact.distance - radius > travel + allowance) {
17278
+ clearUntil = hi;
17279
+ continue;
17280
+ }
17281
+ if (hi - clearUntil <= fractionTolerance) {
17282
+ const final = (witness == null ? void 0 : witness.fraction) === hi ? witness.contact : (_a = probe(hi)) == null ? void 0 : _a.result;
17283
+ if (final && final.distance <= radius)
17284
+ return { status: "hit", fraction: hi, lowerFraction: clearUntil, work, contact: final };
17285
+ }
17286
+ if (mid === lo || mid === hi || hi - lo <= fractionTolerance / 4)
17287
+ return { status: "incomplete", work };
17288
+ pending.push([mid, hi], [lo, mid]);
17289
+ }
17290
+ return witness ? { status: "hit", lowerFraction: clearUntil, work, ...witness } : { status: "miss", work };
17291
+ }
17292
+ function sweepTerrainRotatingSphere(surface2, center, radius, motion, options) {
17293
+ return sweepTerrainRotatingCapsule(surface2, center, center, radius, motion, options);
17056
17294
  }
17057
17295
 
17058
17296
  // dist/terrain/sweep-cylinder.js
@@ -17226,11 +17464,11 @@ function discoverGeographicTerrainLodSeams(cut2) {
17226
17464
 
17227
17465
  // dist/terrain/geographic-poles.js
17228
17466
  function discoverGeographicTerrainPoles(cut2) {
17229
- function collect(latitude, edge2) {
17467
+ function collect(latitude2, edge2) {
17230
17468
  const incident = [];
17231
17469
  for (let tile = 0; tile < cut2.length; tile++) {
17232
17470
  const [west, south, east, north] = getGeographicTileBounds(cut2[tile]);
17233
- if ((edge2 === "north" ? north : south) === latitude)
17471
+ if ((edge2 === "north" ? north : south) === latitude2)
17234
17472
  incident.push({ tile, edge: edge2, longitude: [west, east] });
17235
17473
  }
17236
17474
  incident.sort((a, b) => a.longitude[0] - b.longitude[0]);
@@ -17245,8 +17483,1192 @@ function discoverGeographicTerrainPoles(cut2) {
17245
17483
  }
17246
17484
  if (cursor < 180)
17247
17485
  gaps.push([cursor, 180]);
17248
- return { latitude, incident, gaps };
17486
+ return { latitude: latitude2, incident, gaps };
17249
17487
  }
17250
17488
  return { north: collect(90, "north"), south: collect(-90, "south") };
17251
17489
  }
17490
+
17491
+ // dist/terrain/sweep-rotation.js
17492
+ function sweepTerrainRotatingPolytope(surface2, collider, { pivot, translation, rotation }, { maxWork = 1e5, fractionTolerance = 1e-5 } = {}) {
17493
+ const norm = Math.hypot(...rotation);
17494
+ if (pivot.length !== 3 || translation.length !== 3 || rotation.length !== 4 || !pivot.every(Number.isFinite) || !translation.every(Number.isFinite) || !(norm > 0 && Number.isFinite(norm)) || !Number.isSafeInteger(maxWork) || maxWork < 0 || !(fractionTolerance >= Number.EPSILON && fractionTolerance <= 1))
17495
+ throw new RangeError("Invalid terrain rigid motion");
17496
+ const localPivot = pivot.map((v, i) => v - surface2.origin[i]);
17497
+ const offsets = collider.vertices.map((v) => v.map((x2, i) => x2 - pivot[i]));
17498
+ const radius = offsets.reduce((r, v) => Math.max(r, Math.hypot(...v)), 0);
17499
+ const sign2 = rotation[3] < 0 ? -1 : 1;
17500
+ const vectorNorm = Math.hypot(rotation[0], rotation[1], rotation[2]);
17501
+ const angle3 = 2 * Math.atan2(vectorNorm, Math.abs(rotation[3]));
17502
+ const speed = Math.hypot(...translation) + angle3 * radius;
17503
+ if (!Number.isFinite(speed))
17504
+ throw new RangeError("Terrain rigid motion overflow");
17505
+ const data = surface2.copyData();
17506
+ if (angle3 === 0) {
17507
+ const result = queryTerrainPolytope(data, surface2.origin, collider, translation, maxWork);
17508
+ return result.status === "hit" ? { ...result, lowerFraction: result.fraction } : result;
17509
+ }
17510
+ const [x, y, z] = rotation.slice(0, 3).map((v) => v / vectorNorm * sign2);
17511
+ const zero = [0, 0, 0];
17512
+ let work = 0;
17513
+ const pose = (t) => {
17514
+ const sin = Math.sin(angle3 * t);
17515
+ const cos = Math.cos(angle3 * t);
17516
+ return {
17517
+ faces: collider.faces,
17518
+ vertices: offsets.map(([a, b, c]) => {
17519
+ const projection2 = (x * a + y * b + z * c) * (1 - cos);
17520
+ return [
17521
+ localPivot[0] + translation[0] * t + a * cos + (y * c - z * b) * sin + x * projection2,
17522
+ localPivot[1] + translation[1] * t + b * cos + (z * a - x * c) * sin + y * projection2,
17523
+ localPivot[2] + translation[2] * t + c * cos + (x * b - y * a) * sin + z * projection2
17524
+ ];
17525
+ })
17526
+ };
17527
+ };
17528
+ const probe = (shape, padding = 0) => {
17529
+ if (work >= maxWork)
17530
+ return { status: "incomplete", work: 0 };
17531
+ work++;
17532
+ const result = queryTerrainPolytope(data, zero, shape, zero, maxWork - work, padding);
17533
+ work += result.work;
17534
+ return result;
17535
+ };
17536
+ const initial = probe(pose(0));
17537
+ if (initial.status === "hit")
17538
+ return { ...initial, lowerFraction: 0, work };
17539
+ if (initial.status === "incomplete")
17540
+ return { status: "incomplete", work };
17541
+ let clearUntil = 0;
17542
+ let witness;
17543
+ const pending = [[0, 1]];
17544
+ while (pending.length) {
17545
+ if (witness && witness.fraction - clearUntil <= fractionTolerance)
17546
+ return { ...witness, lowerFraction: clearUntil, work };
17547
+ const [lo, hi] = pending.pop();
17548
+ const mid = lo + (hi - lo) / 2;
17549
+ const shape = pose(mid);
17550
+ const padding = speed * Math.max(mid - lo, hi - mid);
17551
+ const expanded = probe(shape, padding + 8 * Number.EPSILON * (radius + padding));
17552
+ if (expanded.status === "miss") {
17553
+ clearUntil = hi;
17554
+ continue;
17555
+ }
17556
+ if (expanded.status === "incomplete")
17557
+ return { status: "incomplete", work };
17558
+ const hit = probe(shape);
17559
+ if (hit.status === "incomplete")
17560
+ return { status: "incomplete", work };
17561
+ if (hit.status === "hit") {
17562
+ witness = { ...hit, fraction: mid };
17563
+ if (mid - clearUntil <= fractionTolerance)
17564
+ return { ...witness, lowerFraction: clearUntil, work };
17565
+ pending.push([lo, mid]);
17566
+ } else if (hi - clearUntil <= fractionTolerance) {
17567
+ const end = (witness == null ? void 0 : witness.fraction) === hi ? witness : probe(pose(hi));
17568
+ if ((end == null ? void 0 : end.status) === "hit")
17569
+ return { ...end, fraction: hi, lowerFraction: clearUntil, work };
17570
+ if (hi - lo <= fractionTolerance / 4)
17571
+ return { status: "incomplete", work };
17572
+ pending.push([mid, hi], [lo, mid]);
17573
+ } else {
17574
+ if (mid === lo || mid === hi || hi - lo <= fractionTolerance / 4)
17575
+ return { status: "incomplete", work };
17576
+ pending.push([mid, hi], [lo, mid]);
17577
+ }
17578
+ }
17579
+ return witness ? { ...witness, lowerFraction: clearUntil, work } : { status: "miss", work };
17580
+ }
17581
+ function sweepTerrainRotatingBox(surface2, center, halfExtents, motion, options) {
17582
+ return sweepTerrainRotatingPolytope(surface2, createSweepBox(center, halfExtents), motion, options);
17583
+ }
17584
+
17585
+ // dist/terrain/regional-viewshed.js
17586
+ var TerrainRegionalViewStatus = {
17587
+ VISIBLE: 0,
17588
+ BLOCKED: 1,
17589
+ UNKNOWN: 2,
17590
+ MISSING_TARGET: 3,
17591
+ OBSERVER: 4
17592
+ };
17593
+ function createTerrainRegionalViewshed(grid, sample, options) {
17594
+ const { width, height, origin, spacing } = grid;
17595
+ const { observer, sampleStep, radius, targetOffset = 0, maxTargets = 1e5, maxSamples = 4e6 } = options;
17596
+ const count = width * height;
17597
+ if (![width, height, count, maxTargets, maxSamples].every(Number.isSafeInteger) || width < 1 || height < 1 || count > maxTargets || maxSamples < 1 || origin.length !== 2 || spacing.length !== 2 || observer.length !== 3 || ![...origin, ...spacing, ...observer, sampleStep, targetOffset].every(Number.isFinite) || spacing.some((value3) => value3 <= 0) || sampleStep <= 0 || targetOffset < 0 || radius !== void 0 && (!Number.isFinite(radius) || radius <= 0 || observer[2] <= -radius))
17598
+ throw new RangeError("Invalid regional viewshed grid or options");
17599
+ const statuses = new Uint8Array(count);
17600
+ const targetStatuses = new Uint8Array(count);
17601
+ const sampledCoverage = new Uint8Array(count);
17602
+ let samples = 0;
17603
+ function read(x, y) {
17604
+ if (samples >= maxSamples)
17605
+ throw new RangeError("Regional viewshed sample budget exceeded");
17606
+ samples++;
17607
+ const result = sample(x, y);
17608
+ if (!Number.isInteger(result.status) || result.status < 0 || result.status > TerrainSampleStatus.NOT_RESIDENT || result.status === TerrainSampleStatus.VALID && (!Number.isFinite(result.height) || radius !== void 0 && result.height <= -radius))
17609
+ throw new RangeError("Invalid regional viewshed sample");
17610
+ return result;
17611
+ }
17612
+ function sight(distance, elevation) {
17613
+ let rise = elevation - observer[2];
17614
+ let run = distance;
17615
+ if (radius !== void 0) {
17616
+ const theta = distance / radius;
17617
+ const radial = radius + elevation;
17618
+ const halfSine = Math.sin(theta / 2);
17619
+ rise -= radial * (2 * halfSine * halfSine);
17620
+ run = radial * Math.sin(theta);
17621
+ }
17622
+ if (!Number.isFinite(rise) || !Number.isFinite(run) || run <= 0)
17623
+ throw new RangeError("Regional viewshed sight calculation overflow");
17624
+ return [rise, run];
17625
+ }
17626
+ const observerSample = { ...read(observer[0], observer[1]) };
17627
+ const observerValid = observerSample.status === TerrainSampleStatus.VALID;
17628
+ for (let i = 0; i < count; i++) {
17629
+ const x = origin[0] + i % width * spacing[0];
17630
+ const y = origin[1] + Math.floor(i / width) * spacing[1];
17631
+ const dx = x - observer[0];
17632
+ const dy = y - observer[1];
17633
+ const distance = Math.hypot(dx, dy);
17634
+ if (!Number.isFinite(distance) || radius !== void 0 && distance / radius >= Math.PI)
17635
+ throw new RangeError("Regional viewshed distance outside supported range");
17636
+ const target = distance === 0 ? observerSample : read(x, y);
17637
+ targetStatuses[i] = target.status;
17638
+ if (target.status !== TerrainSampleStatus.VALID) {
17639
+ statuses[i] = TerrainRegionalViewStatus.MISSING_TARGET;
17640
+ continue;
17641
+ }
17642
+ if (distance === 0) {
17643
+ statuses[i] = TerrainRegionalViewStatus.OBSERVER;
17644
+ sampledCoverage[i] = 1;
17645
+ continue;
17646
+ }
17647
+ const [targetRise, targetRun] = sight(distance, target.height + targetOffset);
17648
+ const segments = Math.max(1, Math.ceil(distance / sampleStep));
17649
+ if (!Number.isSafeInteger(segments) || segments - 1 > maxSamples - samples)
17650
+ throw new RangeError("Regional viewshed sample budget exceeded");
17651
+ let complete = observerValid;
17652
+ let blocked = observerValid && observerSample.height > observer[2];
17653
+ for (let j = 1; j < segments; j++) {
17654
+ const fraction = j / segments;
17655
+ const station = read(observer[0] + dx * fraction, observer[1] + dy * fraction);
17656
+ if (station.status !== TerrainSampleStatus.VALID) {
17657
+ complete = false;
17658
+ } else if (!blocked) {
17659
+ const [rise, run] = sight(distance * fraction, station.height);
17660
+ blocked = compareTerrainSlopes(rise, run, targetRise, targetRun) >= 0;
17661
+ }
17662
+ }
17663
+ sampledCoverage[i] = complete ? 1 : 0;
17664
+ statuses[i] = blocked ? TerrainRegionalViewStatus.BLOCKED : complete ? TerrainRegionalViewStatus.VISIBLE : TerrainRegionalViewStatus.UNKNOWN;
17665
+ }
17666
+ return { statuses, targetStatuses, sampledCoverage, samples };
17667
+ }
17668
+
17669
+ // dist/terrain/hydrology.js
17670
+ function getTerrainCellMetrics(field) {
17671
+ if (field.registration !== "cell")
17672
+ throw new Error("Terrain cell metrics require cell registration");
17673
+ const [cx, cy] = field.columnStep;
17674
+ const [rx, ry] = field.rowStep;
17675
+ const determinant = cx * ry - cy * rx;
17676
+ const columnLength = Math.hypot(cx, cy);
17677
+ const rowLength = Math.hypot(rx, ry);
17678
+ const area = Math.abs(determinant);
17679
+ if (!(area > 0 && Number.isFinite(area) && Number.isFinite(columnLength + rowLength)))
17680
+ throw new RangeError("Invalid terrain cell geometry");
17681
+ const sign2 = Math.sign(determinant);
17682
+ const east = [sign2 * ry / rowLength, -sign2 * rx / rowLength];
17683
+ const south = [-sign2 * cy / columnLength, sign2 * cx / columnLength];
17684
+ return {
17685
+ area,
17686
+ faceLengths: [rowLength, rowLength, columnLength, columnLength],
17687
+ faceNormals: [[-east[0], -east[1]], east, [-south[0], -south[1]], south]
17688
+ };
17689
+ }
17690
+ function createTerrainDrainage(field, { outlets = [], maxCells = 4194304 } = {}) {
17691
+ const { width, height, columnStep, rowStep } = field;
17692
+ const count = width * height;
17693
+ if (!Number.isSafeInteger(maxCells) || maxCells < 0 || count > maxCells || count > 2147483647)
17694
+ throw new RangeError("Terrain drainage exceeds its cell budget");
17695
+ const { area: cellArea } = getTerrainCellMetrics(field);
17696
+ for (const i of outlets) {
17697
+ if (!Number.isInteger(i) || i < 0 || i >= count || field.getHeight(i % width, Math.floor(i / width)) === void 0)
17698
+ throw new RangeError("Terrain outlet must identify a valid cell");
17699
+ }
17700
+ const { heights, validity } = field.copyData();
17701
+ const receiver = new Int32Array(count).fill(-1);
17702
+ const terminal = new Int32Array(count).fill(-1);
17703
+ const contributingCells = new Uint32Array(count);
17704
+ const incoming = new Uint8Array(count);
17705
+ const queue = new Int32Array(count);
17706
+ const outletSet = new Set(outlets);
17707
+ const offsets = [];
17708
+ for (let dy = -1; dy <= 1; dy++) {
17709
+ for (let dx = -1; dx <= 1; dx++) {
17710
+ if (!dx && !dy)
17711
+ continue;
17712
+ const distance = Math.hypot(dx * columnStep[0] + dy * rowStep[0], dx * columnStep[1] + dy * rowStep[1]);
17713
+ if (!(distance > 0 && Number.isFinite(distance)))
17714
+ throw new RangeError("Invalid terrain neighbor distance");
17715
+ offsets.push({ dx, dy, distance });
17716
+ }
17717
+ }
17718
+ for (let i = 0; i < count; i++) {
17719
+ if (!validity[i])
17720
+ continue;
17721
+ contributingCells[i] = 1;
17722
+ if (outletSet.has(i))
17723
+ continue;
17724
+ const col = i % width;
17725
+ const row = Math.floor(i / width);
17726
+ let steepest = 0;
17727
+ for (const { dx, dy, distance } of offsets) {
17728
+ if (col + dx < 0 || col + dx >= width || row + dy < 0 || row + dy >= height)
17729
+ continue;
17730
+ const j = i + dx + dy * width;
17731
+ if (!validity[j] || heights[j] >= heights[i])
17732
+ continue;
17733
+ if (dx && dy && (!validity[i + dx] || !validity[i + dy * width]))
17734
+ continue;
17735
+ const slope2 = (heights[i] - heights[j]) / distance;
17736
+ if (!Number.isFinite(slope2) || slope2 === 0)
17737
+ throw new RangeError("Terrain drainage slope is outside the representable range");
17738
+ if (slope2 > steepest) {
17739
+ steepest = slope2;
17740
+ receiver[i] = j;
17741
+ }
17742
+ }
17743
+ if (receiver[i] >= 0)
17744
+ incoming[receiver[i]]++;
17745
+ }
17746
+ let end = 0;
17747
+ for (let i = 0; i < count; i++)
17748
+ if (validity[i] && !incoming[i])
17749
+ queue[end++] = i;
17750
+ for (let cursor = 0; cursor < end; cursor++) {
17751
+ const i = queue[cursor];
17752
+ const next = receiver[i];
17753
+ if (next < 0)
17754
+ continue;
17755
+ contributingCells[next] += contributingCells[i];
17756
+ if (--incoming[next] === 0)
17757
+ queue[end++] = next;
17758
+ }
17759
+ for (let cursor = end - 1; cursor >= 0; cursor--) {
17760
+ const i = queue[cursor];
17761
+ const next = receiver[i];
17762
+ terminal[i] = next < 0 ? i : terminal[next];
17763
+ }
17764
+ return { receiver, terminal, contributingCells, cellArea };
17765
+ }
17766
+
17767
+ // dist/terrain/depression-fill.js
17768
+ function fillTerrainDepressions(field, { outlets, maxCells = 4194304 }) {
17769
+ if (field.registration !== "cell")
17770
+ throw new Error("Terrain depression fill requires cell registration");
17771
+ const { width, height } = field;
17772
+ const count = width * height;
17773
+ if (!Number.isSafeInteger(maxCells) || maxCells < 0 || count > maxCells || count > 2147483647)
17774
+ throw new RangeError("Terrain depression fill exceeds its cell budget");
17775
+ if (!outlets.length)
17776
+ throw new RangeError("Terrain depression fill requires an outlet");
17777
+ for (const i of outlets) {
17778
+ if (!Number.isInteger(i) || i < 0 || i >= count || field.getHeight(i % width, Math.floor(i / width)) === void 0)
17779
+ throw new RangeError("Terrain outlet must identify a valid cell");
17780
+ }
17781
+ const { heights, validity } = field.copyData();
17782
+ const receiver = new Int32Array(count).fill(-2);
17783
+ const heap = new Int32Array(count);
17784
+ let size = 0;
17785
+ let disconnectedCells = field.validCount;
17786
+ const before = (a, b) => heights[a] < heights[b] || heights[a] === heights[b] && a < b;
17787
+ function push(cell) {
17788
+ let slot = size++;
17789
+ while (slot > 0) {
17790
+ const parent = Math.floor((slot - 1) / 2);
17791
+ if (!before(cell, heap[parent]))
17792
+ break;
17793
+ heap[slot] = heap[parent];
17794
+ slot = parent;
17795
+ }
17796
+ heap[slot] = cell;
17797
+ }
17798
+ function pop() {
17799
+ const first = heap[0];
17800
+ const tail = heap[--size];
17801
+ let slot = 0;
17802
+ let child = 1;
17803
+ while (child < size) {
17804
+ if (child + 1 < size && before(heap[child + 1], heap[child]))
17805
+ child++;
17806
+ if (!before(heap[child], tail))
17807
+ break;
17808
+ heap[slot] = heap[child];
17809
+ slot = child;
17810
+ child = slot * 2 + 1;
17811
+ }
17812
+ if (size)
17813
+ heap[slot] = tail;
17814
+ return first;
17815
+ }
17816
+ function visit(cell, parent) {
17817
+ if (!validity[cell] || receiver[cell] !== -2)
17818
+ return;
17819
+ receiver[cell] = parent;
17820
+ disconnectedCells--;
17821
+ if (parent >= 0)
17822
+ heights[cell] = Math.max(heights[cell], heights[parent]);
17823
+ push(cell);
17824
+ }
17825
+ for (const outlet of outlets)
17826
+ visit(outlet, -1);
17827
+ while (size) {
17828
+ const cell = pop();
17829
+ const column = cell % width;
17830
+ if (column > 0)
17831
+ visit(cell - 1, cell);
17832
+ if (column + 1 < width)
17833
+ visit(cell + 1, cell);
17834
+ if (cell >= width)
17835
+ visit(cell - width, cell);
17836
+ if (cell < count - width)
17837
+ visit(cell + width, cell);
17838
+ }
17839
+ return {
17840
+ field: new HeightField({
17841
+ width,
17842
+ height,
17843
+ heights,
17844
+ validity,
17845
+ origin: field.origin,
17846
+ columnStep: field.columnStep,
17847
+ rowStep: field.rowStep,
17848
+ registration: field.registration,
17849
+ diagonal: field.diagonal,
17850
+ heightReference: field.heightReference
17851
+ }),
17852
+ receiver,
17853
+ disconnectedCells
17854
+ };
17855
+ }
17856
+
17857
+ // dist/terrain/cutout-region.js
17858
+ var PLAN = /* @__PURE__ */ Symbol.for("@math.gl/geospatial/terrain-cutout-polygons/v1");
17859
+ function createTerrainCutoutPlan(plan) {
17860
+ return Object.freeze({ [PLAN]: Object.freeze(plan) });
17861
+ }
17862
+ function getTerrainCutoutPlan(region) {
17863
+ if (Array.isArray(region))
17864
+ return void 0;
17865
+ const plan = region == null ? void 0 : region[PLAN];
17866
+ if (!plan)
17867
+ throw new RangeError("Invalid prepared terrain cutout polygons");
17868
+ return plan;
17869
+ }
17870
+ function copyTerrainCutoutRegion(region) {
17871
+ return getTerrainCutoutPlan(region) ? region : region.map((p) => [p[0], p[1]]);
17872
+ }
17873
+ function sameTerrainCutoutRegion(a, b) {
17874
+ if (getTerrainCutoutPlan(a) || getTerrainCutoutPlan(b))
17875
+ return a === b;
17876
+ const aa = a, bb = b;
17877
+ return aa.length === bb.length && aa.every((p, i) => bb[i].length === 2 && p[0] === bb[i][0] && p[1] === bb[i][1]);
17878
+ }
17879
+
17880
+ // dist/terrain/mesh-cutout.js
17881
+ function splitTerrainMesh(mesh, polygon2, { maxWork = 4e6, maxVertices = 5e5, maxTriangles = 5e5 } = {}) {
17882
+ if (![maxWork, maxVertices, maxTriangles].every((n) => Number.isSafeInteger(n) && n >= 0) || maxVertices > 4294967295 || maxTriangles > 4294967295 || !(mesh.positions instanceof Float32Array || mesh.positions instanceof Float64Array) || !(mesh.indices instanceof Uint16Array || mesh.indices instanceof Uint32Array) || mesh.positions.length % 3 || mesh.indices.length % 3 || mesh.positions.length / 3 > maxVertices || mesh.indices.length / 3 > maxTriangles || !mesh.positions.every(Number.isFinite))
17883
+ throw new RangeError("Invalid terrain cutout mesh or capacity");
17884
+ let work = 0;
17885
+ function charge(amount) {
17886
+ work += amount;
17887
+ if (work > maxWork)
17888
+ throw new RangeError("Terrain cutout work budget exceeded");
17889
+ }
17890
+ const prepared2 = getTerrainCutoutPlan(polygon2);
17891
+ const ring = prepared2 ? void 0 : validatePolygon(polygon2, charge);
17892
+ const lines = (prepared2 == null ? void 0 : prepared2.lines) ?? ring.map((p, i) => [p, ring[(i + 1) % ring.length]]);
17893
+ const vertices = [];
17894
+ for (let i = 0; i < mesh.positions.length; i += 3)
17895
+ vertices.push([mesh.positions[i], mesh.positions[i + 1], mesh.positions[i + 2]]);
17896
+ const faces = [];
17897
+ for (let i = 0; i < mesh.indices.length; i += 3) {
17898
+ const face = [mesh.indices[i], mesh.indices[i + 1], mesh.indices[i + 2]];
17899
+ if (face.some((id) => id >= vertices.length))
17900
+ throw new RangeError("Invalid terrain cutout index");
17901
+ checkTriangle(vertices[face[0]], vertices[face[1]], vertices[face[2]]);
17902
+ faces.push(face);
17903
+ }
17904
+ validateTopology(vertices, faces, charge);
17905
+ const patch = createPiece();
17906
+ const remainder = createPiece();
17907
+ const intersections2 = lines.map(() => /* @__PURE__ */ new Map());
17908
+ let fragmentCount = 0;
17909
+ function addVertex(vertex) {
17910
+ if (vertices.length >= maxVertices || !vertex.every(Number.isFinite))
17911
+ throw new RangeError("Terrain cutout vertex budget or coordinate range exceeded");
17912
+ return vertices.push(vertex) - 1;
17913
+ }
17914
+ function intersection(a, b, da, db, line) {
17915
+ const key3 = edgeKey2(a, b);
17916
+ const cache = intersections2[line];
17917
+ const saved = cache.get(key3);
17918
+ if (saved !== void 0)
17919
+ return saved;
17920
+ const pa = vertices[a], pb = vertices[b];
17921
+ if (pa[0] > pb[0] || pa[0] === pb[0] && (pa[1] > pb[1] || pa[1] === pb[1] && pa[2] > pb[2])) {
17922
+ [a, b] = [b, a];
17923
+ [da, db] = [db, da];
17924
+ }
17925
+ const t = Math.abs(da) / (Math.abs(da) + Math.abs(db));
17926
+ if (!(t > 0 && t < 1))
17927
+ throw new RangeError("Unrepresentable terrain cut intersection");
17928
+ const u = vertices[a];
17929
+ const v = vertices[b];
17930
+ const id = addVertex([
17931
+ u[0] + t * (v[0] - u[0]),
17932
+ u[1] + t * (v[1] - u[1]),
17933
+ u[2] + t * (v[2] - u[2])
17934
+ ]);
17935
+ cache.set(key3, id);
17936
+ return id;
17937
+ }
17938
+ for (let source = 0; source < faces.length; source++) {
17939
+ let fragments = [{ ids: faces[source], inside: true }];
17940
+ for (let line = 0; line < lines.length; line++) {
17941
+ const next = [];
17942
+ const [a, b] = lines[line];
17943
+ for (const fragment of fragments) {
17944
+ const { ids } = fragment;
17945
+ charge(ids.length);
17946
+ const distances = ids.map((id) => cross6(a, b, vertices[id]));
17947
+ if (distances.some((d) => !Number.isFinite(d)))
17948
+ throw new RangeError("Invalid terrain cut coordinates");
17949
+ if (!distances.some((d) => d < 0))
17950
+ next.push(fragment);
17951
+ else if (!distances.some((d) => d > 0))
17952
+ next.push({ ...fragment, inside: false });
17953
+ else {
17954
+ const positive2 = [];
17955
+ const negative = [];
17956
+ for (let i = 0; i < ids.length; i++) {
17957
+ const j = (i + 1) % ids.length;
17958
+ const d = distances[i];
17959
+ const e = distances[j];
17960
+ if (d >= 0)
17961
+ positive2.push(ids[i]);
17962
+ if (d <= 0)
17963
+ negative.push(ids[i]);
17964
+ if (d < 0 && e > 0 || d > 0 && e < 0) {
17965
+ const id = intersection(ids[i], ids[j], d, e, line);
17966
+ positive2.push(id);
17967
+ negative.push(id);
17968
+ }
17969
+ }
17970
+ next.push({ ids: positive2, inside: fragment.inside }, { ids: negative, inside: false });
17971
+ }
17972
+ if (fragmentCount + next.length > maxTriangles)
17973
+ throw new RangeError("Terrain cutout fragment budget exceeded");
17974
+ }
17975
+ fragments = next;
17976
+ }
17977
+ fragmentCount += fragments.length;
17978
+ for (const { ids, inside } of fragments) {
17979
+ let center;
17980
+ if (prepared2 || ids.length > 3) {
17981
+ center = [...vertices[ids[0]]];
17982
+ for (const id of ids) {
17983
+ for (let k = 0; k < 3; k++)
17984
+ center[k] += (vertices[id][k] - vertices[ids[0]][k]) / ids.length;
17985
+ }
17986
+ }
17987
+ const polygonIndex = prepared2 ? prepared2.classify([center[0], center[1]], charge) : inside ? 0 : -1;
17988
+ const piece = polygonIndex >= 0 ? patch : remainder;
17989
+ if (ids.length === 3)
17990
+ emit(piece, ids, source, polygonIndex);
17991
+ else {
17992
+ const hub = addVertex(center);
17993
+ for (let i = 0; i < ids.length; i++)
17994
+ emit(piece, [ids[i], ids[(i + 1) % ids.length], hub], source, polygonIndex);
17995
+ }
17996
+ }
17997
+ }
17998
+ function emit(piece, face, source, polygonIndex) {
17999
+ if (patch.sourceFaces.length + remainder.sourceFaces.length >= maxTriangles)
18000
+ throw new RangeError("Terrain cutout triangle budget exceeded");
18001
+ checkTriangle(vertices[face[0]], vertices[face[1]], vertices[face[2]]);
18002
+ const [a, b, c] = faces[source].map((id) => vertices[id]);
18003
+ const area = cross6(a, b, c);
18004
+ for (let i = 0; i < 3; i++) {
18005
+ const id = face[i];
18006
+ if (!piece.ids.has(id)) {
18007
+ if (patch.ids.size + remainder.ids.size >= maxVertices)
18008
+ throw new RangeError("Terrain cutout output vertex budget exceeded");
18009
+ piece.ids.set(id, piece.ids.size);
18010
+ const p = vertices[id];
18011
+ piece.positions.push(...p);
18012
+ piece.sourceTriangles.push(source);
18013
+ piece.sourceWeights.push(cross6(b, c, p) / area, cross6(c, a, p) / area, cross6(a, b, p) / area);
18014
+ }
18015
+ piece.indices.push(piece.ids.get(id));
18016
+ addEdge(piece.boundary, id, face[(i + 1) % 3], polygonIndex);
18017
+ }
18018
+ piece.sourceFaces.push(source);
18019
+ piece.polygonIndices.push(polygonIndex);
18020
+ }
18021
+ for (const [key3, inside] of patch.boundary) {
18022
+ const outside = remainder.boundary.get(key3);
18023
+ if (!outside)
18024
+ continue;
18025
+ const [a, b] = inside.edge;
18026
+ if (inside.count !== 1 || outside.count !== 1 || outside.edge[0] !== b)
18027
+ throw new Error("Nonconforming terrain cut boundary");
18028
+ patch.cutEdges.push(patch.ids.get(a), patch.ids.get(b));
18029
+ remainder.cutEdges.push(remainder.ids.get(b), remainder.ids.get(a));
18030
+ patch.cutPolygonIndices.push(inside.polygon);
18031
+ remainder.cutPolygonIndices.push(inside.polygon);
18032
+ }
18033
+ return { patch: finish(patch), remainder: finish(remainder) };
18034
+ }
18035
+ function validatePolygon(polygon2, charge) {
18036
+ if (polygon2.length < 3 || polygon2.some((p) => p.length !== 2 || !p.every(Number.isFinite)))
18037
+ throw new RangeError("Invalid terrain cut polygon");
18038
+ const ring = [...polygon2];
18039
+ const orientation3 = cross6(ring[0], ring[1], ring[2]);
18040
+ if (orientation3 < 0)
18041
+ ring.reverse();
18042
+ for (let i = 0; i < ring.length; i++) {
18043
+ charge(ring.length);
18044
+ const j = (i + 1) % ring.length;
18045
+ for (let k = 0; k < ring.length; k++) {
18046
+ if (k === i || k === j)
18047
+ continue;
18048
+ const area = cross6(ring[i], ring[j], ring[k]);
18049
+ if (!(area > 0 && Number.isFinite(area)))
18050
+ throw new RangeError("Terrain cut polygon must be strictly convex");
18051
+ }
18052
+ }
18053
+ return ring;
18054
+ }
18055
+ function checkTriangle(a, b, c) {
18056
+ const area = cross6(a, b, c);
18057
+ const scale3 = Math.hypot(b[0] - a[0], b[1] - a[1]) * Math.hypot(c[0] - a[0], c[1] - a[1]);
18058
+ if (!(area > Number.EPSILON * scale3 && Number.isFinite(area)))
18059
+ throw new RangeError("Terrain cut requires upward nondegenerate XY triangles");
18060
+ }
18061
+ function validateTopology(vertices, faces, charge) {
18062
+ const edges2 = /* @__PURE__ */ new Map();
18063
+ const boxes = faces.map((face) => {
18064
+ for (let i = 0; i < 3; i++)
18065
+ addEdge(edges2, face[i], face[(i + 1) % 3]);
18066
+ const points = face.map((id) => vertices[id]);
18067
+ return {
18068
+ face,
18069
+ points,
18070
+ low: Math.min(...points.map((p) => p[0])),
18071
+ high: Math.max(...points.map((p) => p[0])),
18072
+ minY: Math.min(...points.map((p) => p[1])),
18073
+ maxY: Math.max(...points.map((p) => p[1]))
18074
+ };
18075
+ }).sort((a, b) => a.low - b.low);
18076
+ for (let i = 0; i < boxes.length; i++) {
18077
+ const a = boxes[i];
18078
+ for (let j = i + 1; j < boxes.length && boxes[j].low <= a.high; j++) {
18079
+ charge(1);
18080
+ const b = boxes[j];
18081
+ if (a.maxY < b.minY || b.maxY < a.minY)
18082
+ continue;
18083
+ if (!separates(a.points, b.points) && !separates(b.points, a.points))
18084
+ throw new RangeError("Terrain cut input has overlapping XY triangles");
18085
+ checkJunctions(a.face, b.face, vertices);
18086
+ checkJunctions(b.face, a.face, vertices);
18087
+ }
18088
+ }
18089
+ }
18090
+ function separates(a, b) {
18091
+ return a.some((p, i) => b.every((q) => cross6(p, a[(i + 1) % 3], q) <= 0));
18092
+ }
18093
+ function checkJunctions(a, b, vertices) {
18094
+ for (let i = 0; i < 3; i++) {
18095
+ const u = vertices[a[i]];
18096
+ const v = vertices[a[(i + 1) % 3]];
18097
+ const overlaps2 = b.filter((id) => {
18098
+ const p = vertices[id];
18099
+ if (cross6(u, v, p) !== 0)
18100
+ return false;
18101
+ const axis = Math.abs(v[0] - u[0]) >= Math.abs(v[1] - u[1]) ? 0 : 1;
18102
+ const low = Math.min(u[axis], v[axis]);
18103
+ const high = Math.max(u[axis], v[axis]);
18104
+ if (p[axis] > low && p[axis] < high)
18105
+ throw new RangeError("Terrain cut input has a T-junction");
18106
+ return p[axis] >= low && p[axis] <= high;
18107
+ });
18108
+ if (overlaps2.length >= 2 && (!overlaps2.includes(a[i]) || !overlaps2.includes(a[(i + 1) % 3])))
18109
+ throw new RangeError("Terrain cut input has an unwelded shared edge");
18110
+ }
18111
+ }
18112
+ function addEdge(edges2, a, b, polygon2 = -1) {
18113
+ const key3 = edgeKey2(a, b);
18114
+ const entry = edges2.get(key3);
18115
+ if (!entry)
18116
+ edges2.set(key3, { edge: [a, b], count: 1, polygon: polygon2 });
18117
+ else {
18118
+ if (entry.count !== 1 || entry.edge[0] !== b)
18119
+ throw new RangeError("Terrain cut mesh has inconsistent or nonmanifold edges");
18120
+ entry.count++;
18121
+ }
18122
+ }
18123
+ function edgeKey2(a, b) {
18124
+ return a < b ? a + "," + b : b + "," + a;
18125
+ }
18126
+ function cross6(a, b, c) {
18127
+ return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
18128
+ }
18129
+ function createPiece() {
18130
+ return {
18131
+ ids: /* @__PURE__ */ new Map(),
18132
+ positions: [],
18133
+ indices: [],
18134
+ sourceTriangles: [],
18135
+ sourceWeights: [],
18136
+ sourceFaces: [],
18137
+ boundary: /* @__PURE__ */ new Map(),
18138
+ cutEdges: [],
18139
+ polygonIndices: [],
18140
+ cutPolygonIndices: []
18141
+ };
18142
+ }
18143
+ function finish(piece) {
18144
+ return {
18145
+ positions: Float64Array.from(piece.positions),
18146
+ indices: Uint32Array.from(piece.indices),
18147
+ sourceTriangles: Uint32Array.from(piece.sourceTriangles),
18148
+ sourceWeights: Float64Array.from(piece.sourceWeights),
18149
+ sourceFaces: Uint32Array.from(piece.sourceFaces),
18150
+ cutEdges: Uint32Array.from(piece.cutEdges),
18151
+ polygonIndices: Uint32Array.from(piece.polygonIndices),
18152
+ cutPolygonIndices: Uint32Array.from(piece.cutPolygonIndices)
18153
+ };
18154
+ }
18155
+ function validateTerrainCutoutTopology(mesh, maxWork) {
18156
+ const vertices = [];
18157
+ const faces = [];
18158
+ for (let i = 0; i < mesh.positions.length; i += 3)
18159
+ vertices.push([mesh.positions[i], mesh.positions[i + 1], mesh.positions[i + 2]]);
18160
+ for (let i = 0; i < mesh.indices.length; i += 3)
18161
+ faces.push([mesh.indices[i], mesh.indices[i + 1], mesh.indices[i + 2]]);
18162
+ let work = 0;
18163
+ validateTopology(vertices, faces, (amount) => {
18164
+ work += amount;
18165
+ if (work > maxWork)
18166
+ throw new RangeError("Terrain cutout topology work budget exceeded");
18167
+ });
18168
+ }
18169
+
18170
+ // dist/terrain/cutout-skirts.js
18171
+ function createTerrainCutoutSkirts(cutout, { lift = 0, patch, remainder }) {
18172
+ if (!Number.isFinite(lift))
18173
+ throw new RangeError("Invalid terrain cutout lift");
18174
+ const positions = cutout.patch.positions.slice();
18175
+ for (let i = 2; i < positions.length; i += 3) {
18176
+ positions[i] += lift;
18177
+ if (!Number.isFinite(positions[i]))
18178
+ throw new RangeError("Terrain cutout lift overflow");
18179
+ }
18180
+ return {
18181
+ patch: skirtPiece({ ...cutout.patch, positions }, patch),
18182
+ remainder: skirtPiece(cutout.remainder, remainder)
18183
+ };
18184
+ }
18185
+ function skirtPiece(surface2, options) {
18186
+ if (!surface2.cutEdges.length)
18187
+ return { surface: surface2 };
18188
+ return {
18189
+ surface: surface2,
18190
+ skirt: createTerrainSkirt(surface2, { ...options, edges: surface2.cutEdges })
18191
+ };
18192
+ }
18193
+
18194
+ // dist/terrain/watershed-accumulation.js
18195
+ function accumulateTerrainWatersheds(receiver, { maxCells = 4194304 } = {}) {
18196
+ const count = receiver.length;
18197
+ if (!Number.isSafeInteger(maxCells) || maxCells < 0 || count > maxCells || count > 2147483647)
18198
+ throw new RangeError("Terrain watershed accumulation exceeds its cell budget");
18199
+ const incoming = new Uint32Array(count);
18200
+ const contributingCells = new Uint32Array(count);
18201
+ const terminal = new Int32Array(count).fill(-1);
18202
+ const queue = new Int32Array(count);
18203
+ let active = 0;
18204
+ for (let i = 0; i < count; i++) {
18205
+ const next = receiver[i];
18206
+ if (next === -2)
18207
+ continue;
18208
+ if (next < -1 || next >= count || next >= 0 && receiver[next] === -2)
18209
+ throw new RangeError("Invalid terrain watershed receiver");
18210
+ active++;
18211
+ contributingCells[i] = 1;
18212
+ if (next >= 0)
18213
+ incoming[next]++;
18214
+ }
18215
+ let end = 0;
18216
+ for (let i = 0; i < count; i++) {
18217
+ if (contributingCells[i] && !incoming[i])
18218
+ queue[end++] = i;
18219
+ }
18220
+ for (let cursor = 0; cursor < end; cursor++) {
18221
+ const i = queue[cursor];
18222
+ const next = receiver[i];
18223
+ if (next < 0)
18224
+ continue;
18225
+ contributingCells[next] += contributingCells[i];
18226
+ if (--incoming[next] === 0)
18227
+ queue[end++] = next;
18228
+ }
18229
+ if (end !== active)
18230
+ throw new RangeError("Terrain watershed receiver graph contains a cycle");
18231
+ for (let cursor = end - 1; cursor >= 0; cursor--) {
18232
+ const i = queue[cursor];
18233
+ const next = receiver[i];
18234
+ terminal[i] = next < 0 ? i : terminal[next];
18235
+ }
18236
+ return { terminal, contributingCells };
18237
+ }
18238
+
18239
+ // dist/terrain/tile-cutout.js
18240
+ function splitTerrainMeshTiles(tiles, polygon2, options = {}) {
18241
+ const assembled = assembleTerrainCutoutTiles(tiles, options);
18242
+ return {
18243
+ ...splitTerrainMesh(assembled.mesh, polygon2, { ...options, maxWork: assembled.remainingWork }),
18244
+ sourceTiles: assembled.sourceTiles,
18245
+ sourceTileFaces: assembled.sourceTileFaces
18246
+ };
18247
+ }
18248
+ function assembleTerrainCutoutTiles(tiles, options = {}) {
18249
+ const maxVertices = options.maxVertices ?? 5e5;
18250
+ const maxTriangles = options.maxTriangles ?? 5e5;
18251
+ const maxWork = options.maxWork ?? 4e6;
18252
+ if (![maxVertices, maxTriangles, maxWork].every((n) => Number.isSafeInteger(n) && n >= 0) || maxVertices > 4294967295 || maxTriangles > 4294967295)
18253
+ throw new RangeError("Invalid terrain tile cutout limits");
18254
+ let vertexCount = 0;
18255
+ let faceCount = 0;
18256
+ let work = 0;
18257
+ for (const tile of tiles) {
18258
+ if (!(tile.positions instanceof Float32Array || tile.positions instanceof Float64Array) || !(tile.indices instanceof Uint16Array || tile.indices instanceof Uint32Array) || tile.positions.length % 3 || tile.indices.length % 3)
18259
+ throw new RangeError("Invalid terrain tile cutout mesh");
18260
+ vertexCount += tile.positions.length / 3;
18261
+ faceCount += tile.indices.length / 3;
18262
+ work += 1 + tile.positions.length / 3 + tile.indices.length;
18263
+ if (vertexCount > maxVertices || faceCount > maxTriangles || work > maxWork)
18264
+ throw new RangeError("Terrain tile cutout input budget exceeded");
18265
+ }
18266
+ const positions = new Float64Array(vertexCount * 3);
18267
+ const indices = new Uint32Array(faceCount * 3);
18268
+ const sourceTiles = new Uint32Array(faceCount);
18269
+ const sourceTileFaces = new Uint32Array(faceCount);
18270
+ const vertices = /* @__PURE__ */ new Map();
18271
+ let vertexOffset = 0;
18272
+ let faceOffset = 0;
18273
+ for (let tileIndex = 0; tileIndex < tiles.length; tileIndex++) {
18274
+ const tile = tiles[tileIndex];
18275
+ const remap = new Uint32Array(tile.positions.length / 3);
18276
+ for (let i = 0; i < remap.length; i++) {
18277
+ const x = tile.positions[i * 3];
18278
+ const y = tile.positions[i * 3 + 1];
18279
+ const z = tile.positions[i * 3 + 2];
18280
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
18281
+ throw new RangeError("Invalid terrain tile cutout coordinate");
18282
+ const key3 = `${x},${y},${z}`;
18283
+ let id = vertices.get(key3);
18284
+ if (id === void 0) {
18285
+ id = vertexOffset++;
18286
+ vertices.set(key3, id);
18287
+ positions[id * 3] = x;
18288
+ positions[id * 3 + 1] = y;
18289
+ positions[id * 3 + 2] = z;
18290
+ }
18291
+ remap[i] = id;
18292
+ }
18293
+ for (let i = 0; i < tile.indices.length; i++) {
18294
+ const id = tile.indices[i];
18295
+ if (id >= remap.length)
18296
+ throw new RangeError("Invalid terrain tile cutout index");
18297
+ indices[faceOffset * 3 + i] = remap[id];
18298
+ }
18299
+ for (let i = 0; i < tile.indices.length / 3; i++) {
18300
+ sourceTiles[faceOffset + i] = tileIndex;
18301
+ sourceTileFaces[faceOffset + i] = i;
18302
+ }
18303
+ faceOffset += tile.indices.length / 3;
18304
+ }
18305
+ return {
18306
+ mesh: { positions: positions.subarray(0, vertexOffset * 3), indices },
18307
+ sourceTiles,
18308
+ sourceTileFaces,
18309
+ remainingWork: maxWork - work
18310
+ };
18311
+ }
18312
+
18313
+ // dist/terrain/tile-cutout-update.js
18314
+ var CACHE = /* @__PURE__ */ Symbol("terrain-cutout-cache");
18315
+ function updateTerrainTileCutouts(residents, polygon2, previous, options = {}) {
18316
+ const limits = {
18317
+ maxTiles: options.maxTiles ?? 512,
18318
+ maxPairChecks: options.maxPairChecks ?? 131072,
18319
+ maxBoundaryEdges: options.maxBoundaryEdges ?? 1e6,
18320
+ maxWork: options.maxWork ?? 4e6,
18321
+ maxVertices: options.maxVertices ?? 5e5,
18322
+ maxTriangles: options.maxTriangles ?? 5e5
18323
+ };
18324
+ if (Object.values(limits).some((n) => !Number.isSafeInteger(n) || n < 0) || limits.maxVertices > 4294967295 || limits.maxTriangles > 4294967295 || residents.length > limits.maxTiles)
18325
+ throw new RangeError("Invalid terrain cutout update limits");
18326
+ const prior = previous == null ? void 0 : previous[CACHE];
18327
+ const compatible = prior && sameTerrainCutoutRegion(prior.polygon, polygon2) && Object.keys(limits).every((key3) => prior.options[key3] === limits[key3]);
18328
+ if (!compatible)
18329
+ splitTerrainMesh({ positions: new Float64Array(), indices: new Uint32Array() }, polygon2, limits);
18330
+ const entries = /* @__PURE__ */ new Map();
18331
+ const rebuilt = [];
18332
+ let boundaryCount = 0;
18333
+ for (const resident of residents) {
18334
+ if (!resident.id || typeof resident.id !== "string" || entries.has(resident.id) || !Number.isSafeInteger(resident.revision) || resident.revision < 0)
18335
+ throw new RangeError("Invalid or duplicate terrain cutout resident");
18336
+ const old = compatible ? prior.entries.get(resident.id) : void 0;
18337
+ let entry;
18338
+ if (old && old.resident.mesh === resident.mesh && old.resident.revision === resident.revision)
18339
+ entry = old;
18340
+ else {
18341
+ const split = splitTerrainMesh(resident.mesh, polygon2, limits);
18342
+ const edges2 = [...boundaryEdges(split.patch, 0), ...boundaryEdges(split.remainder, 1)];
18343
+ const bounds2 = [Infinity, Infinity, -Infinity, -Infinity];
18344
+ for (const id of resident.mesh.indices) {
18345
+ const x = resident.mesh.positions[id * 3], y = resident.mesh.positions[id * 3 + 1];
18346
+ bounds2[0] = Math.min(bounds2[0], x);
18347
+ bounds2[1] = Math.min(bounds2[1], y);
18348
+ bounds2[2] = Math.max(bounds2[2], x);
18349
+ bounds2[3] = Math.max(bounds2[3], y);
18350
+ }
18351
+ entry = { resident: { ...resident }, split, displayed: split, bounds: bounds2, edges: edges2 };
18352
+ rebuilt.push(resident.id);
18353
+ }
18354
+ boundaryCount += entry.edges.length;
18355
+ if (boundaryCount > limits.maxBoundaryEdges)
18356
+ throw new RangeError("Terrain cutout boundary budget exceeded");
18357
+ entries.set(resident.id, entry);
18358
+ }
18359
+ const values = [...entries.values()];
18360
+ let pairs = 0;
18361
+ for (let i = 0; i < values.length; i++)
18362
+ for (let j = i + 1; j < values.length; j++) {
18363
+ if (++pairs > limits.maxPairChecks)
18364
+ throw new RangeError("Terrain cutout pair budget exceeded");
18365
+ const a = values[i], b = values[j];
18366
+ if (a.bounds[2] < b.bounds[0] || b.bounds[2] < a.bounds[0] || a.bounds[3] < b.bounds[1] || b.bounds[3] < a.bounds[1])
18367
+ continue;
18368
+ if (compatible && prior.entries.get(a.resident.id) === a && prior.entries.get(b.resident.id) === b)
18369
+ continue;
18370
+ const combined = assembleTerrainCutoutTiles([a.resident.mesh, b.resident.mesh], limits);
18371
+ validateTerrainCutoutTopology(combined.mesh, combined.remainingWork);
18372
+ }
18373
+ const boundaries = /* @__PURE__ */ new Map();
18374
+ const cutKeys = /* @__PURE__ */ new Map();
18375
+ for (let tile = 0; tile < values.length; tile++)
18376
+ for (const edge2 of values[tile].edges) {
18377
+ const other = boundaries.get(edge2.key);
18378
+ if (!other) {
18379
+ boundaries.set(edge2.key, { edge: edge2, paired: false });
18380
+ continue;
18381
+ }
18382
+ if (other.paired || other.edge.start !== edge2.end || other.edge.end !== edge2.start)
18383
+ throw new RangeError("Nonconforming terrain cutout tile boundary");
18384
+ other.paired = true;
18385
+ if (other.edge.side !== edge2.side) {
18386
+ cutKeys.set(edge2.key, edge2.side === 0 ? edge2.polygon : other.edge.polygon);
18387
+ }
18388
+ }
18389
+ const tiles = /* @__PURE__ */ new Map();
18390
+ const changed = [];
18391
+ for (let i = 0; i < values.length; i++) {
18392
+ const entry = values[i];
18393
+ const old = prior == null ? void 0 : prior.entries.get(entry.resident.id);
18394
+ const cuts = [[], []];
18395
+ const polygons2 = [[], []];
18396
+ for (const edge2 of entry.edges) {
18397
+ const polygonIndex = cutKeys.get(edge2.key);
18398
+ if (polygonIndex !== void 0) {
18399
+ cuts[edge2.side].push(edge2.a, edge2.b);
18400
+ polygons2[edge2.side].push(polygonIndex);
18401
+ }
18402
+ }
18403
+ const patch = withEdges(entry.split.patch, cuts[0], polygons2[0], old == null ? void 0 : old.displayed.patch);
18404
+ const remainder = withEdges(entry.split.remainder, cuts[1], polygons2[1], old == null ? void 0 : old.displayed.remainder);
18405
+ const displayed = old && patch === old.displayed.patch && remainder === old.displayed.remainder ? old.displayed : { patch, remainder };
18406
+ if (displayed !== (old == null ? void 0 : old.displayed))
18407
+ changed.push(entry.resident.id);
18408
+ entries.set(entry.resident.id, displayed === entry.displayed ? entry : { ...entry, displayed });
18409
+ tiles.set(entry.resident.id, displayed);
18410
+ }
18411
+ return {
18412
+ cache: { [CACHE]: { polygon: copyTerrainCutoutRegion(polygon2), options: limits, entries } },
18413
+ tiles,
18414
+ changed,
18415
+ rebuilt,
18416
+ removed: prior ? [...prior.entries.keys()].filter((id) => !entries.has(id)) : []
18417
+ };
18418
+ }
18419
+ function withEdges(piece, edges2, polygons2, old) {
18420
+ const same2 = old && old.positions === piece.positions && old.cutEdges.length === edges2.length && old.cutEdges.every((id, i) => id === edges2[i]) && old.cutPolygonIndices.every((id, i) => id === polygons2[i]);
18421
+ return same2 ? old : { ...piece, cutEdges: Uint32Array.from(edges2), cutPolygonIndices: Uint32Array.from(polygons2) };
18422
+ }
18423
+ function boundaryEdges(piece, side) {
18424
+ const edges2 = /* @__PURE__ */ new Map();
18425
+ for (let i = 0; i < piece.indices.length; i += 3)
18426
+ for (let j = 0; j < 3; j++) {
18427
+ const a = piece.indices[i + j], b = piece.indices[i + (j + 1) % 3];
18428
+ const key3 = a < b ? `${a},${b}` : `${b},${a}`;
18429
+ const old = edges2.get(key3);
18430
+ if (old)
18431
+ old.count++;
18432
+ else
18433
+ edges2.set(key3, { a, b, count: 1, polygon: piece.polygonIndices[i / 3] });
18434
+ }
18435
+ const result = [];
18436
+ const point2 = (id) => `${piece.positions[id * 3]},${piece.positions[id * 3 + 1]},${piece.positions[id * 3 + 2]}`;
18437
+ for (const { a, b, count, polygon: polygon2 } of edges2.values())
18438
+ if (count === 1) {
18439
+ const start = point2(a), end = point2(b);
18440
+ result.push({
18441
+ polygon: polygon2,
18442
+ a,
18443
+ b,
18444
+ side,
18445
+ start,
18446
+ end,
18447
+ key: start < end ? `${start}/${end}` : `${end}/${start}`
18448
+ });
18449
+ }
18450
+ return result;
18451
+ }
18452
+
18453
+ // dist/terrain/geographic-cutout.js
18454
+ var RAD = Math.PI / 180;
18455
+ function createGeographicTerrainCutoutFrame(options) {
18456
+ if (options.center.length !== 2)
18457
+ throw new RangeError("Invalid geographic terrain cutout center");
18458
+ const frame2 = {
18459
+ center: [wrap2(options.center[0]), options.center[1]],
18460
+ radius: options.radius ?? 6378137,
18461
+ maxAngularRadius: options.maxAngularRadius ?? 30
18462
+ };
18463
+ validateFrame(frame2);
18464
+ return Object.freeze({ ...frame2, center: Object.freeze(frame2.center) });
18465
+ }
18466
+ function projectGeographicTerrainCutout(positions, frame2) {
18467
+ var _a;
18468
+ validateFrame(frame2);
18469
+ validatePositions(positions);
18470
+ const result = new Float64Array(positions.length);
18471
+ const [sin0, cos0] = latitude(frame2.center[1]);
18472
+ const maximum = chartLimit(frame2);
18473
+ for (let i = 0; i < positions.length; i += 3) {
18474
+ const lon = positions[i], lat = positions[i + 1];
18475
+ if (lat < -90 || lat > 90)
18476
+ throw new RangeError("Invalid geographic terrain latitude");
18477
+ const sin = Math.sin(lat * RAD);
18478
+ const cos = Math.abs(lat) === 90 ? 0 : Math.cos(lat * RAD);
18479
+ const delta = wrap2(wrap2(lon) - frame2.center[0]) * RAD;
18480
+ const dot5 = sin0 * sin + cos0 * cos * Math.cos(delta);
18481
+ const x = cos * Math.sin(delta) / dot5;
18482
+ const y = (cos0 * sin - sin0 * cos * Math.cos(delta)) / dot5;
18483
+ if (!(dot5 > 0) || Math.hypot(x, y) > maximum)
18484
+ throw new RangeError("Terrain coordinate exceeds geographic cutout chart");
18485
+ result[i] = frame2.radius * x;
18486
+ result[i + 1] = frame2.radius * y;
18487
+ result[i] || (result[i] = 0);
18488
+ result[_a = i + 1] || (result[_a] = 0);
18489
+ result[i + 2] = positions[i + 2];
18490
+ }
18491
+ if (!result.every(Number.isFinite))
18492
+ throw new RangeError("Geographic terrain projection overflow");
18493
+ return result;
18494
+ }
18495
+ function unprojectGeographicTerrainCutout(positions, frame2) {
18496
+ validateFrame(frame2);
18497
+ validatePositions(positions);
18498
+ const result = new Float64Array(positions.length);
18499
+ const [sin0, cos0] = latitude(frame2.center[1]);
18500
+ const maximum = chartLimit(frame2);
18501
+ for (let i = 0; i < positions.length; i += 3) {
18502
+ const x = positions[i] / frame2.radius, y = positions[i + 1] / frame2.radius;
18503
+ const distance = Math.hypot(x, y);
18504
+ if (!Number.isFinite(distance) || distance > maximum)
18505
+ throw new RangeError("Terrain coordinate exceeds geographic cutout chart");
18506
+ const horizontal = cos0 - y * sin0;
18507
+ const vertical = sin0 + y * cos0;
18508
+ const lat = Math.atan2(vertical, Math.hypot(horizontal, x)) / RAD;
18509
+ result[i] = Math.abs(lat) === 90 ? frame2.center[0] : wrap2(frame2.center[0] + Math.atan2(x, horizontal) / RAD);
18510
+ result[i + 1] = lat;
18511
+ result[i + 2] = positions[i + 2];
18512
+ }
18513
+ return result;
18514
+ }
18515
+ function wrap2(longitude) {
18516
+ const result = longitude % 360;
18517
+ return result >= 180 ? result - 360 : result < -180 ? result + 360 : result;
18518
+ }
18519
+ function latitude(degrees2) {
18520
+ return [Math.sin(degrees2 * RAD), Math.abs(degrees2) === 90 ? 0 : Math.cos(degrees2 * RAD)];
18521
+ }
18522
+ function validateFrame(frame2) {
18523
+ if (frame2.center.length !== 2 || !frame2.center.every(Number.isFinite) || frame2.center[0] < -180 || frame2.center[0] >= 180 || Math.abs(frame2.center[1]) > 90 || !Number.isFinite(frame2.radius) || frame2.radius <= 0 || !Number.isFinite(frame2.maxAngularRadius) || frame2.maxAngularRadius <= 0 || frame2.maxAngularRadius > 80)
18524
+ throw new RangeError("Invalid geographic terrain cutout frame");
18525
+ }
18526
+ function validatePositions(positions) {
18527
+ if (!(positions instanceof Float32Array || positions instanceof Float64Array) || positions.length % 3 || !positions.every(Number.isFinite))
18528
+ throw new RangeError("Invalid geographic terrain cutout positions");
18529
+ }
18530
+ function chartLimit(frame2) {
18531
+ const distance = Math.tan(frame2.maxAngularRadius * RAD);
18532
+ return distance + 16 * Number.EPSILON * (1 + distance);
18533
+ }
18534
+
18535
+ // dist/terrain/cutout-polygons.js
18536
+ function prepareTerrainCutoutPolygons(polygons2, { maxEdges = 2048, maxWork = 4e6 } = {}) {
18537
+ if (![maxEdges, maxWork].every((n) => Number.isSafeInteger(n) && n >= 0) || !polygons2.length)
18538
+ throw new RangeError("Invalid terrain cutout polygon limits or empty set");
18539
+ let work = 0, edgeCount = 0;
18540
+ const charge = (amount) => {
18541
+ work += amount;
18542
+ if (work > maxWork)
18543
+ throw new RangeError("Terrain cutout polygon work budget exceeded");
18544
+ };
18545
+ if (polygons2.length > Math.floor(maxEdges / 3))
18546
+ throw new RangeError("Terrain cutout polygon edge budget exceeded");
18547
+ const regions = polygons2.map((p) => {
18548
+ var _a;
18549
+ if (1 + (((_a = p.holes) == null ? void 0 : _a.length) ?? 0) > Math.floor((maxEdges - edgeCount) / 3))
18550
+ throw new RangeError("Terrain cutout polygon edge budget exceeded");
18551
+ return [p.outer, ...p.holes ?? []].map((ring) => {
18552
+ edgeCount += ring.length;
18553
+ if (edgeCount > maxEdges)
18554
+ throw new RangeError("Terrain cutout polygon edge budget exceeded");
18555
+ charge(ring.length);
18556
+ if (ring.length < 3 || ring.some((p2) => p2.length !== 2 || !p2.every(Number.isFinite)))
18557
+ throw new RangeError("Invalid terrain cutout polygon ring");
18558
+ return ring.map((p2) => Object.freeze([p2[0], p2[1]]));
18559
+ });
18560
+ });
18561
+ const rings = regions.flat();
18562
+ for (const ring of rings) {
18563
+ let area = 0;
18564
+ for (let i = 0; i < ring.length; i++) {
18565
+ charge(1);
18566
+ const a = ring[i], b = ring[(i + 1) % ring.length], c = ring[(i + 2) % ring.length];
18567
+ if (equal(a, b))
18568
+ throw new RangeError("Duplicate terrain cutout ring vertex");
18569
+ area += orient2(ring[0], a, b);
18570
+ if (orient2(a, b, c) === 0 && (a[0] - b[0]) * (c[0] - b[0]) + (a[1] - b[1]) * (c[1] - b[1]) >= 0)
18571
+ throw new RangeError("Backtracking terrain cutout ring edge");
18572
+ for (let j = i + 1; j < ring.length; j++) {
18573
+ if (j === i + 1 || i === 0 && j === ring.length - 1)
18574
+ continue;
18575
+ charge(1);
18576
+ if (intersects2(a, b, ring[j], ring[(j + 1) % ring.length]))
18577
+ throw new RangeError("Self-intersecting terrain cutout ring");
18578
+ }
18579
+ }
18580
+ if (!Number.isFinite(area) || area === 0)
18581
+ throw new RangeError("Degenerate terrain cutout ring");
18582
+ }
18583
+ for (let i = 0; i < rings.length; i++)
18584
+ for (let j = i + 1; j < rings.length; j++) {
18585
+ const a = rings[i], b = rings[j];
18586
+ for (let x = 0; x < a.length; x++)
18587
+ for (let y = 0; y < b.length; y++) {
18588
+ charge(1);
18589
+ if (intersects2(a[x], a[(x + 1) % a.length], b[y], b[(y + 1) % b.length]))
18590
+ throw new RangeError("Terrain cutout rings must not touch or intersect");
18591
+ }
18592
+ }
18593
+ for (const region of regions)
18594
+ for (let i = 1; i < region.length; i++) {
18595
+ if (contains2(region[0], region[i][0], charge) !== 1)
18596
+ throw new RangeError("Terrain cutout hole must be strictly inside its outer ring");
18597
+ for (let j = 1; j < i; j++)
18598
+ if (contains2(region[j], region[i][0], charge) === 1 || contains2(region[i], region[j][0], charge) === 1)
18599
+ throw new RangeError("Nested terrain cutout holes are not supported");
18600
+ }
18601
+ function inRegion(region, point2, budget) {
18602
+ const outer = contains2(region[0], point2, budget);
18603
+ if (outer !== 1)
18604
+ return outer;
18605
+ for (let i = 1; i < region.length; i++) {
18606
+ const hole = contains2(region[i], point2, budget);
18607
+ if (hole === 0)
18608
+ return 0;
18609
+ if (hole === 1)
18610
+ return -1;
18611
+ }
18612
+ return 1;
18613
+ }
18614
+ for (let i = 0; i < regions.length; i++)
18615
+ for (let j = i + 1; j < regions.length; j++) {
18616
+ if (inRegion(regions[i], regions[j][0][0], charge) === 1 || inRegion(regions[j], regions[i][0][0], charge) === 1)
18617
+ throw new RangeError("Overlapping terrain cutout polygon domains");
18618
+ }
18619
+ const lines = [];
18620
+ for (const ring of rings)
18621
+ for (let i = 0; i < ring.length; i++) {
18622
+ const a = ring[i], b = ring[(i + 1) % ring.length];
18623
+ if (lines.some(([u, v]) => {
18624
+ charge(1);
18625
+ return orient2(u, v, a) === 0 && orient2(u, v, b) === 0;
18626
+ }))
18627
+ continue;
18628
+ lines.push(a[0] < b[0] || a[0] === b[0] && a[1] < b[1] ? [a, b] : [b, a]);
18629
+ }
18630
+ return createTerrainCutoutPlan({
18631
+ lines: Object.freeze(lines.map((line) => Object.freeze(line))),
18632
+ classify(point2, budget) {
18633
+ for (let i = 0; i < regions.length; i++) {
18634
+ const result = inRegion(regions[i], point2, budget);
18635
+ if (result === 0)
18636
+ throw new RangeError("Unrepresentable terrain cutout fragment interior");
18637
+ if (result === 1)
18638
+ return i;
18639
+ }
18640
+ return -1;
18641
+ }
18642
+ });
18643
+ }
18644
+ function equal(a, b) {
18645
+ return a[0] === b[0] && a[1] === b[1];
18646
+ }
18647
+ function orient2(a, b, c) {
18648
+ const value3 = (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
18649
+ if (!Number.isFinite(value3))
18650
+ throw new RangeError("Terrain cutout polygon coordinate overflow");
18651
+ return value3;
18652
+ }
18653
+ function onSegment2(a, b, p) {
18654
+ return p[0] >= Math.min(a[0], b[0]) && p[0] <= Math.max(a[0], b[0]) && p[1] >= Math.min(a[1], b[1]) && p[1] <= Math.max(a[1], b[1]);
18655
+ }
18656
+ function intersects2(a, b, c, d) {
18657
+ const abC = orient2(a, b, c), abD = orient2(a, b, d), cdA = orient2(c, d, a), cdB = orient2(c, d, b);
18658
+ return abC === 0 && onSegment2(a, b, c) || abD === 0 && onSegment2(a, b, d) || cdA === 0 && onSegment2(c, d, a) || cdB === 0 && onSegment2(c, d, b) || (abC > 0 && abD < 0 || abC < 0 && abD > 0) && (cdA > 0 && cdB < 0 || cdA < 0 && cdB > 0);
18659
+ }
18660
+ function contains2(ring, p, charge) {
18661
+ let winding3 = 0;
18662
+ for (let i = 0; i < ring.length; i++) {
18663
+ charge(1);
18664
+ const a = ring[i], b = ring[(i + 1) % ring.length], cross7 = orient2(a, b, p);
18665
+ if (cross7 === 0 && onSegment2(a, b, p))
18666
+ return 0;
18667
+ if (a[1] <= p[1] && b[1] > p[1] && cross7 > 0)
18668
+ winding3++;
18669
+ if (a[1] > p[1] && b[1] <= p[1] && cross7 < 0)
18670
+ winding3--;
18671
+ }
18672
+ return winding3 === 0 ? -1 : 1;
18673
+ }
17252
18674
  //# sourceMappingURL=index.cjs.map