@math.gl/geospatial 5.0.0-beta.1 → 5.0.0-beta.3

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 (177) hide show
  1. package/dist/crs/crs-identifier.d.ts +23 -0
  2. package/dist/crs/crs-identifier.d.ts.map +1 -0
  3. package/dist/crs/crs-identifier.js +74 -0
  4. package/dist/crs/crs-identifier.js.map +1 -0
  5. package/dist/crs/index.cjs +48 -0
  6. package/dist/crs/index.cjs.map +2 -2
  7. package/dist/crs/index.d.ts +1 -0
  8. package/dist/crs/index.d.ts.map +1 -1
  9. package/dist/crs/index.js +1 -0
  10. package/dist/crs/index.js.map +1 -1
  11. package/dist/discontinuous/cap-map.d.ts.map +1 -1
  12. package/dist/discontinuous/cap-map.js +197 -13
  13. package/dist/discontinuous/cap-map.js.map +1 -1
  14. package/dist/discontinuous/elastic/geometry.d.ts +1 -1
  15. package/dist/discontinuous/elastic/geometry.d.ts.map +1 -1
  16. package/dist/discontinuous/elastic/geometry.js +7 -7
  17. package/dist/discontinuous/elastic/geometry.js.map +1 -1
  18. package/dist/discontinuous/elastic/map.d.ts.map +1 -1
  19. package/dist/discontinuous/elastic/map.js +263 -23
  20. package/dist/discontinuous/elastic/map.js.map +1 -1
  21. package/dist/discontinuous/elastic/source-arc.d.ts +10 -0
  22. package/dist/discontinuous/elastic/source-arc.d.ts.map +1 -0
  23. package/dist/discontinuous/elastic/source-arc.js +111 -0
  24. package/dist/discontinuous/elastic/source-arc.js.map +1 -0
  25. package/dist/discontinuous/global-polygons.d.ts +1 -1
  26. package/dist/discontinuous/global-polygons.d.ts.map +1 -1
  27. package/dist/discontinuous/global-polygons.js +49 -1
  28. package/dist/discontinuous/global-polygons.js.map +1 -1
  29. package/dist/discontinuous/map-engine.d.ts +9 -0
  30. package/dist/discontinuous/map-engine.d.ts.map +1 -1
  31. package/dist/discontinuous/map-layout.d.ts +21 -0
  32. package/dist/discontinuous/map-layout.d.ts.map +1 -1
  33. package/dist/discontinuous/map-layout.js +116 -1
  34. package/dist/discontinuous/map-layout.js.map +1 -1
  35. package/dist/discontinuous/map-transition.d.ts.map +1 -1
  36. package/dist/discontinuous/map-transition.js +66 -3
  37. package/dist/discontinuous/map-transition.js.map +1 -1
  38. package/dist/discontinuous/mercator-map.d.ts +2 -2
  39. package/dist/discontinuous/mercator-map.d.ts.map +1 -1
  40. package/dist/discontinuous/mercator-map.js +123 -11
  41. package/dist/discontinuous/mercator-map.js.map +1 -1
  42. package/dist/discontinuous/polygon-constraints.d.ts +16 -0
  43. package/dist/discontinuous/polygon-constraints.d.ts.map +1 -0
  44. package/dist/discontinuous/polygon-constraints.js +157 -0
  45. package/dist/discontinuous/polygon-constraints.js.map +1 -0
  46. package/dist/discontinuous/prepare-features.d.ts +27 -0
  47. package/dist/discontinuous/prepare-features.d.ts.map +1 -1
  48. package/dist/discontinuous/prepare-features.js +106 -5
  49. package/dist/discontinuous/prepare-features.js.map +1 -1
  50. package/dist/discontinuous/rotated-map.d.ts +9 -0
  51. package/dist/discontinuous/rotated-map.d.ts.map +1 -1
  52. package/dist/discontinuous/source-arc.d.ts +4 -0
  53. package/dist/discontinuous/source-arc.d.ts.map +1 -0
  54. package/dist/discontinuous/source-arc.js +23 -0
  55. package/dist/discontinuous/source-arc.js.map +1 -0
  56. package/dist/discontinuous/world-kernels.d.ts +1 -1
  57. package/dist/discontinuous.cjs +1047 -75
  58. package/dist/discontinuous.cjs.map +3 -3
  59. package/dist/index.cjs +422 -0
  60. package/dist/index.cjs.map +3 -3
  61. package/dist/index.d.ts +13 -1
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +8 -1
  64. package/dist/index.js.map +1 -1
  65. package/dist/tasks/definitions.d.ts +90 -0
  66. package/dist/tasks/definitions.d.ts.map +1 -0
  67. package/dist/tasks/definitions.js +54 -0
  68. package/dist/tasks/definitions.js.map +1 -0
  69. package/dist/{workers → tasks}/index.cjs +1223 -191
  70. package/dist/tasks/index.cjs.map +6 -0
  71. package/dist/tasks/index.d.ts +12 -0
  72. package/dist/tasks/index.d.ts.map +1 -0
  73. package/dist/tasks/index.js +30 -0
  74. package/dist/tasks/index.js.map +1 -0
  75. package/dist/{workers → tasks}/map-worker.d.ts.map +1 -1
  76. package/dist/tasks/map-worker.js +7 -0
  77. package/dist/tasks/map-worker.js.map +1 -0
  78. package/dist/{workers → tasks}/operations.d.ts +6 -4
  79. package/dist/tasks/operations.d.ts.map +1 -0
  80. package/dist/{workers → tasks}/operations.js +3 -5
  81. package/dist/tasks/operations.js.map +1 -0
  82. package/dist/tasks/projection-worker.d.ts.map +1 -0
  83. package/dist/tasks/projection-worker.js +7 -0
  84. package/dist/tasks/projection-worker.js.map +1 -0
  85. package/dist/terrain/filtered-pyramid.d.ts +22 -0
  86. package/dist/terrain/filtered-pyramid.d.ts.map +1 -0
  87. package/dist/terrain/filtered-pyramid.js +71 -0
  88. package/dist/terrain/filtered-pyramid.js.map +1 -0
  89. package/dist/terrain/index.cjs +375 -1
  90. package/dist/terrain/index.cjs.map +2 -2
  91. package/dist/terrain/index.d.ts +12 -0
  92. package/dist/terrain/index.d.ts.map +1 -1
  93. package/dist/terrain/index.js +7 -0
  94. package/dist/terrain/index.js.map +1 -1
  95. package/dist/terrain/profile-horizon.d.ts +20 -0
  96. package/dist/terrain/profile-horizon.d.ts.map +1 -0
  97. package/dist/terrain/profile-horizon.js +69 -0
  98. package/dist/terrain/profile-horizon.js.map +1 -0
  99. package/dist/terrain/profile-slope.d.ts +3 -0
  100. package/dist/terrain/profile-slope.d.ts.map +1 -0
  101. package/dist/terrain/profile-slope.js +35 -0
  102. package/dist/terrain/profile-slope.js.map +1 -0
  103. package/dist/terrain/profile-viewshed.d.ts +17 -0
  104. package/dist/terrain/profile-viewshed.d.ts.map +1 -0
  105. package/dist/terrain/profile-viewshed.js +51 -0
  106. package/dist/terrain/profile-viewshed.js.map +1 -0
  107. package/dist/terrain/profile-visibility.d.ts +21 -0
  108. package/dist/terrain/profile-visibility.d.ts.map +1 -0
  109. package/dist/terrain/profile-visibility.js +61 -0
  110. package/dist/terrain/profile-visibility.js.map +1 -0
  111. package/dist/terrain/vertex-halo-invalidation.d.ts +16 -0
  112. package/dist/terrain/vertex-halo-invalidation.d.ts.map +1 -0
  113. package/dist/terrain/vertex-halo-invalidation.js +50 -0
  114. package/dist/terrain/vertex-halo-invalidation.js.map +1 -0
  115. package/dist/terrain/vertex-halo-update.d.ts +18 -0
  116. package/dist/terrain/vertex-halo-update.d.ts.map +1 -0
  117. package/dist/terrain/vertex-halo-update.js +76 -0
  118. package/dist/terrain/vertex-halo-update.js.map +1 -0
  119. package/dist/terrain/vertex-halos.d.ts +26 -0
  120. package/dist/terrain/vertex-halos.d.ts.map +1 -0
  121. package/dist/terrain/vertex-halos.js +80 -0
  122. package/dist/terrain/vertex-halos.js.map +1 -0
  123. package/dist/turf.cjs +69 -5
  124. package/dist/turf.cjs.map +2 -2
  125. package/dist/turf.d.ts +9 -0
  126. package/dist/turf.d.ts.map +1 -1
  127. package/dist/turf.js +67 -0
  128. package/dist/turf.js.map +1 -1
  129. package/package.json +10 -15
  130. package/src/crs/crs-identifier.ts +86 -0
  131. package/src/crs/index.ts +1 -0
  132. package/src/discontinuous/cap-map.ts +248 -19
  133. package/src/discontinuous/elastic/geometry.ts +18 -7
  134. package/src/discontinuous/elastic/map.ts +334 -30
  135. package/src/discontinuous/elastic/source-arc.ts +129 -0
  136. package/src/discontinuous/global-polygons.ts +56 -2
  137. package/src/discontinuous/map-layout.ts +165 -2
  138. package/src/discontinuous/map-transition.ts +67 -3
  139. package/src/discontinuous/mercator-map.ts +151 -12
  140. package/src/discontinuous/polygon-constraints.ts +184 -0
  141. package/src/discontinuous/prepare-features.ts +154 -6
  142. package/src/discontinuous/source-arc.ts +31 -0
  143. package/src/index.ts +13 -0
  144. package/src/tasks/definitions.ts +89 -0
  145. package/src/tasks/index.ts +39 -0
  146. package/src/tasks/map-worker.ts +6 -0
  147. package/src/{workers → tasks}/operations.ts +11 -7
  148. package/src/tasks/projection-worker.ts +6 -0
  149. package/src/terrain/filtered-pyramid.ts +95 -0
  150. package/src/terrain/index.ts +12 -0
  151. package/src/terrain/profile-horizon.ts +86 -0
  152. package/src/terrain/profile-slope.ts +32 -0
  153. package/src/terrain/profile-viewshed.ts +57 -0
  154. package/src/terrain/profile-visibility.ts +81 -0
  155. package/src/terrain/vertex-halo-invalidation.ts +57 -0
  156. package/src/terrain/vertex-halo-update.ts +91 -0
  157. package/src/terrain/vertex-halos.ts +101 -0
  158. package/src/turf.ts +86 -0
  159. package/dist/workers/index.cjs.map +0 -6
  160. package/dist/workers/index.d.ts +0 -12
  161. package/dist/workers/index.d.ts.map +0 -1
  162. package/dist/workers/index.js +0 -41
  163. package/dist/workers/index.js.map +0 -1
  164. package/dist/workers/map-worker.js +0 -7
  165. package/dist/workers/map-worker.js.map +0 -1
  166. package/dist/workers/operations.cjs +0 -20036
  167. package/dist/workers/operations.cjs.map +0 -6
  168. package/dist/workers/operations.d.ts.map +0 -1
  169. package/dist/workers/operations.js.map +0 -1
  170. package/dist/workers/projection-worker.d.ts.map +0 -1
  171. package/dist/workers/projection-worker.js +0 -7
  172. package/dist/workers/projection-worker.js.map +0 -1
  173. package/src/workers/index.ts +0 -59
  174. package/src/workers/map-worker.ts +0 -7
  175. package/src/workers/projection-worker.ts +0 -7
  176. /package/dist/{workers → tasks}/map-worker.d.ts +0 -0
  177. /package/dist/{workers → tasks}/projection-worker.d.ts +0 -0
