@math.gl/geospatial 5.0.0-beta.11 → 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 (276) hide show
  1. package/README.md +3 -3
  2. package/dist/index.cjs +725 -229
  3. package/dist/index.cjs.map +3 -3
  4. package/dist/index.d.ts +5 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +4 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/projection/experimental/core.cjs.map +1 -1
  9. package/dist/projection/experimental/crs/spatial-reference.d.ts.map +1 -1
  10. package/dist/projection/experimental/crs/spatial-reference.js.map +1 -1
  11. package/dist/projection/experimental/crs/types.d.ts.map +1 -1
  12. package/dist/projection/experimental/lazy-projections/aea.cjs +4 -1
  13. package/dist/projection/experimental/lazy-projections/aea.cjs.map +1 -1
  14. package/dist/projection/experimental/lazy-projections/aea.d.ts.map +1 -1
  15. package/dist/projection/experimental/lazy-projections/aea.js +4 -1
  16. package/dist/projection/experimental/lazy-projections/aea.js.map +1 -1
  17. package/dist/projection/experimental/lazy-projections/bonne.cjs +4 -1
  18. package/dist/projection/experimental/lazy-projections/bonne.cjs.map +1 -1
  19. package/dist/projection/experimental/lazy-projections/bonne.d.ts.map +1 -1
  20. package/dist/projection/experimental/lazy-projections/bonne.js +4 -1
  21. package/dist/projection/experimental/lazy-projections/bonne.js.map +1 -1
  22. package/dist/projection/experimental/lazy-projections/cass.cjs +4 -1
  23. package/dist/projection/experimental/lazy-projections/cass.cjs.map +1 -1
  24. package/dist/projection/experimental/lazy-projections/cass.d.ts.map +1 -1
  25. package/dist/projection/experimental/lazy-projections/cass.js +4 -1
  26. package/dist/projection/experimental/lazy-projections/cass.js.map +1 -1
  27. package/dist/projection/experimental/lazy-projections/eck6.cjs +4 -1
  28. package/dist/projection/experimental/lazy-projections/eck6.cjs.map +1 -1
  29. package/dist/projection/experimental/lazy-projections/eck6.d.ts.map +1 -1
  30. package/dist/projection/experimental/lazy-projections/eck6.js +4 -1
  31. package/dist/projection/experimental/lazy-projections/eck6.js.map +1 -1
  32. package/dist/projection/experimental/lazy-projections/eqdc.cjs +4 -1
  33. package/dist/projection/experimental/lazy-projections/eqdc.cjs.map +1 -1
  34. package/dist/projection/experimental/lazy-projections/eqdc.d.ts.map +1 -1
  35. package/dist/projection/experimental/lazy-projections/eqdc.js +4 -1
  36. package/dist/projection/experimental/lazy-projections/eqdc.js.map +1 -1
  37. package/dist/projection/experimental/lazy-projections/eqearth.cjs +4 -1
  38. package/dist/projection/experimental/lazy-projections/eqearth.cjs.map +1 -1
  39. package/dist/projection/experimental/lazy-projections/eqearth.d.ts.map +1 -1
  40. package/dist/projection/experimental/lazy-projections/eqearth.js +4 -1
  41. package/dist/projection/experimental/lazy-projections/eqearth.js.map +1 -1
  42. package/dist/projection/experimental/lazy-projections/equi.cjs +4 -1
  43. package/dist/projection/experimental/lazy-projections/equi.cjs.map +1 -1
  44. package/dist/projection/experimental/lazy-projections/equi.d.ts.map +1 -1
  45. package/dist/projection/experimental/lazy-projections/equi.js +4 -1
  46. package/dist/projection/experimental/lazy-projections/equi.js.map +1 -1
  47. package/dist/projection/experimental/lazy-projections/geocent.cjs +4 -1
  48. package/dist/projection/experimental/lazy-projections/geocent.cjs.map +1 -1
  49. package/dist/projection/experimental/lazy-projections/geocent.d.ts.map +1 -1
  50. package/dist/projection/experimental/lazy-projections/geocent.js +4 -1
  51. package/dist/projection/experimental/lazy-projections/geocent.js.map +1 -1
  52. package/dist/projection/experimental/lazy-projections/geos.cjs +4 -1
  53. package/dist/projection/experimental/lazy-projections/geos.cjs.map +1 -1
  54. package/dist/projection/experimental/lazy-projections/geos.d.ts.map +1 -1
  55. package/dist/projection/experimental/lazy-projections/geos.js +4 -1
  56. package/dist/projection/experimental/lazy-projections/geos.js.map +1 -1
  57. package/dist/projection/experimental/lazy-projections/gnom.cjs +4 -1
  58. package/dist/projection/experimental/lazy-projections/gnom.cjs.map +1 -1
  59. package/dist/projection/experimental/lazy-projections/gnom.d.ts.map +1 -1
  60. package/dist/projection/experimental/lazy-projections/gnom.js +4 -1
  61. package/dist/projection/experimental/lazy-projections/gnom.js.map +1 -1
  62. package/dist/projection/experimental/lazy-projections/index.cjs +92 -23
  63. package/dist/projection/experimental/lazy-projections/index.cjs.map +1 -1
  64. package/dist/projection/experimental/lazy-projections/krovak.cjs +4 -1
  65. package/dist/projection/experimental/lazy-projections/krovak.cjs.map +1 -1
  66. package/dist/projection/experimental/lazy-projections/krovak.d.ts.map +1 -1
  67. package/dist/projection/experimental/lazy-projections/krovak.js +4 -1
  68. package/dist/projection/experimental/lazy-projections/krovak.js.map +1 -1
  69. package/dist/projection/experimental/lazy-projections/merc.cjs +4 -1
  70. package/dist/projection/experimental/lazy-projections/merc.cjs.map +1 -1
  71. package/dist/projection/experimental/lazy-projections/merc.d.ts.map +1 -1
  72. package/dist/projection/experimental/lazy-projections/merc.js +4 -1
  73. package/dist/projection/experimental/lazy-projections/merc.js.map +1 -1
  74. package/dist/projection/experimental/lazy-projections/mill.cjs +4 -1
  75. package/dist/projection/experimental/lazy-projections/mill.cjs.map +1 -1
  76. package/dist/projection/experimental/lazy-projections/mill.d.ts.map +1 -1
  77. package/dist/projection/experimental/lazy-projections/mill.js +4 -1
  78. package/dist/projection/experimental/lazy-projections/mill.js.map +1 -1
  79. package/dist/projection/experimental/lazy-projections/moll.cjs +4 -1
  80. package/dist/projection/experimental/lazy-projections/moll.cjs.map +1 -1
  81. package/dist/projection/experimental/lazy-projections/moll.d.ts.map +1 -1
  82. package/dist/projection/experimental/lazy-projections/moll.js +4 -1
  83. package/dist/projection/experimental/lazy-projections/moll.js.map +1 -1
  84. package/dist/projection/experimental/lazy-projections/nzmg.cjs +4 -1
  85. package/dist/projection/experimental/lazy-projections/nzmg.cjs.map +1 -1
  86. package/dist/projection/experimental/lazy-projections/nzmg.d.ts.map +1 -1
  87. package/dist/projection/experimental/lazy-projections/nzmg.js +4 -1
  88. package/dist/projection/experimental/lazy-projections/nzmg.js.map +1 -1
  89. package/dist/projection/experimental/lazy-projections/omerc.cjs +4 -1
  90. package/dist/projection/experimental/lazy-projections/omerc.cjs.map +1 -1
  91. package/dist/projection/experimental/lazy-projections/omerc.d.ts.map +1 -1
  92. package/dist/projection/experimental/lazy-projections/omerc.js +4 -1
  93. package/dist/projection/experimental/lazy-projections/omerc.js.map +1 -1
  94. package/dist/projection/experimental/lazy-projections/ortho.cjs +4 -1
  95. package/dist/projection/experimental/lazy-projections/ortho.cjs.map +1 -1
  96. package/dist/projection/experimental/lazy-projections/ortho.d.ts.map +1 -1
  97. package/dist/projection/experimental/lazy-projections/ortho.js +4 -1
  98. package/dist/projection/experimental/lazy-projections/ortho.js.map +1 -1
  99. package/dist/projection/experimental/lazy-projections/poly.cjs +4 -1
  100. package/dist/projection/experimental/lazy-projections/poly.cjs.map +1 -1
  101. package/dist/projection/experimental/lazy-projections/poly.d.ts.map +1 -1
  102. package/dist/projection/experimental/lazy-projections/poly.js +4 -1
  103. package/dist/projection/experimental/lazy-projections/poly.js.map +1 -1
  104. package/dist/projection/experimental/lazy-projections/robin.cjs +4 -1
  105. package/dist/projection/experimental/lazy-projections/robin.cjs.map +1 -1
  106. package/dist/projection/experimental/lazy-projections/robin.d.ts.map +1 -1
  107. package/dist/projection/experimental/lazy-projections/robin.js +4 -1
  108. package/dist/projection/experimental/lazy-projections/robin.js.map +1 -1
  109. package/dist/projection/experimental/lazy-projections/sinu.cjs +4 -1
  110. package/dist/projection/experimental/lazy-projections/sinu.cjs.map +1 -1
  111. package/dist/projection/experimental/lazy-projections/sinu.d.ts.map +1 -1
  112. package/dist/projection/experimental/lazy-projections/sinu.js +4 -1
  113. package/dist/projection/experimental/lazy-projections/sinu.js.map +1 -1
  114. package/dist/projection/experimental/lazy-projections/stere.cjs +4 -1
  115. package/dist/projection/experimental/lazy-projections/stere.cjs.map +1 -1
  116. package/dist/projection/experimental/lazy-projections/stere.d.ts.map +1 -1
  117. package/dist/projection/experimental/lazy-projections/stere.js +4 -1
  118. package/dist/projection/experimental/lazy-projections/stere.js.map +1 -1
  119. package/dist/projection/experimental/lazy-projections/tpers.cjs +4 -1
  120. package/dist/projection/experimental/lazy-projections/tpers.cjs.map +1 -1
  121. package/dist/projection/experimental/lazy-projections/tpers.d.ts.map +1 -1
  122. package/dist/projection/experimental/lazy-projections/tpers.js +4 -1
  123. package/dist/projection/experimental/lazy-projections/tpers.js.map +1 -1
  124. package/dist/projection/experimental/lazy-projections/vandg.cjs +4 -1
  125. package/dist/projection/experimental/lazy-projections/vandg.cjs.map +1 -1
  126. package/dist/projection/experimental/lazy-projections/vandg.d.ts.map +1 -1
  127. package/dist/projection/experimental/lazy-projections/vandg.js +4 -1
  128. package/dist/projection/experimental/lazy-projections/vandg.js.map +1 -1
  129. package/dist/projection/index.cjs.map +1 -1
  130. package/dist/projection/index.d.ts.map +1 -1
  131. package/dist/projection/index.js.map +1 -1
  132. package/dist/projection/lib/projection.js.map +1 -1
  133. package/dist/projection/pipeline.cjs.map +1 -1
  134. package/dist/projection/transform-analysis.cjs.map +1 -1
  135. package/dist/tasks/index.cjs.map +1 -1
  136. package/dist/terrain/cutout-polygons.d.ts +21 -0
  137. package/dist/terrain/cutout-polygons.d.ts.map +1 -0
  138. package/dist/terrain/cutout-polygons.js +172 -0
  139. package/dist/terrain/cutout-polygons.js.map +1 -0
  140. package/dist/terrain/cutout-region.d.ts +34 -0
  141. package/dist/terrain/cutout-region.d.ts.map +1 -0
  142. package/dist/terrain/cutout-region.js +33 -0
  143. package/dist/terrain/cutout-region.js.map +1 -0
  144. package/dist/terrain/geographic-cutout.d.ts +38 -0
  145. package/dist/terrain/geographic-cutout.d.ts.map +1 -0
  146. package/dist/terrain/geographic-cutout.js +120 -0
  147. package/dist/terrain/geographic-cutout.js.map +1 -0
  148. package/dist/terrain/index.cjs +532 -36
  149. package/dist/terrain/index.cjs.map +3 -3
  150. package/dist/terrain/index.d.ts +5 -0
  151. package/dist/terrain/index.d.ts.map +1 -1
  152. package/dist/terrain/index.js +4 -0
  153. package/dist/terrain/index.js.map +1 -1
  154. package/dist/terrain/mesh-cutout.d.ts +10 -5
  155. package/dist/terrain/mesh-cutout.d.ts.map +1 -1
  156. package/dist/terrain/mesh-cutout.js +62 -20
  157. package/dist/terrain/mesh-cutout.js.map +1 -1
  158. package/dist/terrain/tile-cutout-update.d.ts +73 -0
  159. package/dist/terrain/tile-cutout-update.d.ts.map +1 -0
  160. package/dist/terrain/tile-cutout-update.js +181 -0
  161. package/dist/terrain/tile-cutout-update.js.map +1 -0
  162. package/dist/terrain/tile-cutout.d.ts +33 -0
  163. package/dist/terrain/tile-cutout.d.ts.map +1 -0
  164. package/dist/terrain/tile-cutout.js +93 -0
  165. package/dist/terrain/tile-cutout.js.map +1 -0
  166. package/dist/turf/expressions.cjs +4 -4
  167. package/dist/turf/expressions.cjs.map +2 -2
  168. package/dist/turf/expressions.d.ts +1 -1
  169. package/dist/turf/expressions.d.ts.map +1 -1
  170. package/dist/turf/expressions.js +2 -2
  171. package/dist/turf/expressions.js.map +1 -1
  172. package/dist/turf.cjs +25 -25
  173. package/dist/turf.cjs.map +2 -2
  174. package/dist/turf.d.ts +1 -1
  175. package/dist/turf.d.ts.map +1 -1
  176. package/dist/turf.js +2 -2
  177. package/dist/turf.js.map +1 -1
  178. package/dist/web-mercator/assert.d.ts +2 -0
  179. package/dist/web-mercator/assert.d.ts.map +1 -0
  180. package/dist/web-mercator/assert.js +12 -0
  181. package/dist/web-mercator/assert.js.map +1 -0
  182. package/dist/web-mercator/fit-bounds.d.ts +52 -0
  183. package/dist/web-mercator/fit-bounds.d.ts.map +1 -0
  184. package/dist/web-mercator/fit-bounds.js +70 -0
  185. package/dist/web-mercator/fit-bounds.js.map +1 -0
  186. package/dist/web-mercator/fly-to-viewport.d.ts +19 -0
  187. package/dist/web-mercator/fly-to-viewport.d.ts.map +1 -0
  188. package/dist/web-mercator/fly-to-viewport.js +94 -0
  189. package/dist/web-mercator/fly-to-viewport.js.map +1 -0
  190. package/dist/web-mercator/get-bounds.d.ts +3 -0
  191. package/dist/web-mercator/get-bounds.d.ts.map +1 -0
  192. package/dist/web-mercator/get-bounds.js +56 -0
  193. package/dist/web-mercator/get-bounds.js.map +1 -0
  194. package/dist/web-mercator/index.cjs +705 -0
  195. package/dist/web-mercator/index.cjs.map +6 -0
  196. package/dist/web-mercator/index.d.ts +14 -0
  197. package/dist/web-mercator/index.d.ts.map +1 -0
  198. package/dist/web-mercator/index.js +14 -0
  199. package/dist/web-mercator/index.js.map +1 -0
  200. package/dist/web-mercator/math-utils.d.ts +7 -0
  201. package/dist/web-mercator/math-utils.d.ts.map +1 -0
  202. package/dist/web-mercator/math-utils.js +30 -0
  203. package/dist/web-mercator/math-utils.js.map +1 -0
  204. package/dist/web-mercator/mercator-meters.d.ts +29 -0
  205. package/dist/web-mercator/mercator-meters.d.ts.map +1 -0
  206. package/dist/web-mercator/mercator-meters.js +61 -0
  207. package/dist/web-mercator/mercator-meters.js.map +1 -0
  208. package/dist/web-mercator/normalize-viewport-props.d.ts +16 -0
  209. package/dist/web-mercator/normalize-viewport-props.d.ts.map +1 -0
  210. package/dist/web-mercator/normalize-viewport-props.js +45 -0
  211. package/dist/web-mercator/normalize-viewport-props.js.map +1 -0
  212. package/dist/web-mercator/web-mercator-utils.d.ts +192 -0
  213. package/dist/web-mercator/web-mercator-utils.d.ts.map +1 -0
  214. package/dist/web-mercator/web-mercator-utils.js +321 -0
  215. package/dist/web-mercator/web-mercator-utils.js.map +1 -0
  216. package/dist/web-mercator/web-mercator-viewport.d.ts +177 -0
  217. package/dist/web-mercator/web-mercator-viewport.d.ts.map +1 -0
  218. package/dist/web-mercator/web-mercator-viewport.js +276 -0
  219. package/dist/web-mercator/web-mercator-viewport.js.map +1 -0
  220. package/dist/web-mercator.d.ts +1 -1
  221. package/dist/web-mercator.d.ts.map +1 -1
  222. package/dist/web-mercator.js +1 -1
  223. package/dist/web-mercator.js.map +1 -1
  224. package/package.json +19 -458
  225. package/src/index.ts +36 -5
  226. package/src/projection/experimental/crs/spatial-reference.ts +1 -6
  227. package/src/projection/experimental/crs/types.ts +1 -1
  228. package/src/projection/experimental/crs/wkt.ts +1 -1
  229. package/src/projection/experimental/crs-descriptor.ts +1 -1
  230. package/src/projection/experimental/lazy-projections/aea.ts +4 -1
  231. package/src/projection/experimental/lazy-projections/bonne.ts +4 -1
  232. package/src/projection/experimental/lazy-projections/cass.ts +4 -1
  233. package/src/projection/experimental/lazy-projections/eck6.ts +4 -1
  234. package/src/projection/experimental/lazy-projections/eqdc.ts +4 -1
  235. package/src/projection/experimental/lazy-projections/eqearth.ts +4 -1
  236. package/src/projection/experimental/lazy-projections/equi.ts +4 -1
  237. package/src/projection/experimental/lazy-projections/geocent.ts +4 -1
  238. package/src/projection/experimental/lazy-projections/geos.ts +4 -1
  239. package/src/projection/experimental/lazy-projections/gnom.ts +4 -1
  240. package/src/projection/experimental/lazy-projections/krovak.ts +4 -1
  241. package/src/projection/experimental/lazy-projections/merc.ts +4 -1
  242. package/src/projection/experimental/lazy-projections/mill.ts +4 -1
  243. package/src/projection/experimental/lazy-projections/moll.ts +4 -1
  244. package/src/projection/experimental/lazy-projections/nzmg.ts +4 -1
  245. package/src/projection/experimental/lazy-projections/omerc.ts +4 -1
  246. package/src/projection/experimental/lazy-projections/ortho.ts +4 -1
  247. package/src/projection/experimental/lazy-projections/poly.ts +4 -1
  248. package/src/projection/experimental/lazy-projections/robin.ts +4 -1
  249. package/src/projection/experimental/lazy-projections/sinu.ts +4 -1
  250. package/src/projection/experimental/lazy-projections/stere.ts +4 -1
  251. package/src/projection/experimental/lazy-projections/tpers.ts +4 -1
  252. package/src/projection/experimental/lazy-projections/vandg.ts +4 -1
  253. package/src/projection/index.ts +1 -1
  254. package/src/projection/lib/projection.ts +1 -1
  255. package/src/terrain/cutout-polygons.ts +202 -0
  256. package/src/terrain/cutout-region.ts +54 -0
  257. package/src/terrain/geographic-cutout.ts +154 -0
  258. package/src/terrain/index.ts +24 -0
  259. package/src/terrain/mesh-cutout.ts +85 -23
  260. package/src/terrain/tile-cutout-update.ts +293 -0
  261. package/src/terrain/tile-cutout.ts +123 -0
  262. package/src/turf/expressions.ts +2 -2
  263. package/src/turf.ts +3 -7
  264. package/src/web-mercator/assert.ts +11 -0
  265. package/src/web-mercator/fit-bounds.ts +132 -0
  266. package/src/web-mercator/fly-to-viewport.ts +157 -0
  267. package/src/web-mercator/get-bounds.ts +62 -0
  268. package/src/web-mercator/index.ts +49 -0
  269. package/src/web-mercator/math-utils.ts +35 -0
  270. package/src/web-mercator/mercator-meters.ts +83 -0
  271. package/src/web-mercator/normalize-viewport-props.ts +58 -0
  272. package/src/web-mercator/web-mercator-utils.ts +468 -0
  273. package/src/web-mercator/web-mercator-viewport.ts +406 -0
  274. package/src/web-mercator.ts +1 -1
  275. package/dist/projection/experimental/index.cjs +0 -11707
  276. package/dist/projection/experimental/index.cjs.map +0 -6
