@math.gl/geospatial 5.0.0-beta.4 → 5.0.0-beta.6

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 (579) hide show
  1. package/README.md +192 -2
  2. package/THIRD-PARTY-NOTICES.md +192 -20
  3. package/dist/expressions.d.ts +1 -1
  4. package/dist/expressions.d.ts.map +1 -1
  5. package/dist/index.cjs +6953 -10021
  6. package/dist/index.cjs.map +3 -3
  7. package/dist/index.d.ts +40 -8
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +20 -4
  10. package/dist/index.js.map +1 -1
  11. package/dist/projection/experimental/common/adjust_lat.js +1 -1
  12. package/dist/projection/experimental/common/adjust_lat.js.map +1 -1
  13. package/dist/projection/experimental/common/adjust_lon.js +1 -1
  14. package/dist/projection/experimental/common/adjust_lon.js.map +1 -1
  15. package/dist/projection/experimental/common/asinhy.js +1 -1
  16. package/dist/projection/experimental/common/asinhy.js.map +1 -1
  17. package/dist/projection/experimental/common/asinz.js +1 -1
  18. package/dist/projection/experimental/common/asinz.js.map +1 -1
  19. package/dist/projection/experimental/common/authlat.js +1 -1
  20. package/dist/projection/experimental/common/authlat.js.map +1 -1
  21. package/dist/projection/experimental/common/authset.js +1 -1
  22. package/dist/projection/experimental/common/authset.js.map +1 -1
  23. package/dist/projection/experimental/common/clens.js +1 -1
  24. package/dist/projection/experimental/common/clens.js.map +1 -1
  25. package/dist/projection/experimental/common/clens_cmplx.js +1 -1
  26. package/dist/projection/experimental/common/clens_cmplx.js.map +1 -1
  27. package/dist/projection/experimental/common/constants.js +1 -1
  28. package/dist/projection/experimental/common/constants.js.map +1 -1
  29. package/dist/projection/experimental/common/cosh.js +1 -1
  30. package/dist/projection/experimental/common/cosh.js.map +1 -1
  31. package/dist/projection/experimental/common/e0fn.js +1 -1
  32. package/dist/projection/experimental/common/e0fn.js.map +1 -1
  33. package/dist/projection/experimental/common/e1fn.js +1 -1
  34. package/dist/projection/experimental/common/e1fn.js.map +1 -1
  35. package/dist/projection/experimental/common/e2fn.js +1 -1
  36. package/dist/projection/experimental/common/e2fn.js.map +1 -1
  37. package/dist/projection/experimental/common/e3fn.js +1 -1
  38. package/dist/projection/experimental/common/e3fn.js.map +1 -1
  39. package/dist/projection/experimental/common/fL.js +1 -1
  40. package/dist/projection/experimental/common/fL.js.map +1 -1
  41. package/dist/projection/experimental/common/gN.js +1 -1
  42. package/dist/projection/experimental/common/gN.js.map +1 -1
  43. package/dist/projection/experimental/common/gatg.js +1 -1
  44. package/dist/projection/experimental/common/gatg.js.map +1 -1
  45. package/dist/projection/experimental/common/hypot.js +1 -1
  46. package/dist/projection/experimental/common/hypot.js.map +1 -1
  47. package/dist/projection/experimental/common/imlfn.js +1 -1
  48. package/dist/projection/experimental/common/imlfn.js.map +1 -1
  49. package/dist/projection/experimental/common/invlatiso.js +1 -1
  50. package/dist/projection/experimental/common/invlatiso.js.map +1 -1
  51. package/dist/projection/experimental/common/iqsfnz.js +1 -1
  52. package/dist/projection/experimental/common/iqsfnz.js.map +1 -1
  53. package/dist/projection/experimental/common/latiso.js +1 -1
  54. package/dist/projection/experimental/common/latiso.js.map +1 -1
  55. package/dist/projection/experimental/common/log1py.js +1 -1
  56. package/dist/projection/experimental/common/log1py.js.map +1 -1
  57. package/dist/projection/experimental/common/mlfn.js +1 -1
  58. package/dist/projection/experimental/common/mlfn.js.map +1 -1
  59. package/dist/projection/experimental/common/msfnz.js +1 -1
  60. package/dist/projection/experimental/common/msfnz.js.map +1 -1
  61. package/dist/projection/experimental/common/phi2z.js +1 -1
  62. package/dist/projection/experimental/common/phi2z.js.map +1 -1
  63. package/dist/projection/experimental/common/pj_enfn.js +1 -1
  64. package/dist/projection/experimental/common/pj_enfn.js.map +1 -1
  65. package/dist/projection/experimental/common/pj_inv_mlfn.js +1 -1
  66. package/dist/projection/experimental/common/pj_inv_mlfn.js.map +1 -1
  67. package/dist/projection/experimental/common/pj_mlfn.js +1 -1
  68. package/dist/projection/experimental/common/pj_mlfn.js.map +1 -1
  69. package/dist/projection/experimental/common/qsfnz.js +1 -1
  70. package/dist/projection/experimental/common/qsfnz.js.map +1 -1
  71. package/dist/projection/experimental/common/sign.js +1 -1
  72. package/dist/projection/experimental/common/sign.js.map +1 -1
  73. package/dist/projection/experimental/common/sinh.js +1 -1
  74. package/dist/projection/experimental/common/sinh.js.map +1 -1
  75. package/dist/projection/experimental/common/srat.js +1 -1
  76. package/dist/projection/experimental/common/srat.js.map +1 -1
  77. package/dist/projection/experimental/common/tsfnz.js +1 -1
  78. package/dist/projection/experimental/common/tsfnz.js.map +1 -1
  79. package/dist/projection/experimental/common/vincenty.js +1 -1
  80. package/dist/projection/experimental/common/vincenty.js.map +1 -1
  81. package/dist/projection/experimental/core.cjs +100 -2
  82. package/dist/projection/experimental/core.cjs.map +2 -2
  83. package/dist/projection/experimental/core.d.ts +1 -0
  84. package/dist/projection/experimental/core.d.ts.map +1 -1
  85. package/dist/projection/experimental/crs/datum-table.js +1 -1
  86. package/dist/projection/experimental/crs/datum-table.js.map +1 -1
  87. package/dist/projection/experimental/crs/ellipsoid-table.js +1 -1
  88. package/dist/projection/experimental/crs/ellipsoid-table.js.map +1 -1
  89. package/dist/projection/experimental/crs/primemeridian-table.js +1 -1
  90. package/dist/projection/experimental/crs/primemeridian-table.js.map +1 -1
  91. package/dist/projection/experimental/crs/structured.js +1 -1
  92. package/dist/projection/experimental/crs/structured.js.map +1 -1
  93. package/dist/projection/experimental/crs/wkt.js +1 -1
  94. package/dist/projection/experimental/crs/wkt.js.map +1 -1
  95. package/dist/projection/experimental/datum.js +1 -1
  96. package/dist/projection/experimental/datum.js.map +1 -1
  97. package/dist/projection/experimental/ellipsoidal-gnomonic.js +1 -1
  98. package/dist/projection/experimental/ellipsoidal-gnomonic.js.map +1 -1
  99. package/dist/projection/experimental/entries/projections/eqc.cjs +1 -0
  100. package/dist/projection/experimental/entries/projections/eqc.cjs.map +1 -1
  101. package/dist/projection/experimental/entries/projections/merc.cjs +1 -0
  102. package/dist/projection/experimental/entries/projections/merc.cjs.map +1 -1
  103. package/dist/projection/experimental/grids/geotiff.js +1 -1
  104. package/dist/projection/experimental/grids/geotiff.js.map +1 -1
  105. package/dist/projection/experimental/grids/ntv2.js +1 -1
  106. package/dist/projection/experimental/grids/ntv2.js.map +1 -1
  107. package/dist/projection/experimental/index.cjs +102 -2
  108. package/dist/projection/experimental/index.cjs.map +3 -3
  109. package/dist/projection/experimental/kernels/aea.js +1 -1
  110. package/dist/projection/experimental/kernels/aea.js.map +1 -1
  111. package/dist/projection/experimental/kernels/aeqd.js +1 -1
  112. package/dist/projection/experimental/kernels/aeqd.js.map +1 -1
  113. package/dist/projection/experimental/kernels/bonne.js +1 -1
  114. package/dist/projection/experimental/kernels/bonne.js.map +1 -1
  115. package/dist/projection/experimental/kernels/cass.js +1 -1
  116. package/dist/projection/experimental/kernels/cass.js.map +1 -1
  117. package/dist/projection/experimental/kernels/cea.js +1 -1
  118. package/dist/projection/experimental/kernels/cea.js.map +1 -1
  119. package/dist/projection/experimental/kernels/eck6.js +1 -1
  120. package/dist/projection/experimental/kernels/eck6.js.map +1 -1
  121. package/dist/projection/experimental/kernels/eqdc.js +1 -1
  122. package/dist/projection/experimental/kernels/eqdc.js.map +1 -1
  123. package/dist/projection/experimental/kernels/eqearth.js +1 -1
  124. package/dist/projection/experimental/kernels/eqearth.js.map +1 -1
  125. package/dist/projection/experimental/kernels/equi.js +1 -1
  126. package/dist/projection/experimental/kernels/equi.js.map +1 -1
  127. package/dist/projection/experimental/kernels/etmerc.js +1 -1
  128. package/dist/projection/experimental/kernels/etmerc.js.map +1 -1
  129. package/dist/projection/experimental/kernels/gauss.js +1 -1
  130. package/dist/projection/experimental/kernels/gauss.js.map +1 -1
  131. package/dist/projection/experimental/kernels/geos.js +1 -1
  132. package/dist/projection/experimental/kernels/geos.js.map +1 -1
  133. package/dist/projection/experimental/kernels/gnom.js +1 -1
  134. package/dist/projection/experimental/kernels/gnom.js.map +1 -1
  135. package/dist/projection/experimental/kernels/gstmerc.js +1 -1
  136. package/dist/projection/experimental/kernels/gstmerc.js.map +1 -1
  137. package/dist/projection/experimental/kernels/krovak.js +1 -1
  138. package/dist/projection/experimental/kernels/krovak.js.map +1 -1
  139. package/dist/projection/experimental/kernels/laea.js +1 -1
  140. package/dist/projection/experimental/kernels/laea.js.map +1 -1
  141. package/dist/projection/experimental/kernels/lcc.js +1 -1
  142. package/dist/projection/experimental/kernels/lcc.js.map +1 -1
  143. package/dist/projection/experimental/kernels/mill.js +1 -1
  144. package/dist/projection/experimental/kernels/mill.js.map +1 -1
  145. package/dist/projection/experimental/kernels/moll.js +1 -1
  146. package/dist/projection/experimental/kernels/moll.js.map +1 -1
  147. package/dist/projection/experimental/kernels/nzmg.js +1 -1
  148. package/dist/projection/experimental/kernels/nzmg.js.map +1 -1
  149. package/dist/projection/experimental/kernels/omerc.js +1 -1
  150. package/dist/projection/experimental/kernels/omerc.js.map +1 -1
  151. package/dist/projection/experimental/kernels/poly.js +1 -1
  152. package/dist/projection/experimental/kernels/poly.js.map +1 -1
  153. package/dist/projection/experimental/kernels/qsc.js +1 -1
  154. package/dist/projection/experimental/kernels/qsc.js.map +1 -1
  155. package/dist/projection/experimental/kernels/robin.js +1 -1
  156. package/dist/projection/experimental/kernels/robin.js.map +1 -1
  157. package/dist/projection/experimental/kernels/sinu.js +1 -1
  158. package/dist/projection/experimental/kernels/sinu.js.map +1 -1
  159. package/dist/projection/experimental/kernels/somerc.js +1 -1
  160. package/dist/projection/experimental/kernels/somerc.js.map +1 -1
  161. package/dist/projection/experimental/kernels/stere.js +1 -1
  162. package/dist/projection/experimental/kernels/stere.js.map +1 -1
  163. package/dist/projection/experimental/kernels/sterea.js +1 -1
  164. package/dist/projection/experimental/kernels/sterea.js.map +1 -1
  165. package/dist/projection/experimental/kernels/tmerc.js +1 -1
  166. package/dist/projection/experimental/kernels/tmerc.js.map +1 -1
  167. package/dist/projection/experimental/kernels/tpers.js +1 -1
  168. package/dist/projection/experimental/kernels/tpers.js.map +1 -1
  169. package/dist/projection/experimental/kernels/vandg.js +1 -1
  170. package/dist/projection/experimental/kernels/vandg.js.map +1 -1
  171. package/dist/projection/experimental/kinematic-helmert.js +1 -1
  172. package/dist/projection/experimental/kinematic-helmert.js.map +1 -1
  173. package/dist/projection/experimental/lazy-projections/index.cjs +100 -2
  174. package/dist/projection/experimental/lazy-projections/index.cjs.map +2 -2
  175. package/dist/projection/experimental/projections/equidistant-cylindrical.d.ts.map +1 -1
  176. package/dist/projection/experimental/projections/equidistant-cylindrical.js +1 -0
  177. package/dist/projection/experimental/projections/equidistant-cylindrical.js.map +1 -1
  178. package/dist/projection/experimental/projections/mercator.d.ts.map +1 -1
  179. package/dist/projection/experimental/projections/mercator.js +1 -0
  180. package/dist/projection/experimental/projections/mercator.js.map +1 -1
  181. package/dist/projection/experimental/transform-description.d.ts +8 -0
  182. package/dist/projection/experimental/transform-description.d.ts.map +1 -0
  183. package/dist/projection/experimental/transform-description.js +57 -0
  184. package/dist/projection/experimental/transform-description.js.map +1 -0
  185. package/dist/projection/experimental/types.d.ts +5 -0
  186. package/dist/projection/experimental/types.d.ts.map +1 -1
  187. package/dist/projection/experimental/typescript-projection.d.ts +4 -0
  188. package/dist/projection/experimental/typescript-projection.d.ts.map +1 -1
  189. package/dist/projection/experimental/typescript-projection.js +54 -5
  190. package/dist/projection/experimental/typescript-projection.js.map +1 -1
  191. package/dist/projection/index.cjs +102 -2
  192. package/dist/projection/index.cjs.map +3 -3
  193. package/dist/projection/transform-analysis.cjs +100 -2
  194. package/dist/projection/transform-analysis.cjs.map +2 -2
  195. package/dist/projection/transform-description.d.ts +44 -0
  196. package/dist/projection/transform-description.d.ts.map +1 -0
  197. package/dist/projection/transform-description.js +5 -0
  198. package/dist/projection/transform-description.js.map +1 -0
  199. package/dist/projection/types.d.ts +4 -0
  200. package/dist/projection/types.d.ts.map +1 -1
  201. package/dist/tasks/definitions.d.ts +3 -3
  202. package/dist/tasks/index.cjs +107 -2
  203. package/dist/tasks/index.cjs.map +3 -3
  204. package/dist/tasks/index.d.ts +1 -1
  205. package/dist/tasks/index.d.ts.map +1 -1
  206. package/dist/tasks/map-worker.js +1 -1
  207. package/dist/tasks/map-worker.js.map +1 -1
  208. package/dist/tasks/operations.d.ts +1 -1
  209. package/dist/tasks/operations.d.ts.map +1 -1
  210. package/dist/tasks/projection-worker.js +1 -1
  211. package/dist/tasks/projection-worker.js.map +1 -1
  212. package/dist/terrain/bounds-regions.d.ts +15 -0
  213. package/dist/terrain/bounds-regions.d.ts.map +1 -0
  214. package/dist/terrain/bounds-regions.js +84 -0
  215. package/dist/terrain/bounds-regions.js.map +1 -0
  216. package/dist/terrain/bounds-update.d.ts +11 -0
  217. package/dist/terrain/bounds-update.d.ts.map +1 -0
  218. package/dist/terrain/bounds-update.js +10 -0
  219. package/dist/terrain/bounds-update.js.map +1 -0
  220. package/dist/terrain/box-index.d.ts +9 -0
  221. package/dist/terrain/box-index.d.ts.map +1 -0
  222. package/dist/terrain/box-index.js +43 -0
  223. package/dist/terrain/box-index.js.map +1 -0
  224. package/dist/terrain/contour-mixed-weld.d.ts +25 -0
  225. package/dist/terrain/contour-mixed-weld.d.ts.map +1 -0
  226. package/dist/terrain/contour-mixed-weld.js +194 -0
  227. package/dist/terrain/contour-mixed-weld.js.map +1 -0
  228. package/dist/terrain/contour-simplify.d.ts +1 -0
  229. package/dist/terrain/contour-simplify.d.ts.map +1 -1
  230. package/dist/terrain/contour-simplify.js +5 -1
  231. package/dist/terrain/contour-simplify.js.map +1 -1
  232. package/dist/terrain/contour-topology.d.ts +30 -0
  233. package/dist/terrain/contour-topology.d.ts.map +1 -0
  234. package/dist/terrain/contour-topology.js +236 -0
  235. package/dist/terrain/contour-topology.js.map +1 -0
  236. package/dist/terrain/delatin-regions.d.ts +14 -0
  237. package/dist/terrain/delatin-regions.d.ts.map +1 -0
  238. package/dist/terrain/delatin-regions.js +15 -0
  239. package/dist/terrain/delatin-regions.js.map +1 -0
  240. package/dist/terrain/dirty-regions.d.ts +11 -0
  241. package/dist/terrain/dirty-regions.d.ts.map +1 -0
  242. package/dist/terrain/dirty-regions.js +34 -0
  243. package/dist/terrain/dirty-regions.js.map +1 -0
  244. package/dist/terrain/gradient-pyramid-regions.d.ts +15 -0
  245. package/dist/terrain/gradient-pyramid-regions.d.ts.map +1 -0
  246. package/dist/terrain/gradient-pyramid-regions.js +112 -0
  247. package/dist/terrain/gradient-pyramid-regions.js.map +1 -0
  248. package/dist/terrain/gradient-pyramid-update.d.ts +11 -0
  249. package/dist/terrain/gradient-pyramid-update.d.ts.map +1 -0
  250. package/dist/terrain/gradient-pyramid-update.js +17 -0
  251. package/dist/terrain/gradient-pyramid-update.js.map +1 -0
  252. package/dist/terrain/height-field.d.ts.map +1 -1
  253. package/dist/terrain/height-field.js +48 -5
  254. package/dist/terrain/height-field.js.map +1 -1
  255. package/dist/terrain/index.cjs +1613 -79
  256. package/dist/terrain/index.cjs.map +3 -3
  257. package/dist/terrain/index.d.ts +40 -0
  258. package/dist/terrain/index.d.ts.map +1 -1
  259. package/dist/terrain/index.js +20 -0
  260. package/dist/terrain/index.js.map +1 -1
  261. package/dist/terrain/isobands.d.ts +24 -0
  262. package/dist/terrain/isobands.d.ts.map +1 -0
  263. package/dist/terrain/isobands.js +281 -0
  264. package/dist/terrain/isobands.js.map +1 -0
  265. package/dist/terrain/lod-morph-evaluate.d.ts +8 -0
  266. package/dist/terrain/lod-morph-evaluate.d.ts.map +1 -0
  267. package/dist/terrain/lod-morph-evaluate.js +30 -0
  268. package/dist/terrain/lod-morph-evaluate.js.map +1 -0
  269. package/dist/terrain/lod-morph.d.ts +35 -0
  270. package/dist/terrain/lod-morph.d.ts.map +1 -0
  271. package/dist/terrain/lod-morph.js +87 -0
  272. package/dist/terrain/lod-morph.js.map +1 -0
  273. package/dist/terrain/martini-regions.d.ts +14 -0
  274. package/dist/terrain/martini-regions.d.ts.map +1 -0
  275. package/dist/terrain/martini-regions.js +26 -0
  276. package/dist/terrain/martini-regions.js.map +1 -0
  277. package/dist/terrain/mesh-error.d.ts.map +1 -1
  278. package/dist/terrain/mesh-error.js +9 -1
  279. package/dist/terrain/mesh-error.js.map +1 -1
  280. package/dist/terrain/mesh-regions-data.d.ts +24 -0
  281. package/dist/terrain/mesh-regions-data.d.ts.map +1 -0
  282. package/dist/terrain/mesh-regions-data.js +80 -0
  283. package/dist/terrain/mesh-regions-data.js.map +1 -0
  284. package/dist/terrain/mesh-regions.d.ts +12 -0
  285. package/dist/terrain/mesh-regions.d.ts.map +1 -0
  286. package/dist/terrain/mesh-regions.js +10 -0
  287. package/dist/terrain/mesh-regions.js.map +1 -0
  288. package/dist/terrain/mesh-update.d.ts +11 -0
  289. package/dist/terrain/mesh-update.d.ts.map +1 -0
  290. package/dist/terrain/mesh-update.js +10 -0
  291. package/dist/terrain/mesh-update.js.map +1 -0
  292. package/dist/terrain/mixed-gradient-update.d.ts +15 -0
  293. package/dist/terrain/mixed-gradient-update.d.ts.map +1 -0
  294. package/dist/terrain/mixed-gradient-update.js +24 -0
  295. package/dist/terrain/mixed-gradient-update.js.map +1 -0
  296. package/dist/terrain/mixed-halo-update.d.ts +16 -0
  297. package/dist/terrain/mixed-halo-update.d.ts.map +1 -0
  298. package/dist/terrain/mixed-halo-update.js +46 -0
  299. package/dist/terrain/mixed-halo-update.js.map +1 -0
  300. package/dist/terrain/mixed-vertex-halos.d.ts +32 -0
  301. package/dist/terrain/mixed-vertex-halos.d.ts.map +1 -0
  302. package/dist/terrain/mixed-vertex-halos.js +125 -0
  303. package/dist/terrain/mixed-vertex-halos.js.map +1 -0
  304. package/dist/terrain/persistent-bounds.d.ts +16 -0
  305. package/dist/terrain/persistent-bounds.d.ts.map +1 -0
  306. package/dist/terrain/persistent-bounds.js +51 -0
  307. package/dist/terrain/persistent-bounds.js.map +1 -0
  308. package/dist/terrain/persistent-gradients.d.ts +16 -0
  309. package/dist/terrain/persistent-gradients.d.ts.map +1 -0
  310. package/dist/terrain/persistent-gradients.js +69 -0
  311. package/dist/terrain/persistent-gradients.js.map +1 -0
  312. package/dist/terrain/persistent-hierarchy-data.d.ts +41 -0
  313. package/dist/terrain/persistent-hierarchy-data.d.ts.map +1 -0
  314. package/dist/terrain/persistent-hierarchy-data.js +130 -0
  315. package/dist/terrain/persistent-hierarchy-data.js.map +1 -0
  316. package/dist/terrain/sample-triangle-height.d.ts +4 -0
  317. package/dist/terrain/sample-triangle-height.d.ts.map +1 -0
  318. package/dist/terrain/sample-triangle-height.js +46 -0
  319. package/dist/terrain/sample-triangle-height.js.map +1 -0
  320. package/dist/terrain/tile-update-data.d.ts +14 -0
  321. package/dist/terrain/tile-update-data.d.ts.map +1 -0
  322. package/dist/terrain/tile-update-data.js +23 -0
  323. package/dist/terrain/tile-update-data.js.map +1 -0
  324. package/dist/terrain/tiled.d.ts +10 -2
  325. package/dist/terrain/tiled.d.ts.map +1 -1
  326. package/dist/terrain/tiled.js +5 -1
  327. package/dist/terrain/tiled.js.map +1 -1
  328. package/dist/terrain/types.d.ts +6 -0
  329. package/dist/terrain/types.d.ts.map +1 -1
  330. package/dist/turf.cjs +25 -671
  331. package/dist/turf.cjs.map +3 -3
  332. package/dist/turf.d.ts +1 -1
  333. package/dist/turf.d.ts.map +1 -1
  334. package/dist/turf.js +2 -2
  335. package/dist/turf.js.map +1 -1
  336. package/package.json +15 -19
  337. package/src/expressions.ts +1 -1
  338. package/src/index.ts +64 -123
  339. package/src/projection/experimental/common/adjust_lat.ts +1 -1
  340. package/src/projection/experimental/common/adjust_lon.ts +1 -1
  341. package/src/projection/experimental/common/asinhy.ts +1 -1
  342. package/src/projection/experimental/common/asinz.ts +1 -1
  343. package/src/projection/experimental/common/authlat.ts +1 -1
  344. package/src/projection/experimental/common/authset.ts +1 -1
  345. package/src/projection/experimental/common/clens.ts +1 -1
  346. package/src/projection/experimental/common/clens_cmplx.ts +1 -1
  347. package/src/projection/experimental/common/constants.ts +1 -1
  348. package/src/projection/experimental/common/cosh.ts +1 -1
  349. package/src/projection/experimental/common/e0fn.ts +1 -1
  350. package/src/projection/experimental/common/e1fn.ts +1 -1
  351. package/src/projection/experimental/common/e2fn.ts +1 -1
  352. package/src/projection/experimental/common/e3fn.ts +1 -1
  353. package/src/projection/experimental/common/fL.ts +1 -1
  354. package/src/projection/experimental/common/gN.ts +1 -1
  355. package/src/projection/experimental/common/gatg.ts +1 -1
  356. package/src/projection/experimental/common/hypot.ts +1 -1
  357. package/src/projection/experimental/common/imlfn.ts +1 -1
  358. package/src/projection/experimental/common/invlatiso.ts +1 -1
  359. package/src/projection/experimental/common/iqsfnz.ts +1 -1
  360. package/src/projection/experimental/common/latiso.ts +1 -1
  361. package/src/projection/experimental/common/log1py.ts +1 -1
  362. package/src/projection/experimental/common/mlfn.ts +1 -1
  363. package/src/projection/experimental/common/msfnz.ts +1 -1
  364. package/src/projection/experimental/common/phi2z.ts +1 -1
  365. package/src/projection/experimental/common/pj_enfn.ts +1 -1
  366. package/src/projection/experimental/common/pj_inv_mlfn.ts +1 -1
  367. package/src/projection/experimental/common/pj_mlfn.ts +1 -1
  368. package/src/projection/experimental/common/qsfnz.ts +1 -1
  369. package/src/projection/experimental/common/sign.ts +1 -1
  370. package/src/projection/experimental/common/sinh.ts +1 -1
  371. package/src/projection/experimental/common/srat.ts +1 -1
  372. package/src/projection/experimental/common/tsfnz.ts +1 -1
  373. package/src/projection/experimental/common/vincenty.ts +1 -1
  374. package/src/projection/experimental/core.ts +8 -0
  375. package/src/projection/experimental/crs/datum-table.ts +1 -1
  376. package/src/projection/experimental/crs/ellipsoid-table.ts +1 -1
  377. package/src/projection/experimental/crs/primemeridian-table.ts +1 -1
  378. package/src/projection/experimental/crs/structured.ts +1 -1
  379. package/src/projection/experimental/crs/wkt.ts +1 -1
  380. package/src/projection/experimental/datum.ts +1 -1
  381. package/src/projection/experimental/ellipsoidal-gnomonic.ts +1 -1
  382. package/src/projection/experimental/exact-helmert.ts +1 -1
  383. package/src/projection/experimental/grids/geotiff.ts +1 -1
  384. package/src/projection/experimental/grids/grid.ts +1 -1
  385. package/src/projection/experimental/grids/ntv2.ts +1 -1
  386. package/src/projection/experimental/helmert-flat.ts +1 -1
  387. package/src/projection/experimental/kernels/aea.ts +1 -1
  388. package/src/projection/experimental/kernels/aeqd.ts +1 -1
  389. package/src/projection/experimental/kernels/bonne.ts +1 -1
  390. package/src/projection/experimental/kernels/cass.ts +1 -1
  391. package/src/projection/experimental/kernels/cea.ts +1 -1
  392. package/src/projection/experimental/kernels/eck6.ts +1 -1
  393. package/src/projection/experimental/kernels/eqdc.ts +1 -1
  394. package/src/projection/experimental/kernels/eqearth.ts +1 -1
  395. package/src/projection/experimental/kernels/equi.ts +1 -1
  396. package/src/projection/experimental/kernels/etmerc.ts +1 -1
  397. package/src/projection/experimental/kernels/gauss.ts +1 -1
  398. package/src/projection/experimental/kernels/geos.ts +1 -1
  399. package/src/projection/experimental/kernels/gnom.ts +1 -1
  400. package/src/projection/experimental/kernels/gstmerc.ts +1 -1
  401. package/src/projection/experimental/kernels/krovak.ts +1 -1
  402. package/src/projection/experimental/kernels/laea.ts +1 -1
  403. package/src/projection/experimental/kernels/lcc.ts +1 -1
  404. package/src/projection/experimental/kernels/mill.ts +1 -1
  405. package/src/projection/experimental/kernels/moll.ts +1 -1
  406. package/src/projection/experimental/kernels/nzmg.ts +1 -1
  407. package/src/projection/experimental/kernels/omerc.ts +1 -1
  408. package/src/projection/experimental/kernels/ortho.ts +1 -1
  409. package/src/projection/experimental/kernels/poly.ts +1 -1
  410. package/src/projection/experimental/kernels/qsc.ts +1 -1
  411. package/src/projection/experimental/kernels/robin.ts +1 -1
  412. package/src/projection/experimental/kernels/sinu.ts +1 -1
  413. package/src/projection/experimental/kernels/somerc.ts +1 -1
  414. package/src/projection/experimental/kernels/stere.ts +1 -1
  415. package/src/projection/experimental/kernels/sterea.ts +1 -1
  416. package/src/projection/experimental/kernels/tmerc.ts +1 -1
  417. package/src/projection/experimental/kernels/tpers.ts +1 -1
  418. package/src/projection/experimental/kernels/vandg.ts +1 -1
  419. package/src/projection/experimental/kinematic-helmert-flat.ts +1 -1
  420. package/src/projection/experimental/kinematic-helmert.ts +1 -1
  421. package/src/projection/experimental/projection-pipeline.ts +1 -1
  422. package/src/projection/experimental/projections/equidistant-cylindrical.ts +1 -0
  423. package/src/projection/experimental/projections/mercator.ts +1 -0
  424. package/src/projection/experimental/projections/ob-tran.ts +1 -1
  425. package/src/projection/experimental/transform-description.ts +82 -0
  426. package/src/projection/experimental/types.ts +5 -0
  427. package/src/projection/experimental/typescript-projection.ts +54 -6
  428. package/src/projection/transform-description.ts +69 -0
  429. package/src/projection/types.ts +11 -0
  430. package/src/tasks/definitions.ts +1 -1
  431. package/src/tasks/index.ts +1 -1
  432. package/src/tasks/map-worker.ts +1 -1
  433. package/src/tasks/operations.ts +1 -1
  434. package/src/tasks/projection-worker.ts +1 -1
  435. package/src/terrain/bounds-regions.ts +106 -0
  436. package/src/terrain/bounds-update.ts +19 -0
  437. package/src/terrain/box-index.ts +47 -0
  438. package/src/terrain/contour-mixed-weld.ts +254 -0
  439. package/src/terrain/contour-simplify.ts +10 -2
  440. package/src/terrain/contour-topology.ts +263 -0
  441. package/src/terrain/delatin-regions.ts +25 -0
  442. package/src/terrain/dirty-regions.ts +61 -0
  443. package/src/terrain/gradient-pyramid-regions.ts +140 -0
  444. package/src/terrain/gradient-pyramid-update.ts +25 -0
  445. package/src/terrain/height-field.ts +45 -5
  446. package/src/terrain/index.ts +58 -0
  447. package/src/terrain/isobands.ts +348 -0
  448. package/src/terrain/lod-morph-evaluate.ts +36 -0
  449. package/src/terrain/lod-morph.ts +138 -0
  450. package/src/terrain/martini-regions.ts +38 -0
  451. package/src/terrain/mesh-error.ts +14 -1
  452. package/src/terrain/mesh-regions-data.ts +113 -0
  453. package/src/terrain/mesh-regions.ts +18 -0
  454. package/src/terrain/mesh-update.ts +15 -0
  455. package/src/terrain/mixed-gradient-update.ts +40 -0
  456. package/src/terrain/mixed-halo-update.ts +56 -0
  457. package/src/terrain/mixed-vertex-halos.ts +170 -0
  458. package/src/terrain/persistent-bounds.ts +95 -0
  459. package/src/terrain/persistent-gradients.ts +117 -0
  460. package/src/terrain/persistent-hierarchy-data.ts +196 -0
  461. package/src/terrain/sample-triangle-height.ts +50 -0
  462. package/src/terrain/tile-update-data.ts +32 -0
  463. package/src/terrain/tiled.ts +16 -3
  464. package/src/terrain/types.ts +9 -1
  465. package/src/turf.ts +7 -3
  466. package/crs/README.md +0 -84
  467. package/crs/schemas/README.md +0 -9
  468. package/dist/geoarrow/builder-entry.d.ts +0 -4
  469. package/dist/geoarrow/builder-entry.d.ts.map +0 -1
  470. package/dist/geoarrow/builder-entry.js +0 -5
  471. package/dist/geoarrow/builder-entry.js.map +0 -1
  472. package/dist/geoarrow/builder.d.ts +0 -106
  473. package/dist/geoarrow/builder.d.ts.map +0 -1
  474. package/dist/geoarrow/builder.js +0 -668
  475. package/dist/geoarrow/builder.js.map +0 -1
  476. package/dist/geoarrow/codecs.d.ts +0 -24
  477. package/dist/geoarrow/codecs.d.ts.map +0 -1
  478. package/dist/geoarrow/codecs.js +0 -916
  479. package/dist/geoarrow/codecs.js.map +0 -1
  480. package/dist/geoarrow/index.cjs +0 -4352
  481. package/dist/geoarrow/index.cjs.map +0 -6
  482. package/dist/geoarrow/index.d.ts +0 -21
  483. package/dist/geoarrow/index.d.ts.map +0 -1
  484. package/dist/geoarrow/index.js +0 -15
  485. package/dist/geoarrow/index.js.map +0 -1
  486. package/dist/geoarrow/kernels.d.ts +0 -56
  487. package/dist/geoarrow/kernels.d.ts.map +0 -1
  488. package/dist/geoarrow/kernels.js +0 -982
  489. package/dist/geoarrow/kernels.js.map +0 -1
  490. package/dist/geoarrow/layout.d.ts +0 -66
  491. package/dist/geoarrow/layout.d.ts.map +0 -1
  492. package/dist/geoarrow/layout.js +0 -723
  493. package/dist/geoarrow/layout.js.map +0 -1
  494. package/dist/geoarrow/stream-tessellate.d.ts +0 -34
  495. package/dist/geoarrow/stream-tessellate.d.ts.map +0 -1
  496. package/dist/geoarrow/stream-tessellate.js +0 -171
  497. package/dist/geoarrow/stream-tessellate.js.map +0 -1
  498. package/dist/geoarrow/stream.d.ts +0 -29
  499. package/dist/geoarrow/stream.d.ts.map +0 -1
  500. package/dist/geoarrow/stream.js +0 -100
  501. package/dist/geoarrow/stream.js.map +0 -1
  502. package/dist/geoarrow/tessellate.d.ts +0 -31
  503. package/dist/geoarrow/tessellate.d.ts.map +0 -1
  504. package/dist/geoarrow/tessellate.js +0 -102
  505. package/dist/geoarrow/tessellate.js.map +0 -1
  506. package/dist/geoarrow/tessellation-entry.d.ts +0 -4
  507. package/dist/geoarrow/tessellation-entry.d.ts.map +0 -1
  508. package/dist/geoarrow/tessellation-entry.js +0 -5
  509. package/dist/geoarrow/tessellation-entry.js.map +0 -1
  510. package/dist/geoarrow/types.d.ts +0 -155
  511. package/dist/geoarrow/types.d.ts.map +0 -1
  512. package/dist/geoarrow/types.js +0 -71
  513. package/dist/geoarrow/types.js.map +0 -1
  514. package/dist/geoarrow/views.d.ts +0 -45
  515. package/dist/geoarrow/views.d.ts.map +0 -1
  516. package/dist/geoarrow/views.js +0 -114
  517. package/dist/geoarrow/views.js.map +0 -1
  518. package/dist/geoarrow/wkb-entry.d.ts +0 -4
  519. package/dist/geoarrow/wkb-entry.d.ts.map +0 -1
  520. package/dist/geoarrow/wkb-entry.js +0 -6
  521. package/dist/geoarrow/wkb-entry.js.map +0 -1
  522. package/dist/geoarrow/worker.d.ts +0 -11
  523. package/dist/geoarrow/worker.d.ts.map +0 -1
  524. package/dist/geoarrow/worker.js +0 -10
  525. package/dist/geoarrow/worker.js.map +0 -1
  526. package/dist/wkb/index.d.ts +0 -11
  527. package/dist/wkb/index.d.ts.map +0 -1
  528. package/dist/wkb/index.js +0 -9
  529. package/dist/wkb/index.js.map +0 -1
  530. package/dist/wkb/types.d.ts +0 -30
  531. package/dist/wkb/types.d.ts.map +0 -1
  532. package/dist/wkb/types.js +0 -34
  533. package/dist/wkb/types.js.map +0 -1
  534. package/dist/wkb/wkb-builder.d.ts +0 -91
  535. package/dist/wkb/wkb-builder.d.ts.map +0 -1
  536. package/dist/wkb/wkb-builder.js +0 -283
  537. package/dist/wkb/wkb-builder.js.map +0 -1
  538. package/dist/wkb/wkb-reader.d.ts +0 -74
  539. package/dist/wkb/wkb-reader.d.ts.map +0 -1
  540. package/dist/wkb/wkb-reader.js +0 -251
  541. package/dist/wkb/wkb-reader.js.map +0 -1
  542. package/dist/wkb/wkb.d.ts +0 -21
  543. package/dist/wkb/wkb.d.ts.map +0 -1
  544. package/dist/wkb/wkb.js +0 -204
  545. package/dist/wkb/wkb.js.map +0 -1
  546. package/dist/wkb/wkt.d.ts +0 -19
  547. package/dist/wkb/wkt.d.ts.map +0 -1
  548. package/dist/wkb/wkt.js +0 -321
  549. package/dist/wkb/wkt.js.map +0 -1
  550. package/projection/THIRD-PARTY-NOTICES.md +0 -210
  551. package/src/discontinuous/elastic/README.md +0 -20
  552. package/src/discontinuous/spherical-clip/README.md +0 -16
  553. package/src/discontinuous/world-kernels/README.md +0 -24
  554. package/src/geoarrow/builder-entry.ts +0 -18
  555. package/src/geoarrow/builder.ts +0 -860
  556. package/src/geoarrow/codecs.ts +0 -1268
  557. package/src/geoarrow/index.ts +0 -111
  558. package/src/geoarrow/kernels.ts +0 -1290
  559. package/src/geoarrow/layout.ts +0 -900
  560. package/src/geoarrow/stream-tessellate.ts +0 -205
  561. package/src/geoarrow/stream.ts +0 -130
  562. package/src/geoarrow/tessellate.ts +0 -133
  563. package/src/geoarrow/tessellation-entry.ts +0 -7
  564. package/src/geoarrow/types.ts +0 -259
  565. package/src/geoarrow/views.ts +0 -150
  566. package/src/geoarrow/wkb-entry.ts +0 -13
  567. package/src/geoarrow/worker.ts +0 -20
  568. package/src/terrain/vendor/README.md +0 -20
  569. package/src/vendor/geographiclib-geodesic/README.md +0 -26
  570. package/src/wkb/index.ts +0 -38
  571. package/src/wkb/types.ts +0 -54
  572. package/src/wkb/wkb-builder.ts +0 -395
  573. package/src/wkb/wkb-reader.ts +0 -401
  574. package/src/wkb/wkb.ts +0 -255
  575. package/src/wkb/wkt.ts +0 -375
  576. /package/{projection/APACHE-2.0-LICENSE.txt → APACHE-2.0-LICENSE.txt} +0 -0
  577. /package/{projection/PROJ-LICENSE.txt → PROJ-LICENSE.txt} +0 -0
  578. /package/{projection/PROJ4-LICENSE.md → PROJ4-LICENSE.md} +0 -0
  579. /package/{crs/schemas → src/crs}/projjson.schema.json +0 -0
