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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (360) hide show
  1. package/README.md +3 -3
  2. package/dist/crs/index.cjs +54 -0
  3. package/dist/crs/index.cjs.map +2 -2
  4. package/dist/crs/index.d.ts +1 -0
  5. package/dist/crs/index.d.ts.map +1 -1
  6. package/dist/crs/index.js +1 -0
  7. package/dist/crs/index.js.map +1 -1
  8. package/dist/crs/spatial-reference-metadata.d.ts +20 -0
  9. package/dist/crs/spatial-reference-metadata.d.ts.map +1 -0
  10. package/dist/crs/spatial-reference-metadata.js +86 -0
  11. package/dist/crs/spatial-reference-metadata.js.map +1 -0
  12. package/dist/expressions.d.ts +1 -1
  13. package/dist/expressions.d.ts.map +1 -1
  14. package/dist/index.cjs +1738 -316
  15. package/dist/index.cjs.map +3 -3
  16. package/dist/index.d.ts +14 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +12 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/projection/experimental/core.cjs.map +1 -1
  21. package/dist/projection/experimental/crs/spatial-reference.d.ts.map +1 -1
  22. package/dist/projection/experimental/crs/spatial-reference.js.map +1 -1
  23. package/dist/projection/experimental/crs/types.d.ts.map +1 -1
  24. package/dist/projection/experimental/lazy-projections/aea.cjs +4 -1
  25. package/dist/projection/experimental/lazy-projections/aea.cjs.map +1 -1
  26. package/dist/projection/experimental/lazy-projections/aea.d.ts.map +1 -1
  27. package/dist/projection/experimental/lazy-projections/aea.js +4 -1
  28. package/dist/projection/experimental/lazy-projections/aea.js.map +1 -1
  29. package/dist/projection/experimental/lazy-projections/bonne.cjs +4 -1
  30. package/dist/projection/experimental/lazy-projections/bonne.cjs.map +1 -1
  31. package/dist/projection/experimental/lazy-projections/bonne.d.ts.map +1 -1
  32. package/dist/projection/experimental/lazy-projections/bonne.js +4 -1
  33. package/dist/projection/experimental/lazy-projections/bonne.js.map +1 -1
  34. package/dist/projection/experimental/lazy-projections/cass.cjs +4 -1
  35. package/dist/projection/experimental/lazy-projections/cass.cjs.map +1 -1
  36. package/dist/projection/experimental/lazy-projections/cass.d.ts.map +1 -1
  37. package/dist/projection/experimental/lazy-projections/cass.js +4 -1
  38. package/dist/projection/experimental/lazy-projections/cass.js.map +1 -1
  39. package/dist/projection/experimental/lazy-projections/eck6.cjs +4 -1
  40. package/dist/projection/experimental/lazy-projections/eck6.cjs.map +1 -1
  41. package/dist/projection/experimental/lazy-projections/eck6.d.ts.map +1 -1
  42. package/dist/projection/experimental/lazy-projections/eck6.js +4 -1
  43. package/dist/projection/experimental/lazy-projections/eck6.js.map +1 -1
  44. package/dist/projection/experimental/lazy-projections/eqdc.cjs +4 -1
  45. package/dist/projection/experimental/lazy-projections/eqdc.cjs.map +1 -1
  46. package/dist/projection/experimental/lazy-projections/eqdc.d.ts.map +1 -1
  47. package/dist/projection/experimental/lazy-projections/eqdc.js +4 -1
  48. package/dist/projection/experimental/lazy-projections/eqdc.js.map +1 -1
  49. package/dist/projection/experimental/lazy-projections/eqearth.cjs +4 -1
  50. package/dist/projection/experimental/lazy-projections/eqearth.cjs.map +1 -1
  51. package/dist/projection/experimental/lazy-projections/eqearth.d.ts.map +1 -1
  52. package/dist/projection/experimental/lazy-projections/eqearth.js +4 -1
  53. package/dist/projection/experimental/lazy-projections/eqearth.js.map +1 -1
  54. package/dist/projection/experimental/lazy-projections/equi.cjs +4 -1
  55. package/dist/projection/experimental/lazy-projections/equi.cjs.map +1 -1
  56. package/dist/projection/experimental/lazy-projections/equi.d.ts.map +1 -1
  57. package/dist/projection/experimental/lazy-projections/equi.js +4 -1
  58. package/dist/projection/experimental/lazy-projections/equi.js.map +1 -1
  59. package/dist/projection/experimental/lazy-projections/geocent.cjs +4 -1
  60. package/dist/projection/experimental/lazy-projections/geocent.cjs.map +1 -1
  61. package/dist/projection/experimental/lazy-projections/geocent.d.ts.map +1 -1
  62. package/dist/projection/experimental/lazy-projections/geocent.js +4 -1
  63. package/dist/projection/experimental/lazy-projections/geocent.js.map +1 -1
  64. package/dist/projection/experimental/lazy-projections/geos.cjs +4 -1
  65. package/dist/projection/experimental/lazy-projections/geos.cjs.map +1 -1
  66. package/dist/projection/experimental/lazy-projections/geos.d.ts.map +1 -1
  67. package/dist/projection/experimental/lazy-projections/geos.js +4 -1
  68. package/dist/projection/experimental/lazy-projections/geos.js.map +1 -1
  69. package/dist/projection/experimental/lazy-projections/gnom.cjs +4 -1
  70. package/dist/projection/experimental/lazy-projections/gnom.cjs.map +1 -1
  71. package/dist/projection/experimental/lazy-projections/gnom.d.ts.map +1 -1
  72. package/dist/projection/experimental/lazy-projections/gnom.js +4 -1
  73. package/dist/projection/experimental/lazy-projections/gnom.js.map +1 -1
  74. package/dist/projection/experimental/lazy-projections/index.cjs +92 -23
  75. package/dist/projection/experimental/lazy-projections/index.cjs.map +1 -1
  76. package/dist/projection/experimental/lazy-projections/krovak.cjs +4 -1
  77. package/dist/projection/experimental/lazy-projections/krovak.cjs.map +1 -1
  78. package/dist/projection/experimental/lazy-projections/krovak.d.ts.map +1 -1
  79. package/dist/projection/experimental/lazy-projections/krovak.js +4 -1
  80. package/dist/projection/experimental/lazy-projections/krovak.js.map +1 -1
  81. package/dist/projection/experimental/lazy-projections/merc.cjs +4 -1
  82. package/dist/projection/experimental/lazy-projections/merc.cjs.map +1 -1
  83. package/dist/projection/experimental/lazy-projections/merc.d.ts.map +1 -1
  84. package/dist/projection/experimental/lazy-projections/merc.js +4 -1
  85. package/dist/projection/experimental/lazy-projections/merc.js.map +1 -1
  86. package/dist/projection/experimental/lazy-projections/mill.cjs +4 -1
  87. package/dist/projection/experimental/lazy-projections/mill.cjs.map +1 -1
  88. package/dist/projection/experimental/lazy-projections/mill.d.ts.map +1 -1
  89. package/dist/projection/experimental/lazy-projections/mill.js +4 -1
  90. package/dist/projection/experimental/lazy-projections/mill.js.map +1 -1
  91. package/dist/projection/experimental/lazy-projections/moll.cjs +4 -1
  92. package/dist/projection/experimental/lazy-projections/moll.cjs.map +1 -1
  93. package/dist/projection/experimental/lazy-projections/moll.d.ts.map +1 -1
  94. package/dist/projection/experimental/lazy-projections/moll.js +4 -1
  95. package/dist/projection/experimental/lazy-projections/moll.js.map +1 -1
  96. package/dist/projection/experimental/lazy-projections/nzmg.cjs +4 -1
  97. package/dist/projection/experimental/lazy-projections/nzmg.cjs.map +1 -1
  98. package/dist/projection/experimental/lazy-projections/nzmg.d.ts.map +1 -1
  99. package/dist/projection/experimental/lazy-projections/nzmg.js +4 -1
  100. package/dist/projection/experimental/lazy-projections/nzmg.js.map +1 -1
  101. package/dist/projection/experimental/lazy-projections/omerc.cjs +4 -1
  102. package/dist/projection/experimental/lazy-projections/omerc.cjs.map +1 -1
  103. package/dist/projection/experimental/lazy-projections/omerc.d.ts.map +1 -1
  104. package/dist/projection/experimental/lazy-projections/omerc.js +4 -1
  105. package/dist/projection/experimental/lazy-projections/omerc.js.map +1 -1
  106. package/dist/projection/experimental/lazy-projections/ortho.cjs +4 -1
  107. package/dist/projection/experimental/lazy-projections/ortho.cjs.map +1 -1
  108. package/dist/projection/experimental/lazy-projections/ortho.d.ts.map +1 -1
  109. package/dist/projection/experimental/lazy-projections/ortho.js +4 -1
  110. package/dist/projection/experimental/lazy-projections/ortho.js.map +1 -1
  111. package/dist/projection/experimental/lazy-projections/poly.cjs +4 -1
  112. package/dist/projection/experimental/lazy-projections/poly.cjs.map +1 -1
  113. package/dist/projection/experimental/lazy-projections/poly.d.ts.map +1 -1
  114. package/dist/projection/experimental/lazy-projections/poly.js +4 -1
  115. package/dist/projection/experimental/lazy-projections/poly.js.map +1 -1
  116. package/dist/projection/experimental/lazy-projections/robin.cjs +4 -1
  117. package/dist/projection/experimental/lazy-projections/robin.cjs.map +1 -1
  118. package/dist/projection/experimental/lazy-projections/robin.d.ts.map +1 -1
  119. package/dist/projection/experimental/lazy-projections/robin.js +4 -1
  120. package/dist/projection/experimental/lazy-projections/robin.js.map +1 -1
  121. package/dist/projection/experimental/lazy-projections/sinu.cjs +4 -1
  122. package/dist/projection/experimental/lazy-projections/sinu.cjs.map +1 -1
  123. package/dist/projection/experimental/lazy-projections/sinu.d.ts.map +1 -1
  124. package/dist/projection/experimental/lazy-projections/sinu.js +4 -1
  125. package/dist/projection/experimental/lazy-projections/sinu.js.map +1 -1
  126. package/dist/projection/experimental/lazy-projections/stere.cjs +4 -1
  127. package/dist/projection/experimental/lazy-projections/stere.cjs.map +1 -1
  128. package/dist/projection/experimental/lazy-projections/stere.d.ts.map +1 -1
  129. package/dist/projection/experimental/lazy-projections/stere.js +4 -1
  130. package/dist/projection/experimental/lazy-projections/stere.js.map +1 -1
  131. package/dist/projection/experimental/lazy-projections/tpers.cjs +4 -1
  132. package/dist/projection/experimental/lazy-projections/tpers.cjs.map +1 -1
  133. package/dist/projection/experimental/lazy-projections/tpers.d.ts.map +1 -1
  134. package/dist/projection/experimental/lazy-projections/tpers.js +4 -1
  135. package/dist/projection/experimental/lazy-projections/tpers.js.map +1 -1
  136. package/dist/projection/experimental/lazy-projections/vandg.cjs +4 -1
  137. package/dist/projection/experimental/lazy-projections/vandg.cjs.map +1 -1
  138. package/dist/projection/experimental/lazy-projections/vandg.d.ts.map +1 -1
  139. package/dist/projection/experimental/lazy-projections/vandg.js +4 -1
  140. package/dist/projection/experimental/lazy-projections/vandg.js.map +1 -1
  141. package/dist/projection/index.cjs.map +1 -1
  142. package/dist/projection/index.d.ts.map +1 -1
  143. package/dist/projection/index.js.map +1 -1
  144. package/dist/projection/lib/projection.js.map +1 -1
  145. package/dist/projection/pipeline.cjs.map +1 -1
  146. package/dist/projection/transform-analysis.cjs.map +1 -1
  147. package/dist/tasks/index.cjs +181 -84
  148. package/dist/tasks/index.cjs.map +2 -2
  149. package/dist/tasks/terrain-residency.d.ts.map +1 -1
  150. package/dist/tasks/terrain-residency.js +80 -18
  151. package/dist/tasks/terrain-residency.js.map +1 -1
  152. package/dist/terrain/cutout-polygons.d.ts +21 -0
  153. package/dist/terrain/cutout-polygons.d.ts.map +1 -0
  154. package/dist/terrain/cutout-polygons.js +172 -0
  155. package/dist/terrain/cutout-polygons.js.map +1 -0
  156. package/dist/terrain/cutout-region.d.ts +34 -0
  157. package/dist/terrain/cutout-region.d.ts.map +1 -0
  158. package/dist/terrain/cutout-region.js +33 -0
  159. package/dist/terrain/cutout-region.js.map +1 -0
  160. package/dist/terrain/cutout-skirts.d.ts +34 -0
  161. package/dist/terrain/cutout-skirts.d.ts.map +1 -0
  162. package/dist/terrain/cutout-skirts.js +29 -0
  163. package/dist/terrain/cutout-skirts.js.map +1 -0
  164. package/dist/terrain/depression-fill.d.ts +25 -0
  165. package/dist/terrain/depression-fill.d.ts.map +1 -0
  166. package/dist/terrain/depression-fill.js +106 -0
  167. package/dist/terrain/depression-fill.js.map +1 -0
  168. package/dist/terrain/geographic-cutout.d.ts +38 -0
  169. package/dist/terrain/geographic-cutout.d.ts.map +1 -0
  170. package/dist/terrain/geographic-cutout.js +120 -0
  171. package/dist/terrain/geographic-cutout.js.map +1 -0
  172. package/dist/terrain/hydrology.d.ts +42 -0
  173. package/dist/terrain/hydrology.d.ts.map +1 -0
  174. package/dist/terrain/hydrology.js +112 -0
  175. package/dist/terrain/hydrology.js.map +1 -0
  176. package/dist/terrain/index.cjs +1529 -107
  177. package/dist/terrain/index.cjs.map +3 -3
  178. package/dist/terrain/index.d.ts +15 -1
  179. package/dist/terrain/index.d.ts.map +1 -1
  180. package/dist/terrain/index.js +13 -0
  181. package/dist/terrain/index.js.map +1 -1
  182. package/dist/terrain/lod-screen-error.d.ts +28 -0
  183. package/dist/terrain/lod-screen-error.d.ts.map +1 -0
  184. package/dist/terrain/lod-screen-error.js +95 -0
  185. package/dist/terrain/lod-screen-error.js.map +1 -0
  186. package/dist/terrain/lod-select.d.ts +26 -10
  187. package/dist/terrain/lod-select.d.ts.map +1 -1
  188. package/dist/terrain/lod-select.js +27 -14
  189. package/dist/terrain/lod-select.js.map +1 -1
  190. package/dist/terrain/mesh-cutout.d.ts +45 -0
  191. package/dist/terrain/mesh-cutout.d.ts.map +1 -0
  192. package/dist/terrain/mesh-cutout.js +336 -0
  193. package/dist/terrain/mesh-cutout.js.map +1 -0
  194. package/dist/terrain/mesh-skirts.d.ts +8 -2
  195. package/dist/terrain/mesh-skirts.d.ts.map +1 -1
  196. package/dist/terrain/mesh-skirts.js +5 -4
  197. package/dist/terrain/mesh-skirts.js.map +1 -1
  198. package/dist/terrain/mixed-halo-update.d.ts.map +1 -1
  199. package/dist/terrain/mixed-halo-update.js +58 -23
  200. package/dist/terrain/mixed-halo-update.js.map +1 -1
  201. package/dist/terrain/mixed-vertex-halos.d.ts +24 -1
  202. package/dist/terrain/mixed-vertex-halos.d.ts.map +1 -1
  203. package/dist/terrain/mixed-vertex-halos.js +75 -58
  204. package/dist/terrain/mixed-vertex-halos.js.map +1 -1
  205. package/dist/terrain/regional-viewshed.d.ts +55 -0
  206. package/dist/terrain/regional-viewshed.d.ts.map +1 -0
  207. package/dist/terrain/regional-viewshed.js +119 -0
  208. package/dist/terrain/regional-viewshed.js.map +1 -0
  209. package/dist/terrain/sweep-polytope.d.ts +4 -0
  210. package/dist/terrain/sweep-polytope.d.ts.map +1 -1
  211. package/dist/terrain/sweep-polytope.js +15 -5
  212. package/dist/terrain/sweep-polytope.js.map +1 -1
  213. package/dist/terrain/sweep-rotating-capsule.d.ts +17 -0
  214. package/dist/terrain/sweep-rotating-capsule.d.ts.map +1 -0
  215. package/dist/terrain/sweep-rotating-capsule.js +118 -0
  216. package/dist/terrain/sweep-rotating-capsule.js.map +1 -0
  217. package/dist/terrain/sweep-rotation.d.ts +35 -0
  218. package/dist/terrain/sweep-rotation.d.ts.map +1 -0
  219. package/dist/terrain/sweep-rotation.js +114 -0
  220. package/dist/terrain/sweep-rotation.js.map +1 -0
  221. package/dist/terrain/tile-cutout-update.d.ts +73 -0
  222. package/dist/terrain/tile-cutout-update.d.ts.map +1 -0
  223. package/dist/terrain/tile-cutout-update.js +181 -0
  224. package/dist/terrain/tile-cutout-update.js.map +1 -0
  225. package/dist/terrain/tile-cutout.d.ts +33 -0
  226. package/dist/terrain/tile-cutout.d.ts.map +1 -0
  227. package/dist/terrain/tile-cutout.js +93 -0
  228. package/dist/terrain/tile-cutout.js.map +1 -0
  229. package/dist/terrain/watershed-accumulation.d.ts +20 -0
  230. package/dist/terrain/watershed-accumulation.d.ts.map +1 -0
  231. package/dist/terrain/watershed-accumulation.js +53 -0
  232. package/dist/terrain/watershed-accumulation.js.map +1 -0
  233. package/dist/turf/expressions.cjs +4 -4
  234. package/dist/turf/expressions.cjs.map +2 -2
  235. package/dist/turf/expressions.d.ts +2 -2
  236. package/dist/turf/expressions.d.ts.map +1 -1
  237. package/dist/turf/expressions.js +2 -2
  238. package/dist/turf/expressions.js.map +1 -1
  239. package/dist/turf.cjs +25 -25
  240. package/dist/turf.cjs.map +2 -2
  241. package/dist/turf.d.ts +1 -1
  242. package/dist/turf.d.ts.map +1 -1
  243. package/dist/turf.js +2 -2
  244. package/dist/turf.js.map +1 -1
  245. package/dist/web-mercator/assert.d.ts +2 -0
  246. package/dist/web-mercator/assert.d.ts.map +1 -0
  247. package/dist/web-mercator/assert.js +12 -0
  248. package/dist/web-mercator/assert.js.map +1 -0
  249. package/dist/web-mercator/fit-bounds.d.ts +52 -0
  250. package/dist/web-mercator/fit-bounds.d.ts.map +1 -0
  251. package/dist/web-mercator/fit-bounds.js +70 -0
  252. package/dist/web-mercator/fit-bounds.js.map +1 -0
  253. package/dist/web-mercator/fly-to-viewport.d.ts +19 -0
  254. package/dist/web-mercator/fly-to-viewport.d.ts.map +1 -0
  255. package/dist/web-mercator/fly-to-viewport.js +94 -0
  256. package/dist/web-mercator/fly-to-viewport.js.map +1 -0
  257. package/dist/web-mercator/get-bounds.d.ts +3 -0
  258. package/dist/web-mercator/get-bounds.d.ts.map +1 -0
  259. package/dist/web-mercator/get-bounds.js +56 -0
  260. package/dist/web-mercator/get-bounds.js.map +1 -0
  261. package/dist/web-mercator/index.cjs +705 -0
  262. package/dist/web-mercator/index.cjs.map +6 -0
  263. package/dist/web-mercator/index.d.ts +14 -0
  264. package/dist/web-mercator/index.d.ts.map +1 -0
  265. package/dist/web-mercator/index.js +14 -0
  266. package/dist/web-mercator/index.js.map +1 -0
  267. package/dist/web-mercator/math-utils.d.ts +7 -0
  268. package/dist/web-mercator/math-utils.d.ts.map +1 -0
  269. package/dist/web-mercator/math-utils.js +30 -0
  270. package/dist/web-mercator/math-utils.js.map +1 -0
  271. package/dist/web-mercator/mercator-meters.d.ts +29 -0
  272. package/dist/web-mercator/mercator-meters.d.ts.map +1 -0
  273. package/dist/web-mercator/mercator-meters.js +61 -0
  274. package/dist/web-mercator/mercator-meters.js.map +1 -0
  275. package/dist/web-mercator/normalize-viewport-props.d.ts +16 -0
  276. package/dist/web-mercator/normalize-viewport-props.d.ts.map +1 -0
  277. package/dist/web-mercator/normalize-viewport-props.js +45 -0
  278. package/dist/web-mercator/normalize-viewport-props.js.map +1 -0
  279. package/dist/web-mercator/web-mercator-utils.d.ts +192 -0
  280. package/dist/web-mercator/web-mercator-utils.d.ts.map +1 -0
  281. package/dist/web-mercator/web-mercator-utils.js +321 -0
  282. package/dist/web-mercator/web-mercator-utils.js.map +1 -0
  283. package/dist/web-mercator/web-mercator-viewport.d.ts +177 -0
  284. package/dist/web-mercator/web-mercator-viewport.d.ts.map +1 -0
  285. package/dist/web-mercator/web-mercator-viewport.js +276 -0
  286. package/dist/web-mercator/web-mercator-viewport.js.map +1 -0
  287. package/dist/web-mercator.d.ts +1 -1
  288. package/dist/web-mercator.d.ts.map +1 -1
  289. package/dist/web-mercator.js +1 -1
  290. package/dist/web-mercator.js.map +1 -1
  291. package/package.json +19 -458
  292. package/src/crs/index.ts +7 -0
  293. package/src/crs/spatial-reference-metadata.ts +118 -0
  294. package/src/expressions.ts +1 -1
  295. package/src/index.ts +92 -4
  296. package/src/projection/experimental/crs/spatial-reference.ts +1 -6
  297. package/src/projection/experimental/crs/types.ts +1 -1
  298. package/src/projection/experimental/crs/wkt.ts +1 -1
  299. package/src/projection/experimental/crs-descriptor.ts +1 -1
  300. package/src/projection/experimental/lazy-projections/aea.ts +4 -1
  301. package/src/projection/experimental/lazy-projections/bonne.ts +4 -1
  302. package/src/projection/experimental/lazy-projections/cass.ts +4 -1
  303. package/src/projection/experimental/lazy-projections/eck6.ts +4 -1
  304. package/src/projection/experimental/lazy-projections/eqdc.ts +4 -1
  305. package/src/projection/experimental/lazy-projections/eqearth.ts +4 -1
  306. package/src/projection/experimental/lazy-projections/equi.ts +4 -1
  307. package/src/projection/experimental/lazy-projections/geocent.ts +4 -1
  308. package/src/projection/experimental/lazy-projections/geos.ts +4 -1
  309. package/src/projection/experimental/lazy-projections/gnom.ts +4 -1
  310. package/src/projection/experimental/lazy-projections/krovak.ts +4 -1
  311. package/src/projection/experimental/lazy-projections/merc.ts +4 -1
  312. package/src/projection/experimental/lazy-projections/mill.ts +4 -1
  313. package/src/projection/experimental/lazy-projections/moll.ts +4 -1
  314. package/src/projection/experimental/lazy-projections/nzmg.ts +4 -1
  315. package/src/projection/experimental/lazy-projections/omerc.ts +4 -1
  316. package/src/projection/experimental/lazy-projections/ortho.ts +4 -1
  317. package/src/projection/experimental/lazy-projections/poly.ts +4 -1
  318. package/src/projection/experimental/lazy-projections/robin.ts +4 -1
  319. package/src/projection/experimental/lazy-projections/sinu.ts +4 -1
  320. package/src/projection/experimental/lazy-projections/stere.ts +4 -1
  321. package/src/projection/experimental/lazy-projections/tpers.ts +4 -1
  322. package/src/projection/experimental/lazy-projections/vandg.ts +4 -1
  323. package/src/projection/index.ts +1 -1
  324. package/src/projection/lib/projection.ts +1 -1
  325. package/src/tasks/terrain-residency.ts +86 -21
  326. package/src/terrain/cutout-polygons.ts +202 -0
  327. package/src/terrain/cutout-region.ts +54 -0
  328. package/src/terrain/cutout-skirts.ts +52 -0
  329. package/src/terrain/depression-fill.ts +125 -0
  330. package/src/terrain/geographic-cutout.ts +154 -0
  331. package/src/terrain/hydrology.ts +149 -0
  332. package/src/terrain/index.ts +85 -1
  333. package/src/terrain/lod-screen-error.ts +128 -0
  334. package/src/terrain/lod-select.ts +65 -31
  335. package/src/terrain/mesh-cutout.ts +420 -0
  336. package/src/terrain/mesh-skirts.ts +10 -7
  337. package/src/terrain/mixed-halo-update.ts +54 -20
  338. package/src/terrain/mixed-vertex-halos.ts +94 -78
  339. package/src/terrain/regional-viewshed.ts +177 -0
  340. package/src/terrain/sweep-polytope.ts +49 -25
  341. package/src/terrain/sweep-rotating-capsule.ts +139 -0
  342. package/src/terrain/sweep-rotation.ts +149 -0
  343. package/src/terrain/tile-cutout-update.ts +293 -0
  344. package/src/terrain/tile-cutout.ts +123 -0
  345. package/src/terrain/watershed-accumulation.ts +67 -0
  346. package/src/turf/expressions.ts +3 -3
  347. package/src/turf.ts +3 -7
  348. package/src/web-mercator/assert.ts +11 -0
  349. package/src/web-mercator/fit-bounds.ts +132 -0
  350. package/src/web-mercator/fly-to-viewport.ts +157 -0
  351. package/src/web-mercator/get-bounds.ts +62 -0
  352. package/src/web-mercator/index.ts +49 -0
  353. package/src/web-mercator/math-utils.ts +35 -0
  354. package/src/web-mercator/mercator-meters.ts +83 -0
  355. package/src/web-mercator/normalize-viewport-props.ts +58 -0
  356. package/src/web-mercator/web-mercator-utils.ts +468 -0
  357. package/src/web-mercator/web-mercator-viewport.ts +406 -0
  358. package/src/web-mercator.ts +1 -1
  359. package/dist/projection/experimental/index.cjs +0 -11707
  360. package/dist/projection/experimental/index.cjs.map +0 -6
