@math.gl/geospatial 5.0.0-beta.8 → 5.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (620) hide show
  1. package/README.md +3 -3
  2. package/dist/crs/crs-descriptor-types.d.ts +2 -1
  3. package/dist/crs/crs-descriptor-types.d.ts.map +1 -1
  4. package/dist/crs/index.cjs +54 -0
  5. package/dist/crs/index.cjs.map +2 -2
  6. package/dist/crs/index.d.ts +1 -0
  7. package/dist/crs/index.d.ts.map +1 -1
  8. package/dist/crs/index.js +1 -0
  9. package/dist/crs/index.js.map +1 -1
  10. package/dist/crs/spatial-reference-metadata.d.ts +20 -0
  11. package/dist/crs/spatial-reference-metadata.d.ts.map +1 -0
  12. package/dist/crs/spatial-reference-metadata.js +86 -0
  13. package/dist/crs/spatial-reference-metadata.js.map +1 -0
  14. package/dist/ellipsoid-helpers/ellipsoid-transform.d.ts +1 -1
  15. package/dist/ellipsoid-helpers/ellipsoid-transform.d.ts.map +1 -1
  16. package/dist/ellipsoid-helpers/ellipsoid-transform.js +2 -2
  17. package/dist/ellipsoid-helpers/ellipsoid-transform.js.map +1 -1
  18. package/dist/ellipsoid-helpers/scale-to-geodetic-surface.js +1 -1
  19. package/dist/ellipsoid-helpers/scale-to-geodetic-surface.js.map +1 -1
  20. package/dist/ellipsoid-helpers/tangent-plane-numerics.d.ts +1 -1
  21. package/dist/ellipsoid-helpers/tangent-plane-numerics.d.ts.map +1 -1
  22. package/dist/ellipsoid-tangent-plane.d.ts +2 -2
  23. package/dist/ellipsoid-tangent-plane.d.ts.map +1 -1
  24. package/dist/ellipsoid-tangent-plane.js +1 -1
  25. package/dist/ellipsoid-tangent-plane.js.map +1 -1
  26. package/dist/ellipsoid-transforms.d.ts +2 -2
  27. package/dist/ellipsoid-transforms.d.ts.map +1 -1
  28. package/dist/ellipsoid-transforms.js +1 -1
  29. package/dist/ellipsoid-transforms.js.map +1 -1
  30. package/dist/ellipsoid.d.ts +2 -2
  31. package/dist/ellipsoid.d.ts.map +1 -1
  32. package/dist/ellipsoid.js +2 -2
  33. package/dist/ellipsoid.js.map +1 -1
  34. package/dist/expressions.d.ts +1 -1
  35. package/dist/expressions.d.ts.map +1 -1
  36. package/dist/expressions.js +1 -1
  37. package/dist/expressions.js.map +1 -1
  38. package/dist/geodesic-buffer.d.ts +1 -1
  39. package/dist/geodesic-buffer.d.ts.map +1 -1
  40. package/dist/geodesic-path.d.ts +1 -1
  41. package/dist/geodesic-path.d.ts.map +1 -1
  42. package/dist/geometry-constructors.d.ts +6 -0
  43. package/dist/geometry-constructors.d.ts.map +1 -0
  44. package/dist/geometry-constructors.js +37 -0
  45. package/dist/geometry-constructors.js.map +1 -0
  46. package/dist/geometry-inspection.d.ts +8 -0
  47. package/dist/geometry-inspection.d.ts.map +1 -0
  48. package/dist/geometry-inspection.js +61 -0
  49. package/dist/geometry-inspection.js.map +1 -0
  50. package/dist/index.cjs +3773 -846
  51. package/dist/index.cjs.map +3 -3
  52. package/dist/index.d.ts +173 -0
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +115 -0
  55. package/dist/index.js.map +1 -1
  56. package/dist/line-simplification.d.ts +4 -0
  57. package/dist/line-simplification.d.ts.map +1 -0
  58. package/dist/line-simplification.js +83 -0
  59. package/dist/line-simplification.js.map +1 -0
  60. package/dist/linear-referencing.d.ts +6 -0
  61. package/dist/linear-referencing.d.ts.map +1 -0
  62. package/dist/linear-referencing.js +74 -0
  63. package/dist/linear-referencing.js.map +1 -0
  64. package/dist/lng-lat-rectangle.d.ts +1 -1
  65. package/dist/lng-lat-rectangle.d.ts.map +1 -1
  66. package/dist/lng-lat-rectangle.js +1 -1
  67. package/dist/lng-lat-rectangle.js.map +1 -1
  68. package/dist/local-reference-frame.d.ts +3 -3
  69. package/dist/local-reference-frame.d.ts.map +1 -1
  70. package/dist/local-reference-frame.js +2 -2
  71. package/dist/local-reference-frame.js.map +1 -1
  72. package/dist/make-obb-from-region.d.ts +1 -1
  73. package/dist/make-obb-from-region.d.ts.map +1 -1
  74. package/dist/make-obb-from-region.js +1 -1
  75. package/dist/make-obb-from-region.js.map +1 -1
  76. package/dist/maps/air-ocean-mesh.js +1 -1
  77. package/dist/maps/air-ocean-mesh.js.map +1 -1
  78. package/dist/maps/myriahedral/unfold.d.ts +1 -1
  79. package/dist/maps/myriahedral/unfold.d.ts.map +1 -1
  80. package/dist/maps/myriahedral/unfold.js +1 -1
  81. package/dist/maps/myriahedral/unfold.js.map +1 -1
  82. package/dist/maps/presets.cjs +6 -6
  83. package/dist/maps/presets.cjs.map +2 -2
  84. package/dist/maps.cjs +6 -6
  85. package/dist/maps.cjs.map +2 -2
  86. package/dist/projection/deformation.cjs +5 -5
  87. package/dist/projection/deformation.cjs.map +2 -2
  88. package/dist/projection/experimental/core.cjs +8 -4
  89. package/dist/projection/experimental/core.cjs.map +1 -1
  90. package/dist/projection/experimental/crs/spatial-reference.d.ts.map +1 -1
  91. package/dist/projection/experimental/crs/spatial-reference.js.map +1 -1
  92. package/dist/projection/experimental/crs/types.d.ts +1 -1
  93. package/dist/projection/experimental/crs/types.d.ts.map +1 -1
  94. package/dist/projection/experimental/crs-rendering-scale.d.ts.map +1 -1
  95. package/dist/projection/experimental/crs-rendering-scale.js +13 -2
  96. package/dist/projection/experimental/crs-rendering-scale.js.map +1 -1
  97. package/dist/projection/experimental/datum.js +1 -1
  98. package/dist/projection/experimental/datum.js.map +1 -1
  99. package/dist/projection/experimental/entries/projections/geocent.cjs +3 -3
  100. package/dist/projection/experimental/entries/projections/geocent.cjs.map +1 -1
  101. package/dist/projection/experimental/lazy-projections/aea.cjs +4 -1
  102. package/dist/projection/experimental/lazy-projections/aea.cjs.map +1 -1
  103. package/dist/projection/experimental/lazy-projections/aea.d.ts.map +1 -1
  104. package/dist/projection/experimental/lazy-projections/aea.js +4 -1
  105. package/dist/projection/experimental/lazy-projections/aea.js.map +1 -1
  106. package/dist/projection/experimental/lazy-projections/bonne.cjs +4 -1
  107. package/dist/projection/experimental/lazy-projections/bonne.cjs.map +1 -1
  108. package/dist/projection/experimental/lazy-projections/bonne.d.ts.map +1 -1
  109. package/dist/projection/experimental/lazy-projections/bonne.js +4 -1
  110. package/dist/projection/experimental/lazy-projections/bonne.js.map +1 -1
  111. package/dist/projection/experimental/lazy-projections/cass.cjs +4 -1
  112. package/dist/projection/experimental/lazy-projections/cass.cjs.map +1 -1
  113. package/dist/projection/experimental/lazy-projections/cass.d.ts.map +1 -1
  114. package/dist/projection/experimental/lazy-projections/cass.js +4 -1
  115. package/dist/projection/experimental/lazy-projections/cass.js.map +1 -1
  116. package/dist/projection/experimental/lazy-projections/eck6.cjs +4 -1
  117. package/dist/projection/experimental/lazy-projections/eck6.cjs.map +1 -1
  118. package/dist/projection/experimental/lazy-projections/eck6.d.ts.map +1 -1
  119. package/dist/projection/experimental/lazy-projections/eck6.js +4 -1
  120. package/dist/projection/experimental/lazy-projections/eck6.js.map +1 -1
  121. package/dist/projection/experimental/lazy-projections/eqdc.cjs +4 -1
  122. package/dist/projection/experimental/lazy-projections/eqdc.cjs.map +1 -1
  123. package/dist/projection/experimental/lazy-projections/eqdc.d.ts.map +1 -1
  124. package/dist/projection/experimental/lazy-projections/eqdc.js +4 -1
  125. package/dist/projection/experimental/lazy-projections/eqdc.js.map +1 -1
  126. package/dist/projection/experimental/lazy-projections/eqearth.cjs +4 -1
  127. package/dist/projection/experimental/lazy-projections/eqearth.cjs.map +1 -1
  128. package/dist/projection/experimental/lazy-projections/eqearth.d.ts.map +1 -1
  129. package/dist/projection/experimental/lazy-projections/eqearth.js +4 -1
  130. package/dist/projection/experimental/lazy-projections/eqearth.js.map +1 -1
  131. package/dist/projection/experimental/lazy-projections/equi.cjs +4 -1
  132. package/dist/projection/experimental/lazy-projections/equi.cjs.map +1 -1
  133. package/dist/projection/experimental/lazy-projections/equi.d.ts.map +1 -1
  134. package/dist/projection/experimental/lazy-projections/equi.js +4 -1
  135. package/dist/projection/experimental/lazy-projections/equi.js.map +1 -1
  136. package/dist/projection/experimental/lazy-projections/geocent.cjs +4 -1
  137. package/dist/projection/experimental/lazy-projections/geocent.cjs.map +1 -1
  138. package/dist/projection/experimental/lazy-projections/geocent.d.ts.map +1 -1
  139. package/dist/projection/experimental/lazy-projections/geocent.js +4 -1
  140. package/dist/projection/experimental/lazy-projections/geocent.js.map +1 -1
  141. package/dist/projection/experimental/lazy-projections/geos.cjs +4 -1
  142. package/dist/projection/experimental/lazy-projections/geos.cjs.map +1 -1
  143. package/dist/projection/experimental/lazy-projections/geos.d.ts.map +1 -1
  144. package/dist/projection/experimental/lazy-projections/geos.js +4 -1
  145. package/dist/projection/experimental/lazy-projections/geos.js.map +1 -1
  146. package/dist/projection/experimental/lazy-projections/gnom.cjs +4 -1
  147. package/dist/projection/experimental/lazy-projections/gnom.cjs.map +1 -1
  148. package/dist/projection/experimental/lazy-projections/gnom.d.ts.map +1 -1
  149. package/dist/projection/experimental/lazy-projections/gnom.js +4 -1
  150. package/dist/projection/experimental/lazy-projections/gnom.js.map +1 -1
  151. package/dist/projection/experimental/lazy-projections/index.cjs +100 -27
  152. package/dist/projection/experimental/lazy-projections/index.cjs.map +1 -1
  153. package/dist/projection/experimental/lazy-projections/krovak.cjs +4 -1
  154. package/dist/projection/experimental/lazy-projections/krovak.cjs.map +1 -1
  155. package/dist/projection/experimental/lazy-projections/krovak.d.ts.map +1 -1
  156. package/dist/projection/experimental/lazy-projections/krovak.js +4 -1
  157. package/dist/projection/experimental/lazy-projections/krovak.js.map +1 -1
  158. package/dist/projection/experimental/lazy-projections/merc.cjs +4 -1
  159. package/dist/projection/experimental/lazy-projections/merc.cjs.map +1 -1
  160. package/dist/projection/experimental/lazy-projections/merc.d.ts.map +1 -1
  161. package/dist/projection/experimental/lazy-projections/merc.js +4 -1
  162. package/dist/projection/experimental/lazy-projections/merc.js.map +1 -1
  163. package/dist/projection/experimental/lazy-projections/mill.cjs +4 -1
  164. package/dist/projection/experimental/lazy-projections/mill.cjs.map +1 -1
  165. package/dist/projection/experimental/lazy-projections/mill.d.ts.map +1 -1
  166. package/dist/projection/experimental/lazy-projections/mill.js +4 -1
  167. package/dist/projection/experimental/lazy-projections/mill.js.map +1 -1
  168. package/dist/projection/experimental/lazy-projections/moll.cjs +4 -1
  169. package/dist/projection/experimental/lazy-projections/moll.cjs.map +1 -1
  170. package/dist/projection/experimental/lazy-projections/moll.d.ts.map +1 -1
  171. package/dist/projection/experimental/lazy-projections/moll.js +4 -1
  172. package/dist/projection/experimental/lazy-projections/moll.js.map +1 -1
  173. package/dist/projection/experimental/lazy-projections/nzmg.cjs +4 -1
  174. package/dist/projection/experimental/lazy-projections/nzmg.cjs.map +1 -1
  175. package/dist/projection/experimental/lazy-projections/nzmg.d.ts.map +1 -1
  176. package/dist/projection/experimental/lazy-projections/nzmg.js +4 -1
  177. package/dist/projection/experimental/lazy-projections/nzmg.js.map +1 -1
  178. package/dist/projection/experimental/lazy-projections/omerc.cjs +4 -1
  179. package/dist/projection/experimental/lazy-projections/omerc.cjs.map +1 -1
  180. package/dist/projection/experimental/lazy-projections/omerc.d.ts.map +1 -1
  181. package/dist/projection/experimental/lazy-projections/omerc.js +4 -1
  182. package/dist/projection/experimental/lazy-projections/omerc.js.map +1 -1
  183. package/dist/projection/experimental/lazy-projections/ortho.cjs +4 -1
  184. package/dist/projection/experimental/lazy-projections/ortho.cjs.map +1 -1
  185. package/dist/projection/experimental/lazy-projections/ortho.d.ts.map +1 -1
  186. package/dist/projection/experimental/lazy-projections/ortho.js +4 -1
  187. package/dist/projection/experimental/lazy-projections/ortho.js.map +1 -1
  188. package/dist/projection/experimental/lazy-projections/poly.cjs +4 -1
  189. package/dist/projection/experimental/lazy-projections/poly.cjs.map +1 -1
  190. package/dist/projection/experimental/lazy-projections/poly.d.ts.map +1 -1
  191. package/dist/projection/experimental/lazy-projections/poly.js +4 -1
  192. package/dist/projection/experimental/lazy-projections/poly.js.map +1 -1
  193. package/dist/projection/experimental/lazy-projections/robin.cjs +4 -1
  194. package/dist/projection/experimental/lazy-projections/robin.cjs.map +1 -1
  195. package/dist/projection/experimental/lazy-projections/robin.d.ts.map +1 -1
  196. package/dist/projection/experimental/lazy-projections/robin.js +4 -1
  197. package/dist/projection/experimental/lazy-projections/robin.js.map +1 -1
  198. package/dist/projection/experimental/lazy-projections/sinu.cjs +4 -1
  199. package/dist/projection/experimental/lazy-projections/sinu.cjs.map +1 -1
  200. package/dist/projection/experimental/lazy-projections/sinu.d.ts.map +1 -1
  201. package/dist/projection/experimental/lazy-projections/sinu.js +4 -1
  202. package/dist/projection/experimental/lazy-projections/sinu.js.map +1 -1
  203. package/dist/projection/experimental/lazy-projections/stere.cjs +4 -1
  204. package/dist/projection/experimental/lazy-projections/stere.cjs.map +1 -1
  205. package/dist/projection/experimental/lazy-projections/stere.d.ts.map +1 -1
  206. package/dist/projection/experimental/lazy-projections/stere.js +4 -1
  207. package/dist/projection/experimental/lazy-projections/stere.js.map +1 -1
  208. package/dist/projection/experimental/lazy-projections/tpers.cjs +4 -1
  209. package/dist/projection/experimental/lazy-projections/tpers.cjs.map +1 -1
  210. package/dist/projection/experimental/lazy-projections/tpers.d.ts.map +1 -1
  211. package/dist/projection/experimental/lazy-projections/tpers.js +4 -1
  212. package/dist/projection/experimental/lazy-projections/tpers.js.map +1 -1
  213. package/dist/projection/experimental/lazy-projections/vandg.cjs +4 -1
  214. package/dist/projection/experimental/lazy-projections/vandg.cjs.map +1 -1
  215. package/dist/projection/experimental/lazy-projections/vandg.d.ts.map +1 -1
  216. package/dist/projection/experimental/lazy-projections/vandg.js +4 -1
  217. package/dist/projection/experimental/lazy-projections/vandg.js.map +1 -1
  218. package/dist/projection/experimental/spatial-deformation.js +1 -1
  219. package/dist/projection/experimental/spatial-deformation.js.map +1 -1
  220. package/dist/projection/index.cjs +8 -4
  221. package/dist/projection/index.cjs.map +1 -1
  222. package/dist/projection/index.d.ts.map +1 -1
  223. package/dist/projection/index.js.map +1 -1
  224. package/dist/projection/lib/projection.js.map +1 -1
  225. package/dist/projection/pipeline.cjs +3 -3
  226. package/dist/projection/pipeline.cjs.map +1 -1
  227. package/dist/projection/temporal.cjs +5 -5
  228. package/dist/projection/temporal.cjs.map +2 -2
  229. package/dist/projection/transform-analysis.cjs +3 -3
  230. package/dist/projection/transform-analysis.cjs.map +1 -1
  231. package/dist/rhumb-path.d.ts +1 -1
  232. package/dist/rhumb-path.d.ts.map +1 -1
  233. package/dist/spatial-planar-intersects.d.ts +4 -0
  234. package/dist/spatial-planar-intersects.d.ts.map +1 -0
  235. package/dist/spatial-planar-intersects.js +108 -0
  236. package/dist/spatial-planar-intersects.js.map +1 -0
  237. package/dist/spatial-planar.d.ts +16 -0
  238. package/dist/spatial-planar.d.ts.map +1 -0
  239. package/dist/spatial-planar.js +240 -0
  240. package/dist/spatial-planar.js.map +1 -0
  241. package/dist/spatial-sql.d.ts +45 -0
  242. package/dist/spatial-sql.d.ts.map +1 -0
  243. package/dist/spatial-sql.js +192 -0
  244. package/dist/spatial-sql.js.map +1 -0
  245. package/dist/st-functions.cjs +1616 -0
  246. package/dist/st-functions.cjs.map +6 -0
  247. package/dist/st-functions.d.ts +307 -0
  248. package/dist/st-functions.d.ts.map +1 -0
  249. package/dist/st-functions.js +593 -0
  250. package/dist/st-functions.js.map +1 -0
  251. package/dist/subdivide-globe-mesh.js +1 -1
  252. package/dist/subdivide-globe-mesh.js.map +1 -1
  253. package/dist/tasks/index.cjs +1266 -155
  254. package/dist/tasks/index.cjs.map +3 -3
  255. package/dist/tasks/index.d.ts +12 -0
  256. package/dist/tasks/index.d.ts.map +1 -1
  257. package/dist/tasks/index.js +26 -0
  258. package/dist/tasks/index.js.map +1 -1
  259. package/dist/tasks/terrain-coverage-worker.d.ts +2 -0
  260. package/dist/tasks/terrain-coverage-worker.d.ts.map +1 -0
  261. package/dist/tasks/terrain-coverage-worker.js +7 -0
  262. package/dist/tasks/terrain-coverage-worker.js.map +1 -0
  263. package/dist/tasks/terrain-coverage.d.ts +25 -0
  264. package/dist/tasks/terrain-coverage.d.ts.map +1 -0
  265. package/dist/tasks/terrain-coverage.js +15 -0
  266. package/dist/tasks/terrain-coverage.js.map +1 -0
  267. package/dist/tasks/terrain-residency-worker.d.ts +2 -0
  268. package/dist/tasks/terrain-residency-worker.d.ts.map +1 -0
  269. package/dist/tasks/terrain-residency-worker.js +7 -0
  270. package/dist/tasks/terrain-residency-worker.js.map +1 -0
  271. package/dist/tasks/terrain-residency.d.ts +73 -0
  272. package/dist/tasks/terrain-residency.d.ts.map +1 -0
  273. package/dist/tasks/terrain-residency.js +203 -0
  274. package/dist/tasks/terrain-residency.js.map +1 -0
  275. package/dist/terrain/breakline-mesh.d.ts +18 -0
  276. package/dist/terrain/breakline-mesh.d.ts.map +1 -0
  277. package/dist/terrain/breakline-mesh.js +126 -0
  278. package/dist/terrain/breakline-mesh.js.map +1 -0
  279. package/dist/terrain/breakline-preprocess.d.ts +11 -0
  280. package/dist/terrain/breakline-preprocess.d.ts.map +1 -0
  281. package/dist/terrain/breakline-preprocess.js +94 -0
  282. package/dist/terrain/breakline-preprocess.js.map +1 -0
  283. package/dist/terrain/continuous-mesh-error.d.ts +34 -0
  284. package/dist/terrain/continuous-mesh-error.d.ts.map +1 -0
  285. package/dist/terrain/continuous-mesh-error.js +221 -0
  286. package/dist/terrain/continuous-mesh-error.js.map +1 -0
  287. package/dist/terrain/cutout-polygons.d.ts +21 -0
  288. package/dist/terrain/cutout-polygons.d.ts.map +1 -0
  289. package/dist/terrain/cutout-polygons.js +172 -0
  290. package/dist/terrain/cutout-polygons.js.map +1 -0
  291. package/dist/terrain/cutout-region.d.ts +34 -0
  292. package/dist/terrain/cutout-region.d.ts.map +1 -0
  293. package/dist/terrain/cutout-region.js +33 -0
  294. package/dist/terrain/cutout-region.js.map +1 -0
  295. package/dist/terrain/cutout-skirts.d.ts +34 -0
  296. package/dist/terrain/cutout-skirts.d.ts.map +1 -0
  297. package/dist/terrain/cutout-skirts.js +29 -0
  298. package/dist/terrain/cutout-skirts.js.map +1 -0
  299. package/dist/terrain/depression-fill.d.ts +25 -0
  300. package/dist/terrain/depression-fill.d.ts.map +1 -0
  301. package/dist/terrain/depression-fill.js +106 -0
  302. package/dist/terrain/depression-fill.js.map +1 -0
  303. package/dist/terrain/geographic-cutout.d.ts +38 -0
  304. package/dist/terrain/geographic-cutout.d.ts.map +1 -0
  305. package/dist/terrain/geographic-cutout.js +120 -0
  306. package/dist/terrain/geographic-cutout.js.map +1 -0
  307. package/dist/terrain/geographic-lod-seams.d.ts +10 -0
  308. package/dist/terrain/geographic-lod-seams.d.ts.map +1 -0
  309. package/dist/terrain/geographic-lod-seams.js +100 -0
  310. package/dist/terrain/geographic-lod-seams.js.map +1 -0
  311. package/dist/terrain/geographic-neighbor.d.ts +18 -0
  312. package/dist/terrain/geographic-neighbor.d.ts.map +1 -0
  313. package/dist/terrain/geographic-neighbor.js +44 -0
  314. package/dist/terrain/geographic-neighbor.js.map +1 -0
  315. package/dist/terrain/geographic-poles.d.ts +24 -0
  316. package/dist/terrain/geographic-poles.d.ts.map +1 -0
  317. package/dist/terrain/geographic-poles.js +34 -0
  318. package/dist/terrain/geographic-poles.js.map +1 -0
  319. package/dist/terrain/geographic-seam.d.ts +21 -0
  320. package/dist/terrain/geographic-seam.d.ts.map +1 -0
  321. package/dist/terrain/geographic-seam.js +52 -0
  322. package/dist/terrain/geographic-seam.js.map +1 -0
  323. package/dist/terrain/hydrology.d.ts +42 -0
  324. package/dist/terrain/hydrology.d.ts.map +1 -0
  325. package/dist/terrain/hydrology.js +112 -0
  326. package/dist/terrain/hydrology.js.map +1 -0
  327. package/dist/terrain/index.cjs +3158 -213
  328. package/dist/terrain/index.cjs.map +3 -3
  329. package/dist/terrain/index.d.ts +32 -0
  330. package/dist/terrain/index.d.ts.map +1 -1
  331. package/dist/terrain/index.js +30 -0
  332. package/dist/terrain/index.js.map +1 -1
  333. package/dist/terrain/lod-screen-error.d.ts +28 -0
  334. package/dist/terrain/lod-screen-error.d.ts.map +1 -0
  335. package/dist/terrain/lod-screen-error.js +95 -0
  336. package/dist/terrain/lod-screen-error.js.map +1 -0
  337. package/dist/terrain/lod-select.d.ts +48 -0
  338. package/dist/terrain/lod-select.d.ts.map +1 -0
  339. package/dist/terrain/lod-select.js +73 -0
  340. package/dist/terrain/lod-select.js.map +1 -0
  341. package/dist/terrain/lod-stitch.d.ts +15 -0
  342. package/dist/terrain/lod-stitch.d.ts.map +1 -0
  343. package/dist/terrain/lod-stitch.js +64 -0
  344. package/dist/terrain/lod-stitch.js.map +1 -0
  345. package/dist/terrain/mesh-coverage.d.ts +35 -0
  346. package/dist/terrain/mesh-coverage.d.ts.map +1 -0
  347. package/dist/terrain/mesh-coverage.js +186 -0
  348. package/dist/terrain/mesh-coverage.js.map +1 -0
  349. package/dist/terrain/mesh-cutout.d.ts +45 -0
  350. package/dist/terrain/mesh-cutout.d.ts.map +1 -0
  351. package/dist/terrain/mesh-cutout.js +336 -0
  352. package/dist/terrain/mesh-cutout.js.map +1 -0
  353. package/dist/terrain/mesh-regions-data.d.ts +2 -2
  354. package/dist/terrain/mesh-regions-data.d.ts.map +1 -1
  355. package/dist/terrain/mesh-regions-data.js +20 -10
  356. package/dist/terrain/mesh-regions-data.js.map +1 -1
  357. package/dist/terrain/mesh-skirts.d.ts +8 -2
  358. package/dist/terrain/mesh-skirts.d.ts.map +1 -1
  359. package/dist/terrain/mesh-skirts.js +5 -4
  360. package/dist/terrain/mesh-skirts.js.map +1 -1
  361. package/dist/terrain/mixed-halo-update.d.ts.map +1 -1
  362. package/dist/terrain/mixed-halo-update.js +138 -26
  363. package/dist/terrain/mixed-halo-update.js.map +1 -1
  364. package/dist/terrain/mixed-vertex-halos.d.ts +34 -1
  365. package/dist/terrain/mixed-vertex-halos.d.ts.map +1 -1
  366. package/dist/terrain/mixed-vertex-halos.js +98 -43
  367. package/dist/terrain/mixed-vertex-halos.js.map +1 -1
  368. package/dist/terrain/regional-viewshed.d.ts +55 -0
  369. package/dist/terrain/regional-viewshed.d.ts.map +1 -0
  370. package/dist/terrain/regional-viewshed.js +119 -0
  371. package/dist/terrain/regional-viewshed.js.map +1 -0
  372. package/dist/terrain/surface.d.ts +1 -1
  373. package/dist/terrain/surface.d.ts.map +1 -1
  374. package/dist/terrain/surface.js +1 -1
  375. package/dist/terrain/surface.js.map +1 -1
  376. package/dist/terrain/sweep-capsule.d.ts +27 -0
  377. package/dist/terrain/sweep-capsule.d.ts.map +1 -0
  378. package/dist/terrain/sweep-capsule.js +104 -0
  379. package/dist/terrain/sweep-capsule.js.map +1 -0
  380. package/dist/terrain/sweep-cylinder.d.ts +16 -0
  381. package/dist/terrain/sweep-cylinder.d.ts.map +1 -0
  382. package/dist/terrain/sweep-cylinder.js +52 -0
  383. package/dist/terrain/sweep-cylinder.js.map +1 -0
  384. package/dist/terrain/sweep-plane.d.ts +9 -0
  385. package/dist/terrain/sweep-plane.d.ts.map +1 -0
  386. package/dist/terrain/sweep-plane.js +52 -0
  387. package/dist/terrain/sweep-plane.js.map +1 -0
  388. package/dist/terrain/sweep-polytope.d.ts +42 -0
  389. package/dist/terrain/sweep-polytope.d.ts.map +1 -0
  390. package/dist/terrain/sweep-polytope.js +189 -0
  391. package/dist/terrain/sweep-polytope.js.map +1 -0
  392. package/dist/terrain/sweep-rotating-capsule.d.ts +17 -0
  393. package/dist/terrain/sweep-rotating-capsule.d.ts.map +1 -0
  394. package/dist/terrain/sweep-rotating-capsule.js +118 -0
  395. package/dist/terrain/sweep-rotating-capsule.js.map +1 -0
  396. package/dist/terrain/sweep-rotation.d.ts +35 -0
  397. package/dist/terrain/sweep-rotation.d.ts.map +1 -0
  398. package/dist/terrain/sweep-rotation.js +114 -0
  399. package/dist/terrain/sweep-rotation.js.map +1 -0
  400. package/dist/terrain/sweep-sphere.d.ts +27 -0
  401. package/dist/terrain/sweep-sphere.d.ts.map +1 -0
  402. package/dist/terrain/sweep-sphere.js +69 -0
  403. package/dist/terrain/sweep-sphere.js.map +1 -0
  404. package/dist/terrain/tile-cutout-update.d.ts +73 -0
  405. package/dist/terrain/tile-cutout-update.d.ts.map +1 -0
  406. package/dist/terrain/tile-cutout-update.js +181 -0
  407. package/dist/terrain/tile-cutout-update.js.map +1 -0
  408. package/dist/terrain/tile-cutout.d.ts +33 -0
  409. package/dist/terrain/tile-cutout.d.ts.map +1 -0
  410. package/dist/terrain/tile-cutout.js +93 -0
  411. package/dist/terrain/tile-cutout.js.map +1 -0
  412. package/dist/terrain/valid-domain-mesh.d.ts +29 -0
  413. package/dist/terrain/valid-domain-mesh.d.ts.map +1 -0
  414. package/dist/terrain/valid-domain-mesh.js +183 -0
  415. package/dist/terrain/valid-domain-mesh.js.map +1 -0
  416. package/dist/terrain/valid-domain-regions.d.ts +16 -0
  417. package/dist/terrain/valid-domain-regions.d.ts.map +1 -0
  418. package/dist/terrain/valid-domain-regions.js +19 -0
  419. package/dist/terrain/valid-domain-regions.js.map +1 -0
  420. package/dist/terrain/watershed-accumulation.d.ts +20 -0
  421. package/dist/terrain/watershed-accumulation.d.ts.map +1 -0
  422. package/dist/terrain/watershed-accumulation.js +53 -0
  423. package/dist/terrain/watershed-accumulation.js.map +1 -0
  424. package/dist/triaxial.d.ts +1 -1
  425. package/dist/triaxial.d.ts.map +1 -1
  426. package/dist/turf-expressions.cjs +1997 -0
  427. package/dist/turf-expressions.cjs.map +6 -0
  428. package/dist/turf-expressions.d.ts +3 -0
  429. package/dist/turf-expressions.d.ts.map +1 -0
  430. package/dist/turf-expressions.js +7 -0
  431. package/dist/turf-expressions.js.map +1 -0
  432. package/dist/turf-functions.cjs +743 -0
  433. package/dist/turf-functions.cjs.map +6 -0
  434. package/dist/turf-functions.d.ts +90 -0
  435. package/dist/turf-functions.d.ts.map +1 -0
  436. package/dist/{turf/expressions.js → turf-functions.js} +51 -5
  437. package/dist/turf-functions.js.map +1 -0
  438. package/dist/turf.cjs +25 -25
  439. package/dist/turf.cjs.map +2 -2
  440. package/dist/turf.d.ts +1 -1
  441. package/dist/turf.d.ts.map +1 -1
  442. package/dist/turf.js +2 -2
  443. package/dist/turf.js.map +1 -1
  444. package/dist/type-utils.d.ts +1 -1
  445. package/dist/type-utils.d.ts.map +1 -1
  446. package/dist/type-utils.js +1 -1
  447. package/dist/type-utils.js.map +1 -1
  448. package/dist/web-mercator/assert.d.ts +2 -0
  449. package/dist/web-mercator/assert.d.ts.map +1 -0
  450. package/dist/web-mercator/assert.js +12 -0
  451. package/dist/web-mercator/assert.js.map +1 -0
  452. package/dist/web-mercator/fit-bounds.d.ts +52 -0
  453. package/dist/web-mercator/fit-bounds.d.ts.map +1 -0
  454. package/dist/web-mercator/fit-bounds.js +70 -0
  455. package/dist/web-mercator/fit-bounds.js.map +1 -0
  456. package/dist/web-mercator/fly-to-viewport.d.ts +19 -0
  457. package/dist/web-mercator/fly-to-viewport.d.ts.map +1 -0
  458. package/dist/web-mercator/fly-to-viewport.js +94 -0
  459. package/dist/web-mercator/fly-to-viewport.js.map +1 -0
  460. package/dist/web-mercator/get-bounds.d.ts +3 -0
  461. package/dist/web-mercator/get-bounds.d.ts.map +1 -0
  462. package/dist/web-mercator/get-bounds.js +56 -0
  463. package/dist/web-mercator/get-bounds.js.map +1 -0
  464. package/dist/web-mercator/index.cjs +705 -0
  465. package/dist/web-mercator/index.cjs.map +6 -0
  466. package/dist/web-mercator/index.d.ts +14 -0
  467. package/dist/web-mercator/index.d.ts.map +1 -0
  468. package/dist/web-mercator/index.js +14 -0
  469. package/dist/web-mercator/index.js.map +1 -0
  470. package/dist/web-mercator/math-utils.d.ts +7 -0
  471. package/dist/web-mercator/math-utils.d.ts.map +1 -0
  472. package/dist/web-mercator/math-utils.js +30 -0
  473. package/dist/web-mercator/math-utils.js.map +1 -0
  474. package/dist/web-mercator/mercator-meters.d.ts +29 -0
  475. package/dist/web-mercator/mercator-meters.d.ts.map +1 -0
  476. package/dist/web-mercator/mercator-meters.js +61 -0
  477. package/dist/web-mercator/mercator-meters.js.map +1 -0
  478. package/dist/web-mercator/normalize-viewport-props.d.ts +16 -0
  479. package/dist/web-mercator/normalize-viewport-props.d.ts.map +1 -0
  480. package/dist/web-mercator/normalize-viewport-props.js +45 -0
  481. package/dist/web-mercator/normalize-viewport-props.js.map +1 -0
  482. package/dist/web-mercator/web-mercator-utils.d.ts +192 -0
  483. package/dist/web-mercator/web-mercator-utils.d.ts.map +1 -0
  484. package/dist/web-mercator/web-mercator-utils.js +321 -0
  485. package/dist/web-mercator/web-mercator-utils.js.map +1 -0
  486. package/dist/web-mercator/web-mercator-viewport.d.ts +177 -0
  487. package/dist/web-mercator/web-mercator-viewport.d.ts.map +1 -0
  488. package/dist/web-mercator/web-mercator-viewport.js +276 -0
  489. package/dist/web-mercator/web-mercator-viewport.js.map +1 -0
  490. package/dist/web-mercator.d.ts +1 -1
  491. package/dist/web-mercator.d.ts.map +1 -1
  492. package/dist/web-mercator.js +1 -1
  493. package/dist/web-mercator.js.map +1 -1
  494. package/package.json +35 -462
  495. package/src/crs/crs-descriptor-types.ts +2 -1
  496. package/src/crs/index.ts +7 -0
  497. package/src/crs/spatial-reference-metadata.ts +118 -0
  498. package/src/ellipsoid-helpers/ellipsoid-transform.ts +3 -3
  499. package/src/ellipsoid-helpers/scale-to-geodetic-surface.ts +1 -1
  500. package/src/ellipsoid-helpers/tangent-plane-numerics.ts +1 -1
  501. package/src/ellipsoid-tangent-plane.ts +2 -2
  502. package/src/ellipsoid-transforms.ts +2 -2
  503. package/src/ellipsoid.ts +7 -3
  504. package/src/expressions.ts +2 -2
  505. package/src/geodesic-buffer.ts +1 -1
  506. package/src/geodesic-path.ts +1 -1
  507. package/src/geometry-constructors.ts +36 -0
  508. package/src/geometry-inspection.ts +66 -0
  509. package/src/index.ts +314 -4
  510. package/src/line-simplification.ts +97 -0
  511. package/src/linear-referencing.ts +94 -0
  512. package/src/lng-lat-rectangle.ts +1 -1
  513. package/src/local-reference-frame.ts +4 -4
  514. package/src/make-obb-from-region.ts +9 -1
  515. package/src/maps/air-ocean-mesh.ts +1 -1
  516. package/src/maps/myriahedral/unfold.ts +1 -1
  517. package/src/projection/experimental/crs/spatial-reference.ts +1 -6
  518. package/src/projection/experimental/crs/types.ts +2 -2
  519. package/src/projection/experimental/crs/wkt.ts +1 -1
  520. package/src/projection/experimental/crs-descriptor.ts +1 -1
  521. package/src/projection/experimental/crs-rendering-scale.ts +16 -4
  522. package/src/projection/experimental/datum.ts +1 -1
  523. package/src/projection/experimental/lazy-projections/aea.ts +4 -1
  524. package/src/projection/experimental/lazy-projections/bonne.ts +4 -1
  525. package/src/projection/experimental/lazy-projections/cass.ts +4 -1
  526. package/src/projection/experimental/lazy-projections/eck6.ts +4 -1
  527. package/src/projection/experimental/lazy-projections/eqdc.ts +4 -1
  528. package/src/projection/experimental/lazy-projections/eqearth.ts +4 -1
  529. package/src/projection/experimental/lazy-projections/equi.ts +4 -1
  530. package/src/projection/experimental/lazy-projections/geocent.ts +4 -1
  531. package/src/projection/experimental/lazy-projections/geos.ts +4 -1
  532. package/src/projection/experimental/lazy-projections/gnom.ts +4 -1
  533. package/src/projection/experimental/lazy-projections/krovak.ts +4 -1
  534. package/src/projection/experimental/lazy-projections/merc.ts +4 -1
  535. package/src/projection/experimental/lazy-projections/mill.ts +4 -1
  536. package/src/projection/experimental/lazy-projections/moll.ts +4 -1
  537. package/src/projection/experimental/lazy-projections/nzmg.ts +4 -1
  538. package/src/projection/experimental/lazy-projections/omerc.ts +4 -1
  539. package/src/projection/experimental/lazy-projections/ortho.ts +4 -1
  540. package/src/projection/experimental/lazy-projections/poly.ts +4 -1
  541. package/src/projection/experimental/lazy-projections/robin.ts +4 -1
  542. package/src/projection/experimental/lazy-projections/sinu.ts +4 -1
  543. package/src/projection/experimental/lazy-projections/stere.ts +4 -1
  544. package/src/projection/experimental/lazy-projections/tpers.ts +4 -1
  545. package/src/projection/experimental/lazy-projections/vandg.ts +4 -1
  546. package/src/projection/experimental/spatial-deformation.ts +1 -1
  547. package/src/projection/index.ts +1 -1
  548. package/src/projection/lib/projection.ts +1 -1
  549. package/src/rhumb-path.ts +1 -1
  550. package/src/spatial-planar-intersects.ts +134 -0
  551. package/src/spatial-planar.ts +266 -0
  552. package/src/spatial-sql.ts +276 -0
  553. package/src/st-functions.ts +852 -0
  554. package/src/subdivide-globe-mesh.ts +1 -1
  555. package/src/tasks/index.ts +34 -0
  556. package/src/tasks/terrain-coverage-worker.ts +6 -0
  557. package/src/tasks/terrain-coverage.ts +25 -0
  558. package/src/tasks/terrain-residency-worker.ts +6 -0
  559. package/src/tasks/terrain-residency.ts +250 -0
  560. package/src/terrain/breakline-mesh.ts +164 -0
  561. package/src/terrain/breakline-preprocess.ts +106 -0
  562. package/src/terrain/cdt2d.d.ts +10 -0
  563. package/src/terrain/continuous-mesh-error.ts +321 -0
  564. package/src/terrain/cutout-polygons.ts +202 -0
  565. package/src/terrain/cutout-region.ts +54 -0
  566. package/src/terrain/cutout-skirts.ts +52 -0
  567. package/src/terrain/depression-fill.ts +125 -0
  568. package/src/terrain/geographic-cutout.ts +154 -0
  569. package/src/terrain/geographic-lod-seams.ts +109 -0
  570. package/src/terrain/geographic-neighbor.ts +58 -0
  571. package/src/terrain/geographic-poles.ts +52 -0
  572. package/src/terrain/geographic-seam.ts +73 -0
  573. package/src/terrain/hydrology.ts +149 -0
  574. package/src/terrain/index.ts +160 -0
  575. package/src/terrain/lod-screen-error.ts +128 -0
  576. package/src/terrain/lod-select.ts +129 -0
  577. package/src/terrain/lod-stitch.ts +88 -0
  578. package/src/terrain/mesh-coverage.ts +215 -0
  579. package/src/terrain/mesh-cutout.ts +420 -0
  580. package/src/terrain/mesh-regions-data.ts +21 -13
  581. package/src/terrain/mesh-skirts.ts +10 -7
  582. package/src/terrain/mixed-halo-update.ts +147 -25
  583. package/src/terrain/mixed-vertex-halos.ts +125 -55
  584. package/src/terrain/regional-viewshed.ts +177 -0
  585. package/src/terrain/surface.ts +1 -1
  586. package/src/terrain/sweep-capsule.ts +148 -0
  587. package/src/terrain/sweep-cylinder.ts +64 -0
  588. package/src/terrain/sweep-plane.ts +61 -0
  589. package/src/terrain/sweep-polytope.ts +253 -0
  590. package/src/terrain/sweep-rotating-capsule.ts +139 -0
  591. package/src/terrain/sweep-rotation.ts +149 -0
  592. package/src/terrain/sweep-sphere.ts +100 -0
  593. package/src/terrain/tile-cutout-update.ts +293 -0
  594. package/src/terrain/tile-cutout.ts +123 -0
  595. package/src/terrain/valid-domain-mesh.ts +221 -0
  596. package/src/terrain/valid-domain-regions.ts +41 -0
  597. package/src/terrain/watershed-accumulation.ts +67 -0
  598. package/src/triaxial.ts +1 -1
  599. package/src/turf-expressions.ts +7 -0
  600. package/src/{turf/expressions.ts → turf-functions.ts} +121 -6
  601. package/src/turf.ts +3 -7
  602. package/src/type-utils.ts +2 -2
  603. package/src/web-mercator/assert.ts +11 -0
  604. package/src/web-mercator/fit-bounds.ts +132 -0
  605. package/src/web-mercator/fly-to-viewport.ts +157 -0
  606. package/src/web-mercator/get-bounds.ts +62 -0
  607. package/src/web-mercator/index.ts +49 -0
  608. package/src/web-mercator/math-utils.ts +35 -0
  609. package/src/web-mercator/mercator-meters.ts +83 -0
  610. package/src/web-mercator/normalize-viewport-props.ts +58 -0
  611. package/src/web-mercator/web-mercator-utils.ts +468 -0
  612. package/src/web-mercator/web-mercator-viewport.ts +406 -0
  613. package/src/web-mercator.ts +1 -1
  614. package/dist/projection/experimental/index.cjs +0 -11707
  615. package/dist/projection/experimental/index.cjs.map +0 -6
  616. package/dist/turf/expressions.cjs +0 -87
  617. package/dist/turf/expressions.cjs.map +0 -6
  618. package/dist/turf/expressions.d.ts +0 -24
  619. package/dist/turf/expressions.d.ts.map +0 -1
  620. package/dist/turf/expressions.js.map +0 -1