@@ -10,9 +10,9 @@ var __export = (target, all) => {
10
10
  };
11
11
  var __copyProps = (to, from, except, desc) => {
12
12
  if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ for (let key2 of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key2) && key2 !== except)
15
+ __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
16
16
  }
17
17
  return to;
18
18
  };
@@ -35,6 +35,7 @@ __export(index_exports, {
35
35
  HeightFieldMinMax: () => HeightFieldMinMax,
36
36
  TERRAIN_BUFFER_VERSION: () => TERRAIN_BUFFER_VERSION,
37
37
  TerrainContourBoundaryAxis: () => TerrainContourBoundaryAxis,
38
+ TerrainMorphStatus: () => TerrainMorphStatus,
38
39
  TerrainProfileViewStatus: () => TerrainProfileViewStatus,
39
40
  TerrainSampleStatus: () => TerrainSampleStatus,
40
41
  TerrainSurface: () => TerrainSurface,
@@ -46,12 +47,17 @@ __export(index_exports, {
46
47
  createTerrainFilteredPyramid: () => createTerrainFilteredPyramid,
47
48
  createTerrainGradientGrid: () => createTerrainGradientGrid,
48
49
  createTerrainGradientPyramid: () => createTerrainGradientPyramid,
50
+ createTerrainIsobands: () => createTerrainIsobands,
51
+ createTerrainLodMorph: () => createTerrainLodMorph,
49
52
  createTerrainMesh: () => createTerrainMesh,
53
+ createTerrainMixedVertexTileHalos: () => createTerrainMixedVertexTileHalos,
50
54
  createTerrainSkirt: () => createTerrainSkirt,
51
55
  createTerrainSlopeAspectGrid: () => createTerrainSlopeAspectGrid,
52
56
  createTerrainSurface: () => createTerrainSurface,
53
57
  createTerrainVertexTileHalos: () => createTerrainVertexTileHalos,
54
58
  diagnoseTerrainContourBoundaries: () => diagnoseTerrainContourBoundaries,
59
+ evaluateTerrainLodMorph: () => evaluateTerrainLodMorph,
60
+ getTerrainHierarchyNode: () => getTerrainHierarchyNode,
55
61
  getTerrainMeshEdge: () => getTerrainMeshEdge,
56
62
  getTerrainProfileHorizon: () => getTerrainProfileHorizon,
57
63
  getTerrainProfileViewshed: () => getTerrainProfileViewshed,
@@ -64,12 +70,26 @@ __export(index_exports, {
64
70
  reconcileTerrainVertexTiles: () => reconcileTerrainVertexTiles,
65
71
  sampleTerrainProfile: () => sampleTerrainProfile,
66
72
  simplifyTerrainContourPaths: () => simplifyTerrainContourPaths,
73
+ simplifyTerrainContourPathsTopology: () => simplifyTerrainContourPathsTopology,
67
74
  stitchTerrainContourTiles: () => stitchTerrainContourTiles,
68
75
  stitchTerrainContours: () => stitchTerrainContours,
69
76
  stitchTerrainMeshEdges: () => stitchTerrainMeshEdges,
70
77
  unpackTerrainHeightField: () => unpackTerrainHeightField,
78
+ updateTerrainBounds: () => updateTerrainBounds,
79
+ updateTerrainBoundsRegions: () => updateTerrainBoundsRegions,
80
+ updateTerrainDelatinMeshRegions: () => updateTerrainDelatinMeshRegions,
81
+ updateTerrainGradientPyramidRegions: () => updateTerrainGradientPyramidRegions,
82
+ updateTerrainGradientPyramids: () => updateTerrainGradientPyramids,
83
+ updateTerrainMartiniMeshRegions: () => updateTerrainMartiniMeshRegions,
84
+ updateTerrainMeshRegions: () => updateTerrainMeshRegions,
85
+ updateTerrainMeshes: () => updateTerrainMeshes,
86
+ updateTerrainMixedGradientGrids: () => updateTerrainMixedGradientGrids,
87
+ updateTerrainMixedVertexTileHalos: () => updateTerrainMixedVertexTileHalos,
88
+ updateTerrainPersistentBounds: () => updateTerrainPersistentBounds,
89
+ updateTerrainPersistentGradients: () => updateTerrainPersistentGradients,
71
90
  updateTerrainVertexTileHalos: () => updateTerrainVertexTileHalos,
72
- weldTerrainContourTiles: () => weldTerrainContourTiles
91
+ weldTerrainContourTiles: () => weldTerrainContourTiles,
92
+ weldTerrainMixedContourTiles: () => weldTerrainMixedContourTiles
73
93
  });
74
94
  module.exports = __toCommonJS(index_exports);
75
95
 
@@ -170,6 +190,12 @@ var HeightField = class {
170
190
  if (interpolation !== "nearest" && interpolation !== "bilinear" && interpolation !== "triangle") {
171
191
  throw new Error("Unknown terrain interpolation");
172
192
  }
193
+ const domain = (options == null ? void 0 : options.domain) ?? "samples";
194
+ const noData = (options == null ? void 0 : options.noData) ?? "cell";
195
+ if (domain !== "samples" && domain !== "footprint")
196
+ throw new Error("Unknown terrain sample domain");
197
+ if (noData !== "cell" && noData !== "support")
198
+ throw new Error("Unknown terrain nodata policy");
173
199
  if (!Number.isFinite(x) || !Number.isFinite(y))
174
200
  return result;
175
201
  const dx = x - this.origin[0];
@@ -184,11 +210,23 @@ var HeightField = class {
184
210
  const errorY = 4 * Number.EPSILON * Math.abs(y) + 4 * Number.EPSILON * Math.abs(this.origin[1]);
185
211
  const toleranceU = tolerance + Math.abs(this.inverse[0]) * errorX + Math.abs(this.inverse[1]) * errorY;
186
212
  const toleranceV = tolerance + Math.abs(this.inverse[2]) * errorX + Math.abs(this.inverse[3]) * errorY;
187
- if (u < -toleranceU || v < -toleranceV || u > this.width - 1 + toleranceU || v > this.height - 1 + toleranceV) {
213
+ const margin = domain === "footprint" && this.registration === "cell" ? 0.5 : 0;
214
+ if (u < -margin - toleranceU || v < -margin - toleranceV || u > this.width - 1 + margin + toleranceU || v > this.height - 1 + margin + toleranceV) {
188
215
  return resetSample(result, TerrainSampleStatus.OUTSIDE_DOMAIN);
189
216
  }
217
+ const edgeToleranceU = Math.min(1e-6, toleranceU);
218
+ const edgeToleranceV = Math.min(1e-6, toleranceV);
219
+ const clampedColumn = margin > 0 && (u < -edgeToleranceU || u > this.width - 1 + edgeToleranceU);
220
+ const clampedRow = margin > 0 && (v < -edgeToleranceV || v > this.height - 1 + edgeToleranceV);
190
221
  u = Math.max(0, Math.min(this.width - 1, u));
191
222
  v = Math.max(0, Math.min(this.height - 1, v));
223
+ if (noData === "support" && interpolation === "bilinear") {
224
+ const column2 = Math.round(u), row2 = Math.round(v);
225
+ if (Math.abs(u - column2) <= Math.min(1e-6, toleranceU))
226
+ u = column2;
227
+ if (Math.abs(v - row2) <= Math.min(1e-6, toleranceV))
228
+ v = row2;
229
+ }
192
230
  if (interpolation === "nearest") {
193
231
  const value = this.getHeight(Math.floor(u + 0.5), Math.floor(v + 0.5));
194
232
  if (value === void 0)
@@ -214,7 +252,21 @@ var HeightField = class {
214
252
  let dv;
215
253
  if (interpolation === "bilinear") {
216
254
  if (!this.validity[a] || !this.validity[b] || !this.validity[c] || !this.validity[d]) {
217
- return resetSample(result, TerrainSampleStatus.NO_DATA);
255
+ if (noData === "cell")
256
+ return resetSample(result, TerrainSampleStatus.NO_DATA);
257
+ const weightA = (1 - u) * (1 - v);
258
+ const weightB = u * (1 - v);
259
+ const weightC = (1 - u) * v;
260
+ const weightD = u * v;
261
+ if (weightA > 0 && !this.validity[a] || weightB > 0 && !this.validity[b] || weightC > 0 && !this.validity[c] || weightD > 0 && !this.validity[d])
262
+ return resetSample(result, TerrainSampleStatus.NO_DATA);
263
+ const height = weightA * za + weightB * zb + weightC * zc + weightD * zd;
264
+ if (!Number.isFinite(height))
265
+ return resetSample(result, TerrainSampleStatus.NUMERIC_ERROR);
266
+ result.status = TerrainSampleStatus.VALID;
267
+ result.height = height;
268
+ result.gradientStatus = TerrainSampleStatus.NO_DATA;
269
+ return result;
218
270
  }
219
271
  result.height = (1 - v) * ((1 - u) * za + u * zb) + v * ((1 - u) * zc + u * zd);
220
272
  du = (1 - v) * (zb - za) + v * (zd - zc);
@@ -239,6 +291,10 @@ var HeightField = class {
239
291
  if (!Number.isFinite(result.height))
240
292
  return resetSample(result, TerrainSampleStatus.NUMERIC_ERROR);
241
293
  result.status = TerrainSampleStatus.VALID;
294
+ if (clampedColumn)
295
+ du = 0;
296
+ if (clampedRow)
297
+ dv = 0;
242
298
  const gx = du * this.inverse[0] + dv * this.inverse[2];
243
299
  const gy = du * this.inverse[1] + dv * this.inverse[3];
244
300
  if (!Number.isFinite(gx) || !Number.isFinite(gy)) {
@@ -321,19 +377,19 @@ function validateBatch(positions, output) {
321
377
  }
322
378
  const count = positions.length / 2;
323
379
  const buffers = [positions];
324
- for (const [key, size] of [
380
+ for (const [key2, size] of [
325
381
  ["heights", 1],
326
382
  ["statuses", 1],
327
383
  ["gradients", 2],
328
384
  ["normals", 3],
329
385
  ["gradientStatuses", 1]
330
386
  ]) {
331
- const buffer = output[key];
332
- if (buffer === void 0 && key !== "heights" && key !== "statuses")
387
+ const buffer = output[key2];
388
+ if (buffer === void 0 && key2 !== "heights" && key2 !== "statuses")
333
389
  continue;
334
- const byte = key === "statuses" || key === "gradientStatuses";
390
+ const byte = key2 === "statuses" || key2 === "gradientStatuses";
335
391
  if ((byte ? !(buffer instanceof Uint8Array) : !isTerrainArray(buffer)) || buffer.length < count * size) {
336
- throw new Error(`Terrain batch ${key} has an invalid type or insufficient length`);
392
+ throw new Error(`Terrain batch ${key2} has an invalid type or insufficient length`);
337
393
  }
338
394
  for (const other of buffers) {
339
395
  if (buffer.buffer === other.buffer && buffer.byteOffset < other.byteOffset + other.byteLength && other.byteOffset < buffer.byteOffset + buffer.byteLength) {
@@ -368,9 +424,9 @@ function createTerrainSkirt(mesh, options) {
368
424
  if (!Number.isFinite(area) || area <= 0)
369
425
  throw new Error("Terrain skirt requires upward nondegenerate XY triangles");
370
426
  for (let j = 0; j < 3; j++) {
371
- const u = ids[j], v = ids[(j + 1) % 3], key = edgeKey(u, v), prior = boundary.get(key);
427
+ const u = ids[j], v = ids[(j + 1) % 3], key2 = edgeKey(u, v), prior = boundary.get(key2);
372
428
  if (!prior)
373
- boundary.set(key, { a: u, b: v, count: 1 });
429
+ boundary.set(key2, { a: u, b: v, count: 1 });
374
430
  else {
375
431
  if (prior.count !== 1 || prior.a !== v || prior.b !== u)
376
432
  throw new Error("Terrain skirt mesh has nonmanifold or inconsistent edges");
@@ -383,10 +439,10 @@ function createTerrainSkirt(mesh, options) {
383
439
  selected = [];
384
440
  const used = /* @__PURE__ */ new Set();
385
441
  for (let i = 0; i < edges.length; i += 2) {
386
- const key = edgeKey(edges[i], edges[i + 1]), edge = boundary.get(key);
387
- if (!edge || edge.count !== 1 || used.has(key))
442
+ const key2 = edgeKey(edges[i], edges[i + 1]), edge = boundary.get(key2);
443
+ if (!edge || edge.count !== 1 || used.has(key2))
388
444
  throw new Error("Terrain skirt selection must contain unique boundary edges");
389
- used.add(key);
445
+ used.add(key2);
390
446
  selected.push(edge);
391
447
  }
392
448
  } else
@@ -671,10 +727,10 @@ var TiledHeightField = class _TiledHeightField {
671
727
  throw new Error("Terrain requires unique matrix identifiers");
672
728
  for (const tile of props.tiles) {
673
729
  const matrix = this.validateTileId(tile);
674
- const key = tileKey(tile.matrixId, tile.column, tile.row);
675
- if (this.tiles.has(key))
730
+ const key2 = tileKey(tile.matrixId, tile.column, tile.row);
731
+ if (this.tiles.has(key2))
676
732
  throw new Error("Duplicate terrain tile");
677
- this.tiles.set(key, copyTileData(tile, matrix));
733
+ this.tiles.set(key2, copyTileData(tile, matrix));
678
734
  }
679
735
  for (const tile of props.tiles)
680
736
  this.buildHalo(this.getMatrix(tile.matrixId), tile.column, tile.row, props.diagonal);
@@ -703,10 +759,10 @@ var TiledHeightField = class _TiledHeightField {
703
759
  const touched = /* @__PURE__ */ new Map();
704
760
  for (const tile of [...update.tiles ?? [], ...update.remove ?? []]) {
705
761
  this.validateTileId(tile);
706
- const key = tileKey(tile.matrixId, tile.column, tile.row);
707
- if (touched.has(key))
762
+ const key2 = tileKey(tile.matrixId, tile.column, tile.row);
763
+ if (touched.has(key2))
708
764
  throw new Error("Terrain update contains duplicate or conflicting tile identifiers");
709
- touched.set(key, tile);
765
+ touched.set(key2, tile);
710
766
  }
711
767
  for (const tile of update.tiles ?? [])
712
768
  replacements.set(tileKey(tile.matrixId, tile.column, tile.row), copyTileData(tile, this.getMatrix(tile.matrixId)));
@@ -717,18 +773,18 @@ var TiledHeightField = class _TiledHeightField {
717
773
  diagonal: this.diagonal,
718
774
  heightReference: this.heightReference
719
775
  });
720
- for (const [key, tile] of this.tiles)
721
- next.tiles.set(key, tile);
722
- for (const [key, halo] of this.halos)
723
- next.halos.set(key, halo);
776
+ for (const [key2, tile] of this.tiles)
777
+ next.tiles.set(key2, tile);
778
+ for (const [key2, halo] of this.halos)
779
+ next.halos.set(key2, halo);
724
780
  const affected = /* @__PURE__ */ new Map();
725
- for (const [key, tile] of touched) {
726
- if (replacements.has(key))
727
- next.tiles.set(key, replacements.get(key));
781
+ for (const [key2, tile] of touched) {
782
+ if (replacements.has(key2))
783
+ next.tiles.set(key2, replacements.get(key2));
728
784
  else {
729
- if (!next.tiles.delete(key))
785
+ if (!next.tiles.delete(key2))
730
786
  continue;
731
- next.halos.delete(key);
787
+ next.halos.delete(key2);
732
788
  }
733
789
  for (let row = tile.row - 1; row <= tile.row + 1; row++)
734
790
  for (let column = tile.column - 1; column <= tile.column + 1; column++) {
@@ -741,11 +797,11 @@ var TiledHeightField = class _TiledHeightField {
741
797
  }
742
798
  }
743
799
  const changes = [];
744
- for (const [key, tile] of affected) {
745
- if (next.tiles.has(key)) {
800
+ for (const [key2, tile] of affected) {
801
+ if (next.tiles.has(key2)) {
746
802
  next.buildHalo(next.getMatrix(tile.matrixId), tile.column, tile.row, this.diagonal);
747
803
  changes.push({ ...tile, resident: true });
748
- } else if (this.tiles.has(key))
804
+ } else if (this.tiles.has(key2))
749
805
  changes.push(tile);
750
806
  }
751
807
  next.changes = freezeChanges(changes);
@@ -776,8 +832,12 @@ var TiledHeightField = class _TiledHeightField {
776
832
  heightReference: this.heightReference
777
833
  };
778
834
  }
779
- /** Queries never mix resolutions. Only absent residency permits coarser fallback. */
835
+ /** Queries never mix resolutions. Only absent residency permits coarser fallback.
836
+ * Raster footprint/masked-support policies are specific to HeightField, not tiled halos.
837
+ */
780
838
  sample(x, y, options) {
839
+ if ("domain" in options || "noData" in options)
840
+ throw new Error("Raster sampling policies require a HeightField");
781
841
  const requested = this.getMatrix(options.matrixId);
782
842
  if (options.fallback !== void 0 && options.fallback !== "none" && options.fallback !== "coarser")
783
843
  throw new Error("Unknown terrain fallback");
@@ -1464,10 +1524,10 @@ function buildTopology(indices, validity) {
1464
1524
  if (!validity[triangle])
1465
1525
  continue;
1466
1526
  const a = indices[i], b = indices[triangle * 3 + (i % 3 + 1) % 3];
1467
- const key = a < b ? `${a}/${b}` : `${b}/${a}`;
1468
- const opposite = edges.get(key);
1527
+ const key2 = a < b ? `${a}/${b}` : `${b}/${a}`;
1528
+ const opposite = edges.get(key2);
1469
1529
  if (opposite === void 0)
1470
- edges.set(key, i);
1530
+ edges.set(key2, i);
1471
1531
  else {
1472
1532
  if (halfedges[opposite] !== -1)
1473
1533
  throw new Error("Nonmanifold terrain edge");
@@ -1637,7 +1697,8 @@ function measureTerrainMeshError(field, mesh, options = {}) {
1637
1697
  const x = mesh.gridCoordinates[i * 2] + shift, y = mesh.gridCoordinates[i * 2 + 1] + shift;
1638
1698
  for (let axis = 0; axis < 2; axis++) {
1639
1699
  const expected = field.origin[axis] - mesh.origin[axis] + x * field.columnStep[axis] + y * field.rowStep[axis];
1640
- if (!Number.isFinite(expected) || mesh.positions[i * 3 + axis] !== expected)
1700
+ const tolerance = Math.min(16 * Number.EPSILON * (Math.abs(field.origin[axis] - mesh.origin[axis]) + Math.abs(x * field.columnStep[axis]) + Math.abs(y * field.rowStep[axis])), 1e-9 * Math.max(Math.abs(field.columnStep[axis]), Math.abs(field.rowStep[axis])));
1701
+ if (!Number.isFinite(expected) || Math.abs(mesh.positions[i * 3 + axis] - expected) > tolerance)
1641
1702
  throw new Error("Terrain mesh XY does not match the source grid frame");
1642
1703
  }
1643
1704
  }
@@ -1672,9 +1733,9 @@ function measureTerrainMeshError(field, mesh, options = {}) {
1672
1733
  throw new Error("Terrain mesh sample-test budget exceeded");
1673
1734
  const dx = baseX + (column + shift) * columnX + (row + shift) * rowX - px;
1674
1735
  const dy = baseY + (column + shift) * columnY + (row + shift) * rowY - py;
1675
- const sign = Math.sign(xyArea), area = Math.abs(xyArea);
1676
- const nu = (dx * vy - dy * vx) * sign;
1677
- const nv = (ux * dy - uy * dx) * sign;
1736
+ const sign2 = Math.sign(xyArea), area = Math.abs(xyArea);
1737
+ const nu = (dx * vy - dy * vx) * sign2;
1738
+ const nv = (ux * dy - uy * dx) * sign2;
1678
1739
  const tolerance = 16 * Number.EPSILON * (Math.abs(dx * vy) + Math.abs(dy * vx) + Math.abs(ux * dy) + Math.abs(uy * dx) + area);
1679
1740
  if (nu < -tolerance || nv < -tolerance || nu + nv > area + tolerance)
1680
1741
  continue;
@@ -2383,8 +2444,8 @@ function createTerrainContours(field, levels, options = {}) {
2383
2444
  const exact = height(a) === level ? a : height(b) === level ? b : void 0;
2384
2445
  return exact === void 0 ? { a, b, key: `e${a}/${b}` } : { a: exact, b: exact, key: `v${exact}` };
2385
2446
  };
2386
- const vertex = ({ a, b, key }) => {
2387
- const existing = vertices.get(key);
2447
+ const vertex = ({ a, b, key: key2 }) => {
2448
+ const existing = vertices.get(key2);
2388
2449
  if (existing !== void 0)
2389
2450
  return existing;
2390
2451
  if (positions.length / 3 >= maxVertices)
@@ -2411,7 +2472,7 @@ function createTerrainContours(field, levels, options = {}) {
2411
2472
  const index = positions.length / 3;
2412
2473
  positions.push(px, py, pz);
2413
2474
  coordinates.push(x, y);
2414
- vertices.set(key, index);
2475
+ vertices.set(key2, index);
2415
2476
  return index;
2416
2477
  };
2417
2478
  const triangle = (a, b, c) => {
@@ -2428,14 +2489,14 @@ function createTerrainContours(field, levels, options = {}) {
2428
2489
  if (hits.length !== 2 || hits[0].key === hits[1].key)
2429
2490
  return;
2430
2491
  const va = vertex(hits[0]), vb = vertex(hits[1]);
2431
- const key = va < vb ? `${va}/${vb}` : `${vb}/${va}`;
2432
- if (edges.has(key))
2492
+ const key2 = va < vb ? `${va}/${vb}` : `${vb}/${va}`;
2493
+ if (edges.has(key2))
2433
2494
  return;
2434
2495
  if (segments.length / 2 >= maxSegments)
2435
2496
  throw new Error("Terrain contour segment capacity exceeded");
2436
2497
  if (positions[3 * va] === positions[3 * vb] && positions[3 * va + 1] === positions[3 * vb + 1])
2437
2498
  throw new Error("Terrain contour segment collapses; use a local origin");
2438
- edges.add(key);
2499
+ edges.add(key2);
2439
2500
  segments.push(va, vb);
2440
2501
  levelIndices.push(levelIndex);
2441
2502
  };
@@ -2522,10 +2583,10 @@ function stitchTerrainContours(contours, options = {}) {
2522
2583
  validateContourVertex(contours, b, level, assignments);
2523
2584
  if (a === b || contours.positions[3 * a] === contours.positions[3 * b] && contours.positions[3 * a + 1] === contours.positions[3 * b + 1])
2524
2585
  throw new Error("Degenerate terrain contour segment");
2525
- const key = a < b ? `${a}/${b}` : `${b}/${a}`;
2526
- if (unique.has(key))
2586
+ const key2 = a < b ? `${a}/${b}` : `${b}/${a}`;
2587
+ if (unique.has(key2))
2527
2588
  throw new Error("Duplicate terrain contour segment");
2528
- unique.add(key);
2589
+ unique.add(key2);
2529
2590
  degrees[a]++;
2530
2591
  degrees[b]++;
2531
2592
  }
@@ -2713,10 +2774,10 @@ function diagnoseTerrainContourBoundaries(contours, options) {
2713
2774
  validateContourVertex(contours, b, level, assignments);
2714
2775
  if (a === b || contours.positions[3 * a] === contours.positions[3 * b] && contours.positions[3 * a + 1] === contours.positions[3 * b + 1])
2715
2776
  throw new Error("Degenerate terrain contour segment");
2716
- const key = a < b ? `${a}/${b}` : `${b}/${a}`;
2717
- if (seen.has(key))
2777
+ const key2 = a < b ? `${a}/${b}` : `${b}/${a}`;
2778
+ if (seen.has(key2))
2718
2779
  throw new Error("Duplicate terrain contour segment");
2719
- seen.add(key);
2780
+ seen.add(key2);
2720
2781
  degrees[a]++;
2721
2782
  degrees[b]++;
2722
2783
  }
@@ -2852,6 +2913,10 @@ function simplifyTerrainContourPaths(paths, options) {
2852
2913
  uses[vertex]++;
2853
2914
  }
2854
2915
  }
2916
+ const protectedIds = new Set(options.protectedVertexIndices);
2917
+ for (const id of protectedIds)
2918
+ if (id >= count)
2919
+ throw new Error("Invalid protected contour vertex");
2855
2920
  const keep = new Uint8Array(paths.indices.length);
2856
2921
  let distanceTests = 0, maxDeviation = 0;
2857
2922
  for (let p = 0; p < pathCount; p++) {
@@ -2862,7 +2927,7 @@ function simplifyTerrainContourPaths(paths, options) {
2862
2927
  keep[start + Math.floor(2 * (end - start) / 3)] = 1;
2863
2928
  }
2864
2929
  for (let i = start; i <= end; i++)
2865
- if (uses[paths.indices[i]] > 1)
2930
+ if (uses[paths.indices[i]] > 1 || protectedIds.has(paths.indices[i]))
2866
2931
  keep[i] = 1;
2867
2932
  const stack = [];
2868
2933
  let previous = start;
@@ -3083,9 +3148,9 @@ function compareTerrainSlopes(a, ad, b, bd) {
3083
3148
  const bytes = new DataView(new ArrayBuffer(8));
3084
3149
  const parts = (value) => {
3085
3150
  bytes.setFloat64(0, Math.abs(value));
3086
- const bits = bytes.getBigUint64(0);
3087
- const exponent = Number(bits >> 52n & 0x7ffn);
3088
- const fraction = bits & 0xfffffffffffffn;
3151
+ const bits2 = bytes.getBigUint64(0);
3152
+ const exponent = Number(bits2 >> 52n & 0x7ffn);
3153
+ const fraction = bits2 & 0xfffffffffffffn;
3089
3154
  return exponent ? [fraction | 0x10000000000000n, exponent - 1075] : [fraction, -1074];
3090
3155
  };
3091
3156
  const [am, ae] = parts(a), [bdm, bde] = parts(bd);
@@ -3202,10 +3267,10 @@ function reconcileTerrainVertexTiles(tiles, options) {
3202
3267
  const shared = /* @__PURE__ */ new Map();
3203
3268
  const result = [];
3204
3269
  for (const tile of sorted) {
3205
- const key = `${tile.column},${tile.row}`;
3206
- if (!Number.isSafeInteger(tile.column) || !Number.isSafeInteger(tile.row) || seen.has(key))
3270
+ const key2 = `${tile.column},${tile.row}`;
3271
+ if (!Number.isSafeInteger(tile.column) || !Number.isSafeInteger(tile.row) || seen.has(key2))
3207
3272
  throw new Error("Invalid or duplicate vertex tile address");
3208
- seen.add(key);
3273
+ seen.add(key2);
3209
3274
  const x = tile.column * (width - 1), y = tile.row * (height - 1);
3210
3275
  if (![x, y, x + width - 1, y + height - 1].every(Number.isSafeInteger))
3211
3276
  throw new Error("Vertex tile lattice overflow");
@@ -3356,20 +3421,20 @@ function getTerrainVertexHaloAffectedTiles(resident, changed, options) {
3356
3421
  if (!Number.isSafeInteger(limit) || limit < 0 || resident.length > limit || changed.length > limit || !Number.isSafeInteger(options.width) || options.width < 2 || !Number.isSafeInteger(options.height) || options.height < 2)
3357
3422
  throw new Error("Invalid vertex halo tile capacity");
3358
3423
  const addresses = /* @__PURE__ */ new Map();
3359
- const key = (tile) => {
3424
+ const key2 = (tile) => {
3360
3425
  if (!Number.isSafeInteger(tile.column) || !Number.isSafeInteger(tile.row))
3361
3426
  throw new Error("Invalid vertex tile address");
3362
3427
  return `${tile.column},${tile.row}`;
3363
3428
  };
3364
3429
  for (const tile of resident) {
3365
- const id = key(tile);
3430
+ const id = key2(tile);
3366
3431
  if (addresses.has(id))
3367
3432
  throw new Error("Duplicate resident vertex tile address");
3368
3433
  addresses.set(id, { column: tile.column, row: tile.row });
3369
3434
  }
3370
3435
  const affected = /* @__PURE__ */ new Map();
3371
3436
  for (const tile of changed) {
3372
- key(tile);
3437
+ key2(tile);
3373
3438
  const rx = options.width === 2 ? 2 : 1, ry = options.height === 2 ? 2 : 1;
3374
3439
  for (let x = -rx; x <= rx; x++)
3375
3440
  for (let y = -ry; y <= ry; y++) {
@@ -3396,26 +3461,26 @@ function updateTerrainVertexTileHalos(previous, resident, changed, options) {
3396
3461
  const equalPair = (a, b) => a[0] === b[0] && a[1] === b[1];
3397
3462
  if (prior.width !== options.width || prior.height !== options.height || !equalPair(prior.origin ?? [0, 0], options.origin ?? [0, 0]) || !equalPair(prior.columnStep ?? [1, 0], options.columnStep ?? [1, 0]) || !equalPair(prior.rowStep ?? [0, 1], options.rowStep ?? [0, 1]) || (prior.heightReference ?? "unknown") !== (options.heightReference ?? "unknown") || (prior.maxHeightDifference ?? 0) !== (options.maxHeightDifference ?? 0))
3398
3463
  throw new Error("Vertex tile options changed; rebuild the full snapshot");
3399
- const key = (t) => `${t.column},${t.row}`;
3464
+ const key2 = (t) => `${t.column},${t.row}`;
3400
3465
  const affected = getTerrainVertexHaloAffectedTiles(resident, changed, options);
3401
3466
  getTerrainVertexHaloAffectedTiles(previous, [], options);
3402
- const previousMap = new Map(previous.map((tile) => [key(tile), tile]));
3403
- const currentKeys = new Set(resident.map(key));
3404
- const changedKeys = new Set(changed.map(key));
3467
+ const previousMap = new Map(previous.map((tile) => [key2(tile), tile]));
3468
+ const currentKeys = new Set(resident.map(key2));
3469
+ const changedKeys = new Set(changed.map(key2));
3405
3470
  for (const tile of resident) {
3406
- if (!previousMap.has(key(tile)) && !changedKeys.has(key(tile)))
3471
+ if (!previousMap.has(key2(tile)) && !changedKeys.has(key2(tile)))
3407
3472
  throw new Error("Unreported vertex tile arrival");
3408
3473
  }
3409
3474
  const removed = [];
3410
3475
  for (const tile of previous) {
3411
- if (!currentKeys.has(key(tile))) {
3412
- if (!changedKeys.has(key(tile)))
3476
+ if (!currentKeys.has(key2(tile))) {
3477
+ if (!changedKeys.has(key2(tile)))
3413
3478
  throw new Error("Unreported vertex tile eviction");
3414
3479
  removed.push({ column: tile.column, row: tile.row });
3415
3480
  }
3416
3481
  }
3417
3482
  removed.sort((a, b) => a.column - b.column || a.row - b.row);
3418
- const affectedKeys = new Set(affected.map(key));
3483
+ const affectedKeys = new Set(affected.map(key2));
3419
3484
  const rx = options.width === 2 ? 2 : 1;
3420
3485
  const ry = options.height === 2 ? 2 : 1;
3421
3486
  const needed = /* @__PURE__ */ new Set();
@@ -3426,12 +3491,12 @@ function updateTerrainVertexTileHalos(previous, resident, changed, options) {
3426
3491
  if (Number.isSafeInteger(column) && Number.isSafeInteger(row))
3427
3492
  needed.add(`${column},${row}`);
3428
3493
  }
3429
- const source = resident.filter((tile) => needed.has(key(tile)));
3494
+ const source = resident.filter((tile) => needed.has(key2(tile)));
3430
3495
  const rebuilt = createTerrainVertexTileHalos(source, options).tiles;
3431
- const results = new Map(previous.filter((tile) => currentKeys.has(key(tile)) && !affectedKeys.has(key(tile))).map((tile) => [key(tile), tile]));
3496
+ const results = new Map(previous.filter((tile) => currentKeys.has(key2(tile)) && !affectedKeys.has(key2(tile))).map((tile) => [key2(tile), tile]));
3432
3497
  for (const tile of rebuilt)
3433
- if (affectedKeys.has(key(tile)))
3434
- results.set(key(tile), tile);
3498
+ if (affectedKeys.has(key2(tile)))
3499
+ results.set(key2(tile), tile);
3435
3500
  if (results.size !== resident.length)
3436
3501
  throw new Error("Incomplete vertex halo update");
3437
3502
  return {
@@ -3542,9 +3607,9 @@ function stitchTerrainMeshEdges(a, edgeA, b, edgeB, options = {}) {
3542
3607
  let direction = 0;
3543
3608
  for (let i = 0; i < mesh.indices.length; i += 3)
3544
3609
  for (let j = 0; j < 3; j++) {
3545
- const u = mesh.indices[i + j], v = mesh.indices[i + (j + 1) % 3], key = pair(u, v);
3546
- if (pairs.has(key)) {
3547
- pairs.set(key, pairs.get(key) + 1);
3610
+ const u = mesh.indices[i + j], v = mesh.indices[i + (j + 1) % 3], key2 = pair(u, v);
3611
+ if (pairs.has(key2)) {
3612
+ pairs.set(key2, pairs.get(key2) + 1);
3548
3613
  const nextDirection = Math.sign(mesh.gridCoordinates[2 * v + 1 - axis] - mesh.gridCoordinates[2 * u + 1 - axis]);
3549
3614
  if (direction && direction !== nextDirection)
3550
3615
  throw new Error("Inconsistent stitching boundary orientation");
@@ -3714,4 +3779,1473 @@ function stitchTerrainMeshEdges(a, edgeA, b, edgeB, options = {}) {
3714
3779
  function pair(a, b) {
3715
3780
  return a < b ? `${a},${b}` : `${b},${a}`;
3716
3781
  }
3782
+
3783
+ // dist/terrain/contour-mixed-weld.js
3784
+ function weldTerrainMixedContourTiles(tiles, options = {}) {
3785
+ const limits = contourPathLimits(options);
3786
+ const maxTiles = options.maxTiles ?? 4096;
3787
+ const budget = options.maxBoundaryTests ?? 1e7;
3788
+ const tolerance = options.maxPositionDifference ?? 0;
3789
+ if (!Number.isSafeInteger(maxTiles) || maxTiles < 1 || !tiles.length || tiles.length > maxTiles || !Number.isSafeInteger(budget) || budget < 0 || !Number.isFinite(tolerance) || tolerance < 0)
3790
+ throw new Error("Invalid mixed contour capacity or tolerance");
3791
+ let tests = 0;
3792
+ const charge = () => {
3793
+ if (++tests > budget)
3794
+ throw new Error("Mixed contour boundary-test budget exceeded");
3795
+ };
3796
+ const sorted = [...tiles].sort((a, b) => a.column - b.column || a.row - b.row || a.spacing - b.spacing);
3797
+ const bounds = sorted.map((t) => {
3798
+ if (![t.column, t.row, t.width, t.height, t.spacing].every(Number.isSafeInteger) || t.width < 2 || t.height < 2 || t.spacing < 1 || 2 ** Math.round(Math.log2(t.spacing)) !== t.spacing)
3799
+ throw new Error("Invalid mixed contour tile lattice");
3800
+ const x1 = t.column + (t.width - 1) * t.spacing, y1 = t.row + (t.height - 1) * t.spacing;
3801
+ if (![(t.width - 1) * t.spacing, (t.height - 1) * t.spacing, x1, y1].every(Number.isSafeInteger))
3802
+ throw new Error("Mixed contour lattice overflow");
3803
+ return [t.column, t.row, x1, y1];
3804
+ });
3805
+ for (let i = 0; i < bounds.length; i++)
3806
+ for (let j = 0; j < i; j++) {
3807
+ charge();
3808
+ const a = bounds[i], b = bounds[j];
3809
+ if (Math.max(a[0], b[0]) < Math.min(a[2], b[2]) && Math.max(a[1], b[1]) < Math.min(a[3], b[3]))
3810
+ throw new Error("Mixed contour tile interiors overlap");
3811
+ }
3812
+ const first = sorted[0].contours, origin = [...first.origin];
3813
+ const positions = [], grid = [], vertexLevels = [];
3814
+ const roundedBoundary = /* @__PURE__ */ new Map();
3815
+ const boundary = /* @__PURE__ */ new Set(), shared = /* @__PURE__ */ new Map();
3816
+ const edges = [];
3817
+ let inputVertices = 0, inputSegments = 0;
3818
+ for (let ti = 0; ti < sorted.length; ti++) {
3819
+ const tile = sorted[ti], data = tile.contours;
3820
+ const count = validateContourData(data, limits);
3821
+ inputVertices += count;
3822
+ if (inputVertices > limits.maxVertices)
3823
+ throw new Error("Mixed contour input vertex capacity exceeded");
3824
+ if (data.heightReference !== first.heightReference || data.levels.length !== first.levels.length || !data.levels.every((v, i) => v === first.levels[i]))
3825
+ throw new Error("Mixed contour levels or height reference differ");
3826
+ if (!(data.segments instanceof Uint32Array) || data.segments.length % 2 || !(data.levelIndices instanceof Uint32Array) || data.levelIndices.length !== data.segments.length / 2)
3827
+ throw new Error("Invalid mixed contour segments");
3828
+ inputSegments += data.levelIndices.length;
3829
+ if (inputSegments > limits.maxSegments)
3830
+ throw new Error("Mixed contour input segment capacity exceeded");
3831
+ const assigned = new Uint32Array(count).fill(4294967295), remap = /* @__PURE__ */ new Map();
3832
+ const local = /* @__PURE__ */ new Set();
3833
+ const vertex = (v, level) => {
3834
+ validateContourVertex(data, v, level, assigned);
3835
+ const existing = remap.get(v);
3836
+ if (existing !== void 0)
3837
+ return existing;
3838
+ const x = data.gridCoordinates[2 * v], y = data.gridCoordinates[2 * v + 1];
3839
+ if (x < 0 || x > tile.width - 1 || y < 0 || y > tile.height - 1)
3840
+ throw new Error("Mixed contour vertex outside tile");
3841
+ const sx = x * tile.spacing, sy = y * tile.spacing;
3842
+ const gx = tile.column + sx, gy = tile.row + sy;
3843
+ if (Math.abs(gx - tile.column - sx) > 8 * Number.EPSILON * Math.max(1, Math.abs(sx)) || Math.abs(gy - tile.row - sy) > 8 * Number.EPSILON * Math.max(1, Math.abs(sy)))
3844
+ throw new Error("Mixed contour lattice loses precision");
3845
+ const px = data.positions[3 * v] + (data.origin[0] - origin[0]), py = data.positions[3 * v + 1] + (data.origin[1] - origin[1]);
3846
+ const pz = data.levels[level] - origin[2];
3847
+ if (![gx, gy, px, py, pz].every(Number.isFinite))
3848
+ throw new Error("Mixed contour frame overflow");
3849
+ const onEdge = x === 0 || y === 0 || x === tile.width - 1 || y === tile.height - 1;
3850
+ const xi = Math.floor(sx), yi = Math.floor(sy);
3851
+ const key2 = `${level}/${tile.column + xi}/${sx - xi}/${tile.row + yi}/${sy - yi}`;
3852
+ if (onEdge) {
3853
+ const rounded = `${level}/${gx}/${gy}`;
3854
+ const identity = roundedBoundary.get(rounded);
3855
+ if (identity !== void 0 && identity !== key2)
3856
+ throw new Error("Mixed contour lattice loses precision");
3857
+ roundedBoundary.set(rounded, key2);
3858
+ }
3859
+ if (onEdge && local.has(key2))
3860
+ throw new Error("Duplicate mixed contour boundary vertex");
3861
+ if (onEdge)
3862
+ local.add(key2);
3863
+ let id = onEdge ? shared.get(key2) : void 0;
3864
+ if (id !== void 0) {
3865
+ if (Math.hypot(px - positions[3 * id], py - positions[3 * id + 1]) > tolerance)
3866
+ throw new Error("Mixed contour boundary positions disagree");
3867
+ } else {
3868
+ id = positions.length / 3;
3869
+ if (id >= limits.maxVertices)
3870
+ throw new Error("Mixed contour vertex capacity exceeded");
3871
+ positions.push(px, py, pz);
3872
+ grid.push(gx, gy);
3873
+ vertexLevels.push(level);
3874
+ if (onEdge) {
3875
+ shared.set(key2, id);
3876
+ boundary.add(id);
3877
+ }
3878
+ }
3879
+ remap.set(v, id);
3880
+ return id;
3881
+ };
3882
+ const localEdges = /* @__PURE__ */ new Set();
3883
+ for (let i = 0; i < data.levelIndices.length; i++) {
3884
+ const level = data.levelIndices[i], a = vertex(data.segments[2 * i], level), b = vertex(data.segments[2 * i + 1], level);
3885
+ if (a === b || positions[3 * a] === positions[3 * b] && positions[3 * a + 1] === positions[3 * b + 1])
3886
+ throw new Error("Degenerate mixed contour segment");
3887
+ const key2 = a < b ? `${a}/${b}` : `${b}/${a}`;
3888
+ if (localEdges.has(key2))
3889
+ throw new Error("Duplicate mixed contour segment");
3890
+ localEdges.add(key2);
3891
+ const box = bounds[ti];
3892
+ const seam = grid[2 * a] === grid[2 * b] && (grid[2 * a] === box[0] || grid[2 * a] === box[2]) || grid[2 * a + 1] === grid[2 * b + 1] && (grid[2 * a + 1] === box[1] || grid[2 * a + 1] === box[3]);
3893
+ edges.push({ a, b, level, tile: ti, seam });
3894
+ }
3895
+ }
3896
+ const segments = [], levels = [], emitted = /* @__PURE__ */ new Map();
3897
+ for (const edge of edges) {
3898
+ const { a, b, level } = edge;
3899
+ const axis = grid[2 * a] === grid[2 * b] ? 1 : 0;
3900
+ const start = grid[2 * a + axis], end = grid[2 * b + axis];
3901
+ const cuts = [a, b];
3902
+ if (edge.seam)
3903
+ for (const v of boundary) {
3904
+ charge();
3905
+ const value = grid[2 * v + axis];
3906
+ if (vertexLevels[v] !== level || grid[2 * v + 1 - axis] !== grid[2 * a + 1 - axis] || value <= Math.min(start, end) || value >= Math.max(start, end))
3907
+ continue;
3908
+ const f = (value - start) / (end - start);
3909
+ const px = positions[3 * a] + f * (positions[3 * b] - positions[3 * a]);
3910
+ const py = positions[3 * a + 1] + f * (positions[3 * b + 1] - positions[3 * a + 1]);
3911
+ if (Math.hypot(px - positions[3 * v], py - positions[3 * v + 1]) > tolerance)
3912
+ throw new Error("Mixed contour boundary positions disagree");
3913
+ cuts.push(v);
3914
+ }
3915
+ cuts.sort((u, v) => grid[2 * u + axis] - grid[2 * v + axis]);
3916
+ for (let i = 1; i < cuts.length; i++) {
3917
+ const u = cuts[i - 1], v = cuts[i], key2 = u < v ? `${u}/${v}` : `${v}/${u}`;
3918
+ const prior = emitted.get(key2);
3919
+ if (prior !== void 0) {
3920
+ if (prior === edge.tile)
3921
+ throw new Error("Overlapping mixed contour segments within tile");
3922
+ continue;
3923
+ }
3924
+ if (levels.length >= limits.maxSegments)
3925
+ throw new Error("Mixed contour output segment capacity exceeded");
3926
+ emitted.set(key2, edge.tile);
3927
+ segments.push(u, v);
3928
+ levels.push(level);
3929
+ }
3930
+ }
3931
+ return {
3932
+ positions: Float64Array.from(positions),
3933
+ gridCoordinates: Float64Array.from(grid),
3934
+ segments: Uint32Array.from(segments),
3935
+ levelIndices: Uint32Array.from(levels),
3936
+ levels: first.levels.slice(),
3937
+ origin,
3938
+ heightReference: first.heightReference
3939
+ };
3940
+ }
3941
+
3942
+ // dist/terrain/sample-triangle-height.js
3943
+ function sampleTerrainTriangleHeight(field, x, y) {
3944
+ if (Number.isInteger(x) && Number.isInteger(y))
3945
+ return field.getHeight(x, y);
3946
+ const column = Math.min(Math.floor(x), field.width - 2);
3947
+ const row = Math.min(Math.floor(y), field.height - 2);
3948
+ const u = x - column, v = y - row;
3949
+ let a, b, c, d;
3950
+ if (field.diagonal === "00-11") {
3951
+ if (v <= u) {
3952
+ a = 1 - u;
3953
+ b = u - v;
3954
+ c = 0;
3955
+ d = v;
3956
+ } else {
3957
+ a = 1 - v;
3958
+ b = 0;
3959
+ c = v - u;
3960
+ d = u;
3961
+ }
3962
+ } else if (u + v <= 1) {
3963
+ a = 1 - u - v;
3964
+ b = u;
3965
+ c = v;
3966
+ d = 0;
3967
+ } else {
3968
+ a = 0;
3969
+ b = 1 - v;
3970
+ c = 1 - u;
3971
+ d = u + v - 1;
3972
+ }
3973
+ const za = a ? field.getHeight(column, row) : 0;
3974
+ const zb = b ? field.getHeight(column + 1, row) : 0;
3975
+ const zc = c ? field.getHeight(column, row + 1) : 0;
3976
+ const zd = d ? field.getHeight(column + 1, row + 1) : 0;
3977
+ if (za === void 0 || zb === void 0 || zc === void 0 || zd === void 0)
3978
+ return void 0;
3979
+ const height = a * za + b * zb + c * zc + d * zd;
3980
+ if (!Number.isFinite(height))
3981
+ throw new Error("Terrain triangle numeric sampling failure");
3982
+ return height;
3983
+ }
3984
+
3985
+ // dist/terrain/mixed-vertex-halos.js
3986
+ function createTerrainMixedVertexTileHalos(tiles, options = {}) {
3987
+ return buildMixedVertexTileHalos(tiles, options);
3988
+ }
3989
+ function buildMixedVertexTileHalos(tiles, options = {}, targets) {
3990
+ const maxSamples = options.maxSamples ?? 4e6, maxTests = options.maxTileTests ?? 1e7;
3991
+ if (![maxSamples, maxTests].every((v) => Number.isSafeInteger(v) && v >= 0))
3992
+ throw new Error("Invalid mixed halo capacity");
3993
+ let count = 0;
3994
+ const addresses = /* @__PURE__ */ new Set();
3995
+ let frame;
3996
+ const sources = [...tiles].sort((a, b) => a.spacing - b.spacing || a.column - b.column || a.row - b.row).map((tile) => {
3997
+ if (![tile.column, tile.row, tile.spacing].every(Number.isSafeInteger) || tile.spacing < 1 || 2 ** Math.round(Math.log2(tile.spacing)) !== tile.spacing)
3998
+ throw new Error("Invalid mixed halo lattice");
3999
+ const key2 = `${tile.spacing}/${tile.column}/${tile.row}`;
4000
+ if (addresses.has(key2))
4001
+ throw new Error("Duplicate mixed halo tile");
4002
+ addresses.add(key2);
4003
+ count += (tile.field.width + 2) * (tile.field.height + 2);
4004
+ if (!Number.isSafeInteger(count) || count > maxSamples)
4005
+ throw new Error("Mixed halo sample capacity exceeded");
4006
+ const field = new HeightField(tile.field);
4007
+ if (field.registration !== "vertex")
4008
+ throw new Error("Mixed halos require vertex registration");
4009
+ const column = field.columnStep.map((v) => v / tile.spacing);
4010
+ const row = field.rowStep.map((v) => v / tile.spacing);
4011
+ const origin = field.origin.map((v, axis) => v - tile.column * column[axis] - tile.row * row[axis]);
4012
+ const scale = field.origin.map((v, i) => Math.max(1, Math.abs(v), Math.abs(tile.column * column[i]), Math.abs(tile.row * row[i])));
4013
+ if (!origin.every(Number.isFinite))
4014
+ throw new Error("Mixed halo coordinate overflow");
4015
+ if (frame && (frame.reference !== field.heightReference || column.some((v, i) => v !== frame.column[i]) || row.some((v, i) => v !== frame.row[i]) || origin.some((v, i) => Math.abs(v - frame.origin[i]) > Math.min(16 * Number.EPSILON * Math.max(scale[i], frame.scale[i]), 1e-9 * Math.max(Math.abs(column[i]), Math.abs(row[i]))))))
4016
+ throw new Error("Mixed halo frames or height references differ");
4017
+ frame ?? (frame = { origin, column, row, reference: field.heightReference, scale });
4018
+ return { ...tile, source: field };
4019
+ });
4020
+ for (const axis of ["column", "row"]) {
4021
+ let min = Infinity, max = -Infinity;
4022
+ for (const tile of sources) {
4023
+ const size = axis === "column" ? tile.source.width : tile.source.height;
4024
+ const low = tile[axis] - tile.spacing, high = tile[axis] + size * tile.spacing;
4025
+ if (![low, high].every(Number.isSafeInteger))
4026
+ throw new Error("Mixed halo lattice overflow");
4027
+ min = Math.min(min, low);
4028
+ max = Math.max(max, high);
4029
+ }
4030
+ if (sources.length && !Number.isSafeInteger(max - min))
4031
+ throw new Error("Mixed halo lattice span overflow");
4032
+ }
4033
+ let tests = 0;
4034
+ return {
4035
+ tiles: sources.filter((tile) => !targets || targets.has(`${tile.spacing}/${tile.column}/${tile.row}`)).map((tile) => {
4036
+ const source = tile.source, width = source.width + 2, height = source.height + 2;
4037
+ const heights = new Float64Array(width * height), validity = new Uint8Array(heights.length), statuses = new Uint8Array(heights.length);
4038
+ for (let y = 0; y < height; y++)
4039
+ for (let x = 0; x < width; x++) {
4040
+ const gx = tile.column + (x - 1) * tile.spacing, gy = tile.row + (y - 1) * tile.spacing;
4041
+ if (![gx, gy].every(Number.isSafeInteger))
4042
+ throw new Error("Mixed halo lattice overflow");
4043
+ for (const candidate of sources) {
4044
+ if (++tests > maxTests)
4045
+ throw new Error("Mixed halo tile-test budget exceeded");
4046
+ const cx = (gx - candidate.column) / candidate.spacing, cy = (gy - candidate.row) / candidate.spacing;
4047
+ const f = candidate.source;
4048
+ if (cx < 0 || cy < 0 || cx > f.width - 1 || cy > f.height - 1)
4049
+ continue;
4050
+ const value = sampleTerrainTriangleHeight(f, cx, cy);
4051
+ const i = y * width + x;
4052
+ statuses[i] = value === void 0 ? 1 : 2;
4053
+ if (value !== void 0) {
4054
+ heights[i] = value;
4055
+ validity[i] = 1;
4056
+ }
4057
+ break;
4058
+ }
4059
+ }
4060
+ const origin = [
4061
+ source.origin[0] - source.columnStep[0] - source.rowStep[0],
4062
+ source.origin[1] - source.columnStep[1] - source.rowStep[1]
4063
+ ];
4064
+ if (!origin.every(Number.isFinite))
4065
+ throw new Error("Mixed halo coordinate overflow");
4066
+ return {
4067
+ column: tile.column,
4068
+ row: tile.row,
4069
+ spacing: tile.spacing,
4070
+ statuses,
4071
+ field: {
4072
+ ...tile.field,
4073
+ width,
4074
+ height,
4075
+ heights,
4076
+ validity,
4077
+ offset: 0,
4078
+ stride: width,
4079
+ origin,
4080
+ columnStep: [...source.columnStep],
4081
+ rowStep: [...source.rowStep]
4082
+ }
4083
+ };
4084
+ })
4085
+ };
4086
+ }
4087
+
4088
+ // dist/terrain/mixed-halo-update.js
4089
+ var key = (t) => `${t.spacing}/${t.column}/${t.row}`;
4090
+ function updateTerrainMixedVertexTileHalos(previous, resident, options = {}) {
4091
+ const budget = options.maxDependencyTests ?? 1e7;
4092
+ if (!Number.isSafeInteger(budget) || budget < 0)
4093
+ throw new Error("Invalid mixed halo dependency budget");
4094
+ const old = new Map(previous == null ? void 0 : previous.sources.map((t) => [key(t), t]));
4095
+ const current = new Map(resident.map((t) => [key(t), t]));
4096
+ const changed = [...old.values()].filter((t) => current.get(key(t)) !== t).concat(resident.filter((t) => old.get(key(t)) !== t));
4097
+ const cached = new Map(previous == null ? void 0 : previous.tiles.map((t) => [key(t), t]));
4098
+ const targets = /* @__PURE__ */ new Set();
4099
+ let tests = 0;
4100
+ for (const tile of resident) {
4101
+ if (!cached.has(key(tile)))
4102
+ targets.add(key(tile));
4103
+ for (const source of changed) {
4104
+ if (++tests > budget)
4105
+ throw new Error("Mixed halo dependency budget exceeded");
4106
+ if (tile.column - tile.spacing <= source.column + (source.field.width - 1) * source.spacing && tile.column + tile.field.width * tile.spacing >= source.column && tile.row - tile.spacing <= source.row + (source.field.height - 1) * source.spacing && tile.row + tile.field.height * tile.spacing >= source.row)
4107
+ targets.add(key(tile));
4108
+ }
4109
+ }
4110
+ const built = buildMixedVertexTileHalos(resident, options, targets).tiles;
4111
+ for (const tile of built)
4112
+ cached.set(key(tile), tile);
4113
+ const tiles = resident.map((t) => cached.get(key(t))).sort((a, b) => a.spacing - b.spacing || a.column - b.column || a.row - b.row);
4114
+ return {
4115
+ sources: resident.slice(),
4116
+ tiles,
4117
+ rebuilt: built.map(key),
4118
+ removed: [...old.keys()].filter((k) => !current.has(k)).sort()
4119
+ };
4120
+ }
4121
+
4122
+ // dist/terrain/mixed-gradient-update.js
4123
+ function updateTerrainMixedGradientGrids(previous, halos, options = {}) {
4124
+ const method = options.method ?? "horn";
4125
+ if (method !== "horn" && method !== "zevenbergen-thorne")
4126
+ throw new Error("Unknown terrain gradient method");
4127
+ const limit = options.maxSamples ?? 4e6;
4128
+ const count = halos.tiles.reduce((n, t) => n + t.field.width * t.field.height, 0);
4129
+ if (!Number.isSafeInteger(limit) || limit < 0 || !Number.isSafeInteger(count) || count > limit)
4130
+ throw new Error("Mixed gradient sample capacity exceeded");
4131
+ const cache = new Map((previous == null ? void 0 : previous.method) === method ? previous.tiles.map((t) => [t.halo, t]) : []);
4132
+ return {
4133
+ method,
4134
+ tiles: halos.tiles.map((halo) => cache.get(halo) ?? {
4135
+ halo,
4136
+ grid: createTerrainGradientGrid(new HeightField(halo.field), { method, maxSamples: limit })
4137
+ })
4138
+ };
4139
+ }
4140
+
4141
+ // dist/terrain/box-index.js
4142
+ var overlaps = (a, b) => a.minX <= b.maxX && b.minX <= a.maxX && a.minY <= b.maxY && b.minY <= a.maxY;
4143
+ function createTerrainBoxIndex(boxes) {
4144
+ const build = (ids) => {
4145
+ const box = { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
4146
+ for (const id of ids) {
4147
+ const b = boxes[id];
4148
+ box.minX = Math.min(box.minX, b.minX);
4149
+ box.minY = Math.min(box.minY, b.minY);
4150
+ box.maxX = Math.max(box.maxX, b.maxX);
4151
+ box.maxY = Math.max(box.maxY, b.maxY);
4152
+ }
4153
+ if (ids.length <= 8)
4154
+ return { ...box, ids };
4155
+ const axis = box.maxX - box.minX >= box.maxY - box.minY ? "X" : "Y";
4156
+ ids.sort((a, b) => boxes[a][`min${axis}`] / 2 + boxes[a][`max${axis}`] / 2 - (boxes[b][`min${axis}`] / 2 + boxes[b][`max${axis}`] / 2) || a - b);
4157
+ const mid = ids.length >>> 1;
4158
+ return { ...box, left: build(ids.slice(0, mid)), right: build(ids.slice(mid)) };
4159
+ };
4160
+ const root = build(boxes.map((_, i) => i));
4161
+ return (query, charge) => {
4162
+ const found = [], stack = [root];
4163
+ while (stack.length) {
4164
+ charge();
4165
+ const node = stack.pop();
4166
+ if (!overlaps(node, query))
4167
+ continue;
4168
+ if (node.ids) {
4169
+ for (const id of node.ids) {
4170
+ charge();
4171
+ if (overlaps(boxes[id], query))
4172
+ found.push(id);
4173
+ }
4174
+ } else
4175
+ stack.push(node.right, node.left);
4176
+ }
4177
+ return found.sort((a, b) => a - b);
4178
+ };
4179
+ }
4180
+
4181
+ // dist/terrain/contour-topology.js
4182
+ var bits = new DataView(new ArrayBuffer(8));
4183
+ function integer(x) {
4184
+ bits.setFloat64(0, x);
4185
+ const high = bits.getUint32(0), low = bits.getUint32(4);
4186
+ const exponent = high >>> 20 & 2047;
4187
+ const mantissa = BigInt(high & 1048575) << 32n | BigInt(low);
4188
+ const value = exponent ? (1n << 52n | mantissa) << BigInt(exponent - 1) : mantissa;
4189
+ return high >>> 31 ? -value : value;
4190
+ }
4191
+ var orientation = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
4192
+ var sign = (v) => v < 0n ? -1 : v > 0n ? 1 : 0;
4193
+ var between = (a, b, p) => p >= (a < b ? a : b) && p <= (a > b ? a : b);
4194
+ var on = (a, b, p) => orientation(a, b, p) === 0n && between(a.x, b.x, p.x) && between(a.y, b.y, p.y);
4195
+ function intersects(a, b, c, d) {
4196
+ return on(a, b, c) || on(a, b, d) || on(c, d, a) || on(c, d, b) || sign(orientation(a, b, c)) * sign(orientation(a, b, d)) < 0 && sign(orientation(c, d, a)) * sign(orientation(c, d, b)) < 0;
4197
+ }
4198
+ function simplifyTerrainContourPathsTopology(paths, options) {
4199
+ if (options.rejection !== void 0 && options.rejection !== "batch" && options.rejection !== "path")
4200
+ throw new Error("Invalid contour rejection policy");
4201
+ const candidate = simplifyTerrainContourPaths(paths, options);
4202
+ const budget = options.maxTopologyTests ?? 1e6;
4203
+ if (!Number.isSafeInteger(budget) || budget < 0)
4204
+ throw new Error("Invalid contour topology budget");
4205
+ let topologyTests = 0;
4206
+ const charge = () => {
4207
+ if (++topologyTests > budget)
4208
+ throw new Error("Contour topology work budget exceeded");
4209
+ };
4210
+ const points = new Array(paths.positions.length / 3);
4211
+ for (const i of new Set(paths.indices))
4212
+ points[i] = { x: integer(paths.positions[3 * i]), y: integer(paths.positions[3 * i + 1]) };
4213
+ const edges = [];
4214
+ for (let p = 0; p < paths.closed.length; p++)
4215
+ for (let i = paths.offsets[p]; i + 1 < paths.offsets[p + 1]; i++)
4216
+ edges.push({ a: paths.indices[i], b: paths.indices[i + 1], p, i });
4217
+ const box = (a, b) => ({
4218
+ minX: Math.min(paths.positions[3 * a], paths.positions[3 * b]),
4219
+ maxX: Math.max(paths.positions[3 * a], paths.positions[3 * b]),
4220
+ minY: Math.min(paths.positions[3 * a + 1], paths.positions[3 * b + 1]),
4221
+ maxY: Math.max(paths.positions[3 * a + 1], paths.positions[3 * b + 1])
4222
+ });
4223
+ const edgeBoxes = edges.map((e) => box(e.a, e.b)), edgeIndex = createTerrainBoxIndex(edgeBoxes);
4224
+ const vertexIds = [...new Set(paths.indices)], vertexIndex = createTerrainBoxIndex(vertexIds.map((v) => box(v, v)));
4225
+ for (let i = 0; i < edges.length; i++)
4226
+ for (const j of edgeIndex(edgeBoxes[i], charge)) {
4227
+ if (j <= i)
4228
+ continue;
4229
+ charge();
4230
+ const a = edges[i], b = edges[j];
4231
+ const common = [a.a, a.b].filter((v) => v === b.a || v === b.b);
4232
+ if (common.length === 1) {
4233
+ const v = common[0], x = a.a === v ? a.b : a.a, y = b.a === v ? b.b : b.a;
4234
+ if (on(points[v], points[x], points[y]) || on(points[v], points[y], points[x]))
4235
+ throw new Error("Overlapping contour edges");
4236
+ } else if (intersects(points[a.a], points[a.b], points[b.a], points[b.b]))
4237
+ throw new Error("Contour input has crossings or unshared touches");
4238
+ }
4239
+ let rejected = false;
4240
+ const rejectedPaths = /* @__PURE__ */ new Set();
4241
+ for (let p = 0; p < paths.closed.length; p++) {
4242
+ let start = paths.offsets[p];
4243
+ for (let k = candidate.offsets[p] + 1; k < candidate.offsets[p + 1]; k++) {
4244
+ const endId = candidate.sourceVertexIndices[candidate.indices[k]];
4245
+ let end = start + 1;
4246
+ while (paths.indices[end] !== endId)
4247
+ end++;
4248
+ if (end > start + 1) {
4249
+ const a = paths.indices[start], b = paths.indices[end];
4250
+ const pa = points[a], pb = points[b];
4251
+ const axis = pa.x !== pb.x ? "x" : "y";
4252
+ const direction = sign(pb[axis] - pa[axis]);
4253
+ let straight = true;
4254
+ for (let i = start + 1; i <= end; i++) {
4255
+ charge();
4256
+ const q = points[paths.indices[i]], prior = points[paths.indices[i - 1]];
4257
+ if (!on(pa, pb, q) || sign(q[axis] - prior[axis]) !== direction)
4258
+ straight = false;
4259
+ }
4260
+ const interior = new Set(Array.from(paths.indices.subarray(start + 1, end)));
4261
+ let unsafe = false;
4262
+ for (const edgeId of edgeIndex(box(a, b), charge)) {
4263
+ const edge = edges[edgeId];
4264
+ if (edge.p === p && edge.i >= start && edge.i < end) {
4265
+ if (straight)
4266
+ continue;
4267
+ charge();
4268
+ const others2 = [edge.a, edge.b].filter((v) => v !== a && v !== b);
4269
+ if (others2.some((v) => on(points[a], points[b], points[v])) || others2.length === 2 && intersects(points[a], points[b], points[edge.a], points[edge.b]))
4270
+ unsafe = true;
4271
+ continue;
4272
+ }
4273
+ charge();
4274
+ const others = [edge.a, edge.b].filter((v) => v !== a && v !== b);
4275
+ if (others.some((v) => on(points[a], points[b], points[v])) || others.length === 2 && intersects(points[a], points[b], points[edge.a], points[edge.b]))
4276
+ unsafe = true;
4277
+ }
4278
+ const swept = { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
4279
+ for (let i = start; i <= end; i++) {
4280
+ const v = paths.indices[i];
4281
+ swept.minX = Math.min(swept.minX, paths.positions[3 * v]);
4282
+ swept.maxX = Math.max(swept.maxX, paths.positions[3 * v]);
4283
+ swept.minY = Math.min(swept.minY, paths.positions[3 * v + 1]);
4284
+ swept.maxY = Math.max(swept.maxY, paths.positions[3 * v + 1]);
4285
+ }
4286
+ for (const vertexId of vertexIndex(swept, charge)) {
4287
+ const vertex = vertexIds[vertexId];
4288
+ if (vertex === a || vertex === b || interior.has(vertex))
4289
+ continue;
4290
+ let inside = false;
4291
+ for (let i = start, j = end; i <= end; j = i++) {
4292
+ charge();
4293
+ const u = points[paths.indices[i]], v = points[paths.indices[j]], q = points[vertex];
4294
+ if (on(u, v, q)) {
4295
+ unsafe = true;
4296
+ break;
4297
+ }
4298
+ if (u.y > q.y !== v.y > q.y && orientation(u, v, q) > 0n === v.y > u.y)
4299
+ inside = !inside;
4300
+ }
4301
+ if (inside)
4302
+ unsafe = true;
4303
+ }
4304
+ if (unsafe) {
4305
+ rejected = true;
4306
+ rejectedPaths.add(p);
4307
+ }
4308
+ }
4309
+ start = end;
4310
+ }
4311
+ }
4312
+ const outputEdges = [];
4313
+ for (let p = 0; p < candidate.closed.length; p++)
4314
+ for (let i = candidate.offsets[p]; i + 1 < candidate.offsets[p + 1]; i++)
4315
+ outputEdges.push({
4316
+ p,
4317
+ a: candidate.sourceVertexIndices[candidate.indices[i]],
4318
+ b: candidate.sourceVertexIndices[candidate.indices[i + 1]]
4319
+ });
4320
+ const outputBoxes = outputEdges.map((e) => box(e.a, e.b)), outputIndex = createTerrainBoxIndex(outputBoxes);
4321
+ for (let i = 0; i < outputEdges.length; i++)
4322
+ for (const j of outputIndex(outputBoxes[i], charge)) {
4323
+ if (j <= i)
4324
+ continue;
4325
+ charge();
4326
+ const a = outputEdges[i], b = outputEdges[j];
4327
+ const common = [a.a, a.b].filter((v) => v === b.a || v === b.b);
4328
+ if (common.length === 1) {
4329
+ const v = common[0], x = a.a === v ? a.b : a.a, y = b.a === v ? b.b : b.a;
4330
+ if (on(points[v], points[x], points[y]) || on(points[v], points[y], points[x])) {
4331
+ rejected = true;
4332
+ rejectedPaths.add(a.p);
4333
+ rejectedPaths.add(b.p);
4334
+ }
4335
+ } else if (intersects(points[a.a], points[a.b], points[b.a], points[b.b])) {
4336
+ rejected = true;
4337
+ rejectedPaths.add(a.p);
4338
+ rejectedPaths.add(b.p);
4339
+ }
4340
+ }
4341
+ if (rejected && options.rejection === "path") {
4342
+ const indices = [], offsets = [0];
4343
+ for (let p = 0; p < paths.closed.length; p++) {
4344
+ if (rejectedPaths.has(p))
4345
+ for (let i = paths.offsets[p]; i < paths.offsets[p + 1]; i++)
4346
+ indices.push(paths.indices[i]);
4347
+ else
4348
+ for (let i = candidate.offsets[p]; i < candidate.offsets[p + 1]; i++)
4349
+ indices.push(candidate.sourceVertexIndices[candidate.indices[i]]);
4350
+ offsets.push(indices.length);
4351
+ }
4352
+ return {
4353
+ ...paths,
4354
+ positions: paths.positions.slice(),
4355
+ gridCoordinates: paths.gridCoordinates.slice(),
4356
+ indices: Uint32Array.from(indices),
4357
+ offsets: Uint32Array.from(offsets),
4358
+ closed: paths.closed.slice(),
4359
+ levelIndices: paths.levelIndices.slice(),
4360
+ levels: paths.levels.slice(),
4361
+ origin: Object.freeze([...paths.origin]),
4362
+ sourceVertexIndices: Uint32Array.from({ length: points.length }, (_, i) => i),
4363
+ maxDeviation: candidate.maxDeviation,
4364
+ requestedMaxError: options.maxError,
4365
+ distanceTests: candidate.distanceTests,
4366
+ topologyTests,
4367
+ rejected: true
4368
+ };
4369
+ }
4370
+ if (!rejected)
4371
+ return { ...candidate, topologyTests, rejected: false };
4372
+ return {
4373
+ ...paths,
4374
+ positions: paths.positions.slice(),
4375
+ gridCoordinates: paths.gridCoordinates.slice(),
4376
+ indices: paths.indices.slice(),
4377
+ offsets: paths.offsets.slice(),
4378
+ levelIndices: paths.levelIndices.slice(),
4379
+ closed: paths.closed.slice(),
4380
+ levels: paths.levels.slice(),
4381
+ origin: Object.freeze([...paths.origin]),
4382
+ sourceVertexIndices: Uint32Array.from({ length: points.length }, (_, i) => i),
4383
+ maxDeviation: 0,
4384
+ requestedMaxError: options.maxError,
4385
+ distanceTests: candidate.distanceTests,
4386
+ topologyTests,
4387
+ rejected: true
4388
+ };
4389
+ }
4390
+
4391
+ // dist/terrain/isobands.js
4392
+ function createTerrainIsobands(fields, levels, options = {}) {
4393
+ const maxLevels = options.maxLevels ?? 256;
4394
+ if (!Number.isSafeInteger(maxLevels) || maxLevels < 2 || levels.length > maxLevels)
4395
+ throw new Error("Isoband level capacity exceeded");
4396
+ if (levels.length < 2 || levels.some((v, i) => !Number.isFinite(v) || i > 0 && v <= levels[i - 1]))
4397
+ throw new Error("Invalid isoband levels");
4398
+ const maxTriangles = options.maxTriangles ?? 2e6, maxVertices = options.maxVertices ?? 2e6, maxEdges = options.maxEdges ?? 6 * maxTriangles, maxTests = options.maxTests ?? 32 * maxTriangles;
4399
+ if (![maxTriangles, maxVertices, maxEdges, maxTests].every((n) => Number.isSafeInteger(n) && n >= 0))
4400
+ throw new Error("Invalid isoband capacity");
4401
+ const count = fields.reduce((n, f) => n + 2 * (f.width - 1) * (f.height - 1), 0);
4402
+ if (!Number.isSafeInteger(count) || count > maxTriangles)
4403
+ throw new Error("Isoband triangle capacity exceeded");
4404
+ const originals = /* @__PURE__ */ new Map(), vertices = /* @__PURE__ */ new Map();
4405
+ const frame = fields[0];
4406
+ for (const f of fields)
4407
+ if (f.heightReference !== frame.heightReference)
4408
+ throw new Error("Isoband height references differ");
4409
+ let tests = 0, edgeCount = 0;
4410
+ const charge = () => {
4411
+ if (++tests > maxTests)
4412
+ throw new Error("Isoband work budget exceeded");
4413
+ };
4414
+ const rectangles = fields.map((f) => {
4415
+ if (f.registration !== frame.registration || f.columnStep.some((v, i) => v !== frame.columnStep[i]) || f.rowStep.some((v, i) => v !== frame.rowStep[i]))
4416
+ throw new Error("Isoband tiles require a conforming common frame");
4417
+ const dx = f.origin[0] - frame.origin[0], dy = f.origin[1] - frame.origin[1];
4418
+ const determinant = frame.columnStep[0] * frame.rowStep[1] - frame.columnStep[1] * frame.rowStep[0];
4419
+ const x = Math.round((dx * frame.rowStep[1] - dy * frame.rowStep[0]) / determinant), y = Math.round((dy * frame.columnStep[0] - dx * frame.columnStep[1]) / determinant);
4420
+ if (!Number.isSafeInteger(x) || !Number.isSafeInteger(y))
4421
+ throw new Error("Isoband tiles require integral lattice origins");
4422
+ for (let axis = 0; axis < 2; axis++) {
4423
+ const a = x * frame.columnStep[axis], b = y * frame.rowStep[axis];
4424
+ const expected = frame.origin[axis] + a + b;
4425
+ const tolerance = Math.min(16 * Number.EPSILON * Math.max(1, Math.abs(f.origin[axis]), Math.abs(frame.origin[axis]), Math.abs(a), Math.abs(b)), 1e-9 * Math.max(Math.abs(frame.columnStep[axis]), Math.abs(frame.rowStep[axis])));
4426
+ if (!Number.isFinite(expected) || Math.abs(f.origin[axis] - expected) > tolerance)
4427
+ throw new Error("Isoband tiles require integral lattice origins");
4428
+ }
4429
+ return { x, y, right: x + f.width - 1, top: y + f.height - 1 };
4430
+ });
4431
+ const rectangleBoxes = rectangles.map((r) => ({ minX: r.x, minY: r.y, maxX: r.right, maxY: r.top })), rectangleIndex = createTerrainBoxIndex(rectangleBoxes);
4432
+ const rangeIndex = createTerrainBoxIndex(fields.map((f) => {
4433
+ var _a, _b;
4434
+ return {
4435
+ minX: ((_a = f.heightRange) == null ? void 0 : _a[0]) ?? Infinity,
4436
+ maxX: ((_b = f.heightRange) == null ? void 0 : _b[1]) ?? -Infinity,
4437
+ minY: 0,
4438
+ maxY: 0
4439
+ };
4440
+ }));
4441
+ for (let i = 0; i < rectangles.length; i++)
4442
+ for (const j of rectangleIndex(rectangleBoxes[i], charge)) {
4443
+ if (j <= i)
4444
+ continue;
4445
+ charge();
4446
+ const a = rectangles[i], b = rectangles[j];
4447
+ if (a.x < b.right && b.x < a.right && a.y < b.top && b.y < a.top)
4448
+ throw new Error("Overlapping isoband tiles");
4449
+ for (let y = Math.max(a.y, b.y); y <= Math.min(a.top, b.top); y++)
4450
+ for (let x = Math.max(a.x, b.x); x <= Math.min(a.right, b.right); x++) {
4451
+ charge();
4452
+ const u = fields[i].getHeight(x - a.x, y - a.y), v = fields[j].getHeight(x - b.x, y - b.y);
4453
+ if (u !== void 0 && v !== void 0 && u !== v)
4454
+ throw new Error("Isoband shared heights differ");
4455
+ }
4456
+ }
4457
+ const rings = [], bands = [];
4458
+ const register = (v) => {
4459
+ if (!vertices.has(v.key)) {
4460
+ if (vertices.size >= maxVertices)
4461
+ throw new Error("Isoband vertex capacity exceeded");
4462
+ vertices.set(v.key, v);
4463
+ }
4464
+ return vertices.get(v.key);
4465
+ };
4466
+ const clip = (poly, level, above) => {
4467
+ const out = [];
4468
+ for (let i = 0; i < poly.length; i++) {
4469
+ charge();
4470
+ const a = poly[i], b = poly[(i + 1) % poly.length], ia = above ? a.z >= level : a.z <= level, ib = above ? b.z >= level : b.z <= level;
4471
+ if (ia)
4472
+ out.push(a);
4473
+ if (ia !== ib) {
4474
+ if (a.z === level) {
4475
+ out.push(a);
4476
+ continue;
4477
+ }
4478
+ if (b.z === level) {
4479
+ out.push(b);
4480
+ continue;
4481
+ }
4482
+ const support = [.../* @__PURE__ */ new Set([...a.support, ...b.support])].sort();
4483
+ if (support.length !== 2)
4484
+ throw new Error("Invalid isoband intersection support");
4485
+ const u = originals.get(support[0]), v = originals.get(support[1]);
4486
+ const scale = Math.max(Math.abs(u.z), Math.abs(v.z), Math.abs(level), 1);
4487
+ const t = (level / scale - u.z / scale) / (v.z / scale - u.z / scale);
4488
+ const point = {
4489
+ x: u.x * (1 - t) + v.x * t,
4490
+ y: u.y * (1 - t) + v.y * t,
4491
+ z: level,
4492
+ key: `e:${support.join("|")}:${level}`,
4493
+ support
4494
+ };
4495
+ if (![point.x, point.y, t].every(Number.isFinite))
4496
+ throw new Error("Isoband arithmetic overflow");
4497
+ out.push(register(point));
4498
+ }
4499
+ }
4500
+ return out.filter((v, i) => v.key !== out[(i + 1) % out.length].key);
4501
+ };
4502
+ for (let band = 0; band + 1 < levels.length; band++) {
4503
+ const edges = /* @__PURE__ */ new Map();
4504
+ for (const fieldId of rangeIndex({ minX: levels[band], maxX: levels[band + 1], minY: 0, maxY: 0 }, charge))
4505
+ for (let y = 0; y < fields[fieldId].height - 1; y++)
4506
+ for (let x = 0; x < fields[fieldId].width - 1; x++) {
4507
+ const f = fields[fieldId];
4508
+ const nodes = [
4509
+ [x, y],
4510
+ [x + 1, y],
4511
+ [x, y + 1],
4512
+ [x + 1, y + 1]
4513
+ ].map(([c, r]) => {
4514
+ const z = f.getHeight(c, r);
4515
+ if (z === void 0)
4516
+ return void 0;
4517
+ const shift = f.registration === "cell" ? 0.5 : 0;
4518
+ const px = frame.origin[0] + (rectangles[fieldId].x + c + shift) * frame.columnStep[0] + (rectangles[fieldId].y + r + shift) * frame.rowStep[0], py = frame.origin[1] + (rectangles[fieldId].x + c + shift) * frame.columnStep[1] + (rectangles[fieldId].y + r + shift) * frame.rowStep[1];
4519
+ if (![px, py].every(Number.isFinite))
4520
+ throw new Error("Isoband coordinate overflow");
4521
+ const key2 = `v:${px},${py}`, v = { x: px, y: py, z, key: key2, support: [key2] };
4522
+ const old = originals.get(key2);
4523
+ if (old && old.z !== z)
4524
+ throw new Error("Isoband shared heights differ");
4525
+ originals.set(key2, v);
4526
+ return v;
4527
+ });
4528
+ for (const ids of f.diagonal === "00-11" ? [
4529
+ [0, 1, 3],
4530
+ [0, 3, 2]
4531
+ ] : [
4532
+ [0, 1, 2],
4533
+ [1, 3, 2]
4534
+ ]) {
4535
+ charge();
4536
+ if (ids.some((i) => !nodes[i]))
4537
+ continue;
4538
+ let poly = ids.map((i) => nodes[i]);
4539
+ if (poly.every((v) => v.z === levels[band + 1]) && band + 2 < levels.length)
4540
+ continue;
4541
+ if ((poly[1].x - poly[0].x) * (poly[2].y - poly[0].y) - (poly[1].y - poly[0].y) * (poly[2].x - poly[0].x) < 0)
4542
+ poly.reverse();
4543
+ poly = clip(clip(poly, levels[band], true), levels[band + 1], false);
4544
+ if (poly.length < 3)
4545
+ continue;
4546
+ const area2 = poly.reduce((n, a, i) => {
4547
+ const b = poly[(i + 1) % poly.length], o = poly[0];
4548
+ return n + (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y);
4549
+ }, 0);
4550
+ if (!Number.isFinite(area2))
4551
+ throw new Error("Isoband area arithmetic overflow");
4552
+ if (area2 === 0)
4553
+ continue;
4554
+ for (let i = 0; i < poly.length; i++) {
4555
+ const a = register(poly[i]), b = register(poly[(i + 1) % poly.length]);
4556
+ if (++edgeCount > maxEdges)
4557
+ throw new Error("Isoband edge capacity exceeded");
4558
+ const key2 = `${a.key}>${b.key}`, reverse = `${b.key}>${a.key}`;
4559
+ if (edges.has(reverse))
4560
+ edges.delete(reverse);
4561
+ else {
4562
+ if (edges.has(key2))
4563
+ throw new Error("Overlapping isoband tiles");
4564
+ edges.set(key2, { a, b });
4565
+ }
4566
+ }
4567
+ }
4568
+ }
4569
+ const outgoing = /* @__PURE__ */ new Map();
4570
+ for (const [key2, e] of edges) {
4571
+ if (!outgoing.has(e.a.key))
4572
+ outgoing.set(e.a.key, /* @__PURE__ */ new Set());
4573
+ outgoing.get(e.a.key).add(key2);
4574
+ }
4575
+ while (edges.size) {
4576
+ const first = edges.values().next().value, ring = [];
4577
+ let edge = first;
4578
+ for (; ; ) {
4579
+ charge();
4580
+ ring.push(edge.a);
4581
+ edges.delete(`${edge.a.key}>${edge.b.key}`);
4582
+ outgoing.get(edge.a.key).delete(`${edge.a.key}>${edge.b.key}`);
4583
+ if (edge.b.key === first.a.key)
4584
+ break;
4585
+ const choices = [...outgoing.get(edge.b.key) ?? []].map((k) => edges.get(k));
4586
+ if (!choices.length)
4587
+ throw new Error("Open isoband boundary");
4588
+ const angle = (e) => Math.atan2((edge.b.x - edge.a.x) * (e.b.y - e.a.y) - (edge.b.y - edge.a.y) * (e.b.x - e.a.x), (edge.b.x - edge.a.x) * (e.b.x - e.a.x) + (edge.b.y - edge.a.y) * (e.b.y - e.a.y));
4589
+ choices.sort((a, b) => angle(b) - angle(a) || a.b.key.localeCompare(b.b.key));
4590
+ edge = choices[0];
4591
+ }
4592
+ rings.push(ring);
4593
+ bands.push(band);
4594
+ }
4595
+ }
4596
+ const area = (ring) => ring.reduce((n, a, i) => {
4597
+ const b = ring[(i + 1) % ring.length], o = ring[0];
4598
+ return n + (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y);
4599
+ }, 0);
4600
+ const areas = rings.map(area), parents = new Int32Array(rings.length).fill(-1);
4601
+ const ringBoxes = rings.map((r) => r.reduce((b, v) => ({
4602
+ minX: Math.min(b.minX, v.x),
4603
+ minY: Math.min(b.minY, v.y),
4604
+ maxX: Math.max(b.maxX, v.x),
4605
+ maxY: Math.max(b.maxY, v.y)
4606
+ }), { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity }));
4607
+ const ringIndex = createTerrainBoxIndex(ringBoxes);
4608
+ for (let i = 0; i < rings.length; i++)
4609
+ if (areas[i] < 0) {
4610
+ let best = Infinity;
4611
+ const q = rings[i][0];
4612
+ for (const j of ringIndex({ minX: q.x, maxX: q.x, minY: q.y, maxY: q.y }, charge))
4613
+ if (bands[j] === bands[i] && areas[j] > 0) {
4614
+ let inside = false;
4615
+ const ring = rings[j];
4616
+ for (let k = 0, l = ring.length - 1; k < ring.length; l = k++) {
4617
+ charge();
4618
+ const a = ring[k], b = ring[l];
4619
+ if (a.y > q.y !== b.y > q.y && q.x < (b.x - a.x) * (q.y - a.y) / (b.y - a.y) + a.x)
4620
+ inside = !inside;
4621
+ }
4622
+ if (inside && areas[j] < best) {
4623
+ parents[i] = j;
4624
+ best = areas[j];
4625
+ }
4626
+ }
4627
+ if (parents[i] < 0)
4628
+ throw new Error("Uncontained isoband hole");
4629
+ }
4630
+ const used = /* @__PURE__ */ new Map(), positions = [], indices = [], offsets = [0];
4631
+ for (const ring of rings) {
4632
+ for (const v of [...ring, ring[0]]) {
4633
+ if (!used.has(v.key)) {
4634
+ used.set(v.key, used.size);
4635
+ positions.push(v.x, v.y);
4636
+ }
4637
+ indices.push(used.get(v.key));
4638
+ }
4639
+ offsets.push(indices.length);
4640
+ }
4641
+ return {
4642
+ positions: Float64Array.from(positions),
4643
+ indices: Uint32Array.from(indices),
4644
+ offsets: Uint32Array.from(offsets),
4645
+ bandIndices: Uint32Array.from(bands),
4646
+ parents,
4647
+ levels: Float64Array.from(levels),
4648
+ heightReference: (frame == null ? void 0 : frame.heightReference) ?? "unknown"
4649
+ };
4650
+ }
4651
+
4652
+ // dist/terrain/tile-update-data.js
4653
+ function updateTerrainTileData(previous, resident, create, maxSamples = 4e6) {
4654
+ if (!Number.isSafeInteger(maxSamples) || maxSamples < 0)
4655
+ throw new Error("Invalid terrain update sample capacity");
4656
+ let count = 0;
4657
+ const ids = /* @__PURE__ */ new Set();
4658
+ for (const tile of resident) {
4659
+ if (typeof tile.id !== "string" || ids.has(tile.id))
4660
+ throw new Error("Invalid or duplicate terrain update tile");
4661
+ ids.add(tile.id);
4662
+ count += tile.field.width * tile.field.height;
4663
+ if (!Number.isSafeInteger(count) || count > maxSamples)
4664
+ throw new Error("Terrain update sample capacity exceeded");
4665
+ }
4666
+ const cached = new Map(previous == null ? void 0 : previous.map((t) => [t.source.id, t]));
4667
+ return resident.map((source) => {
4668
+ const old = cached.get(source.id);
4669
+ return (old == null ? void 0 : old.source.field) === source.field ? { source, data: old.data } : { source, data: create(source.field) };
4670
+ });
4671
+ }
4672
+
4673
+ // dist/terrain/mesh-update.js
4674
+ function updateTerrainMeshes(previous, resident, options = {}) {
4675
+ return updateTerrainTileData(previous, resident, createTerrainMesh, options.maxSamples);
4676
+ }
4677
+
4678
+ // dist/terrain/bounds-update.js
4679
+ function updateTerrainBounds(previous, resident, options = {}) {
4680
+ return updateTerrainTileData(previous, resident, (f) => new HeightFieldMinMax(f), options.maxSamples);
4681
+ }
4682
+
4683
+ // dist/terrain/gradient-pyramid-update.js
4684
+ function updateTerrainGradientPyramids(previous, gradients, options = {}) {
4685
+ const limit = options.maxSamples ?? 4e6;
4686
+ const count = gradients.tiles.reduce((n, t) => n + t.grid.width * t.grid.height, 0);
4687
+ if (!Number.isSafeInteger(limit) || limit < 0 || !Number.isSafeInteger(count) || count > limit)
4688
+ throw new Error("Gradient pyramid update sample capacity exceeded");
4689
+ const cached = new Map(previous == null ? void 0 : previous.map((t) => [t.source.grid, t.data]));
4690
+ return gradients.tiles.map((source) => ({
4691
+ source,
4692
+ data: cached.get(source.grid) ?? createTerrainGradientPyramid(source.grid, { maxSamples: limit })
4693
+ }));
4694
+ }
4695
+
4696
+ // dist/terrain/dirty-regions.js
4697
+ function validateTerrainDirtyWindows(windows, width, height, maxWindows = 1e5) {
4698
+ if (windows.length > maxWindows)
4699
+ throw new Error("Terrain dirty window capacity exceeded");
4700
+ for (const w of windows)
4701
+ if (![w.minColumn, w.minRow, w.maxColumn, w.maxRow].every(Number.isSafeInteger) || w.minColumn < 0 || w.minRow < 0 || w.maxColumn >= width || w.maxRow >= height || w.minColumn > w.maxColumn || w.minRow > w.maxRow)
4702
+ throw new Error("Invalid terrain dirty sample window");
4703
+ }
4704
+ function sameTerrainFrame(a, b) {
4705
+ return a.width === b.width && a.height === b.height && a.registration === b.registration && a.diagonal === b.diagonal && a.heightReference === b.heightReference && a.origin.every((v, i) => v === b.origin[i]) && a.columnStep.every((v, i) => v === b.columnStep[i]) && a.rowStep.every((v, i) => v === b.rowStep[i]);
4706
+ }
4707
+ function terrainDirtyIndices(windows, width, height, expand, charge) {
4708
+ const ids = /* @__PURE__ */ new Set();
4709
+ for (const w of windows)
4710
+ for (let y = Math.max(0, w.minRow - expand); y <= Math.min(height - 1, w.maxRow + expand); y++)
4711
+ for (let x = Math.max(0, w.minColumn - expand); x <= Math.min(width - 1, w.maxColumn + expand); x++) {
4712
+ charge();
4713
+ ids.add(y * width + x);
4714
+ }
4715
+ return ids;
4716
+ }
4717
+
4718
+ // dist/terrain/mesh-regions-data.js
4719
+ function updateMeshRegions(previous, field, dirty, options, configuration, create) {
4720
+ const cells = options.cellsPerRegion ?? 32, limit = options.maxSamples ?? 4e6, budget = options.maxTests ?? 1e7;
4721
+ if (![cells, limit, budget].every(Number.isSafeInteger) || cells < 1 || limit < 0 || budget < 0)
4722
+ throw new Error("Invalid terrain mesh region capacity");
4723
+ validateTerrainDirtyWindows(dirty, field.width, field.height);
4724
+ let count = 0, tests = 0;
4725
+ const regions = [], rebuilt = [];
4726
+ const reusable = previous && sameTerrainFrame(previous.field, field) && previous.cellsPerRegion === cells && previous.configuration === configuration;
4727
+ const cache = new Map(previous == null ? void 0 : previous.regions.map((r) => [`${r.column},${r.row}`, r]));
4728
+ for (let row = 0; row < field.height - 1; row += cells)
4729
+ for (let column = 0; column < field.width - 1; column += cells) {
4730
+ const width = Math.min(cells, field.width - 1 - column) + 1, height = Math.min(cells, field.height - 1 - row) + 1;
4731
+ count += width * height;
4732
+ if (!Number.isSafeInteger(count) || count > limit)
4733
+ throw new Error("Terrain mesh region sample capacity exceeded");
4734
+ let affected = !reusable;
4735
+ for (const w of reusable ? dirty : []) {
4736
+ if (++tests > budget)
4737
+ throw new Error("Terrain mesh region work budget exceeded");
4738
+ if (w.minColumn <= column + width - 1 && w.maxColumn >= column && w.minRow <= row + height - 1 && w.maxRow >= row)
4739
+ affected = true;
4740
+ }
4741
+ const old = cache.get(`${column},${row}`);
4742
+ if (!affected && old) {
4743
+ regions.push(old);
4744
+ continue;
4745
+ }
4746
+ const heights = Float64Array.from({ length: width * height }, (_, i) => field.getHeight(column + i % width, row + Math.floor(i / width)) ?? NaN);
4747
+ const source = new HeightField({
4748
+ width,
4749
+ height,
4750
+ heights,
4751
+ origin: [
4752
+ column * field.columnStep[0] + row * field.rowStep[0],
4753
+ column * field.columnStep[1] + row * field.rowStep[1]
4754
+ ],
4755
+ columnStep: field.columnStep,
4756
+ rowStep: field.rowStep,
4757
+ registration: field.registration,
4758
+ diagonal: field.diagonal,
4759
+ heightReference: field.heightReference
4760
+ });
4761
+ rebuilt.push(regions.length);
4762
+ let data = create(source);
4763
+ if (data) {
4764
+ const mesh = data;
4765
+ const positions = mesh.positions.map((value, i) => {
4766
+ const axis = i % 3;
4767
+ if (axis === 2)
4768
+ return value;
4769
+ const vertex = Math.floor(i / 3), shift = field.registration === "cell" ? 0.5 : 0;
4770
+ const c = column + mesh.gridCoordinates[2 * vertex] + shift, r = row + mesh.gridCoordinates[2 * vertex + 1] + shift;
4771
+ const coordinate = c * field.columnStep[axis] + r * field.rowStep[axis];
4772
+ if (!Number.isFinite(coordinate))
4773
+ throw new Error("Terrain region coordinate overflow");
4774
+ return coordinate;
4775
+ });
4776
+ data = { ...mesh, origin: [0, 0, 0], positions };
4777
+ }
4778
+ regions.push({ column, row, field: source, data });
4779
+ }
4780
+ return {
4781
+ field,
4782
+ origin: [field.origin[0], field.origin[1], 0],
4783
+ cellsPerRegion: cells,
4784
+ configuration,
4785
+ regions,
4786
+ rebuilt: Uint32Array.from(rebuilt)
4787
+ };
4788
+ }
4789
+
4790
+ // dist/terrain/mesh-regions.js
4791
+ function updateTerrainMeshRegions(previous, field, dirty, options = {}) {
4792
+ return updateMeshRegions(previous, field, dirty, options, "regular", createTerrainMesh);
4793
+ }
4794
+
4795
+ // dist/terrain/martini-regions.js
4796
+ function updateTerrainMartiniMeshRegions(previous, field, dirty, options) {
4797
+ const cells = options.cellsPerRegion ?? 32;
4798
+ if (!Number.isSafeInteger(cells) || cells < 1 || cells > 32768 || (cells & cells - 1) !== 0 || (field.width - 1) % cells || (field.height - 1) % cells || !Number.isFinite(options.maxError) || options.maxError < 0)
4799
+ throw new Error("Invalid MARTINI region dimensions or error");
4800
+ return updateMeshRegions(previous, field, dirty, options, `martini:${options.maxError}`, (f) => f.validCount !== f.width * f.height ? null : createMartiniTerrainMesh(f, {
4801
+ maxError: options.maxError,
4802
+ fullEdges: ["minColumn", "maxColumn", "minRow", "maxRow"]
4803
+ }));
4804
+ }
4805
+
4806
+ // dist/terrain/delatin-regions.js
4807
+ function updateTerrainDelatinMeshRegions(previous, field, dirty, options) {
4808
+ if (!Number.isFinite(options.maxError) || options.maxError < 0)
4809
+ throw new Error("Invalid Delatin region error");
4810
+ return updateMeshRegions(previous, field, dirty, options, `delatin:${options.maxError}`, (f) => f.validCount !== f.width * f.height ? null : createDelatinTerrainMesh(f, { maxError: options.maxError }));
4811
+ }
4812
+
4813
+ // dist/terrain/bounds-regions.js
4814
+ function updateTerrainBoundsRegions(previous, field, dirty, options = {}) {
4815
+ const limit = options.maxSamples ?? 4e6, budget = options.maxTests ?? 1e7;
4816
+ if (![limit, budget].every(Number.isSafeInteger) || limit < 0 || budget < 0 || field.width * field.height > limit)
4817
+ throw new Error("Invalid bounds region capacity");
4818
+ validateTerrainDirtyWindows(dirty, field.width, field.height);
4819
+ if (!previous || !sameTerrainFrame(previous.field, field)) {
4820
+ const bounds = new HeightFieldMinMax(field), levels2 = Array.from({ length: bounds.levelCount }, (_, i) => bounds.copyLevel(i));
4821
+ return { field, levels: levels2, updatedCounts: Uint32Array.from(levels2, (l) => l.width * l.height) };
4822
+ }
4823
+ let tests = 0;
4824
+ const charge = () => {
4825
+ if (++tests > budget)
4826
+ throw new Error("Bounds region work budget exceeded");
4827
+ };
4828
+ let ids = terrainDirtyIndices(dirty, field.width - 1, field.height - 1, 1, charge);
4829
+ const counts = [], levels = previous.levels.slice();
4830
+ for (let l = 0; l < levels.length; l++) {
4831
+ counts.push(ids.size);
4832
+ if (!ids.size)
4833
+ continue;
4834
+ const old = levels[l], next = {
4835
+ ...old,
4836
+ minimums: old.minimums.slice(),
4837
+ maximums: old.maximums.slice(),
4838
+ populatedCellCounts: old.populatedCellCounts.slice(),
4839
+ completeCellCounts: old.completeCellCounts.slice()
4840
+ };
4841
+ const parents = /* @__PURE__ */ new Set();
4842
+ for (const id of ids) {
4843
+ charge();
4844
+ const x = id % next.width, y = Math.floor(id / next.width);
4845
+ let min = Infinity, max = -Infinity, populated = 0, complete = 0;
4846
+ if (l === 0) {
4847
+ let valid = 0;
4848
+ for (let dy = 0; dy < 2; dy++)
4849
+ for (let dx = 0; dx < 2; dx++) {
4850
+ const h = field.getHeight(x + dx, y + dy);
4851
+ if (h !== void 0) {
4852
+ valid++;
4853
+ min = Math.min(min, h);
4854
+ max = Math.max(max, h);
4855
+ }
4856
+ }
4857
+ populated = valid ? 1 : 0;
4858
+ complete = valid === 4 ? 1 : 0;
4859
+ } else {
4860
+ const child = levels[l - 1];
4861
+ for (let dy = 0; dy < 2; dy++)
4862
+ for (let dx = 0; dx < 2; dx++) {
4863
+ const cx = x * 2 + dx, cy = y * 2 + dy;
4864
+ if (cx >= child.width || cy >= child.height)
4865
+ continue;
4866
+ const i = cy * child.width + cx;
4867
+ if (child.populatedCellCounts[i]) {
4868
+ min = Math.min(min, child.minimums[i]);
4869
+ max = Math.max(max, child.maximums[i]);
4870
+ }
4871
+ populated += child.populatedCellCounts[i];
4872
+ complete += child.completeCellCounts[i];
4873
+ }
4874
+ }
4875
+ next.minimums[id] = populated ? min : 0;
4876
+ next.maximums[id] = populated ? max : 0;
4877
+ next.populatedCellCounts[id] = populated;
4878
+ next.completeCellCounts[id] = complete;
4879
+ parents.add(Math.floor(y / 2) * Math.ceil(next.width / 2) + Math.floor(x / 2));
4880
+ }
4881
+ levels[l] = next;
4882
+ ids = parents;
4883
+ }
4884
+ return { field, levels, updatedCounts: Uint32Array.from(counts) };
4885
+ }
4886
+
4887
+ // dist/terrain/gradient-pyramid-regions.js
4888
+ function updateTerrainGradientPyramidRegions(previous, grid, dirty, options = {}) {
4889
+ const limit = options.maxSamples ?? 4e6, budget = options.maxTests ?? 1e7;
4890
+ if (![limit, budget].every(Number.isSafeInteger) || limit < 0 || budget < 0 || !Number.isSafeInteger(grid.width) || grid.width < 1 || !Number.isSafeInteger(grid.height) || grid.height < 1 || grid.width * grid.height > limit)
4891
+ throw new Error("Invalid gradient region capacity");
4892
+ if (grid.method !== "horn" && grid.method !== "zevenbergen-thorne" || grid.registration !== "vertex" && grid.registration !== "cell" || typeof grid.heightReference !== "string" || ![grid.origin, grid.columnStep, grid.rowStep].every((v) => v.length === 2 && v.every(Number.isFinite)))
4893
+ throw new Error("Invalid gradient region metadata");
4894
+ validateTerrainDirtyWindows(dirty, grid.width, grid.height);
4895
+ const old = previous == null ? void 0 : previous.source;
4896
+ if (!old || old.width !== grid.width || old.height !== grid.height || old.method !== grid.method || old.registration !== grid.registration || old.heightReference !== grid.heightReference || !old.origin.every((v, i) => v === grid.origin[i]) || !old.columnStep.every((v, i) => v === grid.columnStep[i]) || !old.rowStep.every((v, i) => v === grid.rowStep[i])) {
4897
+ const pyramid = createTerrainGradientPyramid(grid, { maxSamples: limit });
4898
+ return {
4899
+ source: grid,
4900
+ pyramid,
4901
+ updatedCounts: Uint32Array.from(pyramid.levels, (l) => l.width * l.height)
4902
+ };
4903
+ }
4904
+ if (!(grid.gradients instanceof Float64Array) || grid.gradients.length !== 2 * grid.width * grid.height || !(grid.statuses instanceof Uint8Array) || grid.statuses.length !== grid.width * grid.height)
4905
+ throw new Error("Invalid gradient region buffers");
4906
+ const levels = previous.pyramid.levels.slice();
4907
+ let tests = 0;
4908
+ const charge = () => {
4909
+ if (++tests > budget)
4910
+ throw new Error("Gradient region work budget exceeded");
4911
+ };
4912
+ let ids = terrainDirtyIndices(dirty, grid.width, grid.height, 0, charge);
4913
+ const counts = [];
4914
+ for (let l = 0; l < levels.length; l++) {
4915
+ counts.push(ids.size);
4916
+ if (!ids.size)
4917
+ continue;
4918
+ const oldLevel = levels[l], next = {
4919
+ ...oldLevel,
4920
+ gradients: oldLevel.gradients.slice(),
4921
+ validCounts: oldLevel.validCounts.slice(),
4922
+ sampleCounts: oldLevel.sampleCounts
4923
+ };
4924
+ const parents = /* @__PURE__ */ new Set();
4925
+ for (const id of ids) {
4926
+ charge();
4927
+ const x = id % next.width, y = Math.floor(id / next.width);
4928
+ next.validCounts[id] = 0;
4929
+ next.gradients[2 * id] = next.gradients[2 * id + 1] = 0;
4930
+ if (l === 0) {
4931
+ if (grid.statuses[id] > 6)
4932
+ throw new Error("Invalid terrain gradient status");
4933
+ if (grid.statuses[id] === 0) {
4934
+ if (!Number.isFinite(grid.gradients[2 * id]) || !Number.isFinite(grid.gradients[2 * id + 1]))
4935
+ throw new Error("Invalid terrain gradient value");
4936
+ next.validCounts[id] = 1;
4937
+ next.gradients[2 * id] = grid.gradients[2 * id];
4938
+ next.gradients[2 * id + 1] = grid.gradients[2 * id + 1];
4939
+ }
4940
+ } else {
4941
+ const child = levels[l - 1];
4942
+ for (let dy = 0; dy < 2; dy++)
4943
+ for (let dx = 0; dx < 2; dx++) {
4944
+ const cx = x * 2 + dx, cy = y * 2 + dy;
4945
+ if (cx >= child.width || cy >= child.height)
4946
+ continue;
4947
+ const i = cy * child.width + cx, n = child.validCounts[i], count = next.validCounts[id];
4948
+ if (n) {
4949
+ const total = count + n;
4950
+ for (let axis = 0; axis < 2; axis++) {
4951
+ const a = next.gradients[2 * id + axis], b = child.gradients[2 * i + axis];
4952
+ next.gradients[2 * id + axis] = count ? a * (count / total) + b * (n / total) : b;
4953
+ }
4954
+ next.validCounts[id] = total;
4955
+ }
4956
+ }
4957
+ }
4958
+ parents.add(Math.floor(y / 2) * Math.ceil(next.width / 2) + Math.floor(x / 2));
4959
+ }
4960
+ levels[l] = next;
4961
+ ids = parents;
4962
+ }
4963
+ return {
4964
+ source: grid,
4965
+ pyramid: { ...previous.pyramid, levels },
4966
+ updatedCounts: Uint32Array.from(counts)
4967
+ };
4968
+ }
4969
+
4970
+ // dist/terrain/persistent-hierarchy-data.js
4971
+ function getTerrainHierarchyNode(level, column, row) {
4972
+ if (!Number.isSafeInteger(level.width) || level.width < 1 || !Number.isSafeInteger(level.height) || level.height < 1 || !Number.isSafeInteger(level.nodesPerBlock) || level.nodesPerBlock < 1 || !Array.isArray(level.blocks))
4973
+ throw new Error("Invalid persistent hierarchy level");
4974
+ if (!Number.isSafeInteger(column) || !Number.isSafeInteger(row) || column < 0 || row < 0 || column >= level.width || row >= level.height)
4975
+ throw new Error("Invalid persistent hierarchy node");
4976
+ const id = row * level.width + column, block = level.blocks[Math.floor(id / level.nodesPerBlock)], i = block ? 2 * (id - block.offset) : -1;
4977
+ const expectedOffset = Math.floor(id / level.nodesPerBlock) * level.nodesPerBlock;
4978
+ if (!block || block.offset !== expectedOffset || block.count !== Math.min(level.nodesPerBlock, level.width * level.height - expectedOffset) || !(block.values instanceof Float64Array) || !(block.counts instanceof Uint32Array) || block.values.length !== 2 * block.count || block.counts.length !== 2 * block.count)
4979
+ throw new Error("Invalid persistent hierarchy block");
4980
+ return {
4981
+ values: [block.values[i], block.values[i + 1]],
4982
+ counts: [block.counts[i], block.counts[i + 1]]
4983
+ };
4984
+ }
4985
+ function packTerrainHierarchyLevel(width, height, blockSize, values, counts, nodesPerBlock) {
4986
+ if (values.length !== 2 * width * height || counts.length !== values.length || !values.every(Number.isFinite))
4987
+ throw new Error("Invalid persistent hierarchy buffers");
4988
+ const blocks = [];
4989
+ for (let offset = 0; offset < width * height; offset += nodesPerBlock) {
4990
+ const count = Math.min(nodesPerBlock, width * height - offset);
4991
+ blocks.push({
4992
+ offset,
4993
+ count,
4994
+ values: values.slice(2 * offset, 2 * (offset + count)),
4995
+ counts: counts.slice(2 * offset, 2 * (offset + count))
4996
+ });
4997
+ }
4998
+ return { width, height, blockSize, nodesPerBlock, blocks };
4999
+ }
5000
+ function persistentHierarchyOptions(options, count) {
5001
+ const nodesPerBlock = options.nodesPerBlock ?? 256, maxSamples = options.maxSamples ?? 4e6, maxTests = options.maxTests ?? 1e7;
5002
+ if (![nodesPerBlock, maxSamples, maxTests, count].every(Number.isSafeInteger) || nodesPerBlock < 1 || maxSamples < 0 || maxTests < 0 || count < 1 || count > maxSamples)
5003
+ throw new Error("Invalid persistent terrain hierarchy capacity");
5004
+ let tests = 0;
5005
+ return {
5006
+ nodesPerBlock,
5007
+ maxSamples,
5008
+ charge: () => {
5009
+ if (++tests > maxTests)
5010
+ throw new Error("Persistent hierarchy work budget exceeded");
5011
+ }
5012
+ };
5013
+ }
5014
+ function updatePersistentHierarchy(previous, ids, mode, base, charge) {
5015
+ const levels = previous.slice(), updatedNodes = [];
5016
+ let copiedBlocks = 0, copiedBytes = 0;
5017
+ for (let l = 0; l < levels.length; l++) {
5018
+ updatedNodes.push(ids.size);
5019
+ if (!ids.size)
5020
+ continue;
5021
+ const old = levels[l], blocks = old.blocks.slice(), cloned = /* @__PURE__ */ new Set(), parents = /* @__PURE__ */ new Set();
5022
+ const node = (level, x, y) => getTerrainHierarchyNode(level, x, y);
5023
+ for (const id of ids) {
5024
+ charge();
5025
+ const x = id % old.width, y = Math.floor(id / old.width);
5026
+ let value;
5027
+ if (l === 0)
5028
+ value = base(x, y);
5029
+ else {
5030
+ const child = levels[l - 1];
5031
+ let a = mode === "bounds" ? Infinity : 0, b = mode === "bounds" ? -Infinity : 0, c = 0, d = 0;
5032
+ for (let dy = 0; dy < 2; dy++)
5033
+ for (let dx = 0; dx < 2; dx++) {
5034
+ const cx = x * 2 + dx, cy = y * 2 + dy;
5035
+ if (cx >= child.width || cy >= child.height)
5036
+ continue;
5037
+ const v = node(child, cx, cy), n = v.counts[0];
5038
+ d += v.counts[1];
5039
+ if (n) {
5040
+ if (mode === "bounds") {
5041
+ a = Math.min(a, v.values[0]);
5042
+ b = Math.max(b, v.values[1]);
5043
+ } else {
5044
+ const total = c + n;
5045
+ a = c ? a * (c / total) + v.values[0] * (n / total) : v.values[0];
5046
+ b = c ? b * (c / total) + v.values[1] * (n / total) : v.values[1];
5047
+ }
5048
+ c += n;
5049
+ }
5050
+ }
5051
+ if (c && (!Number.isFinite(a) || !Number.isFinite(b)))
5052
+ throw new Error("Persistent hierarchy arithmetic overflow");
5053
+ value = { values: c ? [a, b] : [0, 0], counts: [c, d] };
5054
+ }
5055
+ const blockId = Math.floor(id / old.nodesPerBlock);
5056
+ if (!cloned.has(blockId)) {
5057
+ const source = blocks[blockId];
5058
+ blocks[blockId] = { ...source, values: source.values.slice(), counts: source.counts.slice() };
5059
+ cloned.add(blockId);
5060
+ copiedBlocks++;
5061
+ copiedBytes += blocks[blockId].values.byteLength + blocks[blockId].counts.byteLength;
5062
+ }
5063
+ const block = blocks[blockId], i = 2 * (id - block.offset);
5064
+ block.values[i] = value.values[0];
5065
+ block.values[i + 1] = value.values[1];
5066
+ block.counts[i] = value.counts[0];
5067
+ block.counts[i + 1] = value.counts[1];
5068
+ parents.add(Math.floor(y / 2) * Math.ceil(old.width / 2) + Math.floor(x / 2));
5069
+ }
5070
+ levels[l] = { ...old, blocks };
5071
+ ids = parents;
5072
+ }
5073
+ return { levels, stats: { copiedBlocks, copiedBytes, updatedNodes: Uint32Array.from(updatedNodes) } };
5074
+ }
5075
+
5076
+ // dist/terrain/persistent-bounds.js
5077
+ function updateTerrainPersistentBounds(previous, field, dirty, options = {}) {
5078
+ const { nodesPerBlock, charge } = persistentHierarchyOptions(options, field.width * field.height);
5079
+ validateTerrainDirtyWindows(dirty, field.width, field.height);
5080
+ if (!previous || !sameTerrainFrame(previous.field, field) || previous.levels[0].nodesPerBlock !== nodesPerBlock) {
5081
+ const bounds = new HeightFieldMinMax(field), levels = Array.from({ length: bounds.levelCount }, (_, i) => {
5082
+ const l = bounds.copyLevel(i), values = new Float64Array(2 * l.width * l.height), counts = new Uint32Array(values.length);
5083
+ for (let j = 0; j < l.width * l.height; j++) {
5084
+ values[2 * j] = l.minimums[j];
5085
+ values[2 * j + 1] = l.maximums[j];
5086
+ counts[2 * j] = l.populatedCellCounts[j];
5087
+ counts[2 * j + 1] = l.completeCellCounts[j];
5088
+ }
5089
+ return packTerrainHierarchyLevel(l.width, l.height, l.blockSize, values, counts, nodesPerBlock);
5090
+ });
5091
+ return {
5092
+ field,
5093
+ levels,
5094
+ stats: {
5095
+ copiedBlocks: levels.reduce((n, l) => n + l.blocks.length, 0),
5096
+ copiedBytes: levels.reduce((n, l) => n + l.blocks.reduce((s, b) => s + b.values.byteLength + b.counts.byteLength, 0), 0),
5097
+ updatedNodes: Uint32Array.from(levels, (l) => l.width * l.height)
5098
+ }
5099
+ };
5100
+ }
5101
+ const ids = terrainDirtyIndices(dirty, field.width - 1, field.height - 1, 1, charge);
5102
+ const result = updatePersistentHierarchy(previous.levels, ids, "bounds", (x, y) => {
5103
+ let min = Infinity, max = -Infinity, n = 0;
5104
+ for (let dy = 0; dy < 2; dy++)
5105
+ for (let dx = 0; dx < 2; dx++) {
5106
+ const z = field.getHeight(x + dx, y + dy);
5107
+ if (z !== void 0) {
5108
+ min = Math.min(min, z);
5109
+ max = Math.max(max, z);
5110
+ n++;
5111
+ }
5112
+ }
5113
+ return { values: n ? [min, max] : [0, 0], counts: [n ? 1 : 0, n === 4 ? 1 : 0] };
5114
+ }, charge);
5115
+ return { field, ...result };
5116
+ }
5117
+
5118
+ // dist/terrain/persistent-gradients.js
5119
+ function updateTerrainPersistentGradients(previous, grid, dirty, options = {}) {
5120
+ const { nodesPerBlock, maxSamples, charge } = persistentHierarchyOptions(options, grid.width * grid.height);
5121
+ if (!Number.isSafeInteger(grid.width) || grid.width < 1 || !Number.isSafeInteger(grid.height) || grid.height < 1 || !(grid.gradients instanceof Float64Array) || grid.gradients.length !== 2 * grid.width * grid.height || !(grid.statuses instanceof Uint8Array) || grid.statuses.length !== grid.width * grid.height || grid.method !== "horn" && grid.method !== "zevenbergen-thorne" || grid.registration !== "vertex" && grid.registration !== "cell" || typeof grid.heightReference !== "string" || ![grid.origin, grid.columnStep, grid.rowStep].every((v) => v.length === 2 && v.every(Number.isFinite)))
5122
+ throw new Error("Invalid persistent gradient grid");
5123
+ validateTerrainDirtyWindows(dirty, grid.width, grid.height);
5124
+ const old = previous == null ? void 0 : previous.source;
5125
+ if (!old || old.width !== grid.width || old.height !== grid.height || old.method !== grid.method || old.registration !== grid.registration || old.heightReference !== grid.heightReference || !old.origin.every((v, i) => v === grid.origin[i]) || !old.columnStep.every((v, i) => v === grid.columnStep[i]) || !old.rowStep.every((v, i) => v === grid.rowStep[i]) || previous.levels[0].nodesPerBlock !== nodesPerBlock) {
5126
+ const pyramid = createTerrainGradientPyramid(grid, { maxSamples }), levels = pyramid.levels.map((l) => {
5127
+ const counts = new Uint32Array(2 * l.width * l.height);
5128
+ for (let i = 0; i < l.width * l.height; i++) {
5129
+ counts[2 * i] = l.validCounts[i];
5130
+ counts[2 * i + 1] = l.sampleCounts[i];
5131
+ }
5132
+ return packTerrainHierarchyLevel(l.width, l.height, l.blockSize, l.gradients, counts, nodesPerBlock);
5133
+ });
5134
+ return {
5135
+ source: grid,
5136
+ levels,
5137
+ stats: {
5138
+ copiedBlocks: levels.reduce((n, l) => n + l.blocks.length, 0),
5139
+ copiedBytes: levels.reduce((n, l) => n + l.blocks.reduce((s, b) => s + b.values.byteLength + b.counts.byteLength, 0), 0),
5140
+ updatedNodes: Uint32Array.from(levels, (l) => l.width * l.height)
5141
+ }
5142
+ };
5143
+ }
5144
+ const ids = terrainDirtyIndices(dirty, grid.width, grid.height, 0, charge);
5145
+ const result = updatePersistentHierarchy(previous.levels, ids, "gradient", (x, y) => {
5146
+ const i = y * grid.width + x, s = grid.statuses[i];
5147
+ if (s > 6)
5148
+ throw new Error("Invalid terrain gradient status");
5149
+ if (s === 0 && (!Number.isFinite(grid.gradients[2 * i]) || !Number.isFinite(grid.gradients[2 * i + 1])))
5150
+ throw new Error("Invalid terrain gradient value");
5151
+ return {
5152
+ values: s === 0 ? [grid.gradients[2 * i], grid.gradients[2 * i + 1]] : [0, 0],
5153
+ counts: [s === 0 ? 1 : 0, 1]
5154
+ };
5155
+ }, charge);
5156
+ return { source: grid, ...result };
5157
+ }
5158
+
5159
+ // dist/terrain/lod-morph.js
5160
+ var TerrainMorphStatus = {
5161
+ VALID: 0,
5162
+ FINE_NO_DATA: 1,
5163
+ COARSE_NO_DATA: 2,
5164
+ OUTSIDE_COARSE: 3
5165
+ };
5166
+ function createTerrainLodMorph(fine, coarse, options) {
5167
+ const { ratio } = options, offset = options.coarseOrigin ?? [0, 0], limit = options.maxSamples ?? 4e6, count = fine.width * fine.height;
5168
+ if (!Number.isSafeInteger(ratio) || ratio < 2 || 2 ** Math.round(Math.log2(ratio)) !== ratio || offset.length !== 2 || !offset.every(Number.isSafeInteger) || !Number.isSafeInteger(limit) || limit < 0 || count > limit)
5169
+ throw new Error("Invalid terrain LOD ratio, origin or sample capacity");
5170
+ if (fine.registration !== "vertex" || coarse.registration !== "vertex" || fine.diagonal !== coarse.diagonal || fine.heightReference !== coarse.heightReference)
5171
+ throw new Error("Incompatible terrain LOD registration, diagonal or height reference");
5172
+ for (let axis = 0; axis < 2; axis++) {
5173
+ if (fine.columnStep[axis] * ratio !== coarse.columnStep[axis] || fine.rowStep[axis] * ratio !== coarse.rowStep[axis])
5174
+ throw new Error("Terrain LOD steps differ");
5175
+ const a = offset[0] * fine.columnStep[axis], b = offset[1] * fine.rowStep[axis], expected = fine.origin[axis] + a + b;
5176
+ const tolerance = Math.min(16 * Number.EPSILON * Math.max(1, Math.abs(fine.origin[axis]), Math.abs(coarse.origin[axis]), Math.abs(a), Math.abs(b)), 1e-9 * Math.max(Math.abs(fine.columnStep[axis]), Math.abs(fine.rowStep[axis])));
5177
+ if (!Number.isFinite(expected) || Math.abs(coarse.origin[axis] - expected) > tolerance)
5178
+ throw new Error("Terrain LOD origins differ");
5179
+ }
5180
+ const fineHeights = new Float64Array(count), coarseHeights = new Float64Array(count), deltas = new Float64Array(count), statuses = new Uint8Array(count), coarseCoordinates = new Float64Array(2 * count);
5181
+ let maxNodalDisplacement = 0;
5182
+ for (let y = 0; y < fine.height; y++)
5183
+ for (let x = 0; x < fine.width; x++) {
5184
+ const i = y * fine.width + x, u = (x - offset[0]) / ratio, v = (y - offset[1]) / ratio;
5185
+ if (!Number.isSafeInteger(x - offset[0]) || !Number.isSafeInteger(y - offset[1]))
5186
+ throw new Error("Terrain LOD lattice overflow");
5187
+ coarseCoordinates[2 * i] = u;
5188
+ coarseCoordinates[2 * i + 1] = v;
5189
+ const source = fine.getHeight(x, y);
5190
+ if (source === void 0) {
5191
+ statuses[i] = TerrainMorphStatus.FINE_NO_DATA;
5192
+ continue;
5193
+ }
5194
+ fineHeights[i] = source;
5195
+ if (u < 0 || v < 0 || u > coarse.width - 1 || v > coarse.height - 1) {
5196
+ statuses[i] = TerrainMorphStatus.OUTSIDE_COARSE;
5197
+ continue;
5198
+ }
5199
+ const target = sampleTerrainTriangleHeight(coarse, u, v);
5200
+ if (target === void 0) {
5201
+ statuses[i] = TerrainMorphStatus.COARSE_NO_DATA;
5202
+ continue;
5203
+ }
5204
+ const delta = target - source;
5205
+ if (!Number.isFinite(delta))
5206
+ throw new Error("Terrain LOD displacement overflow");
5207
+ coarseHeights[i] = target;
5208
+ deltas[i] = delta;
5209
+ maxNodalDisplacement = Math.max(maxNodalDisplacement, Math.abs(delta));
5210
+ }
5211
+ return {
5212
+ width: fine.width,
5213
+ height: fine.height,
5214
+ origin: [...fine.origin],
5215
+ columnStep: [...fine.columnStep],
5216
+ rowStep: [...fine.rowStep],
5217
+ heightReference: fine.heightReference,
5218
+ fineHeights,
5219
+ coarseHeights,
5220
+ deltas,
5221
+ statuses,
5222
+ coarseCoordinates,
5223
+ maxNodalDisplacement,
5224
+ ratio,
5225
+ coarseOrigin: [...offset],
5226
+ diagonal: fine.diagonal
5227
+ };
5228
+ }
5229
+
5230
+ // dist/terrain/lod-morph-evaluate.js
5231
+ function evaluateTerrainLodMorph(morph, factor) {
5232
+ const count = morph.width * morph.height;
5233
+ if (!Number.isFinite(factor) || factor < 0 || factor > 1 || !Number.isSafeInteger(count) || count < 1 || morph.fineHeights.length !== count || morph.coarseHeights.length !== count || morph.statuses.length !== count)
5234
+ throw new Error("Invalid terrain morph evaluation");
5235
+ const heights = new Float64Array(count), validity = new Uint8Array(count);
5236
+ for (let i = 0; i < count; i++) {
5237
+ if (morph.statuses[i] > 3)
5238
+ throw new Error("Invalid terrain morph status");
5239
+ if (morph.statuses[i] !== 0)
5240
+ continue;
5241
+ const a = morph.fineHeights[i], b = morph.coarseHeights[i];
5242
+ if (!Number.isFinite(a) || !Number.isFinite(b))
5243
+ throw new Error("Invalid terrain morph height");
5244
+ heights[i] = factor === 0 ? a : factor === 1 ? b : a * (1 - factor) + b * factor;
5245
+ if (!Number.isFinite(heights[i]))
5246
+ throw new Error("Terrain morph arithmetic overflow");
5247
+ validity[i] = 1;
5248
+ }
5249
+ return { heights, validity };
5250
+ }
3717
5251
  //# sourceMappingURL=index.cjs.map