@@ -5,6 +5,7 @@
5
5
  import type {Task} from '@math.gl/tasks';
6
6
  import type {TerrainMixedHaloSnapshot} from '../terrain/mixed-halo-update';
7
7
  import type {TerrainMixedVertexTile} from '../terrain/mixed-vertex-halos';
8
+ import type {HeightFieldProps, TerrainArray} from '../terrain/types';
8
9
 
9
10
  type TileAddress = Pick<TerrainMixedVertexTile, 'column' | 'row' | 'spacing'>;
10
11
  type TerrainResidencyTimings = {
@@ -43,6 +44,9 @@ export type TerrainResidencyTypes = {
43
44
  };
44
45
  };
45
46
 
47
+ /** Address lookup retained with an immutable source layout, not rebuilt per sample batch. */
48
+ const sourceIndexes = new WeakMap<TerrainMixedHaloSnapshot, Map<string, number>>();
49
+
46
50
  const addressKey = ({spacing, column, row}: TileAddress) => `${spacing}/${column}/${row}`;
47
51
 
48
52
  function sameArray(a: ArrayLike<number>, b: ArrayLike<number>): boolean {
@@ -68,6 +72,50 @@ function sameHalo(a: ResidentHalo, b: ResidentHalo): boolean {
68
72
  );
69
73
  }