@@ -0,0 +1,215 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {HeightField} from './height-field';
6
+
7
+ type Point = readonly [number, number];
8
+ type Edge = {a: number; b: number; weight: number};
9
+
10
+ /** Horizontal triangle geometry in the field's fractional sample coordinates. */
11
+ export type TerrainCoverageMesh = {
12
+ gridCoordinates: ArrayLike<number>;
13
+ indices: ArrayLike<number>;
14
+ };
15
+
16
+ export type TerrainMeshCoverage = {
17
+ status: 'certified' | 'mismatch' | 'budget-exhausted';
18
+ /** Nonzero boundary intervals of mesh multiplicity minus reference multiplicity. */
19
+ unmatchedSegments: number;
20
+ witness: {start: Point; end: Point; multiplicityJump: number} | null;
21
+ /** Candidate triangles plus reference half cells examined. */
22
+ trianglesVisited: number;
23
+ /** Edges remaining after cancellation of equal endpoints. */
24
+ residualEdges: number;
25
+ };
26
+
27
+ function gcd(a: bigint, b: bigint): bigint {
28
+ if (a < 0n) a = -a;
29
+ if (b < 0n) b = -b;
30
+ while (b !== 0n) [a, b] = [b, a % b];
31
+ return a;
32
+ }
33
+
34
+ /**
35
+ * Certify that mesh multiplicity is one on the valid raster domain and zero outside,
36
+ * almost everywhere in XY. Coincident and subdivided edges are allowed.
37
+ * The reference is either independently valid triangles or four-corner-valid cells.
38
+ * An explicit reference mesh must tile the intended domain once.
39
+ * The result says nothing about heights or zero-area boundary features.
40
+ * Exact arithmetic applies to the supplied binary64 coordinates, without snapping.
41
+ */
42
+ export function certifyTerrainMeshCoverage(
43
+ field: HeightField,
44
+ mesh: TerrainCoverageMesh,
45
+ options: {reference?: 'triangle' | 'bilinear' | TerrainCoverageMesh; maxTriangles?: number} = {}
46
+ ): TerrainMeshCoverage {
47
+ const {reference = 'triangle', maxTriangles = 2_000_000} = options;
48
+ const referenceMesh = typeof reference === 'object' ? reference : null;
49
+ const validShape = (input: TerrainCoverageMesh) =>
50
+ input.indices.length % 3 === 0 && input.gridCoordinates.length % 2 === 0;
51
+ if (
52
+ !Number.isSafeInteger(maxTriangles) ||
53
+ maxTriangles < 1 ||
54
+ (!referenceMesh && reference !== 'triangle' && reference !== 'bilinear') ||
55
+ !validShape(mesh) ||
56
+ (referenceMesh && !validShape(referenceMesh))
57
+ )
58
+ throw new Error('Invalid terrain coverage input');
59
+
60
+ const trianglesVisited =
61
+ mesh.indices.length / 3 +
62
+ (referenceMesh ? referenceMesh.indices.length / 3 : 2 * (field.width - 1) * (field.height - 1));
63
+ if (trianglesVisited > maxTriangles) {
64
+ return {
65
+ status: 'budget-exhausted',
66
+ unmatchedSegments: 0,
67
+ witness: null,
68
+ trianglesVisited: 0,
69
+ residualEdges: 0
70
+ };
71
+ }
72
+
73
+ // Every finite binary64 value is an integer multiple of 2^-1074.
74
+ const bits = new DataView(new ArrayBuffer(8));
75
+ function exact(value: number): bigint {
76
+ bits.setFloat64(0, value);
77
+ const raw = bits.getBigUint64(0);
78
+ const exponent = Number((raw >> 52n) & 2047n);
79
+ const fraction = raw & ((1n << 52n) - 1n);
80
+ const integer = exponent === 0 ? fraction : ((1n << 52n) | fraction) << BigInt(exponent - 1);
81
+ return value < 0 ? -integer : integer;
82
+ }
83
+
84
+ const vertices: Point[] = [];
85
+ const vertexIds = new Map<string, number>();
86
+ const edges = new Map<number | string, Edge>();
87
+ function vertex(x: number, y: number): number {
88
+ if (!Number.isFinite(x) || !Number.isFinite(y))
89
+ throw new Error('Nonfinite coverage coordinate');
90
+ const key = `${x},${y}`;
91
+ const previous = vertexIds.get(key);
92
+ if (previous !== undefined) return previous;
93
+ const id = vertices.length;
94
+ vertices.push([x, y]);
95
+ vertexIds.set(key, id);
96
+ return id;
97
+ }
98
+ function edge(a: number, b: number, weight: number): void {
99
+ if (a > b) {
100
+ [a, b] = [b, a];
101
+ weight = -weight;
102
+ }
103
+ // Pack two 26-bit vertex IDs into an exactly representable number on ordinary workloads.
104
+ const key = b < 2 ** 26 ? a * 2 ** 26 + b : `${a},${b}`;
105
+ const sum = (edges.get(key)?.weight ?? 0) + weight;
106
+ if (sum === 0) edges.delete(key);
107
+ else edges.set(key, {a, b, weight: sum});
108
+ }
109
+ function triangle(a: number, b: number, c: number, weight: number): void {
110
+ edge(a, b, weight);
111
+ edge(b, c, weight);
112
+ edge(c, a, weight);
113
+ }
114
+ function addMesh({indices, gridCoordinates}: TerrainCoverageMesh, weight: number): void {
115
+ for (let i = 0; i < indices.length; i += 3) {
116
+ const ids = [indices[i], indices[i + 1], indices[i + 2]].map(id => {
117
+ if (!Number.isSafeInteger(id) || id < 0 || id >= gridCoordinates.length / 2)
118
+ throw new Error('Invalid coverage vertex index');
119
+ return vertex(gridCoordinates[id * 2], gridCoordinates[id * 2 + 1]);
120
+ });
121
+ const [a, b, c] = ids.map(id => vertices[id]);
122
+ const left = (b[0] - a[0]) * (c[1] - a[1]);
123
+ const right = (b[1] - a[1]) * (c[0] - a[0]);
124
+ const det = left - right;
125
+ const limit = 8 * Number.EPSILON * (Math.abs(left) + Math.abs(right)) + 8 * Number.MIN_VALUE;
126
+ let sign = Math.sign(det);
127
+ if (!Number.isFinite(det) || Math.abs(det) <= limit) {
128
+ const [ax, ay] = a.map(exact),
129
+ [bx, by] = b.map(exact),
130
+ [cx, cy] = c.map(exact);
131
+ const determinant = (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);
132
+ sign = determinant > 0n ? 1 : determinant < 0n ? -1 : 0;
133
+ }
134
+ if (!sign) throw new Error('Degenerate coverage triangle');
135
+ triangle(ids[0], ids[1], ids[2], weight * sign);
136
+ }
137
+ }
138
+ addMesh(mesh, 1);
139
+ if (referenceMesh) addMesh(referenceMesh, -1);
140
+ else
141
+ for (let y = 0; y < field.height - 1; y++) {
142
+ for (let x = 0; x < field.width - 1; x++) {
143
+ const valid = [
144
+ field.getHeight(x, y),
145
+ field.getHeight(x + 1, y),
146
+ field.getHeight(x, y + 1),
147
+ field.getHeight(x + 1, y + 1)
148
+ ].map(z => z !== undefined);
149
+ if (reference === 'bilinear' && !valid.every(Boolean)) continue;
150
+ const corners: Point[] = [
151
+ [x, y],
152
+ [x + 1, y],
153
+ [x, y + 1],
154
+ [x + 1, y + 1]
155
+ ];
156
+ const faces =
157
+ field.diagonal === '00-11'
158
+ ? [
159
+ [0, 1, 3],
160
+ [0, 3, 2]
161
+ ]
162
+ : [
163
+ [0, 1, 2],
164
+ [1, 3, 2]
165
+ ];
166
+ for (const [a, b, c] of faces) {
167
+ if (!valid[a] || !valid[b] || !valid[c]) continue;
168
+ triangle(vertex(...corners[a]), vertex(...corners[b]), vertex(...corners[c]), -1);
169
+ }
170
+ }
171
+ }
172
+
173
+ // A compactly supported triangle multiplicity is uniquely determined by its oriented
174
+ // boundary. Group collinear residual edges to cancel differently subdivided boundaries.
175
+ const lines = new Map<string, Map<number, {point: Point; delta: number}>>();
176
+ for (const {a, b, weight} of edges.values()) {
177
+ const p = vertices[a],
178
+ q = vertices[b];
179
+ const [x, y] = p.map(exact),
180
+ [u, v] = q.map(exact);
181
+ const divisor = gcd(u - x, v - y);
182
+ let dx = (u - x) / divisor,
183
+ dy = (v - y) / divisor;
184
+ if (dx < 0n || (dx === 0n && dy < 0n)) [dx, dy] = [-dx, -dy];
185
+ const key = `${dx},${dy},${dx * y - dy * x}`;
186
+ let events = lines.get(key);
187
+ if (!events) {
188
+ events = new Map();
189
+ lines.set(key, events);
190
+ }
191
+ const axis = dx === 0n ? 1 : 0;
192
+ const delta = weight;
193
+ events.set(p[axis], {point: p, delta: (events.get(p[axis])?.delta ?? 0) + delta});
194
+ events.set(q[axis], {point: q, delta: (events.get(q[axis])?.delta ?? 0) - delta});
195
+ }
196
+ let unmatchedSegments = 0;
197
+ let witness: TerrainMeshCoverage['witness'] = null;
198
+ for (const events of lines.values()) {
199
+ const sorted = [...events].sort(([a], [b]) => a - b);
200
+ let jump = 0;
201
+ for (let i = 0; i + 1 < sorted.length; i++) {
202
+ jump += sorted[i][1].delta;
203
+ if (!jump) continue;
204
+ unmatchedSegments++;
205
+ witness ??= {start: sorted[i][1].point, end: sorted[i + 1][1].point, multiplicityJump: jump};
206
+ }
207
+ }
208
+ return {
209
+ status: unmatchedSegments ? 'mismatch' : 'certified',
210
+ unmatchedSegments,
211
+ witness,
212
+ trianglesVisited,
213
+ residualEdges: edges.size
214
+ };
215
+ }
@@ -0,0 +1,420 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {getTerrainCutoutPlan, type TerrainCutoutRegion} from './cutout-region';
6
+
7
+ type XY = readonly [number, number];
8
+ type XYZ = readonly [number, number, number];
9
+ type Face = [number, number, number];
10
+ type Edge = [number, number];
11
+
12
+ /** Indexed upward-facing terrain in a shared local Cartesian frame. */
13
+ export type TerrainCutoutInput = {
14
+ positions: Float32Array | Float64Array;
15
+ indices: Uint16Array | Uint32Array;
16
+ };
17
+
18
+ /** A detached surface with interpolation provenance in the original mesh. */
19
+ export type TerrainCutoutPiece = {
20
+ positions: Float64Array;
21
+ indices: Uint32Array;
22
+ /** Input triangle index for each output vertex. */
23
+ sourceTriangles: Uint32Array;
24
+ /** Three barycentric weights per output vertex in input triangle order. */
25
+ sourceWeights: Float64Array;
26
+ /** Input triangle index for each output triangle. */
27
+ sourceFaces: Uint32Array;
28
+ /** Directed boundary edges paired with the other piece in reverse order. */
29
+ cutEdges: Uint32Array;
30
+ /** Input polygon index per output face; 0 for raw convex rings, 0xffffffff for remainder. */
31
+ polygonIndices: Uint32Array;
32
+ /** Patch polygon index per directed cut edge, also present on the paired remainder edge. */
33
+ cutPolygonIndices: Uint32Array;
34
+ };
35
+
36
+ /** Bounds for the splitter's working storage and pair/fragment checks. */
37
+ export type TerrainCutoutOptions = {
38
+ /** Maximum candidate topology checks and clipping vertex visits. */
39
+ maxWork?: number;
40
+ /** Maximum working vertices and, independently, total output vertices. */
41
+ maxVertices?: number;
42
+ /** Maximum intermediate fragments and, independently, total output triangles. */
43
+ maxTriangles?: number;
44
+ };
45
+
46
+ /** Both sides of a terrain cut, with matching directed edges along the opening. */
47
+ export type TerrainCutout = {patch: TerrainCutoutPiece; remainder: TerrainCutoutPiece};
48
+
49
+ type Fragment = {ids: number[]; inside: boolean};
50
+ /** Edge incidence and owning polygon while assembling one output piece. */
51
+ type Boundary = {
52
+ /** Directed output vertex IDs. */
53
+ edge: Edge;
54
+ /** Number of incident output faces. */
55
+ count: number;
56
+ /** Input polygon index of the incident face, or -1 for the remainder. */
57
+ polygon: number;
58
+ };
59
+ type PieceBuilder = {
60
+ ids: Map<number, number>;
61
+ positions: number[];
62
+ indices: number[];
63
+ sourceTriangles: number[];
64
+ sourceWeights: number[];
65
+ sourceFaces: number[];
66
+ boundary: Map<string, Boundary>;
67
+ cutEdges: number[];
68
+ /** One input polygon index per face; remainder -1 converts to Uint32 0xffffffff. */
69
+ polygonIndices: number[];
70
+ /** One owning patch polygon index per directed cut edge, on both sides. */
71
+ cutPolygonIndices: number[];
72
+ };
73
+
74
+ /** Split conforming 2.5D terrain by a convex ring or prepared polygon set in local XY.
75
+ * Either ring winding is accepted. Ring vertices must omit a closing duplicate.
76
+ * Rejects overlapping sheets, nonconforming edges and unrepresentable slivers.
77
+ */
78
+ export function splitTerrainMesh(
79
+ mesh: TerrainCutoutInput,
80
+ polygon: TerrainCutoutRegion,
81
+ {maxWork = 4_000_000, maxVertices = 500_000, maxTriangles = 500_000}: TerrainCutoutOptions = {}
82
+ ): TerrainCutout {
83
+ if (
84
+ ![maxWork, maxVertices, maxTriangles].every(n => Number.isSafeInteger(n) && n >= 0) ||
85
+ maxVertices > 0xffffffff ||
86
+ maxTriangles > 0xffffffff ||
87
+ !(mesh.positions instanceof Float32Array || mesh.positions instanceof Float64Array) ||
88
+ !(mesh.indices instanceof Uint16Array || mesh.indices instanceof Uint32Array) ||
89
+ mesh.positions.length % 3 ||
90
+ mesh.indices.length % 3 ||
91
+ mesh.positions.length / 3 > maxVertices ||
92
+ mesh.indices.length / 3 > maxTriangles ||
93
+ !mesh.positions.every(Number.isFinite)
94
+ )
95
+ throw new RangeError('Invalid terrain cutout mesh or capacity');
96
+
97
+ let work = 0;
98
+ /** Charge bounded work before performing a topology or clipping operation. */
99
+ function charge(amount: number) {
100
+ work += amount;
101
+ if (work > maxWork) throw new RangeError('Terrain cutout work budget exceeded');
102
+ }
103
+
104
+ const prepared = getTerrainCutoutPlan(polygon);
105
+ const ring = prepared ? undefined : validatePolygon(polygon as readonly XY[], charge);
106
+ const lines = prepared?.lines ?? ring!.map((p, i) => [p, ring![(i + 1) % ring!.length]] as const);
107
+ const vertices: XYZ[] = [];
108
+ for (let i = 0; i < mesh.positions.length; i += 3)
109
+ vertices.push([mesh.positions[i], mesh.positions[i + 1], mesh.positions[i + 2]]);
110
+ const faces: Face[] = [];
111
+ for (let i = 0; i < mesh.indices.length; i += 3) {
112
+ const face: Face = [mesh.indices[i], mesh.indices[i + 1], mesh.indices[i + 2]];
113
+ if (face.some(id => id >= vertices.length))
114
+ throw new RangeError('Invalid terrain cutout index');
115
+ checkTriangle(vertices[face[0]], vertices[face[1]], vertices[face[2]]);
116
+ faces.push(face);
117
+ }
118
+ validateTopology(vertices, faces, charge);
119
+
120
+ const patch = createPiece();
121
+ const remainder = createPiece();
122
+ const intersections = lines.map(() => new Map<string, number>());
123
+ let fragmentCount = 0;
124
+
125
+ /** Allocate a vertex once for both pieces and every incident fragment. */
126
+ function addVertex(vertex: XYZ) {
127
+ if (vertices.length >= maxVertices || !vertex.every(Number.isFinite))
128
+ throw new RangeError('Terrain cutout vertex budget or coordinate range exceeded');
129
+ return vertices.push(vertex) - 1;
130
+ }
131
+
132
+ /** Get the same intersection even when a shared edge is traversed backwards. */
133
+ function intersection(a: number, b: number, da: number, db: number, line: number) {
134
+ const key = edgeKey(a, b);
135
+ const cache = intersections[line];
136
+ const saved = cache.get(key);
137
+ if (saved !== undefined) return saved;
138
+ // Canonical coordinate order also makes independently clipped tile edges
139
+ // bit-identical, regardless of their local vertex IDs or face traversal.
140
+ const pa = vertices[a],
141
+ pb = vertices[b];
142
+ if (
143
+ pa[0] > pb[0] ||
144
+ (pa[0] === pb[0] && (pa[1] > pb[1] || (pa[1] === pb[1] && pa[2] > pb[2])))
145
+ ) {
146
+ [a, b] = [b, a];
147
+ [da, db] = [db, da];
148
+ }
149
+ const t = Math.abs(da) / (Math.abs(da) + Math.abs(db));
150
+ if (!(t > 0 && t < 1)) throw new RangeError('Unrepresentable terrain cut intersection');
151
+ const u = vertices[a];
152
+ const v = vertices[b];
153
+ const id = addVertex([
154
+ u[0] + t * (v[0] - u[0]),
155
+ u[1] + t * (v[1] - u[1]),
156
+ u[2] + t * (v[2] - u[2])
157
+ ]);
158
+ cache.set(key, id);
159
+ return id;
160
+ }
161
+
162
+ for (let source = 0; source < faces.length; source++) {
163
+ let fragments: Fragment[] = [{ids: faces[source], inside: true}];
164
+ // Split both sides by every supporting line. This preserves matching
165
+ // subdivisions on remainder edges beyond the finite polygon segments.
166
+ for (let line = 0; line < lines.length; line++) {
167
+ const next: Fragment[] = [];
168
+ const [a, b] = lines[line];
169
+ for (const fragment of fragments) {
170
+ const {ids} = fragment;
171
+ charge(ids.length);
172
+ const distances = ids.map(id => cross(a, b, vertices[id]));
173
+ if (distances.some(d => !Number.isFinite(d)))
174
+ throw new RangeError('Invalid terrain cut coordinates');
175
+ if (!distances.some(d => d < 0)) next.push(fragment);
176
+ else if (!distances.some(d => d > 0)) next.push({...fragment, inside: false});
177
+ else {
178
+ const positive: number[] = [];
179
+ const negative: number[] = [];
180
+ for (let i = 0; i < ids.length; i++) {
181
+ const j = (i + 1) % ids.length;
182
+ const d = distances[i];
183
+ const e = distances[j];
184
+ if (d >= 0) positive.push(ids[i]);
185
+ if (d <= 0) negative.push(ids[i]);
186
+ if ((d < 0 && e > 0) || (d > 0 && e < 0)) {
187
+ const id = intersection(ids[i], ids[j], d, e, line);
188
+ positive.push(id);
189
+ negative.push(id);
190
+ }
191
+ }
192
+ next.push({ids: positive, inside: fragment.inside}, {ids: negative, inside: false});
193
+ }
194
+ if (fragmentCount + next.length > maxTriangles)
195
+ throw new RangeError('Terrain cutout fragment budget exceeded');
196
+ }
197
+ fragments = next;
198
+ }
199
+ fragmentCount += fragments.length;
200
+ for (const {ids, inside} of fragments) {
201
+ // A strict interior point classifies each arrangement cell. Its artificial
202
+ // subdivision edges disappear when same-piece boundary incidences cancel.
203
+ let center: [number, number, number] | undefined;
204
+ if (prepared || ids.length > 3) {
205
+ center = [...vertices[ids[0]]] as [number, number, number];
206
+ for (const id of ids) {
207
+ for (let k = 0; k < 3; k++)
208
+ center[k] += (vertices[id][k] - vertices[ids[0]][k]) / ids.length;
209
+ }
210
+ }
211
+ const polygonIndex = prepared
212
+ ? prepared.classify([center![0], center![1]], charge)
213
+ : inside
214
+ ? 0
215
+ : -1;
216
+ const piece = polygonIndex >= 0 ? patch : remainder;
217
+ if (ids.length === 3) emit(piece, ids as Face, source, polygonIndex);
218
+ else {
219
+ // A center fan retains collinear boundary vertices and therefore pairs
220
+ // every constrained boundary segment with its neighbor.
221
+ const hub = addVertex(center!);
222
+ for (let i = 0; i < ids.length; i++)
223
+ emit(piece, [ids[i], ids[(i + 1) % ids.length], hub], source, polygonIndex);
224
+ }
225
+ }
226
+ }
227
+
228
+ /** Emit a triangle and weld all of its edges by their shared topology IDs. */
229
+ function emit(piece: PieceBuilder, face: Face, source: number, polygonIndex: number) {
230
+ if (patch.sourceFaces.length + remainder.sourceFaces.length >= maxTriangles)
231
+ throw new RangeError('Terrain cutout triangle budget exceeded');
232
+ checkTriangle(vertices[face[0]], vertices[face[1]], vertices[face[2]]);
233
+ const [a, b, c] = faces[source].map(id => vertices[id]);
234
+ const area = cross(a, b, c);
235
+ for (let i = 0; i < 3; i++) {
236
+ const id = face[i];
237
+ if (!piece.ids.has(id)) {
238
+ if (patch.ids.size + remainder.ids.size >= maxVertices)
239
+ throw new RangeError('Terrain cutout output vertex budget exceeded');
240
+ piece.ids.set(id, piece.ids.size);
241
+ const p = vertices[id];
242
+ piece.positions.push(...p);
243
+ piece.sourceTriangles.push(source);
244
+ piece.sourceWeights.push(
245
+ cross(b, c, p) / area,
246
+ cross(c, a, p) / area,
247
+ cross(a, b, p) / area
248
+ );
249
+ }
250
+ piece.indices.push(piece.ids.get(id)!);
251
+ addEdge(piece.boundary, id, face[(i + 1) % 3], polygonIndex);
252
+ }
253
+ piece.sourceFaces.push(source);
254
+ piece.polygonIndices.push(polygonIndex);
255
+ }
256
+
257
+ for (const [key, inside] of patch.boundary) {
258
+ const outside = remainder.boundary.get(key);
259
+ if (!outside) continue;
260
+ const [a, b] = inside.edge;
261
+ if (inside.count !== 1 || outside.count !== 1 || outside.edge[0] !== b)
262
+ throw new Error('Nonconforming terrain cut boundary');
263
+ patch.cutEdges.push(patch.ids.get(a)!, patch.ids.get(b)!);
264
+ remainder.cutEdges.push(remainder.ids.get(b)!, remainder.ids.get(a)!);
265
+ patch.cutPolygonIndices.push(inside.polygon);
266
+ remainder.cutPolygonIndices.push(inside.polygon);
267
+ }
268
+ return {patch: finish(patch), remainder: finish(remainder)};
269
+ }
270
+
271
+ /** Validate a simple strictly convex ring and normalize it to CCW. */
272
+ function validatePolygon(polygon: readonly XY[], charge: (amount: number) => void): XY[] {
273
+ if (polygon.length < 3 || polygon.some(p => p.length !== 2 || !p.every(Number.isFinite)))
274
+ throw new RangeError('Invalid terrain cut polygon');
275
+ const ring = [...polygon];
276
+ const orientation = cross(ring[0], ring[1], ring[2]);
277
+ if (orientation < 0) ring.reverse();
278
+ for (let i = 0; i < ring.length; i++) {
279
+ charge(ring.length);
280
+ const j = (i + 1) % ring.length;
281
+ for (let k = 0; k < ring.length; k++) {
282
+ if (k === i || k === j) continue;
283
+ const area = cross(ring[i], ring[j], ring[k]);
284
+ if (!(area > 0 && Number.isFinite(area)))
285
+ throw new RangeError('Terrain cut polygon must be strictly convex');
286
+ }
287
+ }
288
+ return ring;
289
+ }
290
+
291
+ /** Match TerrainSurface's relative degeneracy threshold without constructing an index. */
292
+ function checkTriangle(a: XYZ, b: XYZ, c: XYZ) {
293
+ const area = cross(a, b, c);
294
+ const scale = Math.hypot(b[0] - a[0], b[1] - a[1]) * Math.hypot(c[0] - a[0], c[1] - a[1]);
295
+ if (!(area > Number.EPSILON * scale && Number.isFinite(area)))
296
+ throw new RangeError('Terrain cut requires upward nondegenerate XY triangles');
297
+ }
298
+
299
+ /** Reject nonmanifold edges, overlaps and hanging vertices using an XY sweep. */
300
+ function validateTopology(vertices: XYZ[], faces: Face[], charge: (amount: number) => void) {
301
+ const edges = new Map<string, Boundary>();
302
+ const boxes = faces
303
+ .map(face => {
304
+ for (let i = 0; i < 3; i++) addEdge(edges, face[i], face[(i + 1) % 3]);
305
+ const points = face.map(id => vertices[id]);
306
+ return {
307
+ face,
308
+ points,
309
+ low: Math.min(...points.map(p => p[0])),
310
+ high: Math.max(...points.map(p => p[0])),
311
+ minY: Math.min(...points.map(p => p[1])),
312
+ maxY: Math.max(...points.map(p => p[1]))
313
+ };
314
+ })
315
+ .sort((a, b) => a.low - b.low);
316
+ for (let i = 0; i < boxes.length; i++) {
317
+ const a = boxes[i];
318
+ for (let j = i + 1; j < boxes.length && boxes[j].low <= a.high; j++) {
319
+ charge(1);
320
+ const b = boxes[j];
321
+ if (a.maxY < b.minY || b.maxY < a.minY) continue;
322
+ if (!separates(a.points, b.points) && !separates(b.points, a.points))
323
+ throw new RangeError('Terrain cut input has overlapping XY triangles');
324
+ checkJunctions(a.face, b.face, vertices);
325
+ checkJunctions(b.face, a.face, vertices);
326
+ }
327
+ }
328
+ }
329
+
330
+ /** Find a triangle edge whose exterior closed half-plane contains the other triangle. */
331
+ function separates(a: XYZ[], b: XYZ[]) {
332
+ return a.some((p, i) => b.every(q => cross(p, a[(i + 1) % 3], q) <= 0));
333
+ }
334
+
335
+ /** Reject a hanging vertex or coincident edge with distinct topology IDs. */
336
+ function checkJunctions(a: Face, b: Face, vertices: XYZ[]) {
337
+ for (let i = 0; i < 3; i++) {
338
+ const u = vertices[a[i]];
339
+ const v = vertices[a[(i + 1) % 3]];
340
+ const overlaps = b.filter(id => {
341
+ const p = vertices[id];
342
+ if (cross(u, v, p) !== 0) return false;
343
+ const axis = Math.abs(v[0] - u[0]) >= Math.abs(v[1] - u[1]) ? 0 : 1;
344
+ const low = Math.min(u[axis], v[axis]);
345
+ const high = Math.max(u[axis], v[axis]);
346
+ if (p[axis] > low && p[axis] < high)
347
+ throw new RangeError('Terrain cut input has a T-junction');
348
+ return p[axis] >= low && p[axis] <= high;
349
+ });
350
+ if (overlaps.length >= 2 && (!overlaps.includes(a[i]) || !overlaps.includes(a[(i + 1) % 3])))
351
+ throw new RangeError('Terrain cut input has an unwelded shared edge');
352
+ }
353
+ }
354
+
355
+ /** Track the first direction and incidence count of an indexed edge. */
356
+ function addEdge(edges: Map<string, Boundary>, a: number, b: number, polygon = -1) {
357
+ const key = edgeKey(a, b);
358
+ const entry = edges.get(key);
359
+ if (!entry) edges.set(key, {edge: [a, b], count: 1, polygon});
360
+ else {
361
+ if (entry.count !== 1 || entry.edge[0] !== b)
362
+ throw new RangeError('Terrain cut mesh has inconsistent or nonmanifold edges');
363
+ entry.count++;
364
+ }
365
+ }
366
+
367
+ /** Shared key independent of the edge direction. */
368
+ function edgeKey(a: number, b: number) {
369
+ return a < b ? a + ',' + b : b + ',' + a;
370
+ }
371
+
372
+ /** Signed doubled triangle area in local XY. */
373
+ function cross(a: XY | XYZ, b: XY | XYZ, c: XY | XYZ) {
374
+ return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
375
+ }
376
+
377
+ /** Allocate detached output staging buffers. */
378
+ function createPiece(): PieceBuilder {
379
+ return {
380
+ ids: new Map(),
381
+ positions: [],
382
+ indices: [],
383
+ sourceTriangles: [],
384
+ sourceWeights: [],
385
+ sourceFaces: [],
386
+ boundary: new Map(),
387
+ cutEdges: [],
388
+ polygonIndices: [],
389
+ cutPolygonIndices: []
390
+ };
391
+ }
392
+
393
+ /** Materialize the public typed arrays. */
394
+ function finish(piece: PieceBuilder): TerrainCutoutPiece {
395
+ return {
396
+ positions: Float64Array.from(piece.positions),
397
+ indices: Uint32Array.from(piece.indices),
398
+ sourceTriangles: Uint32Array.from(piece.sourceTriangles),
399
+ sourceWeights: Float64Array.from(piece.sourceWeights),
400
+ sourceFaces: Uint32Array.from(piece.sourceFaces),
401
+ cutEdges: Uint32Array.from(piece.cutEdges),
402
+ polygonIndices: Uint32Array.from(piece.polygonIndices),
403
+ cutPolygonIndices: Uint32Array.from(piece.cutPolygonIndices)
404
+ };
405
+ }
406
+
407
+ /** @internal Check topology of already range-validated assembled tile inputs. */
408
+ export function validateTerrainCutoutTopology(mesh: TerrainCutoutInput, maxWork: number) {
409
+ const vertices: XYZ[] = [];
410
+ const faces: Face[] = [];
411
+ for (let i = 0; i < mesh.positions.length; i += 3)
412
+ vertices.push([mesh.positions[i], mesh.positions[i + 1], mesh.positions[i + 2]]);
413
+ for (let i = 0; i < mesh.indices.length; i += 3)
414
+ faces.push([mesh.indices[i], mesh.indices[i + 1], mesh.indices[i + 2]]);
415
+ let work = 0;
416
+ validateTopology(vertices, faces, amount => {
417
+ work += amount;
418
+ if (work > maxWork) throw new RangeError('Terrain cutout topology work budget exceeded');
419
+ });
420
+ }
@@ -1,7 +1,7 @@
1
1
  // math.gl
