@math.gl/geospatial 5.0.0-beta.2 → 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.
- package/dist/index.cjs +374 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/tasks/definitions.d.ts +90 -0
- package/dist/tasks/definitions.d.ts.map +1 -0
- package/dist/tasks/definitions.js +54 -0
- package/dist/tasks/definitions.js.map +1 -0
- package/dist/{workers → tasks}/index.cjs +158 -122
- package/dist/tasks/index.cjs.map +6 -0
- package/dist/tasks/index.d.ts +12 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +30 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/{workers → tasks}/map-worker.d.ts.map +1 -1
- package/dist/tasks/map-worker.js +7 -0
- package/dist/tasks/map-worker.js.map +1 -0
- package/dist/{workers → tasks}/operations.d.ts +6 -4
- package/dist/tasks/operations.d.ts.map +1 -0
- package/dist/{workers → tasks}/operations.js +3 -5
- package/dist/tasks/operations.js.map +1 -0
- package/dist/tasks/projection-worker.d.ts.map +1 -0
- package/dist/tasks/projection-worker.js +7 -0
- package/dist/tasks/projection-worker.js.map +1 -0
- package/dist/terrain/filtered-pyramid.d.ts +22 -0
- package/dist/terrain/filtered-pyramid.d.ts.map +1 -0
- package/dist/terrain/filtered-pyramid.js +71 -0
- package/dist/terrain/filtered-pyramid.js.map +1 -0
- package/dist/terrain/index.cjs +375 -1
- package/dist/terrain/index.cjs.map +2 -2
- package/dist/terrain/index.d.ts +12 -0
- package/dist/terrain/index.d.ts.map +1 -1
- package/dist/terrain/index.js +7 -0
- package/dist/terrain/index.js.map +1 -1
- package/dist/terrain/profile-horizon.d.ts +20 -0
- package/dist/terrain/profile-horizon.d.ts.map +1 -0
- package/dist/terrain/profile-horizon.js +69 -0
- package/dist/terrain/profile-horizon.js.map +1 -0
- package/dist/terrain/profile-slope.d.ts +3 -0
- package/dist/terrain/profile-slope.d.ts.map +1 -0
- package/dist/terrain/profile-slope.js +35 -0
- package/dist/terrain/profile-slope.js.map +1 -0
- package/dist/terrain/profile-viewshed.d.ts +17 -0
- package/dist/terrain/profile-viewshed.d.ts.map +1 -0
- package/dist/terrain/profile-viewshed.js +51 -0
- package/dist/terrain/profile-viewshed.js.map +1 -0
- package/dist/terrain/profile-visibility.d.ts +21 -0
- package/dist/terrain/profile-visibility.d.ts.map +1 -0
- package/dist/terrain/profile-visibility.js +61 -0
- package/dist/terrain/profile-visibility.js.map +1 -0
- package/dist/terrain/vertex-halo-invalidation.d.ts +16 -0
- package/dist/terrain/vertex-halo-invalidation.d.ts.map +1 -0
- package/dist/terrain/vertex-halo-invalidation.js +50 -0
- package/dist/terrain/vertex-halo-invalidation.js.map +1 -0
- package/dist/terrain/vertex-halo-update.d.ts +18 -0
- package/dist/terrain/vertex-halo-update.d.ts.map +1 -0
- package/dist/terrain/vertex-halo-update.js +76 -0
- package/dist/terrain/vertex-halo-update.js.map +1 -0
- package/dist/terrain/vertex-halos.d.ts +26 -0
- package/dist/terrain/vertex-halos.d.ts.map +1 -0
- package/dist/terrain/vertex-halos.js +80 -0
- package/dist/terrain/vertex-halos.js.map +1 -0
- package/package.json +10 -15
- package/src/index.ts +12 -0
- package/src/tasks/definitions.ts +89 -0
- package/src/tasks/index.ts +39 -0
- package/src/tasks/map-worker.ts +6 -0
- package/src/{workers → tasks}/operations.ts +11 -7
- package/src/tasks/projection-worker.ts +6 -0
- package/src/terrain/filtered-pyramid.ts +95 -0
- package/src/terrain/index.ts +12 -0
- package/src/terrain/profile-horizon.ts +86 -0
- package/src/terrain/profile-slope.ts +32 -0
- package/src/terrain/profile-viewshed.ts +57 -0
- package/src/terrain/profile-visibility.ts +81 -0
- package/src/terrain/vertex-halo-invalidation.ts +57 -0
- package/src/terrain/vertex-halo-update.ts +91 -0
- package/src/terrain/vertex-halos.ts +101 -0
- package/dist/workers/index.cjs.map +0 -6
- package/dist/workers/index.d.ts +0 -12
- package/dist/workers/index.d.ts.map +0 -1
- package/dist/workers/index.js +0 -41
- package/dist/workers/index.js.map +0 -1
- package/dist/workers/map-worker.js +0 -7
- package/dist/workers/map-worker.js.map +0 -1
- package/dist/workers/operations.cjs +0 -21008
- package/dist/workers/operations.cjs.map +0 -6
- package/dist/workers/operations.d.ts.map +0 -1
- package/dist/workers/operations.js.map +0 -1
- package/dist/workers/projection-worker.d.ts.map +0 -1
- package/dist/workers/projection-worker.js +0 -7
- package/dist/workers/projection-worker.js.map +0 -1
- package/src/workers/index.ts +0 -59
- package/src/workers/map-worker.ts +0 -7
- package/src/workers/projection-worker.ts +0 -7
- /package/dist/{workers → tasks}/map-worker.d.ts +0 -0
- /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,
|
|
@@ -214,6 +222,7 @@ __export(index_exports, {
|
|
|
214
222
|
unitsPerMeter: () => web_mercator_exports.unitsPerMeter,
|
|
215
223
|
unpackTerrainHeightField: () => unpackTerrainHeightField,
|
|
216
224
|
unprojectGrid: () => unprojectGrid,
|
|
225
|
+
updateTerrainVertexTileHalos: () => updateTerrainVertexTileHalos,
|
|
217
226
|
validateGeoArrowColumn: () => validateGeoArrowColumn,
|
|
218
227
|
validateTileMatrix: () => validateTileMatrix,
|
|
219
228
|
validateTileMatrixLimits: () => validateTileMatrixLimits,
|
|
@@ -17694,6 +17703,156 @@ function weighted(value3, part, total) {
|
|
|
17694
17703
|
return value3 * ratio2;
|
|
17695
17704
|
}
|
|
17696
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
|
+
|
|
17697
17856
|
// dist/terrain/vertex-tiles.js
|
|
17698
17857
|
function reconcileTerrainVertexTiles(tiles, options) {
|
|
17699
17858
|
const { width, height } = options;
|
|
@@ -17794,6 +17953,221 @@ function reconcileTerrainVertexTiles(tiles, options) {
|
|
|
17794
17953
|
return { tiles: result, sharedVertices, maxHeightDifference };
|
|
17795
17954
|
}
|
|
17796
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
|
+
|
|
17797
18171
|
// dist/terrain/mesh-stitch.js
|
|
17798
18172
|
function stitchTerrainMeshEdges(a, edgeA, b, edgeB, options = {}) {
|
|
17799
18173
|
const maxVertices = options.maxVertices ?? 2e6, maxTriangles = options.maxTriangles ?? 4e6, maxBoundary = options.maxBoundaryVertices ?? 1e5;
|