70
74
 
75
+ /** Copy already validated resident samples once, preserving precision and nodata normalization. */
76
+ function copyResidentSamples(field: HeightFieldProps): {
77
+ heights: TerrainArray;
78
+ validity: Uint8Array;
79
+ } {
80
+ const {width, height, offset = 0, stride = width} = field;
81
+ const heights =
82
+ field.heights instanceof Float64Array
83
+ ? new Float64Array(width * height)
84
+ : new Float32Array(width * height);
85
+ const validity = new Uint8Array(heights.length);
86
+ for (let y = 0; y < height; y++) {
87
+ for (let x = 0; x < width; x++) {
88
+ const input = offset + y * stride + x;
89
+ const output = y * width + x;
90
+ const value = field.heights[input];
91
+ if (Number.isFinite(value) && (!field.validity || field.validity[input] !== 0)) {
92
+ heights[output] = value;
93
+ validity[output] = 1;
94
+ }
95
+ }
96
+ }
97
+ return {heights, validity};
98
+ }
99
+
100
+ /** Compare halo addresses in the order used by the incremental builder. */
101
+ function compareAddress(a: TileAddress, b: TileAddress): number {
102
+ return a.spacing - b.spacing || a.column - b.column || a.row - b.row;
103
+ }
104
+
105
+ /** Compute changed outputs with a linear merge over sorted snapshots. */
106
+ function changedHalos(previous: readonly ResidentHalo[], next: readonly ResidentHalo[]) {
107
+ const changed: ResidentHalo[] = [];
108
+ let index = 0;
109
+ for (let i = 0; i < next.length; i++) {
110
+ const tile = next[i];
111
+ while (index < previous.length && compareAddress(previous[index], tile) < 0) index++;
112
+ const prior = previous[index];
113
+ if (!prior || (prior !== tile && (compareAddress(prior, tile) !== 0 || !sameHalo(prior, tile))))
114
+ changed.push(tile);
115
+ }
116
+ return changed;
117
+ }
118
+
71
119
  /** Keep mixed halo sources and outputs resident across serialized edit batches. */