2
2
  // SPDX-License-Identifier: MIT
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
- import type {TerrainGridMesh} from './mesh-data';
4
+ import type {TerrainSeamMesh} from './mesh-stitch';
5
5
  import {HeightField} from './height-field';
6
6
  import {
7
7
  validateTerrainDirtyWindows,
@@ -18,7 +18,7 @@ export type TerrainMeshRegions<T> = {
18
18
  rebuilt: Uint32Array;
19
19
  };
20
20
  /** Internal independent chunk updater. Buffers in untouched regions remain shared. */
21
- export function updateMeshRegions<T extends TerrainGridMesh | null>(
21
+ export function updateMeshRegions<T extends TerrainSeamMesh | null>(
22
22
  previous: TerrainMeshRegions<T> | null,
23
23
  field: HeightField,
24
24
  dirty: readonly TerrainDirtyWindow[],
@@ -41,6 +41,24 @@ export function updateMeshRegions<T extends TerrainGridMesh | null>(
41
41
  sameTerrainFrame(previous.field, field) &&
42
42
  previous.cellsPerRegion === cells &&
43
43
  previous.configuration === configuration;
44
+ const affectedRegions = new Set<number>();
45
+ const columns = Math.ceil((field.width - 1) / cells);
46
+ const rows = Math.ceil((field.height - 1) / cells);
47
+ if (reusable) {
48
+ for (const window of dirty) {
49
+ // Shared sample rows and columns belong to both incident regions.
50
+ const firstColumn = Math.max(0, Math.ceil(window.minColumn / cells) - 1);
51
+ const firstRow = Math.max(0, Math.ceil(window.minRow / cells) - 1);
52
+ const lastColumn = Math.min(columns - 1, Math.floor(window.maxColumn / cells));
53
+ const lastRow = Math.min(rows - 1, Math.floor(window.maxRow / cells));
54
+ for (let y = firstRow; y <= lastRow; y++) {
55
+ for (let x = firstColumn; x <= lastColumn; x++) {
56
+ if (++tests > budget) throw new Error('Terrain mesh region work budget exceeded');
57
+ affectedRegions.add(y * columns + x);
58
+ }
59
+ }
60
+ }
61
+ }
44
62
  const cache = new Map(previous?.regions.map(r => [`${r.column},${r.row}`, r]));
45
63
  for (let row = 0; row < field.height - 1; row += cells)
46
64
  for (let column = 0; column < field.width - 1; column += cells) {
@@ -49,17 +67,7 @@ export function updateMeshRegions<T extends TerrainGridMesh | null>(
49
67
  count += width * height;
50
68
  if (!Number.isSafeInteger(count) || count > limit)
51
69
  throw new Error('Terrain mesh region sample capacity exceeded');
52
- let affected = !reusable;
53
- for (const w of reusable ? dirty : []) {
54
- if (++tests > budget) throw new Error('Terrain mesh region work budget exceeded');
55
- if (
56
- w.minColumn <= column + width - 1 &&
57
- w.maxColumn >= column &&
58
- w.minRow <= row + height - 1 &&
59
- w.maxRow >= row
60
- )
61
- affected = true;
62
- }
70
+ const affected = !reusable || affectedRegions.has((row / cells) * columns + column / cells);
63
71
  const old = cache.get(`${column},${row}`);
64
72
  if (!affected && old) {
65
73
  regions.push(old);