@@ -49,6 +49,7 @@ __export(index_exports, {
49
49
  coordinateTerrainLodMorphs: () => coordinateTerrainLodMorphs,
50
50
  createBreaklineTerrainMesh: () => createBreaklineTerrainMesh,
51
51
  createDelatinTerrainMesh: () => createDelatinTerrainMesh,
52
+ createGeographicTerrainCutoutFrame: () => createGeographicTerrainCutoutFrame,
52
53
  createMartiniTerrainMesh: () => createMartiniTerrainMesh,
53
54
  createTerrainContours: () => createTerrainContours,
54
55
  createTerrainCutoutSkirts: () => createTerrainCutoutSkirts,
@@ -85,6 +86,8 @@ __export(index_exports, {
85
86
  measureTerrainMeshError: () => measureTerrainMeshError,
86
87
  measureTerrainProfile: () => measureTerrainProfile,
87
88
  packTerrainHeightField: () => packTerrainHeightField,
89
+ prepareTerrainCutoutPolygons: () => prepareTerrainCutoutPolygons,
90
+ projectGeographicTerrainCutout: () => projectGeographicTerrainCutout,
88
91
  reconcileTerrainVertexTiles: () => reconcileTerrainVertexTiles,
89
92
  sampleTerrainProfile: () => sampleTerrainProfile,
90
93
  selectTerrainLod: () => selectTerrainLod,
@@ -92,6 +95,7 @@ __export(index_exports, {
92
95
  simplifyTerrainContourPathsTopology: () => simplifyTerrainContourPathsTopology,
93
96
  splitTerrainBreaklines: () => splitTerrainBreaklines,
94
97
  splitTerrainMesh: () => splitTerrainMesh,
98
+ splitTerrainMeshTiles: () => splitTerrainMeshTiles,
95
99
  stitchTerrainContourTiles: () => stitchTerrainContourTiles,
96
100
  stitchTerrainContours: () => stitchTerrainContours,
97
101
  stitchTerrainLodCut: () => stitchTerrainLodCut,
@@ -109,6 +113,7 @@ __export(index_exports, {
109
113
  sweepTerrainTaperedCapsule: () => sweepTerrainTaperedCapsule,
110
114
  sweepTerrainTriangleMesh: () => sweepTerrainTriangleMesh,
111
115
  unpackTerrainHeightField: () => unpackTerrainHeightField,
116
+ unprojectGeographicTerrainCutout: () => unprojectGeographicTerrainCutout,
112
117
  updateTerrainBounds: () => updateTerrainBounds,
113
118
  updateTerrainBoundsRegions: () => updateTerrainBoundsRegions,
114
119
  updateTerrainDelatinMeshRegions: () => updateTerrainDelatinMeshRegions,
@@ -121,6 +126,7 @@ __export(index_exports, {
121
126
  updateTerrainMixedVertexTileHalos: () => updateTerrainMixedVertexTileHalos,
122
127
  updateTerrainPersistentBounds: () => updateTerrainPersistentBounds,
123
128
  updateTerrainPersistentGradients: () => updateTerrainPersistentGradients,
129
+ updateTerrainTileCutouts: () => updateTerrainTileCutouts,
124
130
  updateTerrainValidDomainMeshRegions: () => updateTerrainValidDomainMeshRegions,
125
131
  updateTerrainVertexTileHalos: () => updateTerrainVertexTileHalos,
126
132
  weldTerrainContourTiles: () => weldTerrainContourTiles,
@@ -660,17 +666,17 @@ var GeographicHeightField = class {
660
666
  });
661
667
  }
662
668
  /** Longitude must use the bounds' unwrapped interval; no implicit wrapping or clamping. */
663
- sample(longitude, latitude, options, result) {
664
- const valid = Number.isFinite(longitude) && Number.isFinite(latitude);
665
- const inside = valid && longitude >= this.bounds[0] && longitude <= this.bounds[2] && latitude >= this.bounds[1] && latitude <= this.bounds[3];
666
- const sample = this.field.sample(inside ? this.projectX(longitude) : NaN, inside ? this.projectY(latitude) : NaN, options, result);
669
+ sample(longitude, latitude2, options, result) {
670
+ const valid = Number.isFinite(longitude) && Number.isFinite(latitude2);
671
+ const inside = valid && longitude >= this.bounds[0] && longitude <= this.bounds[2] && latitude2 >= this.bounds[1] && latitude2 <= this.bounds[3];
672
+ const sample = this.field.sample(inside ? this.projectX(longitude) : NaN, inside ? this.projectY(latitude2) : NaN, options, result);
667
673
  if (!inside) {
668
674
  sample.status = sample.gradientStatus = valid ? TerrainSampleStatus.OUTSIDE_DOMAIN : TerrainSampleStatus.INVALID_INPUT;
669
675
  return sample;
670
676
  }
671
677
  if (sample.gradientStatus !== TerrainSampleStatus.VALID)
672
678
  return sample;
673
- const phi = latitude * RADIANS;
679
+ const phi = latitude2 * RADIANS;
674
680
  const denominator = 1 - ECCENTRICITY_SQUARED * Math.sin(phi) ** 2;
675
681
  const n = RADIUS / Math.sqrt(denominator);
676
682
  const m = RADIUS * (1 - ECCENTRICITY_SQUARED) / denominator ** 1.5;
@@ -694,8 +700,8 @@ var GeographicHeightField = class {
694
700
  projectX(longitude) {
695
701
  return this.projection === "web-mercator" ? RADIUS * longitude * RADIANS : longitude;
696
702
  }
697
- projectY(latitude) {
698
- return this.projection === "web-mercator" ? RADIUS * Math.asinh(Math.tan(latitude * RADIANS)) : latitude;
703
+ projectY(latitude2) {
704
+ return this.projection === "web-mercator" ? RADIUS * Math.asinh(Math.tan(latitude2 * RADIANS)) : latitude2;
699
705
  }
700
706
  };
701
707
 
@@ -5859,8 +5865,8 @@ function createBreaklineTerrainMesh(field, options) {
5859
5865
  continue;
5860
5866
  }
5861
5867
  const r = points[c], s = points[d];
5862
- const intersects2 = Math.sign(cross(p, q, r)) * Math.sign(cross(p, q, s)) < 0 && Math.sign(cross(r, s, p)) * Math.sign(cross(r, s, q)) < 0;
5863
- if (intersects2 || c !== a && c !== b && onSegment(p, q, r) || d !== a && d !== b && onSegment(p, q, s) || a !== c && a !== d && onSegment(r, s, p) || b !== c && b !== d && onSegment(r, s, q)) {
5868
+ const intersects3 = Math.sign(cross(p, q, r)) * Math.sign(cross(p, q, s)) < 0 && Math.sign(cross(r, s, p)) * Math.sign(cross(r, s, q)) < 0;
5869
+ if (intersects3 || c !== a && c !== b && onSegment(p, q, r) || d !== a && d !== b && onSegment(p, q, s) || a !== c && a !== d && onSegment(r, s, p) || b !== c && b !== d && onSegment(r, s, q)) {
5864
5870
  throw new Error("Breaklines and domain edges must meet only at shared endpoints");
5865
5871
  }
5866
5872
  }
@@ -6093,21 +6099,21 @@ function wrapTerrainLongitude(longitude, west, east) {
6093
6099
  function measureGeographicTerrainSeam(a, b, probes, options = {}) {
6094
6100
  if (a && b && a.heightReference !== b.heightReference)
6095
6101
  throw new Error("Terrain seam height references differ");
6096
- const sample = (field, longitude, latitude) => {
6102
+ const sample = (field, longitude, latitude2) => {
6097
6103
  if (!field || !Number.isFinite(longitude))
6098
- return field == null ? void 0 : field.sample(longitude, latitude, options);
6104
+ return field == null ? void 0 : field.sample(longitude, latitude2, options);
6099
6105
  const mapped = wrapTerrainLongitude(longitude, field.bounds[0], field.bounds[2]);
6100
- return field.sample(mapped ?? longitude, latitude, options);
6106
+ return field.sample(mapped ?? longitude, latitude2, options);
6101
6107
  };
6102
- return probes.map(([longitude, latitude]) => {
6103
- const left = sample(a, longitude, latitude);
6104
- const right = sample(b, longitude, latitude);
6108
+ return probes.map(([longitude, latitude2]) => {
6109
+ const left = sample(a, longitude, latitude2);
6110
+ const right = sample(b, longitude, latitude2);
6105
6111
  const valid = (left == null ? void 0 : left.status) === TerrainSampleStatus.VALID && (right == null ? void 0 : right.status) === TerrainSampleStatus.VALID;
6106
6112
  const derivatives = (left == null ? void 0 : left.gradientStatus) === TerrainSampleStatus.VALID && (right == null ? void 0 : right.gradientStatus) === TerrainSampleStatus.VALID;
6107
6113
  const normalAngle = derivatives ? Math.atan2(Math.hypot(left.normalY * right.normalZ - left.normalZ * right.normalY, left.normalZ * right.normalX - left.normalX * right.normalZ, left.normalX * right.normalY - left.normalY * right.normalX), left.normalX * right.normalX + left.normalY * right.normalY + left.normalZ * right.normalZ) : null;
6108
6114
  return {
6109
6115
  longitude,
6110
- latitude,
6116
+ latitude: latitude2,
6111
6117
  statusA: (left == null ? void 0 : left.status) ?? TerrainSampleStatus.NOT_RESIDENT,
6112
6118
  statusB: (right == null ? void 0 : right.status) ?? TerrainSampleStatus.NOT_RESIDENT,
6113
6119
  gradientStatusA: (left == null ? void 0 : left.gradientStatus) ?? TerrainSampleStatus.NOT_RESIDENT,
@@ -7161,11 +7167,11 @@ function discoverGeographicTerrainLodSeams(cut) {
7161
7167
 
7162
7168
  // dist/terrain/geographic-poles.js
7163
7169
  function discoverGeographicTerrainPoles(cut) {
7164
- function collect(latitude, edge2) {
7170
+ function collect(latitude2, edge2) {
7165
7171
  const incident = [];
7166
7172
  for (let tile = 0; tile < cut.length; tile++) {
7167
7173
  const [west, south, east, north] = getGeographicTileBounds(cut[tile]);
7168
- if ((edge2 === "north" ? north : south) === latitude)
7174
+ if ((edge2 === "north" ? north : south) === latitude2)
7169
7175
  incident.push({ tile, edge: edge2, longitude: [west, east] });
7170
7176
  }
7171
7177
  incident.sort((a, b) => a.longitude[0] - b.longitude[0]);
@@ -7180,7 +7186,7 @@ function discoverGeographicTerrainPoles(cut) {
7180
7186
  }
7181
7187
  if (cursor < 180)
7182
7188
  gaps.push([cursor, 180]);
7183
- return { latitude, incident, gaps };
7189
+ return { latitude: latitude2, incident, gaps };
7184
7190
  }
7185
7191
  return { north: collect(90, "north"), south: collect(-90, "south") };
7186
7192
  }
@@ -7551,6 +7557,29 @@ function fillTerrainDepressions(field, { outlets, maxCells = 4194304 }) {
7551
7557
  };
7552
7558
  }
7553
7559
 
7560
+ // dist/terrain/cutout-region.js
7561
+ var PLAN = /* @__PURE__ */ Symbol.for("@math.gl/geospatial/terrain-cutout-polygons/v1");
7562
+ function createTerrainCutoutPlan(plan) {
7563
+ return Object.freeze({ [PLAN]: Object.freeze(plan) });
7564
+ }
7565
+ function getTerrainCutoutPlan(region) {
7566
+ if (Array.isArray(region))
7567
+ return void 0;
7568
+ const plan = region == null ? void 0 : region[PLAN];
7569
+ if (!plan)
7570
+ throw new RangeError("Invalid prepared terrain cutout polygons");
7571
+ return plan;
7572
+ }
7573
+ function copyTerrainCutoutRegion(region) {
7574
+ return getTerrainCutoutPlan(region) ? region : region.map((p) => [p[0], p[1]]);
7575
+ }
7576
+ function sameTerrainCutoutRegion(a, b) {
7577
+ if (getTerrainCutoutPlan(a) || getTerrainCutoutPlan(b))
7578
+ return a === b;
7579
+ const aa = a, bb = b;
7580
+ return aa.length === bb.length && aa.every((p, i) => bb[i].length === 2 && p[0] === bb[i][0] && p[1] === bb[i][1]);
7581
+ }
7582
+
7554
7583
  // dist/terrain/mesh-cutout.js
7555
7584
  function splitTerrainMesh(mesh, polygon2, { maxWork = 4e6, maxVertices = 5e5, maxTriangles = 5e5 } = {}) {
7556
7585
  if (![maxWork, maxVertices, maxTriangles].every((n) => Number.isSafeInteger(n) && n >= 0) || maxVertices > 4294967295 || maxTriangles > 4294967295 || !(mesh.positions instanceof Float32Array || mesh.positions instanceof Float64Array) || !(mesh.indices instanceof Uint16Array || mesh.indices instanceof Uint32Array) || mesh.positions.length % 3 || mesh.indices.length % 3 || mesh.positions.length / 3 > maxVertices || mesh.indices.length / 3 > maxTriangles || !mesh.positions.every(Number.isFinite))
@@ -7561,7 +7590,9 @@ function splitTerrainMesh(mesh, polygon2, { maxWork = 4e6, maxVertices = 5e5, ma
7561
7590
  if (work > maxWork)
7562
7591
  throw new RangeError("Terrain cutout work budget exceeded");
7563
7592
  }
7564
- const ring = validatePolygon(polygon2, charge);
7593
+ const prepared = getTerrainCutoutPlan(polygon2);
7594
+ const ring = prepared ? void 0 : validatePolygon(polygon2, charge);
7595
+ const lines = (prepared == null ? void 0 : prepared.lines) ?? ring.map((p, i) => [p, ring[(i + 1) % ring.length]]);
7565
7596
  const vertices = [];
7566
7597
  for (let i = 0; i < mesh.positions.length; i += 3)
7567
7598
  vertices.push([mesh.positions[i], mesh.positions[i + 1], mesh.positions[i + 2]]);
@@ -7576,7 +7607,7 @@ function splitTerrainMesh(mesh, polygon2, { maxWork = 4e6, maxVertices = 5e5, ma
7576
7607
  validateTopology(vertices, faces, charge);
7577
7608
  const patch = createPiece();
7578
7609
  const remainder = createPiece();
7579
- const intersections = ring.map(() => /* @__PURE__ */ new Map());
7610
+ const intersections = lines.map(() => /* @__PURE__ */ new Map());
7580
7611
  let fragmentCount = 0;
7581
7612
  function addVertex(vertex) {
7582
7613
  if (vertices.length >= maxVertices || !vertex.every(Number.isFinite))
@@ -7589,6 +7620,11 @@ function splitTerrainMesh(mesh, polygon2, { maxWork = 4e6, maxVertices = 5e5, ma
7589
7620
  const saved = cache.get(key2);
7590
7621
  if (saved !== void 0)
7591
7622
  return saved;
7623
+ const pa = vertices[a], pb = vertices[b];
7624
+ if (pa[0] > pb[0] || pa[0] === pb[0] && (pa[1] > pb[1] || pa[1] === pb[1] && pa[2] > pb[2])) {
7625
+ [a, b] = [b, a];
7626
+ [da, db] = [db, da];
7627
+ }
7592
7628
  const t = Math.abs(da) / (Math.abs(da) + Math.abs(db));
7593
7629
  if (!(t > 0 && t < 1))
7594
7630
  throw new RangeError("Unrepresentable terrain cut intersection");
@@ -7604,10 +7640,9 @@ function splitTerrainMesh(mesh, polygon2, { maxWork = 4e6, maxVertices = 5e5, ma
7604
7640
  }
7605
7641
  for (let source = 0; source < faces.length; source++) {
7606
7642
  let fragments = [{ ids: faces[source], inside: true }];
7607
- for (let line = 0; line < ring.length; line++) {
7643
+ for (let line = 0; line < lines.length; line++) {
7608
7644
  const next = [];
7609
- const a = ring[line];
7610
- const b = ring[(line + 1) % ring.length];
7645
+ const [a, b] = lines[line];
7611
7646
  for (const fragment of fragments) {
7612
7647
  const { ids } = fragment;
7613
7648
  charge(ids.length);
@@ -7644,22 +7679,26 @@ function splitTerrainMesh(mesh, polygon2, { maxWork = 4e6, maxVertices = 5e5, ma
7644
7679
  }
7645
7680
  fragmentCount += fragments.length;
7646
7681
  for (const { ids, inside } of fragments) {
7647
- const piece = inside ? patch : remainder;
7648
- if (ids.length === 3)
7649
- emit(piece, ids, source);
7650
- else {
7651
- const center = [...vertices[ids[0]]];
7682
+ let center;
7683
+ if (prepared || ids.length > 3) {
7684
+ center = [...vertices[ids[0]]];
7652
7685
  for (const id of ids) {
7653
7686
  for (let k = 0; k < 3; k++)
7654
7687
  center[k] += (vertices[id][k] - vertices[ids[0]][k]) / ids.length;
7655
7688
  }
7689
+ }
7690
+ const polygonIndex = prepared ? prepared.classify([center[0], center[1]], charge) : inside ? 0 : -1;
7691
+ const piece = polygonIndex >= 0 ? patch : remainder;
7692
+ if (ids.length === 3)
7693
+ emit(piece, ids, source, polygonIndex);
7694
+ else {
7656
7695
  const hub = addVertex(center);
7657
7696
  for (let i = 0; i < ids.length; i++)
7658
- emit(piece, [ids[i], ids[(i + 1) % ids.length], hub], source);
7697
+ emit(piece, [ids[i], ids[(i + 1) % ids.length], hub], source, polygonIndex);
7659
7698
  }
7660
7699
  }
7661
7700
  }
7662
- function emit(piece, face, source) {
7701
+ function emit(piece, face, source, polygonIndex) {
7663
7702
  if (patch.sourceFaces.length + remainder.sourceFaces.length >= maxTriangles)
7664
7703
  throw new RangeError("Terrain cutout triangle budget exceeded");
7665
7704
  checkTriangle(vertices[face[0]], vertices[face[1]], vertices[face[2]]);
@@ -7677,9 +7716,10 @@ function splitTerrainMesh(mesh, polygon2, { maxWork = 4e6, maxVertices = 5e5, ma
7677
7716
  piece.sourceWeights.push(cross3(b, c, p) / area, cross3(c, a, p) / area, cross3(a, b, p) / area);
7678
7717
  }
7679
7718
  piece.indices.push(piece.ids.get(id));
7680
- addEdge(piece.boundary, id, face[(i + 1) % 3]);
7719
+ addEdge(piece.boundary, id, face[(i + 1) % 3], polygonIndex);
7681
7720
  }
7682
7721
  piece.sourceFaces.push(source);
7722
+ piece.polygonIndices.push(polygonIndex);
7683
7723
  }
7684
7724
  for (const [key2, inside] of patch.boundary) {
7685
7725
  const outside = remainder.boundary.get(key2);
@@ -7690,6 +7730,8 @@ function splitTerrainMesh(mesh, polygon2, { maxWork = 4e6, maxVertices = 5e5, ma
7690
7730
  throw new Error("Nonconforming terrain cut boundary");
7691
7731
  patch.cutEdges.push(patch.ids.get(a), patch.ids.get(b));
7692
7732
  remainder.cutEdges.push(remainder.ids.get(b), remainder.ids.get(a));
7733
+ patch.cutPolygonIndices.push(inside.polygon);
7734
+ remainder.cutPolygonIndices.push(inside.polygon);
7693
7735
  }
7694
7736
  return { patch: finish(patch), remainder: finish(remainder) };
7695
7737
  }
@@ -7770,11 +7812,11 @@ function checkJunctions(a, b, vertices) {
7770
7812
  throw new RangeError("Terrain cut input has an unwelded shared edge");
7771
7813
  }
7772
7814
  }
7773
- function addEdge(edges2, a, b) {
7815
+ function addEdge(edges2, a, b, polygon2 = -1) {
7774
7816
  const key2 = edgeKey2(a, b);
7775
7817
  const entry = edges2.get(key2);
7776
7818
  if (!entry)
7777
- edges2.set(key2, { edge: [a, b], count: 1 });
7819
+ edges2.set(key2, { edge: [a, b], count: 1, polygon: polygon2 });
7778
7820
  else {
7779
7821
  if (entry.count !== 1 || entry.edge[0] !== b)
7780
7822
  throw new RangeError("Terrain cut mesh has inconsistent or nonmanifold edges");
@@ -7796,7 +7838,9 @@ function createPiece() {
7796
7838
  sourceWeights: [],
7797
7839
  sourceFaces: [],
7798
7840
  boundary: /* @__PURE__ */ new Map(),
7799
- cutEdges: []
7841
+ cutEdges: [],
7842
+ polygonIndices: [],
7843
+ cutPolygonIndices: []
7800
7844
  };
7801
7845
  }
7802
7846
  function finish(piece) {
@@ -7806,9 +7850,25 @@ function finish(piece) {
7806
7850
  sourceTriangles: Uint32Array.from(piece.sourceTriangles),
7807
7851
  sourceWeights: Float64Array.from(piece.sourceWeights),
7808
7852
  sourceFaces: Uint32Array.from(piece.sourceFaces),
7809
- cutEdges: Uint32Array.from(piece.cutEdges)
7853
+ cutEdges: Uint32Array.from(piece.cutEdges),
7854
+ polygonIndices: Uint32Array.from(piece.polygonIndices),
7855
+ cutPolygonIndices: Uint32Array.from(piece.cutPolygonIndices)
7810
7856
  };
7811
7857
  }
7858
+ function validateTerrainCutoutTopology(mesh, maxWork) {
7859
+ const vertices = [];
7860
+ const faces = [];
7861
+ for (let i = 0; i < mesh.positions.length; i += 3)
7862
+ vertices.push([mesh.positions[i], mesh.positions[i + 1], mesh.positions[i + 2]]);
7863
+ for (let i = 0; i < mesh.indices.length; i += 3)
7864
+ faces.push([mesh.indices[i], mesh.indices[i + 1], mesh.indices[i + 2]]);
7865
+ let work = 0;
7866
+ validateTopology(vertices, faces, (amount) => {
7867
+ work += amount;
7868
+ if (work > maxWork)
7869
+ throw new RangeError("Terrain cutout topology work budget exceeded");
7870
+ });
7871
+ }
7812
7872
 
7813
7873
  // dist/terrain/cutout-skirts.js
7814
7874
  function createTerrainCutoutSkirts(cutout, { lift = 0, patch, remainder }) {
@@ -7878,4 +7938,440 @@ function accumulateTerrainWatersheds(receiver, { maxCells = 4194304 } = {}) {
7878
7938
  }
7879
7939
  return { terminal, contributingCells };
7880
7940
  }
7941
+
7942
+ // dist/terrain/tile-cutout.js
7943
+ function splitTerrainMeshTiles(tiles, polygon2, options = {}) {
7944
+ const assembled = assembleTerrainCutoutTiles(tiles, options);
7945
+ return {
7946
+ ...splitTerrainMesh(assembled.mesh, polygon2, { ...options, maxWork: assembled.remainingWork }),
7947
+ sourceTiles: assembled.sourceTiles,
7948
+ sourceTileFaces: assembled.sourceTileFaces
7949
+ };
7950
+ }
7951
+ function assembleTerrainCutoutTiles(tiles, options = {}) {
7952
+ const maxVertices = options.maxVertices ?? 5e5;
7953
+ const maxTriangles = options.maxTriangles ?? 5e5;
7954
+ const maxWork = options.maxWork ?? 4e6;
7955
+ if (![maxVertices, maxTriangles, maxWork].every((n) => Number.isSafeInteger(n) && n >= 0) || maxVertices > 4294967295 || maxTriangles > 4294967295)
7956
+ throw new RangeError("Invalid terrain tile cutout limits");
7957
+ let vertexCount = 0;
7958
+ let faceCount = 0;
7959
+ let work = 0;
7960
+ for (const tile of tiles) {
7961
+ if (!(tile.positions instanceof Float32Array || tile.positions instanceof Float64Array) || !(tile.indices instanceof Uint16Array || tile.indices instanceof Uint32Array) || tile.positions.length % 3 || tile.indices.length % 3)
7962
+ throw new RangeError("Invalid terrain tile cutout mesh");
7963
+ vertexCount += tile.positions.length / 3;
7964
+ faceCount += tile.indices.length / 3;
7965
+ work += 1 + tile.positions.length / 3 + tile.indices.length;
7966
+ if (vertexCount > maxVertices || faceCount > maxTriangles || work > maxWork)
7967
+ throw new RangeError("Terrain tile cutout input budget exceeded");
7968
+ }
7969
+ const positions = new Float64Array(vertexCount * 3);
7970
+ const indices = new Uint32Array(faceCount * 3);
7971
+ const sourceTiles = new Uint32Array(faceCount);
7972
+ const sourceTileFaces = new Uint32Array(faceCount);
7973
+ const vertices = /* @__PURE__ */ new Map();
7974
+ let vertexOffset = 0;
7975
+ let faceOffset = 0;
7976
+ for (let tileIndex = 0; tileIndex < tiles.length; tileIndex++) {
7977
+ const tile = tiles[tileIndex];
7978
+ const remap = new Uint32Array(tile.positions.length / 3);
7979
+ for (let i = 0; i < remap.length; i++) {
7980
+ const x = tile.positions[i * 3];
7981
+ const y = tile.positions[i * 3 + 1];
7982
+ const z = tile.positions[i * 3 + 2];
7983
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
7984
+ throw new RangeError("Invalid terrain tile cutout coordinate");
7985
+ const key2 = `${x},${y},${z}`;
7986
+ let id = vertices.get(key2);
7987
+ if (id === void 0) {
7988
+ id = vertexOffset++;
7989
+ vertices.set(key2, id);
7990
+ positions[id * 3] = x;
7991
+ positions[id * 3 + 1] = y;
7992
+ positions[id * 3 + 2] = z;
7993
+ }
7994
+ remap[i] = id;
7995
+ }
7996
+ for (let i = 0; i < tile.indices.length; i++) {
7997
+ const id = tile.indices[i];
7998
+ if (id >= remap.length)
7999
+ throw new RangeError("Invalid terrain tile cutout index");
8000
+ indices[faceOffset * 3 + i] = remap[id];
8001
+ }
8002
+ for (let i = 0; i < tile.indices.length / 3; i++) {
8003
+ sourceTiles[faceOffset + i] = tileIndex;
8004
+ sourceTileFaces[faceOffset + i] = i;
8005
+ }
8006
+ faceOffset += tile.indices.length / 3;
8007
+ }
8008
+ return {
8009
+ mesh: { positions: positions.subarray(0, vertexOffset * 3), indices },
8010
+ sourceTiles,
8011
+ sourceTileFaces,
8012
+ remainingWork: maxWork - work
8013
+ };
8014
+ }
8015
+
8016
+ // dist/terrain/tile-cutout-update.js
8017
+ var CACHE = /* @__PURE__ */ Symbol("terrain-cutout-cache");
8018
+ function updateTerrainTileCutouts(residents, polygon2, previous, options = {}) {
8019
+ const limits = {
8020
+ maxTiles: options.maxTiles ?? 512,
8021
+ maxPairChecks: options.maxPairChecks ?? 131072,
8022
+ maxBoundaryEdges: options.maxBoundaryEdges ?? 1e6,
8023
+ maxWork: options.maxWork ?? 4e6,
8024
+ maxVertices: options.maxVertices ?? 5e5,
8025
+ maxTriangles: options.maxTriangles ?? 5e5
8026
+ };
8027
+ if (Object.values(limits).some((n) => !Number.isSafeInteger(n) || n < 0) || limits.maxVertices > 4294967295 || limits.maxTriangles > 4294967295 || residents.length > limits.maxTiles)
8028
+ throw new RangeError("Invalid terrain cutout update limits");
8029
+ const prior = previous == null ? void 0 : previous[CACHE];
8030
+ const compatible = prior && sameTerrainCutoutRegion(prior.polygon, polygon2) && Object.keys(limits).every((key2) => prior.options[key2] === limits[key2]);
8031
+ if (!compatible)
8032
+ splitTerrainMesh({ positions: new Float64Array(), indices: new Uint32Array() }, polygon2, limits);
8033
+ const entries = /* @__PURE__ */ new Map();
8034
+ const rebuilt = [];
8035
+ let boundaryCount = 0;
8036
+ for (const resident of residents) {
8037
+ if (!resident.id || typeof resident.id !== "string" || entries.has(resident.id) || !Number.isSafeInteger(resident.revision) || resident.revision < 0)
8038
+ throw new RangeError("Invalid or duplicate terrain cutout resident");
8039
+ const old = compatible ? prior.entries.get(resident.id) : void 0;
8040
+ let entry;
8041
+ if (old && old.resident.mesh === resident.mesh && old.resident.revision === resident.revision)
8042
+ entry = old;
8043
+ else {
8044
+ const split = splitTerrainMesh(resident.mesh, polygon2, limits);
8045
+ const edges2 = [...boundaryEdges(split.patch, 0), ...boundaryEdges(split.remainder, 1)];
8046
+ const bounds2 = [Infinity, Infinity, -Infinity, -Infinity];
8047
+ for (const id of resident.mesh.indices) {
8048
+ const x = resident.mesh.positions[id * 3], y = resident.mesh.positions[id * 3 + 1];
8049
+ bounds2[0] = Math.min(bounds2[0], x);
8050
+ bounds2[1] = Math.min(bounds2[1], y);
8051
+ bounds2[2] = Math.max(bounds2[2], x);
8052
+ bounds2[3] = Math.max(bounds2[3], y);
8053
+ }
8054
+ entry = { resident: { ...resident }, split, displayed: split, bounds: bounds2, edges: edges2 };
8055
+ rebuilt.push(resident.id);
8056
+ }
8057
+ boundaryCount += entry.edges.length;
8058
+ if (boundaryCount > limits.maxBoundaryEdges)
8059
+ throw new RangeError("Terrain cutout boundary budget exceeded");
8060
+ entries.set(resident.id, entry);
8061
+ }
8062
+ const values = [...entries.values()];
8063
+ let pairs = 0;
8064
+ for (let i = 0; i < values.length; i++)
8065
+ for (let j = i + 1; j < values.length; j++) {
8066
+ if (++pairs > limits.maxPairChecks)
8067
+ throw new RangeError("Terrain cutout pair budget exceeded");
8068
+ const a = values[i], b = values[j];
8069
+ if (a.bounds[2] < b.bounds[0] || b.bounds[2] < a.bounds[0] || a.bounds[3] < b.bounds[1] || b.bounds[3] < a.bounds[1])
8070
+ continue;
8071
+ if (compatible && prior.entries.get(a.resident.id) === a && prior.entries.get(b.resident.id) === b)
8072
+ continue;
8073
+ const combined = assembleTerrainCutoutTiles([a.resident.mesh, b.resident.mesh], limits);
8074
+ validateTerrainCutoutTopology(combined.mesh, combined.remainingWork);
8075
+ }
8076
+ const boundaries = /* @__PURE__ */ new Map();
8077
+ const cutKeys = /* @__PURE__ */ new Map();
8078
+ for (let tile = 0; tile < values.length; tile++)
8079
+ for (const edge2 of values[tile].edges) {
8080
+ const other = boundaries.get(edge2.key);
8081
+ if (!other) {
8082
+ boundaries.set(edge2.key, { edge: edge2, paired: false });
8083
+ continue;
8084
+ }
8085
+ if (other.paired || other.edge.start !== edge2.end || other.edge.end !== edge2.start)
8086
+ throw new RangeError("Nonconforming terrain cutout tile boundary");
8087
+ other.paired = true;
8088
+ if (other.edge.side !== edge2.side) {
8089
+ cutKeys.set(edge2.key, edge2.side === 0 ? edge2.polygon : other.edge.polygon);
8090
+ }
8091
+ }
8092
+ const tiles = /* @__PURE__ */ new Map();
8093
+ const changed = [];
8094
+ for (let i = 0; i < values.length; i++) {
8095
+ const entry = values[i];
8096
+ const old = prior == null ? void 0 : prior.entries.get(entry.resident.id);
8097
+ const cuts = [[], []];
8098
+ const polygons = [[], []];
8099
+ for (const edge2 of entry.edges) {
8100
+ const polygonIndex = cutKeys.get(edge2.key);
8101
+ if (polygonIndex !== void 0) {
8102
+ cuts[edge2.side].push(edge2.a, edge2.b);
8103
+ polygons[edge2.side].push(polygonIndex);
8104
+ }
8105
+ }
8106
+ const patch = withEdges(entry.split.patch, cuts[0], polygons[0], old == null ? void 0 : old.displayed.patch);
8107
+ const remainder = withEdges(entry.split.remainder, cuts[1], polygons[1], old == null ? void 0 : old.displayed.remainder);
8108
+ const displayed = old && patch === old.displayed.patch && remainder === old.displayed.remainder ? old.displayed : { patch, remainder };
8109
+ if (displayed !== (old == null ? void 0 : old.displayed))
8110
+ changed.push(entry.resident.id);
8111
+ entries.set(entry.resident.id, displayed === entry.displayed ? entry : { ...entry, displayed });
8112
+ tiles.set(entry.resident.id, displayed);
8113
+ }
8114
+ return {
8115
+ cache: { [CACHE]: { polygon: copyTerrainCutoutRegion(polygon2), options: limits, entries } },
8116
+ tiles,
8117
+ changed,
8118
+ rebuilt,
8119
+ removed: prior ? [...prior.entries.keys()].filter((id) => !entries.has(id)) : []
8120
+ };
8121
+ }
8122
+ function withEdges(piece, edges2, polygons, old) {
8123
+ const same = old && old.positions === piece.positions && old.cutEdges.length === edges2.length && old.cutEdges.every((id, i) => id === edges2[i]) && old.cutPolygonIndices.every((id, i) => id === polygons[i]);
8124
+ return same ? old : { ...piece, cutEdges: Uint32Array.from(edges2), cutPolygonIndices: Uint32Array.from(polygons) };
8125
+ }
8126
+ function boundaryEdges(piece, side) {
8127
+ const edges2 = /* @__PURE__ */ new Map();
8128
+ for (let i = 0; i < piece.indices.length; i += 3)
8129
+ for (let j = 0; j < 3; j++) {
8130
+ const a = piece.indices[i + j], b = piece.indices[i + (j + 1) % 3];
8131
+ const key2 = a < b ? `${a},${b}` : `${b},${a}`;
8132
+ const old = edges2.get(key2);
8133
+ if (old)
8134
+ old.count++;
8135
+ else
8136
+ edges2.set(key2, { a, b, count: 1, polygon: piece.polygonIndices[i / 3] });
8137
+ }
8138
+ const result = [];
8139
+ const point = (id) => `${piece.positions[id * 3]},${piece.positions[id * 3 + 1]},${piece.positions[id * 3 + 2]}`;
8140
+ for (const { a, b, count, polygon: polygon2 } of edges2.values())
8141
+ if (count === 1) {
8142
+ const start = point(a), end = point(b);
8143
+ result.push({
8144
+ polygon: polygon2,
8145
+ a,
8146
+ b,
8147
+ side,
8148
+ start,
8149
+ end,
8150
+ key: start < end ? `${start}/${end}` : `${end}/${start}`
8151
+ });
8152
+ }
8153
+ return result;
8154
+ }
8155
+
8156
+ // dist/terrain/geographic-cutout.js
8157
+ var RAD = Math.PI / 180;
8158
+ function createGeographicTerrainCutoutFrame(options) {
8159
+ if (options.center.length !== 2)
8160
+ throw new RangeError("Invalid geographic terrain cutout center");
8161
+ const frame = {
8162
+ center: [wrap(options.center[0]), options.center[1]],
8163
+ radius: options.radius ?? 6378137,
8164
+ maxAngularRadius: options.maxAngularRadius ?? 30
8165
+ };
8166
+ validateFrame(frame);
8167
+ return Object.freeze({ ...frame, center: Object.freeze(frame.center) });
8168
+ }
8169
+ function projectGeographicTerrainCutout(positions, frame) {
8170
+ var _a;
8171
+ validateFrame(frame);
8172
+ validatePositions(positions);
8173
+ const result = new Float64Array(positions.length);
8174
+ const [sin0, cos0] = latitude(frame.center[1]);
8175
+ const maximum = chartLimit(frame);
8176
+ for (let i = 0; i < positions.length; i += 3) {
8177
+ const lon = positions[i], lat = positions[i + 1];
8178
+ if (lat < -90 || lat > 90)
8179
+ throw new RangeError("Invalid geographic terrain latitude");
8180
+ const sin = Math.sin(lat * RAD);
8181
+ const cos = Math.abs(lat) === 90 ? 0 : Math.cos(lat * RAD);
8182
+ const delta = wrap(wrap(lon) - frame.center[0]) * RAD;
8183
+ const dot2 = sin0 * sin + cos0 * cos * Math.cos(delta);
8184
+ const x = cos * Math.sin(delta) / dot2;
8185
+ const y = (cos0 * sin - sin0 * cos * Math.cos(delta)) / dot2;
8186
+ if (!(dot2 > 0) || Math.hypot(x, y) > maximum)
8187
+ throw new RangeError("Terrain coordinate exceeds geographic cutout chart");
8188
+ result[i] = frame.radius * x;
8189
+ result[i + 1] = frame.radius * y;
8190
+ result[i] || (result[i] = 0);
8191
+ result[_a = i + 1] || (result[_a] = 0);
8192
+ result[i + 2] = positions[i + 2];
8193
+ }
8194
+ if (!result.every(Number.isFinite))
8195
+ throw new RangeError("Geographic terrain projection overflow");
8196
+ return result;
8197
+ }
8198
+ function unprojectGeographicTerrainCutout(positions, frame) {
8199
+ validateFrame(frame);
8200
+ validatePositions(positions);
8201
+ const result = new Float64Array(positions.length);
8202
+ const [sin0, cos0] = latitude(frame.center[1]);
8203
+ const maximum = chartLimit(frame);
8204
+ for (let i = 0; i < positions.length; i += 3) {
8205
+ const x = positions[i] / frame.radius, y = positions[i + 1] / frame.radius;
8206
+ const distance = Math.hypot(x, y);
8207
+ if (!Number.isFinite(distance) || distance > maximum)
8208
+ throw new RangeError("Terrain coordinate exceeds geographic cutout chart");
8209
+ const horizontal = cos0 - y * sin0;
8210
+ const vertical = sin0 + y * cos0;
8211
+ const lat = Math.atan2(vertical, Math.hypot(horizontal, x)) / RAD;
8212
+ result[i] = Math.abs(lat) === 90 ? frame.center[0] : wrap(frame.center[0] + Math.atan2(x, horizontal) / RAD);
8213
+ result[i + 1] = lat;
8214
+ result[i + 2] = positions[i + 2];
8215
+ }
8216
+ return result;
8217
+ }
8218
+ function wrap(longitude) {
8219
+ const result = longitude % 360;
8220
+ return result >= 180 ? result - 360 : result < -180 ? result + 360 : result;
8221
+ }
8222
+ function latitude(degrees) {
8223
+ return [Math.sin(degrees * RAD), Math.abs(degrees) === 90 ? 0 : Math.cos(degrees * RAD)];
8224
+ }
8225
+ function validateFrame(frame) {
8226
+ if (frame.center.length !== 2 || !frame.center.every(Number.isFinite) || frame.center[0] < -180 || frame.center[0] >= 180 || Math.abs(frame.center[1]) > 90 || !Number.isFinite(frame.radius) || frame.radius <= 0 || !Number.isFinite(frame.maxAngularRadius) || frame.maxAngularRadius <= 0 || frame.maxAngularRadius > 80)
8227
+ throw new RangeError("Invalid geographic terrain cutout frame");
8228
+ }
8229
+ function validatePositions(positions) {
8230
+ if (!(positions instanceof Float32Array || positions instanceof Float64Array) || positions.length % 3 || !positions.every(Number.isFinite))
8231
+ throw new RangeError("Invalid geographic terrain cutout positions");
8232
+ }
8233
+ function chartLimit(frame) {
8234
+ const distance = Math.tan(frame.maxAngularRadius * RAD);
8235
+ return distance + 16 * Number.EPSILON * (1 + distance);
8236
+ }
8237
+
8238
+ // dist/terrain/cutout-polygons.js
8239
+ function prepareTerrainCutoutPolygons(polygons, { maxEdges = 2048, maxWork = 4e6 } = {}) {
8240
+ if (![maxEdges, maxWork].every((n) => Number.isSafeInteger(n) && n >= 0) || !polygons.length)
8241
+ throw new RangeError("Invalid terrain cutout polygon limits or empty set");
8242
+ let work = 0, edgeCount = 0;
8243
+ const charge = (amount) => {
8244
+ work += amount;
8245
+ if (work > maxWork)
8246
+ throw new RangeError("Terrain cutout polygon work budget exceeded");
8247
+ };
8248
+ if (polygons.length > Math.floor(maxEdges / 3))
8249
+ throw new RangeError("Terrain cutout polygon edge budget exceeded");
8250
+ const regions = polygons.map((p) => {
8251
+ var _a;
8252
+ if (1 + (((_a = p.holes) == null ? void 0 : _a.length) ?? 0) > Math.floor((maxEdges - edgeCount) / 3))
8253
+ throw new RangeError("Terrain cutout polygon edge budget exceeded");
8254
+ return [p.outer, ...p.holes ?? []].map((ring) => {
8255
+ edgeCount += ring.length;
8256
+ if (edgeCount > maxEdges)
8257
+ throw new RangeError("Terrain cutout polygon edge budget exceeded");
8258
+ charge(ring.length);
8259
+ if (ring.length < 3 || ring.some((p2) => p2.length !== 2 || !p2.every(Number.isFinite)))
8260
+ throw new RangeError("Invalid terrain cutout polygon ring");
8261
+ return ring.map((p2) => Object.freeze([p2[0], p2[1]]));
8262
+ });
8263
+ });
8264
+ const rings = regions.flat();
8265
+ for (const ring of rings) {
8266
+ let area = 0;
8267
+ for (let i = 0; i < ring.length; i++) {
8268
+ charge(1);
8269
+ const a = ring[i], b = ring[(i + 1) % ring.length], c = ring[(i + 2) % ring.length];
8270
+ if (equal(a, b))
8271
+ throw new RangeError("Duplicate terrain cutout ring vertex");
8272
+ area += orient2(ring[0], a, b);
8273
+ if (orient2(a, b, c) === 0 && (a[0] - b[0]) * (c[0] - b[0]) + (a[1] - b[1]) * (c[1] - b[1]) >= 0)
8274
+ throw new RangeError("Backtracking terrain cutout ring edge");
8275
+ for (let j = i + 1; j < ring.length; j++) {
8276
+ if (j === i + 1 || i === 0 && j === ring.length - 1)
8277
+ continue;
8278
+ charge(1);
8279
+ if (intersects2(a, b, ring[j], ring[(j + 1) % ring.length]))
8280
+ throw new RangeError("Self-intersecting terrain cutout ring");
8281
+ }
8282
+ }
8283
+ if (!Number.isFinite(area) || area === 0)
8284
+ throw new RangeError("Degenerate terrain cutout ring");
8285
+ }
8286
+ for (let i = 0; i < rings.length; i++)
8287
+ for (let j = i + 1; j < rings.length; j++) {
8288
+ const a = rings[i], b = rings[j];
8289
+ for (let x = 0; x < a.length; x++)
8290
+ for (let y = 0; y < b.length; y++) {
8291
+ charge(1);
8292
+ if (intersects2(a[x], a[(x + 1) % a.length], b[y], b[(y + 1) % b.length]))
8293
+ throw new RangeError("Terrain cutout rings must not touch or intersect");
8294
+ }
8295
+ }
8296
+ for (const region of regions)
8297
+ for (let i = 1; i < region.length; i++) {
8298
+ if (contains(region[0], region[i][0], charge) !== 1)
8299
+ throw new RangeError("Terrain cutout hole must be strictly inside its outer ring");
8300
+ for (let j = 1; j < i; j++)
8301
+ if (contains(region[j], region[i][0], charge) === 1 || contains(region[i], region[j][0], charge) === 1)
8302
+ throw new RangeError("Nested terrain cutout holes are not supported");
8303
+ }
8304
+ function inRegion(region, point, budget) {
8305
+ const outer = contains(region[0], point, budget);
8306
+ if (outer !== 1)
8307
+ return outer;
8308
+ for (let i = 1; i < region.length; i++) {
8309
+ const hole = contains(region[i], point, budget);
8310
+ if (hole === 0)
8311
+ return 0;
8312
+ if (hole === 1)
8313
+ return -1;
8314
+ }
8315
+ return 1;
8316
+ }
8317
+ for (let i = 0; i < regions.length; i++)
8318
+ for (let j = i + 1; j < regions.length; j++) {
8319
+ if (inRegion(regions[i], regions[j][0][0], charge) === 1 || inRegion(regions[j], regions[i][0][0], charge) === 1)
8320
+ throw new RangeError("Overlapping terrain cutout polygon domains");
8321
+ }
8322
+ const lines = [];
8323
+ for (const ring of rings)
8324
+ for (let i = 0; i < ring.length; i++) {
8325
+ const a = ring[i], b = ring[(i + 1) % ring.length];
8326
+ if (lines.some(([u, v]) => {
8327
+ charge(1);
8328
+ return orient2(u, v, a) === 0 && orient2(u, v, b) === 0;
8329
+ }))
8330
+ continue;
8331
+ lines.push(a[0] < b[0] || a[0] === b[0] && a[1] < b[1] ? [a, b] : [b, a]);
8332
+ }
8333
+ return createTerrainCutoutPlan({
8334
+ lines: Object.freeze(lines.map((line) => Object.freeze(line))),
8335
+ classify(point, budget) {
8336
+ for (let i = 0; i < regions.length; i++) {
8337
+ const result = inRegion(regions[i], point, budget);
8338
+ if (result === 0)
8339
+ throw new RangeError("Unrepresentable terrain cutout fragment interior");
8340
+ if (result === 1)
8341
+ return i;
8342
+ }
8343
+ return -1;
8344
+ }
8345
+ });
8346
+ }
8347
+ function equal(a, b) {
8348
+ return a[0] === b[0] && a[1] === b[1];
8349
+ }
8350
+ function orient2(a, b, c) {
8351
+ const value = (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
8352
+ if (!Number.isFinite(value))
8353
+ throw new RangeError("Terrain cutout polygon coordinate overflow");
8354
+ return value;
8355
+ }
8356
+ function onSegment2(a, b, p) {
8357
+ return p[0] >= Math.min(a[0], b[0]) && p[0] <= Math.max(a[0], b[0]) && p[1] >= Math.min(a[1], b[1]) && p[1] <= Math.max(a[1], b[1]);
8358
+ }
8359
+ function intersects2(a, b, c, d) {
8360
+ const abC = orient2(a, b, c), abD = orient2(a, b, d), cdA = orient2(c, d, a), cdB = orient2(c, d, b);
8361
+ return abC === 0 && onSegment2(a, b, c) || abD === 0 && onSegment2(a, b, d) || cdA === 0 && onSegment2(c, d, a) || cdB === 0 && onSegment2(c, d, b) || (abC > 0 && abD < 0 || abC < 0 && abD > 0) && (cdA > 0 && cdB < 0 || cdA < 0 && cdB > 0);
8362
+ }
8363
+ function contains(ring, p, charge) {
8364
+ let winding = 0;
8365
+ for (let i = 0; i < ring.length; i++) {
8366
+ charge(1);
8367
+ const a = ring[i], b = ring[(i + 1) % ring.length], cross4 = orient2(a, b, p);
8368
+ if (cross4 === 0 && onSegment2(a, b, p))
8369
+ return 0;
8370
+ if (a[1] <= p[1] && b[1] > p[1] && cross4 > 0)
8371
+ winding++;
8372
+ if (a[1] > p[1] && b[1] <= p[1] && cross4 < 0)
8373
+ winding--;
8374
+ }
8375
+ return winding === 0 ? -1 : 1;
8376
+ }
7881
8377
  //# sourceMappingURL=index.cjs.map