package/dist/index.cjs CHANGED
@@ -71,8 +71,10 @@ __export(index_exports, {
71
71
  RhumbPath: () => RhumbPath,
72
72
  RhumbPolygon: () => RhumbPolygon,
73
73
  TERRAIN_BUFFER_VERSION: () => TERRAIN_BUFFER_VERSION,
74
+ TerrainProfileViewStatus: () => TerrainProfileViewStatus,
74
75
  TerrainSampleStatus: () => TerrainSampleStatus,
75
76
  TerrainSurface: () => TerrainSurface,
77
+ TerrainVertexHaloStatus: () => TerrainVertexHaloStatus,
76
78
  TiledHeightField: () => TiledHeightField,
77
79
  TriaxialEllipsoid: () => TriaxialEllipsoid,
78
80
  WKBBuilder: () => WKBBuilder,
@@ -99,11 +101,13 @@ __export(index_exports, {
99
101
  createOrthographicCutAtlas: () => createOrthographicCutAtlas,
100
102
  createSpatialReference: () => createSpatialReference,
101
103
  createTerrainContours: () => createTerrainContours,
104
+ createTerrainFilteredPyramid: () => createTerrainFilteredPyramid,
102
105
  createTerrainGradientGrid: () => createTerrainGradientGrid,
103
106
  createTerrainMesh: () => createTerrainMesh,
104
107
  createTerrainSkirt: () => createTerrainSkirt,
105
108
  createTerrainSlopeAspectGrid: () => createTerrainSlopeAspectGrid,
106
109
  createTerrainSurface: () => createTerrainSurface,
110
+ createTerrainVertexTileHalos: () => createTerrainVertexTileHalos,
107
111
  decodeGeoArrowWKB: () => decodeGeoArrowWKB,
108
112
  decodeGeoArrowWKT: () => decodeGeoArrowWKT,
109
113
  eastNorthUpToFixedFrame: () => eastNorthUpToFixedFrame,
@@ -142,7 +146,11 @@ __export(index_exports, {
142
146
  getProjectionMatrix: () => web_mercator_exports.getProjectionMatrix,
143
147
  getProjectionParameters: () => web_mercator_exports.getProjectionParameters,
144
148
  getTerrainMeshEdge: () => getTerrainMeshEdge,
149
+ getTerrainProfileHorizon: () => getTerrainProfileHorizon,
150
+ getTerrainProfileViewshed: () => getTerrainProfileViewshed,
151
+ getTerrainProfileVisibility: () => getTerrainProfileVisibility,
145
152
  getTerrainSlopeAspect: () => getTerrainSlopeAspect,
153
+ getTerrainVertexHaloAffectedTiles: () => getTerrainVertexHaloAffectedTiles,
146
154
  getTileBounds: () => getTileBounds,
147
155
  getTileIndex: () => getTileIndex,
148
156
  getTileRange: () => getTileRange,
@@ -171,6 +179,7 @@ __export(index_exports, {
171
179
  measureTerrainMeshError: () => measureTerrainMeshError,
172
180
  measureTerrainProfile: () => measureTerrainProfile,
173
181
  mergeGeoArrowDimensions: () => mergeGeoArrowDimensions,
182
+ normalizeCRSIdentifier: () => normalizeCRSIdentifier,
174
183
  normalizeGeoArrowUnion: () => normalizeGeoArrowUnion,
175
184
  normalizeViewportProps: () => web_mercator_exports.normalizeViewportProps,
176
185
  packTerrainHeightField: () => packTerrainHeightField,
@@ -213,6 +222,7 @@ __export(index_exports, {
213
222
  unitsPerMeter: () => web_mercator_exports.unitsPerMeter,
214
223
  unpackTerrainHeightField: () => unpackTerrainHeightField,
215
224
  unprojectGrid: () => unprojectGrid,
225
+ updateTerrainVertexTileHalos: () => updateTerrainVertexTileHalos,
216
226
  validateGeoArrowColumn: () => validateGeoArrowColumn,
217
227
  validateTileMatrix: () => validateTileMatrix,
218
228
  validateTileMatrixLimits: () => validateTileMatrixLimits,
@@ -5752,6 +5762,53 @@ function cloneAndFreezeJsonValue(value3) {
5752
5762
  return value3;
5753
5763
  }
5754
5764
 
5765
+ // dist/crs/crs-identifier.js
5766
+ var WMS_CRS_CODES = /* @__PURE__ */ new Map([
5767
+ ["84", "CRS84"],
5768
+ ["83", "CRS83"],
5769
+ ["27", "CRS27"]
5770
+ ]);
5771
+ var KNOWN_AUTHORITIES = /* @__PURE__ */ new Set(["EPSG", "OGC", "ESRI", "IAU"]);
5772
+ var OGC_CRS_CODES = /* @__PURE__ */ new Map([
5773
+ ["CRS84", "CRS84"],
5774
+ ["CRS83", "CRS83"],
5775
+ ["CRS27", "CRS27"],
5776
+ ["CRS84H", "CRS84h"]
5777
+ ]);
5778
+ var AUTHORITY_CODE = /^([A-Z][A-Z0-9_-]*):([A-Z0-9_.-]+)$/i;
5779
+ var OGC_URN = /^urn:ogc:def:crs:([A-Z][A-Z0-9_-]*):([^:]*):([A-Z0-9_.-]+)$/i;
5780
+ var OGC_URI = /^https?:\/\/www\.opengis\.net\/def\/crs\/([A-Z][A-Z0-9_-]*)\/([^/]+)\/([A-Z0-9_.-]+)\/?$/i;
5781
+ function normalizeCRSIdentifier(identifier) {
5782
+ const text = identifier.trim();
5783
+ const authorityCode = AUTHORITY_CODE.exec(text);
5784
+ if (authorityCode) {
5785
+ const [, authority, code] = authorityCode;
5786
+ if (authority.toUpperCase() === "CRS") {
5787
+ const ogcCode = WMS_CRS_CODES.get(code);
5788
+ return ogcCode ? `OGC:${ogcCode}` : identifier;
5789
+ }
5790
+ return formatIdentifier(authority, code);
5791
+ }
5792
+ const versioned = OGC_URN.exec(text) || OGC_URI.exec(text);
5793
+ if (versioned) {
5794
+ const [, authority, version, code] = versioned;
5795
+ return isUnversioned(authority, version, code) ? formatIdentifier(authority, code) : identifier;
5796
+ }
5797
+ return identifier;
5798
+ }
5799
+ function isUnversioned(authority, version, code) {
5800
+ if (version === "" || version === "0")
5801
+ return true;
5802
+ const ogcCode = code.toUpperCase();
5803
+ return authority.toUpperCase() === "OGC" && version === "1.3" && Array.from(WMS_CRS_CODES.values()).includes(ogcCode);
5804
+ }
5805
+ function formatIdentifier(authority, code) {
5806
+ const upperAuthority = authority.toUpperCase();
5807
+ const canonicalAuthority = KNOWN_AUTHORITIES.has(upperAuthority) ? upperAuthority : authority;
5808
+ const canonicalCode = canonicalAuthority === "OGC" ? OGC_CRS_CODES.get(code.toUpperCase()) || code : code;
5809
+ return `${canonicalAuthority}:${canonicalCode}`;
5810
+ }
5811
+
5755
5812
  // dist/crs/wkt-crs.js
5756
5813
  var WKTCRSSyntaxError = class extends SyntaxError {
5757
5814
  /** Create a WKT syntax error at a source location. */
@@ -17646,6 +17703,156 @@ function weighted(value3, part, total) {
17646
17703
  return value3 * ratio2;
17647
17704
  }
17648
17705
 
17706
+ // dist/terrain/profile-visibility.js
17707
+ function getTerrainProfileVisibility(profile, options) {
17708
+ const { observerHeight, targetHeight } = options;
17709
+ const limit = options.maxSamples ?? 1e6;
17710
+ const { distances, heights, statuses, length } = profile;
17711
+ const count = distances.length;
17712
+ if (!(distances instanceof Float64Array) || !(heights instanceof Float64Array) || !(statuses instanceof Uint8Array) || count < 2 || heights.length !== count || statuses.length !== count || !Number.isSafeInteger(limit) || limit < count || !Number.isFinite(observerHeight) || !Number.isFinite(targetHeight) || !Number.isFinite(length) || length <= 0 || distances[0] !== 0 || distances[count - 1] !== length)
17713
+ throw new Error("Invalid terrain visibility profile or options");
17714
+ let missingSampleCount = 0;
17715
+ let firstBlockingSample;
17716
+ let minimumClearance = Infinity;
17717
+ for (let i = 0; i < count; i++) {
17718
+ const distance = distances[i], status = statuses[i];
17719
+ if (!Number.isFinite(distance) || i > 0 && distance <= distances[i - 1])
17720
+ throw new Error("Invalid terrain visibility stationing");
17721
+ if (status > TerrainSampleStatus.NOT_RESIDENT)
17722
+ throw new Error("Invalid terrain visibility status");
17723
+ if (status !== TerrainSampleStatus.VALID) {
17724
+ missingSampleCount++;
17725
+ continue;
17726
+ }
17727
+ if (!Number.isFinite(heights[i]))
17728
+ throw new Error("Invalid terrain visibility height");
17729
+ const fraction = distance / length;
17730
+ const lineHeight = observerHeight * (1 - fraction) + targetHeight * fraction;
17731
+ const clearance = lineHeight - heights[i];
17732
+ if (!Number.isFinite(clearance))
17733
+ throw new Error("Terrain visibility arithmetic overflow");
17734
+ minimumClearance = Math.min(minimumClearance, clearance);
17735
+ if (clearance <= 0 && firstBlockingSample === void 0)
17736
+ firstBlockingSample = i;
17737
+ }
17738
+ return {
17739
+ status: firstBlockingSample !== void 0 ? "blocked" : missingSampleCount ? "unknown" : "clear",
17740
+ firstBlockingSample,
17741
+ missingSampleCount,
17742
+ minimumClearance: minimumClearance === Infinity ? void 0 : minimumClearance
17743
+ };
17744
+ }
17745
+
17746
+ // dist/terrain/profile-slope.js
17747
+ function compareTerrainSlopes(a, ad, b, bd) {
17748
+ const as = a / ad;
17749
+ const bs = b / bd;
17750
+ if (as < bs)
17751
+ return -1;
17752
+ if (as > bs)
17753
+ return 1;
17754
+ if (a === 0 || b === 0 || Math.sign(a) !== Math.sign(b))
17755
+ return Math.sign(a) - Math.sign(b);
17756
+ const bytes = new DataView(new ArrayBuffer(8));
17757
+ const parts = (value3) => {
17758
+ bytes.setFloat64(0, Math.abs(value3));
17759
+ const bits = bytes.getBigUint64(0);
17760
+ const exponent = Number(bits >> 52n & 0x7ffn);
17761
+ const fraction = bits & 0xfffffffffffffn;
17762
+ return exponent ? [fraction | 0x10000000000000n, exponent - 1075] : [fraction, -1074];
17763
+ };
17764
+ const [am, ae] = parts(a), [bdm, bde] = parts(bd);
17765
+ const [bm, be] = parts(b), [adm, ade] = parts(ad);
17766
+ let left = am * bdm;
17767
+ let right = bm * adm;
17768
+ const shift2 = ae + bde - be - ade;
17769
+ if (shift2 > 0)
17770
+ left <<= BigInt(shift2);
17771
+ else if (shift2 < 0)
17772
+ right <<= BigInt(-shift2);
17773
+ return (left < right ? -1 : left > right ? 1 : 0) * Math.sign(a);
17774
+ }
17775
+
17776
+ // dist/terrain/profile-horizon.js
17777
+ function getTerrainProfileHorizon(profile, options) {
17778
+ const { distances, heights, statuses, length } = profile;
17779
+ const count = distances.length;
17780
+ const limit = options.maxSamples ?? 1e6;
17781
+ if (!(distances instanceof Float64Array) || !(heights instanceof Float64Array) || !(statuses instanceof Uint8Array) || count < 2 || heights.length !== count || statuses.length !== count || !Number.isSafeInteger(limit) || limit < count || !Number.isFinite(options.observerHeight) || !Number.isFinite(length) || length <= 0 || distances[0] !== 0 || distances[count - 1] !== length)
17782
+ throw new Error("Invalid terrain horizon profile or options");
17783
+ let winningRise = 0;
17784
+ let winningDistance = 1;
17785
+ let sampleIndex;
17786
+ let missingSampleCount = 0;
17787
+ for (let i = 0; i < count; i++) {
17788
+ const distance = distances[i];
17789
+ const status = statuses[i];
17790
+ if (!Number.isFinite(distance) || i > 0 && distance <= distances[i - 1])
17791
+ throw new Error("Invalid terrain horizon stationing");
17792
+ if (status > TerrainSampleStatus.NOT_RESIDENT)
17793
+ throw new Error("Invalid terrain horizon status");
17794
+ if (status !== TerrainSampleStatus.VALID) {
17795
+ missingSampleCount++;
17796
+ continue;
17797
+ }
17798
+ if (!Number.isFinite(heights[i]))
17799
+ throw new Error("Invalid terrain horizon height");
17800
+ if (i === 0) {
17801
+ if (options.observerHeight <= heights[i])
17802
+ throw new Error("Terrain horizon observer must be above ground");
17803
+ continue;
17804
+ }
17805
+ const delta = heights[i] - options.observerHeight;
17806
+ if (!Number.isFinite(delta))
17807
+ throw new Error("Terrain horizon arithmetic overflow");
17808
+ if (sampleIndex === void 0 || compareTerrainSlopes(delta, distance, winningRise, winningDistance) > 0) {
17809
+ winningRise = delta;
17810
+ winningDistance = distance;
17811
+ sampleIndex = i;
17812
+ }
17813
+ }
17814
+ return {
17815
+ angle: sampleIndex === void 0 ? void 0 : Math.atan2(winningRise, winningDistance),
17816
+ sampleIndex,
17817
+ missingSampleCount,
17818
+ complete: missingSampleCount === 0
17819
+ };
17820
+ }
17821
+
17822
+ // dist/terrain/profile-viewshed.js
17823
+ var TerrainProfileViewStatus = {
17824
+ OBSERVER: 0,
17825
+ VISIBLE: 1,
17826
+ BLOCKED: 2,
17827
+ UNKNOWN: 3,
17828
+ MISSING: 4
17829
+ };
17830
+ function getTerrainProfileViewshed(profile, options) {
17831
+ getTerrainProfileHorizon(profile, options);
17832
+ const result = new Uint8Array(profile.distances.length);
17833
+ let maxRise = 0;
17834
+ let maxDistance = 1;
17835
+ let hasHorizon = false;
17836
+ let missingBefore = profile.statuses[0] !== TerrainSampleStatus.VALID;
17837
+ for (let i = 1; i < result.length; i++) {
17838
+ if (profile.statuses[i] !== TerrainSampleStatus.VALID) {
17839
+ result[i] = TerrainProfileViewStatus.MISSING;
17840
+ missingBefore = true;
17841
+ continue;
17842
+ }
17843
+ const rise = profile.heights[i] - options.observerHeight;
17844
+ const distance = profile.distances[i];
17845
+ const comparison = hasHorizon ? compareTerrainSlopes(rise, distance, maxRise, maxDistance) : 1;
17846
+ result[i] = comparison <= 0 ? TerrainProfileViewStatus.BLOCKED : missingBefore ? TerrainProfileViewStatus.UNKNOWN : TerrainProfileViewStatus.VISIBLE;
17847
+ if (comparison > 0) {
17848
+ maxRise = rise;
17849
+ maxDistance = distance;
17850
+ hasHorizon = true;
17851
+ }
17852
+ }
17853
+ return result;
17854
+ }
17855
+
17649
17856
  // dist/terrain/vertex-tiles.js
17650
17857
  function reconcileTerrainVertexTiles(tiles, options) {
17651
17858
  const { width, height } = options;
@@ -17746,6 +17953,221 @@ function reconcileTerrainVertexTiles(tiles, options) {
17746
17953
  return { tiles: result, sharedVertices, maxHeightDifference };
17747
17954
  }
17748
17955
 
17956
+ // dist/terrain/vertex-halos.js
17957
+ var TerrainVertexHaloStatus = { NOT_RESIDENT: 0, NO_DATA: 1, VALID: 2 };
17958
+ function createTerrainVertexTileHalos(tiles, options) {
17959
+ const { width, height } = options;
17960
+ const paddedWidth = width + 2, paddedHeight = height + 2;
17961
+ const paddedCount = paddedWidth * paddedHeight * tiles.length;
17962
+ if (!Number.isSafeInteger(paddedCount) || paddedCount > (options.maxSamples ?? 4e6))
17963
+ throw new Error("Vertex tile halo sample capacity exceeded");
17964
+ const reconciled = reconcileTerrainVertexTiles(tiles, options);
17965
+ const lattice = /* @__PURE__ */ new Map();
17966
+ for (const tile of reconciled.tiles) {
17967
+ const x = tile.column * (width - 1), y = tile.row * (height - 1);
17968
+ if (![x - 1, y - 1, x + width, y + height].every(Number.isSafeInteger))
17969
+ throw new Error("Vertex tile halo lattice overflow");
17970
+ for (let row = 0; row < height; row++) {
17971
+ for (let col = 0; col < width; col++) {
17972
+ const index = row * width + col;
17973
+ lattice.set(`${x + col},${y + row}`, {
17974
+ height: tile.field.heights[index],
17975
+ valid: tile.field.validity[index] !== 0
17976
+ });
17977
+ }
17978
+ }
17979
+ }
17980
+ const result = reconciled.tiles.map((tile) => {
17981
+ const x = tile.column * (width - 1), y = tile.row * (height - 1);
17982
+ const heights = new Float64Array(paddedWidth * paddedHeight);
17983
+ const validity = new Uint8Array(heights.length);
17984
+ const statuses = new Uint8Array(heights.length);
17985
+ for (let row = 0; row < paddedHeight; row++) {
17986
+ for (let col = 0; col < paddedWidth; col++) {
17987
+ const index = row * paddedWidth + col;
17988
+ const value3 = lattice.get(`${x + col - 1},${y + row - 1}`);
17989
+ if (value3) {
17990
+ statuses[index] = value3.valid ? TerrainVertexHaloStatus.VALID : TerrainVertexHaloStatus.NO_DATA;
17991
+ if (value3.valid) {
17992
+ heights[index] = value3.height;
17993
+ validity[index] = 1;
17994
+ }
17995
+ }
17996
+ }
17997
+ }
17998
+ const origin = tile.field.origin, columnStep = tile.field.columnStep, rowStep = tile.field.rowStep;
17999
+ const paddedOrigin = [
18000
+ origin[0] - columnStep[0] - rowStep[0],
18001
+ origin[1] - columnStep[1] - rowStep[1]
18002
+ ];
18003
+ if (!paddedOrigin.every(Number.isFinite))
18004
+ throw new Error("Vertex tile halo coordinate overflow");
18005
+ return {
18006
+ column: tile.column,
18007
+ row: tile.row,
18008
+ statuses,
18009
+ field: {
18010
+ ...tile.field,
18011
+ width: paddedWidth,
18012
+ height: paddedHeight,
18013
+ heights,
18014
+ validity,
18015
+ origin: paddedOrigin
18016
+ }
18017
+ };
18018
+ });
18019
+ return {
18020
+ tiles: result,
18021
+ sharedVertices: reconciled.sharedVertices,
18022
+ maxHeightDifference: reconciled.maxHeightDifference
18023
+ };
18024
+ }
18025
+
18026
+ // dist/terrain/vertex-halo-invalidation.js
18027
+ function getTerrainVertexHaloAffectedTiles(resident, changed, options) {
18028
+ const limit = options.maxTiles ?? 4096;
18029
+ if (!Number.isSafeInteger(limit) || limit < 0 || resident.length > limit || changed.length > limit || !Number.isSafeInteger(options.width) || options.width < 2 || !Number.isSafeInteger(options.height) || options.height < 2)
18030
+ throw new Error("Invalid vertex halo tile capacity");
18031
+ const addresses = /* @__PURE__ */ new Map();
18032
+ const key2 = (tile) => {
18033
+ if (!Number.isSafeInteger(tile.column) || !Number.isSafeInteger(tile.row))
18034
+ throw new Error("Invalid vertex tile address");
18035
+ return `${tile.column},${tile.row}`;
18036
+ };
18037
+ for (const tile of resident) {
18038
+ const id = key2(tile);
18039
+ if (addresses.has(id))
18040
+ throw new Error("Duplicate resident vertex tile address");
18041
+ addresses.set(id, { column: tile.column, row: tile.row });
18042
+ }
18043
+ const affected = /* @__PURE__ */ new Map();
18044
+ for (const tile of changed) {
18045
+ key2(tile);
18046
+ const rx = options.width === 2 ? 2 : 1, ry = options.height === 2 ? 2 : 1;
18047
+ for (let x = -rx; x <= rx; x++)
18048
+ for (let y = -ry; y <= ry; y++) {
18049
+ const column = tile.column + x, row = tile.row + y;
18050
+ if (!Number.isSafeInteger(column) || !Number.isSafeInteger(row))
18051
+ continue;
18052
+ const id = `${column},${row}`;
18053
+ const target = addresses.get(id);
18054
+ if (target)
18055
+ affected.set(id, target);
18056
+ }
18057
+ }
18058
+ return [...affected.values()].sort((a, b) => a.column - b.column || a.row - b.row);
18059
+ }
18060
+
18061
+ // dist/terrain/vertex-halo-update.js
18062
+ function updateTerrainVertexTileHalos(previous, resident, changed, options) {
18063
+ const prior = options.previousOptions;
18064
+ if (!prior)
18065
+ throw new Error("Previous vertex tile options are required");
18066
+ const paddedCount = (options.width + 2) * (options.height + 2) * resident.length;
18067
+ if (!Number.isSafeInteger(paddedCount) || paddedCount > (options.maxSamples ?? 4e6))
18068
+ throw new Error("Vertex tile halo sample capacity exceeded");
18069
+ const equalPair = (a, b) => a[0] === b[0] && a[1] === b[1];
18070
+ if (prior.width !== options.width || prior.height !== options.height || !equalPair(prior.origin ?? [0, 0], options.origin ?? [0, 0]) || !equalPair(prior.columnStep ?? [1, 0], options.columnStep ?? [1, 0]) || !equalPair(prior.rowStep ?? [0, 1], options.rowStep ?? [0, 1]) || (prior.heightReference ?? "unknown") !== (options.heightReference ?? "unknown") || (prior.maxHeightDifference ?? 0) !== (options.maxHeightDifference ?? 0))
18071
+ throw new Error("Vertex tile options changed; rebuild the full snapshot");
18072
+ const key2 = (t) => `${t.column},${t.row}`;
18073
+ const affected = getTerrainVertexHaloAffectedTiles(resident, changed, options);
18074
+ getTerrainVertexHaloAffectedTiles(previous, [], options);
18075
+ const previousMap = new Map(previous.map((tile) => [key2(tile), tile]));
18076
+ const currentKeys = new Set(resident.map(key2));
18077
+ const changedKeys = new Set(changed.map(key2));
18078
+ for (const tile of resident) {
18079
+ if (!previousMap.has(key2(tile)) && !changedKeys.has(key2(tile)))
18080
+ throw new Error("Unreported vertex tile arrival");
18081
+ }
18082
+ const removed = [];
18083
+ for (const tile of previous) {
18084
+ if (!currentKeys.has(key2(tile))) {
18085
+ if (!changedKeys.has(key2(tile)))
18086
+ throw new Error("Unreported vertex tile eviction");
18087
+ removed.push({ column: tile.column, row: tile.row });
18088
+ }
18089
+ }
18090
+ removed.sort((a, b) => a.column - b.column || a.row - b.row);
18091
+ const affectedKeys = new Set(affected.map(key2));
18092
+ const rx = options.width === 2 ? 2 : 1;
18093
+ const ry = options.height === 2 ? 2 : 1;
18094
+ const needed = /* @__PURE__ */ new Set();
18095
+ for (const tile of affected)
18096
+ for (let x = -rx; x <= rx; x++)
18097
+ for (let y = -ry; y <= ry; y++) {
18098
+ const column = tile.column + x, row = tile.row + y;
18099
+ if (Number.isSafeInteger(column) && Number.isSafeInteger(row))
18100
+ needed.add(`${column},${row}`);
18101
+ }
18102
+ const source = resident.filter((tile) => needed.has(key2(tile)));
18103
+ const rebuilt = createTerrainVertexTileHalos(source, options).tiles;
18104
+ const results = new Map(previous.filter((tile) => currentKeys.has(key2(tile)) && !affectedKeys.has(key2(tile))).map((tile) => [key2(tile), tile]));
18105
+ for (const tile of rebuilt)
18106
+ if (affectedKeys.has(key2(tile)))
18107
+ results.set(key2(tile), tile);
18108
+ if (results.size !== resident.length)
18109
+ throw new Error("Incomplete vertex halo update");
18110
+ return {
18111
+ tiles: [...results.values()].sort((a, b) => a.column - b.column || a.row - b.row),
18112
+ rebuilt: affected,
18113
+ removed
18114
+ };
18115
+ }
18116
+
18117
+ // dist/terrain/filtered-pyramid.js
18118
+ function createTerrainFilteredPyramid(input, options = {}) {
18119
+ const { width, height, heights, validity } = input;
18120
+ const count = width * height;
18121
+ const limit = options.maxSamples ?? 4e6;
18122
+ if (!Number.isSafeInteger(width) || width < 1 || !Number.isSafeInteger(height) || height < 1 || !Number.isSafeInteger(count) || count > 4294967295 || !Number.isSafeInteger(limit) || limit < count || !(heights instanceof Float32Array || heights instanceof Float64Array) || heights.length !== count || validity !== void 0 && (!(validity instanceof Uint8Array) || validity.length !== count))
18123
+ throw new Error("Invalid terrain filtered pyramid input or capacity");
18124
+ const base = {
18125
+ width,
18126
+ height,
18127
+ heights: new Float64Array(count),
18128
+ validCounts: new Uint32Array(count),
18129
+ sampleCounts: new Uint32Array(count).fill(1)
18130
+ };
18131
+ for (let i = 0; i < count; i++)
18132
+ if ((!validity || validity[i] !== 0) && Number.isFinite(heights[i])) {
18133
+ base.heights[i] = heights[i];
18134
+ base.validCounts[i] = 1;
18135
+ }
18136
+ const levels = [base];
18137
+ let source = base;
18138
+ while (source.width > 1 || source.height > 1) {
18139
+ const w = Math.ceil(source.width / 2), h = Math.ceil(source.height / 2);
18140
+ const next = {
18141
+ width: w,
18142
+ height: h,
18143
+ heights: new Float64Array(w * h),
18144
+ validCounts: new Uint32Array(w * h),
18145
+ sampleCounts: new Uint32Array(w * h)
18146
+ };
18147
+ for (let y = 0; y < h; y++)
18148
+ for (let x = 0; x < w; x++) {
18149
+ const out = y * w + x;
18150
+ for (let dy = 0; dy < 2; dy++)
18151
+ for (let dx = 0; dx < 2; dx++) {
18152
+ const sx = x * 2 + dx, sy = y * 2 + dy;
18153
+ if (sx >= source.width || sy >= source.height)
18154
+ continue;
18155
+ const index = sy * source.width + sx;
18156
+ const n = source.validCounts[index], old = next.validCounts[out];
18157
+ next.sampleCounts[out] += source.sampleCounts[index];
18158
+ if (n) {
18159
+ const total = old + n, a = next.heights[out], b = source.heights[index];
18160
+ next.heights[out] = old ? a * (old / total) + b * (n / total) : b;
18161
+ next.validCounts[out] = total;
18162
+ }
18163
+ }
18164
+ }
18165
+ levels.push(next);
18166
+ source = next;
18167
+ }
18168
+ return levels;
18169
+ }
18170
+
17749
18171
  // dist/terrain/mesh-stitch.js
17750
18172
  function stitchTerrainMeshEdges(a, edgeA, b, edgeB, options = {}) {
17751
18173
  const maxVertices = options.maxVertices ?? 2e6, maxTriangles = options.maxTriangles ?? 4e6, maxBoundary = options.maxBoundaryVertices ?? 1e5;