72
120
  export const TerrainResidencyTask = {
73
121
  id: 'terrain-residency',
@@ -88,37 +136,59 @@ export const TerrainResidencyTask = {
88
136
  try {
89
137
  if (input.revision !== state.revision) throw new Error('Stale terrain residency revision');
90
138
 
91
- const [{updateTerrainMixedVertexTileHalos}, {HeightField}] = await Promise.all([
92
- import('../terrain/mixed-halo-update'),
93
- import('../terrain/height-field')
94
- ]);
139
+ const {updateTerrainMixedVertexTileHalos} = await import('../terrain/mixed-halo-update');
95
140
  context.throwIfAborted();
96
- const sources = new Map(state.snapshot?.sources.map(tile => [addressKey(tile), tile]));
141
+ const priorSources = state.snapshot?.sources ?? [];
142
+ let sourceIndex = state.snapshot && sourceIndexes.get(state.snapshot);
143
+ if (!sourceIndex) {
144
+ sourceIndex = new Map();
145
+ for (let i = 0; i < priorSources.length; i++)
146
+ sourceIndex.set(addressKey(priorSources[i]), i);
147
+ }
148
+ // Sample-only transactions copy one reference array. Structural edits lazily
149
+ // create a map; neither path mutates the committed snapshot on rejection.
150
+ const resident = priorSources.slice();
151
+ let structural: Map<string, TerrainMixedVertexTile> | undefined;
152
+ const getSource = (key: string) =>
153
+ structural ? structural.get(key) : resident[sourceIndex.get(key)!];
154
+ const setSource = (key: string, tile: TerrainMixedVertexTile) => {
155
+ if (structural) structural.set(key, tile);
156
+ else resident[sourceIndex.get(key)!] = tile;
157
+ };
158
+ const editLayout = () => {
159
+ if (!structural) {
160
+ structural = new Map();
161
+ for (const tile of resident) structural.set(addressKey(tile), tile);
162
+ }
163
+ return structural;
164
+ };
97
165
  // Several edits to a tile in one batch share one private copy.
98
- const writable = new Map<string, ReturnType<InstanceType<typeof HeightField>['copyData']>>();
166
+ const writable = new Map<string, ReturnType<typeof copyResidentSamples>>();
99
167
  for (const edit of input.edits) {
100
168
  if (edit.type === 'upsert') {
101
169
  const key = addressKey(edit.tile);
102
- sources.set(key, structuredClone(edit.tile));
170
+ editLayout().set(key, structuredClone(edit.tile));
103
171
  writable.delete(key);
104
172
  continue;
105
173
  }
106
174
  const key = addressKey(edit.address);
107
175
  if (edit.type === 'remove') {
108
- sources.delete(key);
176
+ editLayout().delete(key);
109
177
  writable.delete(key);
110
178
  continue;
111
179
  }
112
180
  if (edit.type !== 'samples') throw new Error('Unknown terrain residency edit');
113
- const source = sources.get(key);
181
+ const source = getSource(key);
114
182
  if (!source) throw new Error('Terrain sample edit requires a resident tile');
115
183
  if (!edit.samples.length) continue;
116
184
  let data = writable.get(key);
117
185
  if (!data) {
118
- const copied = new HeightField(source.field).copyData();
119
- data = {heights: copied.heights, validity: copied.validity};
186
+ // Upserts in this transaction have not passed halo validation yet.
187
+ data = structural
188
+ ? new (await import('../terrain/height-field')).HeightField(source.field).copyData()
189
+ : copyResidentSamples(source.field);
120
190
  writable.set(key, data);
121
- sources.set(key, {
191
+ setSource(key, {
122
192
  ...source,
123
193
  field: {...source.field, ...data, offset: 0, stride: source.field.width}
124
194
  });
@@ -141,19 +211,14 @@ export const TerrainResidencyTask = {
141
211
  const applied = input.measureStages ? performance.now() : 0;
142
212
  const next = updateTerrainMixedVertexTileHalos(
143
213
  state.snapshot,
144
- [...sources.values()],
214
+ structural ? [...structural.values()] : resident,
145
215
  state.limits
146
216
  );
147
217
  const updated = input.measureStages ? performance.now() : 0;
148
- const old = new Map(state.snapshot?.tiles.map(tile => [addressKey(tile), tile]));
149
- // Copy outgoing buffers so transfer cannot detach the resident snapshot.
150
- const tiles = structuredClone(
151
- next.tiles.filter(tile => {
152
- const prior = old.get(addressKey(tile));
153
- return !prior || !sameHalo(prior, tile);
154
- })
155
- );
218
+ // Both snapshots are in address order. Unchanged halos retain object identity.
219
+ const tiles = structuredClone(changedHalos(state.snapshot?.tiles ?? [], next.tiles));
156
220
  context.throwIfAborted();
221
+ if (!structural) sourceIndexes.set(next, sourceIndex);
157
222
  state.snapshot = next;
158
223
  state.revision++;
159
224
  const result: TerrainResidencyTypes['output'] = {
@@ -0,0 +1,202 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {
6
+ createTerrainCutoutPlan,
7
+ type CutoutPoint,
8
+ type TerrainCutoutPolygon,
9
+ type TerrainCutoutPolygonSet
10
+ } from './cutout-region';
11
+
12
+ /** Limits for validating and preparing a reusable polygon arrangement. */
13
+ export type TerrainCutoutPolygonOptions = {
14
+ /** Maximum total ring edges. Default 2048. */
15
+ maxEdges?: number;
16
+ /** Maximum validation, containment and line-comparison operations. Default 4000000. */
17
+ maxWork?: number;
18
+ };
19
+ /** Prepare concave polygons, holes and disjoint regions for all terrain cut APIs.
20
+ * Copies inputs. Ring winding is unrestricted. Rings must be simple and finite,
21
+ * with no repeated closing point. Holes are strictly contained and disjoint;
22
+ * separate polygon domains must not overlap or touch. Islands inside another
23
+ * polygon's hole are allowed. Polygon IDs are zero-based input array indices.
24
+ *
25
+ * The immutable descriptor contains CPU functions: reuse it for cache hits,
26
+ * and prepare a new descriptor inside each worker instead of transferring it.
27
+ * Supporting-line arrangements can grow quadratically; split-time budgets
28
+ * remain necessary in addition to these preparation limits.
29
+ */
30
+ export function prepareTerrainCutoutPolygons(
31
+ polygons: readonly TerrainCutoutPolygon[],
32
+ {maxEdges = 2048, maxWork = 4000000}: TerrainCutoutPolygonOptions = {}
33
+ ): TerrainCutoutPolygonSet {
34
+ if (![maxEdges, maxWork].every(n => Number.isSafeInteger(n) && n >= 0) || !polygons.length)
35
+ throw new RangeError('Invalid terrain cutout polygon limits or empty set');
36
+ let work = 0,
37
+ edgeCount = 0;
38
+ /** Bound preprocessing before expensive pair comparisons. */
39
+ const charge = (amount: number) => {
40
+ work += amount;
41
+ if (work > maxWork) throw new RangeError('Terrain cutout polygon work budget exceeded');
42
+ };
43
+ if (polygons.length > Math.floor(maxEdges / 3))
44
+ throw new RangeError('Terrain cutout polygon edge budget exceeded');
45
+ const regions = polygons.map(p => {
46
+ if (1 + (p.holes?.length ?? 0) > Math.floor((maxEdges - edgeCount) / 3))
47
+ throw new RangeError('Terrain cutout polygon edge budget exceeded');
48
+ return [p.outer, ...(p.holes ?? [])].map(ring => {
49
+ edgeCount += ring.length;
50
+ if (edgeCount > maxEdges) throw new RangeError('Terrain cutout polygon edge budget exceeded');
51
+ charge(ring.length);
52
+ if (ring.length < 3 || ring.some(p => p.length !== 2 || !p.every(Number.isFinite)))
53
+ throw new RangeError('Invalid terrain cutout polygon ring');
54
+ return ring.map(p => Object.freeze([p[0], p[1]] as const));
55
+ });
56
+ });
57
+ const rings = regions.flat();
58
+ for (const ring of rings) {
59
+ let area = 0;
60
+ for (let i = 0; i < ring.length; i++) {
61
+ charge(1);
62
+ const a = ring[i],
63
+ b = ring[(i + 1) % ring.length],
64
+ c = ring[(i + 2) % ring.length];
65
+ if (equal(a, b)) throw new RangeError('Duplicate terrain cutout ring vertex');
66
+ area += orient(ring[0], a, b);
67
+ if (
68
+ orient(a, b, c) === 0 &&
69
+ (a[0] - b[0]) * (c[0] - b[0]) + (a[1] - b[1]) * (c[1] - b[1]) >= 0
70
+ )
71
+ throw new RangeError('Backtracking terrain cutout ring edge');
72
+ for (let j = i + 1; j < ring.length; j++) {
73
+ if (j === i + 1 || (i === 0 && j === ring.length - 1)) continue;
74
+ charge(1);
75
+ if (intersects(a, b, ring[j], ring[(j + 1) % ring.length]))
76
+ throw new RangeError('Self-intersecting terrain cutout ring');
77
+ }
78
+ }
79
+ if (!Number.isFinite(area) || area === 0)
80
+ throw new RangeError('Degenerate terrain cutout ring');
81
+ }
82
+ for (let i = 0; i < rings.length; i++)
83
+ for (let j = i + 1; j < rings.length; j++) {
84
+ const a = rings[i],
85
+ b = rings[j];
86
+ for (let x = 0; x < a.length; x++)
87
+ for (let y = 0; y < b.length; y++) {
88
+ charge(1);
89
+ if (intersects(a[x], a[(x + 1) % a.length], b[y], b[(y + 1) % b.length]))
90
+ throw new RangeError('Terrain cutout rings must not touch or intersect');
91
+ }
92
+ }
93
+ for (const region of regions)
94
+ for (let i = 1; i < region.length; i++) {
95
+ if (contains(region[0], region[i][0], charge) !== 1)
96
+ throw new RangeError('Terrain cutout hole must be strictly inside its outer ring');
97
+ for (let j = 1; j < i; j++)
98
+ if (
99
+ contains(region[j], region[i][0], charge) === 1 ||
100
+ contains(region[i], region[j][0], charge) === 1
101
+ )
102
+ throw new RangeError('Nested terrain cutout holes are not supported');
103
+ }
104
+ /** Test the interior of a polygon, excluding every hole. */
105
+ function inRegion(
106
+ region: readonly (readonly CutoutPoint[])[],
107
+ point: CutoutPoint,
108
+ budget: (n: number) => void
109
+ ) {
110
+ const outer = contains(region[0], point, budget);
111
+ if (outer !== 1) return outer;
112
+ for (let i = 1; i < region.length; i++) {
113
+ const hole = contains(region[i], point, budget);
114
+ if (hole === 0) return 0;
115
+ if (hole === 1) return -1;
116
+ }
117
+ return 1;
118
+ }
119
+ for (let i = 0; i < regions.length; i++)
120
+ for (let j = i + 1; j < regions.length; j++) {
121
+ if (
122
+ inRegion(regions[i], regions[j][0][0], charge) === 1 ||
123
+ inRegion(regions[j], regions[i][0][0], charge) === 1
124
+ )
125
+ throw new RangeError('Overlapping terrain cutout polygon domains');
126
+ }
127
+ const lines: (readonly [CutoutPoint, CutoutPoint])[] = [];
128
+ for (const ring of rings)
129
+ for (let i = 0; i < ring.length; i++) {
130
+ const a = ring[i],
131
+ b = ring[(i + 1) % ring.length];
132
+ // Avoid splitting twice by the same supporting line (including collinear vertices).
133
+ if (
134
+ lines.some(([u, v]) => {
135
+ charge(1);
136
+ return orient(u, v, a) === 0 && orient(u, v, b) === 0;
137
+ })
138
+ )
139
+ continue;
140
+ lines.push(a[0] < b[0] || (a[0] === b[0] && a[1] < b[1]) ? [a, b] : [b, a]);
141
+ }
142
+ return createTerrainCutoutPlan({
143
+ lines: Object.freeze(lines.map(line => Object.freeze(line))),
144
+ classify(point, budget) {
145
+ for (let i = 0; i < regions.length; i++) {
146
+ const result = inRegion(regions[i], point, budget);
147
+ if (result === 0) throw new RangeError('Unrepresentable terrain cutout fragment interior');
148
+ if (result === 1) return i;
149
+ }
150
+ return -1;
151
+ }
152
+ });
153
+ }
154
+
155
+ /** Exact coordinate equality for duplicate endpoints. */
156
+ function equal(a: CutoutPoint, b: CutoutPoint) {
157
+ return a[0] === b[0] && a[1] === b[1];
158
+ }
159
+ /** Signed twice-area with explicit overflow rejection. */
160
+ function orient(a: CutoutPoint, b: CutoutPoint, c: CutoutPoint) {
161
+ const value = (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
162
+ if (!Number.isFinite(value)) throw new RangeError('Terrain cutout polygon coordinate overflow');
163
+ return value;
164
+ }
165
+ /** Inclusive segment membership after collinearity has been established. */
166
+ function onSegment(a: CutoutPoint, b: CutoutPoint, p: CutoutPoint) {
167
+ return (
168
+ p[0] >= Math.min(a[0], b[0]) &&
169
+ p[0] <= Math.max(a[0], b[0]) &&
170
+ p[1] >= Math.min(a[1], b[1]) &&
171
+ p[1] <= Math.max(a[1], b[1])
172
+ );
173
+ }
174
+ /** Detect crossings, overlapping edges and mere touches during ring validation. */
175
+ function intersects(a: CutoutPoint, b: CutoutPoint, c: CutoutPoint, d: CutoutPoint) {
176
+ const abC = orient(a, b, c),
177
+ abD = orient(a, b, d),
178
+ cdA = orient(c, d, a),
179
+ cdB = orient(c, d, b);
180
+ return (
181
+ (abC === 0 && onSegment(a, b, c)) ||
182
+ (abD === 0 && onSegment(a, b, d)) ||
183
+ (cdA === 0 && onSegment(c, d, a)) ||
184
+ (cdB === 0 && onSegment(c, d, b)) ||
185
+ (((abC > 0 && abD < 0) || (abC < 0 && abD > 0)) &&
186
+ ((cdA > 0 && cdB < 0) || (cdA < 0 && cdB > 0)))
187
+ );
188
+ }
189
+ /** Winding classification: interior 1, exterior -1, boundary 0. */
190
+ function contains(ring: readonly CutoutPoint[], p: CutoutPoint, charge: (n: number) => void) {
191
+ let winding = 0;
192
+ for (let i = 0; i < ring.length; i++) {
193
+ charge(1);
194
+ const a = ring[i],
195
+ b = ring[(i + 1) % ring.length],
196
+ cross = orient(a, b, p);
197
+ if (cross === 0 && onSegment(a, b, p)) return 0;
198
+ if (a[1] <= p[1] && b[1] > p[1] && cross > 0) winding++;
199
+ if (a[1] > p[1] && b[1] <= p[1] && cross < 0) winding--;
200
+ }
201
+ return winding === 0 ? -1 : 1;
202
+ }
@@ -0,0 +1,54 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ /** A finite local XY coordinate. */
6
+ export type CutoutPoint = readonly [number, number];
7
+ /** One simple outer ring with strictly contained, disjoint hole rings. */
8
+ export type TerrainCutoutPolygon = {
9
+ /** Either winding; omit the repeated closing point. */
10
+ outer: readonly CutoutPoint[];
11
+ /** Either winding; holes must not touch or intersect any other ring. */
12
+ holes?: readonly (readonly CutoutPoint[])[];
13
+ };
14
+ /** Internal prepared partition contract, shared without importing polygon algorithms. */
15
+ export type TerrainCutoutPlan = {
16
+ /** Supporting lines shared by every independently clipped tile. */
17
+ lines: readonly (readonly [CutoutPoint, CutoutPoint])[];
18
+ /** Return polygon index or -1 for the remainder; charge classification work. */
19
+ classify: (point: CutoutPoint, charge: (amount: number) => void) => number;
20
+ };
21
+ /** Versioned brand shared by ESM/CJS and both public entry-point bundles. */
22
+ const PLAN = Symbol.for('@math.gl/geospatial/terrain-cutout-polygons/v1');
23
+ /** Immutable prepared polygon set; create with prepareTerrainCutoutPolygons. */
24
+ export type TerrainCutoutPolygonSet = {readonly [PLAN]: TerrainCutoutPlan};
25
+ /** A strictly convex ring or an opt-in prepared concave/multi-polygon cut. */
26
+ export type TerrainCutoutRegion = readonly CutoutPoint[] | TerrainCutoutPolygonSet;
27
+
28
+ /** @internal Brand a validated plan without exposing its mutable preparation state. */
29
+ export function createTerrainCutoutPlan(plan: TerrainCutoutPlan): TerrainCutoutPolygonSet {
30
+ return Object.freeze({[PLAN]: Object.freeze(plan)});
31
+ }
32
+ /** @internal Read only genuine prepared inputs; arrays use the convex fast path. */
33
+ export function getTerrainCutoutPlan(region: TerrainCutoutRegion): TerrainCutoutPlan | undefined {
34
+ if (Array.isArray(region)) return undefined;
35
+ const plan = (region as TerrainCutoutPolygonSet | undefined)?.[PLAN];
36
+ if (!plan) throw new RangeError('Invalid prepared terrain cutout polygons');
37
+ return plan;
38
+ }
39
+ /** @internal Snapshot raw rings; immutable descriptors retain their identity. */
40
+ export function copyTerrainCutoutRegion(region: TerrainCutoutRegion): TerrainCutoutRegion {
41
+ return getTerrainCutoutPlan(region)
42
+ ? region
43
+ : (region as readonly CutoutPoint[]).map(p => [p[0], p[1]] as const);
44
+ }
45
+ /** @internal Prepared shapes compare by identity; raw rings compare by value. */
46
+ export function sameTerrainCutoutRegion(a: TerrainCutoutRegion, b: TerrainCutoutRegion): boolean {
47
+ if (getTerrainCutoutPlan(a) || getTerrainCutoutPlan(b)) return a === b;
48
+ const aa = a as readonly CutoutPoint[],
49
+ bb = b as readonly CutoutPoint[];
50
+ return (
51
+ aa.length === bb.length &&
52
+ aa.every((p, i) => bb[i].length === 2 && p[0] === bb[i][0] && p[1] === bb[i][1])
53
+ );
54
+ }
@@ -0,0 +1,52 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {TerrainCutout, TerrainCutoutPiece} from './mesh-cutout';
6
+ import {createTerrainSkirt, type TerrainSkirtMesh, type TerrainSkirtOptions} from './mesh-skirts';
7
+
8
+ /** Select wall height or a local base, without allowing arbitrary edge selection. */
9
+ type WallOptions = Pick<TerrainSkirtOptions, 'maxVertices' | 'maxTriangles'> &
10
+ ({height: number; baseZ?: never} | {baseZ: number; height?: never});
11
+
12
+ /** Lift and wall settings for a terrain split. */
13
+ export type TerrainCutoutSkirtOptions = {
14
+ /** Amount added to the patch's local Z coordinates. Defaults to zero. */
15
+ lift?: number;
16
+ /** Wall options for the lifted patch. */
17
+ patch: WallOptions;
18
+ /** Wall options for the unchanged remainder. */
19
+ remainder: WallOptions;
20
+ };
21
+
22
+ /** Raised and stationary surfaces with optional visual skirts. */
23
+ export type SkirtedTerrainCutout = {
24
+ patch: {surface: TerrainCutoutPiece; skirt?: TerrainSkirtMesh};
25
+ remainder: {surface: TerrainCutoutPiece; skirt?: TerrainSkirtMesh};
26
+ };
27
+
28
+ /** Translate the patch and build both walls from the paired cut edges only. */
29
+ export function createTerrainCutoutSkirts(
30
+ cutout: TerrainCutout,
31
+ {lift = 0, patch, remainder}: TerrainCutoutSkirtOptions
32
+ ): SkirtedTerrainCutout {
33
+ if (!Number.isFinite(lift)) throw new RangeError('Invalid terrain cutout lift');
34
+ const positions = cutout.patch.positions.slice();
35
+ for (let i = 2; i < positions.length; i += 3) {
36
+ positions[i] += lift;
37
+ if (!Number.isFinite(positions[i])) throw new RangeError('Terrain cutout lift overflow');
38
+ }
39
+ return {
40
+ patch: skirtPiece({...cutout.patch, positions}, patch),
41
+ remainder: skirtPiece(cutout.remainder, remainder)
42
+ };
43
+ }
44
+
45
+ /** Compose on a nonempty paired boundary only. */
46
+ function skirtPiece(surface: TerrainCutoutPiece, options: WallOptions) {
47
+ if (!surface.cutEdges.length) return {surface};
48
+ return {
49
+ surface,
50
+ skirt: createTerrainSkirt(surface, {...options, edges: surface.cutEdges})
51
+ };
52
+ }
@@ -0,0 +1,125 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {HeightField} from './height-field';
6
+
7
+ /** Outlet and allocation policy for four-neighbor terrain conditioning. */
8
+ export type TerrainDepressionFillOptions = {
9
+ /** Valid row-major cell indices that can drain. Exterior and nodata are closed. */
10
+ outlets: readonly number[];
11
+ /** Maximum grid cells before allocating buffers. Defaults to 4,194,304. */
12
+ maxCells?: number;
13
+ };
14
+
15
+ /** Conditioned terrain and its outlet-connected drainage forest. */
16
+ export type TerrainDepressionFill = {
17
+ /** Derived field, including the original heights of outlet-disconnected cells. */
18
+ field: HeightField;
19
+ /** Next face neighbor toward an outlet, -1 at outlets, -2 for nodata or disconnected cells. */
20
+ receiver: Int32Array;
21
+ /** Number of valid cells with no face-connected path to an outlet. */
22
+ disconnectedCells: number;
23
+ };
24
+
25
+ /**
26
+ * Raise each outlet-connected cell to the lowest spill elevation needed to reach
27
+ * a declared outlet by face neighbors. The returned forest routes across flats.
28
+ * Nodata blocks flow and disconnected components retain their source heights.
29
+ * The source is immutable. Time is O(cells log cells) and storage is O(cells).
30
+ */
31
+ export function fillTerrainDepressions(
32
+ field: HeightField,
33
+ {outlets, maxCells = 4_194_304}: TerrainDepressionFillOptions
34
+ ): TerrainDepressionFill {
35
+ if (field.registration !== 'cell')
36
+ throw new Error('Terrain depression fill requires cell registration');
37
+ const {width, height} = field;
38
+ const count = width * height;
39
+ if (!Number.isSafeInteger(maxCells) || maxCells < 0 || count > maxCells || count > 0x7fffffff)
40
+ throw new RangeError('Terrain depression fill exceeds its cell budget');
41
+ if (!outlets.length) throw new RangeError('Terrain depression fill requires an outlet');
42
+ for (const i of outlets) {
43
+ if (
44
+ !Number.isInteger(i) ||
45
+ i < 0 ||
46
+ i >= count ||
47
+ field.getHeight(i % width, Math.floor(i / width)) === undefined
48
+ )
49
+ throw new RangeError('Terrain outlet must identify a valid cell');
50
+ }
51
+
52
+ const {heights, validity} = field.copyData();
53
+ const receiver = new Int32Array(count).fill(-2);
54
+ const heap = new Int32Array(count);
55
+ let size = 0;
56
+ let disconnectedCells = field.validCount;
57
+
58
+ /** Sort by spill elevation, then by cell index for reproducible flat routing. */
59
+ const before = (a: number, b: number) =>
60
+ heights[a] < heights[b] || (heights[a] === heights[b] && a < b);
61
+
62
+ /** Insert a newly reached cell. Its finalized spill height never changes. */
63
+ function push(cell: number): void {
64
+ let slot = size++;
65
+ while (slot > 0) {
66
+ const parent = Math.floor((slot - 1) / 2);
67
+ if (!before(cell, heap[parent])) break;
68
+ heap[slot] = heap[parent];
69
+ slot = parent;
70
+ }
71
+ heap[slot] = cell;
72
+ }
73
+
74
+ /** Remove the cell with the lowest known spill elevation. */
75
+ function pop(): number {
76
+ const first = heap[0];
77
+ const tail = heap[--size];
78
+ let slot = 0;
79
+ let child = 1;
80
+ while (child < size) {
81
+ if (child + 1 < size && before(heap[child + 1], heap[child])) child++;
82
+ if (!before(heap[child], tail)) break;
83
+ heap[slot] = heap[child];
84
+ slot = child;
85
+ child = slot * 2 + 1;
86
+ }
87
+ if (size) heap[slot] = tail;
88
+ return first;
89
+ }
90
+
91
+ /** First discovery from the minimum frontier finalizes the minimax path cost. */
92
+ function visit(cell: number, parent: number): void {
93
+ if (!validity[cell] || receiver[cell] !== -2) return;
94
+ receiver[cell] = parent;
95
+ disconnectedCells--;
96
+ if (parent >= 0) heights[cell] = Math.max(heights[cell], heights[parent]);
97
+ push(cell);
98
+ }
99
+
100
+ for (const outlet of outlets) visit(outlet, -1);
101
+ while (size) {
102
+ const cell = pop();
103
+ const column = cell % width;
104
+ if (column > 0) visit(cell - 1, cell);
105
+ if (column + 1 < width) visit(cell + 1, cell);
106
+ if (cell >= width) visit(cell - width, cell);
107
+ if (cell < count - width) visit(cell + width, cell);
108
+ }
109
+ return {
110
+ field: new HeightField({
111
+ width,
112
+ height,
113
+ heights,
114
+ validity,
115
+ origin: field.origin,
116
+ columnStep: field.columnStep,
117
+ rowStep: field.rowStep,
118
+ registration: field.registration,
119
+ diagonal: field.diagonal,
120
+ heightReference: field.heightReference
121
+ }),
122
+ receiver,
123
+ disconnectedCells
124
+ };
125
+ }