@math.gl/geospatial 5.0.0-beta.2 → 5.0.0-beta.4
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 +618 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -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/contour-boundary-diagnostics.d.ts +23 -0
- package/dist/terrain/contour-boundary-diagnostics.d.ts.map +1 -0
- package/dist/terrain/contour-boundary-diagnostics.js +62 -0
- package/dist/terrain/contour-boundary-diagnostics.js.map +1 -0
- package/dist/terrain/contour-tile-paths.d.ts +7 -0
- package/dist/terrain/contour-tile-paths.d.ts.map +1 -0
- package/dist/terrain/contour-tile-paths.js +12 -0
- package/dist/terrain/contour-tile-paths.js.map +1 -0
- package/dist/terrain/contour-tile-weld.d.ts +24 -0
- package/dist/terrain/contour-tile-weld.d.ts.map +1 -0
- package/dist/terrain/contour-tile-weld.js +147 -0
- package/dist/terrain/contour-tile-weld.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/gradient-pyramid.d.ts +29 -0
- package/dist/terrain/gradient-pyramid.d.ts.map +1 -0
- package/dist/terrain/gradient-pyramid.js +94 -0
- package/dist/terrain/gradient-pyramid.js.map +1 -0
- package/dist/terrain/index.cjs +619 -1
- package/dist/terrain/index.cjs.map +2 -2
- package/dist/terrain/index.d.ts +19 -0
- package/dist/terrain/index.d.ts.map +1 -1
- package/dist/terrain/index.js +11 -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 +22 -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/contour-boundary-diagnostics.ts +90 -0
- package/src/terrain/contour-tile-paths.ts +20 -0
- package/src/terrain/contour-tile-weld.ts +182 -0
- package/src/terrain/filtered-pyramid.ts +95 -0
- package/src/terrain/gradient-pyramid.ts +129 -0
- package/src/terrain/index.ts +22 -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,11 @@ __export(index_exports, {
|
|
|
71
71
|
RhumbPath: () => RhumbPath,
|
|
72
72
|
RhumbPolygon: () => RhumbPolygon,
|
|
73
73
|
TERRAIN_BUFFER_VERSION: () => TERRAIN_BUFFER_VERSION,
|
|
74
|
+
TerrainContourBoundaryAxis: () => TerrainContourBoundaryAxis,
|
|
75
|
+
TerrainProfileViewStatus: () => TerrainProfileViewStatus,
|
|
74
76
|
TerrainSampleStatus: () => TerrainSampleStatus,
|
|
75
77
|
TerrainSurface: () => TerrainSurface,
|
|
78
|
+
TerrainVertexHaloStatus: () => TerrainVertexHaloStatus,
|
|
76
79
|
TiledHeightField: () => TiledHeightField,
|
|
77
80
|
TriaxialEllipsoid: () => TriaxialEllipsoid,
|
|
78
81
|
WKBBuilder: () => WKBBuilder,
|
|
@@ -99,13 +102,17 @@ __export(index_exports, {
|
|
|
99
102
|
createOrthographicCutAtlas: () => createOrthographicCutAtlas,
|
|
100
103
|
createSpatialReference: () => createSpatialReference,
|
|
101
104
|
createTerrainContours: () => createTerrainContours,
|
|
105
|
+
createTerrainFilteredPyramid: () => createTerrainFilteredPyramid,
|
|
102
106
|
createTerrainGradientGrid: () => createTerrainGradientGrid,
|
|
107
|
+
createTerrainGradientPyramid: () => createTerrainGradientPyramid,
|
|
103
108
|
createTerrainMesh: () => createTerrainMesh,
|
|
104
109
|
createTerrainSkirt: () => createTerrainSkirt,
|
|
105
110
|
createTerrainSlopeAspectGrid: () => createTerrainSlopeAspectGrid,
|
|
106
111
|
createTerrainSurface: () => createTerrainSurface,
|
|
112
|
+
createTerrainVertexTileHalos: () => createTerrainVertexTileHalos,
|
|
107
113
|
decodeGeoArrowWKB: () => decodeGeoArrowWKB,
|
|
108
114
|
decodeGeoArrowWKT: () => decodeGeoArrowWKT,
|
|
115
|
+
diagnoseTerrainContourBoundaries: () => diagnoseTerrainContourBoundaries,
|
|
109
116
|
eastNorthUpToFixedFrame: () => eastNorthUpToFixedFrame,
|
|
110
117
|
encodeGeoArrowWKB: () => encodeGeoArrowWKB,
|
|
111
118
|
encodeGeoArrowWKT: () => encodeGeoArrowWKT,
|
|
@@ -142,7 +149,11 @@ __export(index_exports, {
|
|
|
142
149
|
getProjectionMatrix: () => web_mercator_exports.getProjectionMatrix,
|
|
143
150
|
getProjectionParameters: () => web_mercator_exports.getProjectionParameters,
|
|
144
151
|
getTerrainMeshEdge: () => getTerrainMeshEdge,
|
|
152
|
+
getTerrainProfileHorizon: () => getTerrainProfileHorizon,
|
|
153
|
+
getTerrainProfileViewshed: () => getTerrainProfileViewshed,
|
|
154
|
+
getTerrainProfileVisibility: () => getTerrainProfileVisibility,
|
|
145
155
|
getTerrainSlopeAspect: () => getTerrainSlopeAspect,
|
|
156
|
+
getTerrainVertexHaloAffectedTiles: () => getTerrainVertexHaloAffectedTiles,
|
|
146
157
|
getTileBounds: () => getTileBounds,
|
|
147
158
|
getTileIndex: () => getTileIndex,
|
|
148
159
|
getTileRange: () => getTileRange,
|
|
@@ -201,6 +212,7 @@ __export(index_exports, {
|
|
|
201
212
|
splitGeographicPolyline: () => splitGeographicPolyline,
|
|
202
213
|
splitGlobeBounds: () => splitGlobeBounds,
|
|
203
214
|
standardGridZone: () => standardGridZone,
|
|
215
|
+
stitchTerrainContourTiles: () => stitchTerrainContourTiles,
|
|
204
216
|
stitchTerrainContours: () => stitchTerrainContours,
|
|
205
217
|
stitchTerrainMeshEdges: () => stitchTerrainMeshEdges,
|
|
206
218
|
streamGeoArrow: () => streamGeoArrow,
|
|
@@ -214,6 +226,7 @@ __export(index_exports, {
|
|
|
214
226
|
unitsPerMeter: () => web_mercator_exports.unitsPerMeter,
|
|
215
227
|
unpackTerrainHeightField: () => unpackTerrainHeightField,
|
|
216
228
|
unprojectGrid: () => unprojectGrid,
|
|
229
|
+
updateTerrainVertexTileHalos: () => updateTerrainVertexTileHalos,
|
|
217
230
|
validateGeoArrowColumn: () => validateGeoArrowColumn,
|
|
218
231
|
validateTileMatrix: () => validateTileMatrix,
|
|
219
232
|
validateTileMatrixLimits: () => validateTileMatrixLimits,
|
|
@@ -221,6 +234,7 @@ __export(index_exports, {
|
|
|
221
234
|
validateWKTCRS: () => validateWKTCRS,
|
|
222
235
|
visitGeoArrowCoordinates: () => visitGeoArrowCoordinates,
|
|
223
236
|
visitWKB: () => visitWKB,
|
|
237
|
+
weldTerrainContourTiles: () => weldTerrainContourTiles,
|
|
224
238
|
worldToLngLat: () => web_mercator_exports.worldToLngLat,
|
|
225
239
|
worldToPixels: () => web_mercator_exports.worldToPixels,
|
|
226
240
|
writeWKB: () => writeWKB,
|
|
@@ -17483,6 +17497,245 @@ function stitchTerrainContours(contours, options = {}) {
|
|
|
17483
17497
|
};
|
|
17484
17498
|
}
|
|
17485
17499
|
|
|
17500
|
+
// dist/terrain/contour-tile-weld.js
|
|
17501
|
+
function weldTerrainContourTiles(tiles, options) {
|
|
17502
|
+
const { width, height } = options;
|
|
17503
|
+
const limits = contourPathLimits(options);
|
|
17504
|
+
const tolerance = options.maxPositionDifference ?? 0;
|
|
17505
|
+
const maxTiles = options.maxTiles ?? 4096;
|
|
17506
|
+
if (!Number.isSafeInteger(width) || width < 2 || !Number.isSafeInteger(height) || height < 2 || !Number.isFinite(tolerance) || tolerance < 0 || !Number.isSafeInteger(maxTiles) || maxTiles < 1 || tiles.length > maxTiles || !tiles.length)
|
|
17507
|
+
throw new Error("Invalid terrain contour tile dimensions or tolerance");
|
|
17508
|
+
const sorted = [...tiles].sort((a, b) => a.column - b.column || a.row - b.row);
|
|
17509
|
+
const first = sorted[0].contours;
|
|
17510
|
+
const origin = [...first.origin];
|
|
17511
|
+
const levels = first.levels.slice();
|
|
17512
|
+
const positions = [], grid = [], segments = [], levelIndices = [];
|
|
17513
|
+
const vertices = /* @__PURE__ */ new Map();
|
|
17514
|
+
const edges = /* @__PURE__ */ new Map();
|
|
17515
|
+
const addresses = /* @__PURE__ */ new Set();
|
|
17516
|
+
let inputVertices = 0;
|
|
17517
|
+
let inputSegments = 0;
|
|
17518
|
+
for (let tileIndex = 0; tileIndex < sorted.length; tileIndex++) {
|
|
17519
|
+
const tile = sorted[tileIndex], data = tile.contours;
|
|
17520
|
+
const id = `${tile.column},${tile.row}`;
|
|
17521
|
+
if (!Number.isSafeInteger(tile.column) || !Number.isSafeInteger(tile.row) || addresses.has(id))
|
|
17522
|
+
throw new Error("Invalid or duplicate terrain contour tile address");
|
|
17523
|
+
addresses.add(id);
|
|
17524
|
+
const x0 = tile.column * (width - 1), y0 = tile.row * (height - 1);
|
|
17525
|
+
if (![x0, y0, x0 + width - 1, y0 + height - 1].every(Number.isSafeInteger))
|
|
17526
|
+
throw new Error("Terrain contour tile lattice overflow");
|
|
17527
|
+
const count = validateContourData(data, limits);
|
|
17528
|
+
inputVertices += count;
|
|
17529
|
+
if (inputVertices > limits.maxVertices)
|
|
17530
|
+
throw new Error("Terrain contour input vertex capacity exceeded");
|
|
17531
|
+
if (data.heightReference !== first.heightReference || data.levels.length !== levels.length || !data.levels.every((level, i) => level === levels[i]))
|
|
17532
|
+
throw new Error("Terrain contour tile levels or height reference differ");
|
|
17533
|
+
if (!(data.segments instanceof Uint32Array) || data.segments.length % 2 || !(data.levelIndices instanceof Uint32Array) || data.levelIndices.length !== data.segments.length / 2 || data.levelIndices.length > limits.maxSegments)
|
|
17534
|
+
throw new Error("Invalid terrain contour tile segments");
|
|
17535
|
+
inputSegments += data.levelIndices.length;
|
|
17536
|
+
if (inputSegments > limits.maxSegments)
|
|
17537
|
+
throw new Error("Terrain contour input segment capacity exceeded");
|
|
17538
|
+
const assigned = new Uint32Array(count).fill(4294967295);
|
|
17539
|
+
const remap = new Uint32Array(count).fill(4294967295);
|
|
17540
|
+
const localBoundary = /* @__PURE__ */ new Set();
|
|
17541
|
+
const mapVertex = (source, level) => {
|
|
17542
|
+
validateContourVertex(data, source, level, assigned);
|
|
17543
|
+
if (remap[source] !== 4294967295)
|
|
17544
|
+
return remap[source];
|
|
17545
|
+
const x = data.gridCoordinates[2 * source], y = data.gridCoordinates[2 * source + 1];
|
|
17546
|
+
if (x < 0 || x > width - 1 || y < 0 || y > height - 1)
|
|
17547
|
+
throw new Error("Terrain contour vertex outside tile lattice");
|
|
17548
|
+
const gx = x0 + x, gy = y0 + y;
|
|
17549
|
+
if (!Number.isFinite(gx) || !Number.isFinite(gy) || x % 1 !== 0 && Number.isInteger(gx) || y % 1 !== 0 && Number.isInteger(gy))
|
|
17550
|
+
throw new Error("Terrain contour tile lattice loses precision");
|
|
17551
|
+
const px = data.positions[3 * source] + (data.origin[0] - origin[0]);
|
|
17552
|
+
const py = data.positions[3 * source + 1] + (data.origin[1] - origin[1]);
|
|
17553
|
+
if (!Number.isFinite(px) || !Number.isFinite(py))
|
|
17554
|
+
throw new Error("Terrain contour frame overflow");
|
|
17555
|
+
const boundary = x === 0 || y === 0 || x === width - 1 || y === height - 1;
|
|
17556
|
+
const xi = Math.floor(x), yi = Math.floor(y);
|
|
17557
|
+
const vertexKey = `${level}/${x0 + xi}/${x - xi}/${y0 + yi}/${y - yi}`;
|
|
17558
|
+
if (boundary) {
|
|
17559
|
+
if (localBoundary.has(vertexKey))
|
|
17560
|
+
throw new Error("Duplicate terrain contour boundary vertex");
|
|
17561
|
+
localBoundary.add(vertexKey);
|
|
17562
|
+
}
|
|
17563
|
+
const found = boundary ? vertices.get(vertexKey) : void 0;
|
|
17564
|
+
if (found) {
|
|
17565
|
+
if (found.tile === tileIndex)
|
|
17566
|
+
throw new Error("Duplicate terrain contour boundary vertex");
|
|
17567
|
+
const delta = Math.hypot(px - positions[3 * found.id], py - positions[3 * found.id + 1]);
|
|
17568
|
+
if (!Number.isFinite(delta) || delta > tolerance)
|
|
17569
|
+
throw new Error("Terrain contour boundary positions disagree");
|
|
17570
|
+
remap[source] = found.id;
|
|
17571
|
+
return found.id;
|
|
17572
|
+
}
|
|
17573
|
+
if (positions.length / 3 >= limits.maxVertices)
|
|
17574
|
+
throw new Error("Terrain contour vertex capacity exceeded");
|
|
17575
|
+
const output2 = positions.length / 3;
|
|
17576
|
+
const pz = levels[level] - origin[2];
|
|
17577
|
+
if (!Number.isFinite(pz))
|
|
17578
|
+
throw new Error("Terrain contour frame overflow");
|
|
17579
|
+
positions.push(px, py, pz);
|
|
17580
|
+
grid.push(gx, gy);
|
|
17581
|
+
if (boundary)
|
|
17582
|
+
vertices.set(vertexKey, { id: output2, tile: tileIndex });
|
|
17583
|
+
remap[source] = output2;
|
|
17584
|
+
return output2;
|
|
17585
|
+
};
|
|
17586
|
+
for (let i = 0; i < data.levelIndices.length; i++) {
|
|
17587
|
+
const level = data.levelIndices[i], a = mapVertex(data.segments[2 * i], level), b = mapVertex(data.segments[2 * i + 1], level);
|
|
17588
|
+
if (a === b || positions[3 * a] === positions[3 * b] && positions[3 * a + 1] === positions[3 * b + 1])
|
|
17589
|
+
throw new Error("Degenerate terrain contour segment after rebasing");
|
|
17590
|
+
const edge = a < b ? `${a}/${b}` : `${b}/${a}`;
|
|
17591
|
+
const previous = edges.get(edge);
|
|
17592
|
+
if (previous !== void 0) {
|
|
17593
|
+
if (previous === tileIndex)
|
|
17594
|
+
throw new Error("Duplicate terrain contour segment");
|
|
17595
|
+
continue;
|
|
17596
|
+
}
|
|
17597
|
+
if (levelIndices.length >= limits.maxSegments)
|
|
17598
|
+
throw new Error("Terrain contour segment capacity exceeded");
|
|
17599
|
+
edges.set(edge, tileIndex);
|
|
17600
|
+
segments.push(a, b);
|
|
17601
|
+
levelIndices.push(level);
|
|
17602
|
+
}
|
|
17603
|
+
}
|
|
17604
|
+
return {
|
|
17605
|
+
positions: Float64Array.from(positions),
|
|
17606
|
+
gridCoordinates: Float64Array.from(grid),
|
|
17607
|
+
segments: Uint32Array.from(segments),
|
|
17608
|
+
levelIndices: Uint32Array.from(levelIndices),
|
|
17609
|
+
levels,
|
|
17610
|
+
origin,
|
|
17611
|
+
heightReference: first.heightReference
|
|
17612
|
+
};
|
|
17613
|
+
}
|
|
17614
|
+
|
|
17615
|
+
// dist/terrain/contour-boundary-diagnostics.js
|
|
17616
|
+
var TerrainContourBoundaryAxis = { COLUMN: 1, ROW: 2 };
|
|
17617
|
+
function diagnoseTerrainContourBoundaries(contours, options) {
|
|
17618
|
+
const { width, height } = options;
|
|
17619
|
+
if (!Number.isSafeInteger(width) || width < 2 || !Number.isSafeInteger(height) || height < 2)
|
|
17620
|
+
throw new Error("Invalid terrain contour boundary tile dimensions");
|
|
17621
|
+
const limits = contourPathLimits(options);
|
|
17622
|
+
const count = validateContourData(contours, limits);
|
|
17623
|
+
if (!(contours.segments instanceof Uint32Array) || contours.segments.length % 2 || !(contours.levelIndices instanceof Uint32Array) || contours.levelIndices.length !== contours.segments.length / 2 || contours.levelIndices.length > limits.maxSegments)
|
|
17624
|
+
throw new Error("Invalid terrain contour boundary segments or capacity");
|
|
17625
|
+
const degrees2 = new Uint32Array(count), assignments = new Uint32Array(count).fill(4294967295);
|
|
17626
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17627
|
+
for (let i = 0; i < contours.levelIndices.length; i++) {
|
|
17628
|
+
const a = contours.segments[2 * i], b = contours.segments[2 * i + 1], level = contours.levelIndices[i];
|
|
17629
|
+
validateContourVertex(contours, a, level, assignments);
|
|
17630
|
+
validateContourVertex(contours, b, level, assignments);
|
|
17631
|
+
if (a === b || contours.positions[3 * a] === contours.positions[3 * b] && contours.positions[3 * a + 1] === contours.positions[3 * b + 1])
|
|
17632
|
+
throw new Error("Degenerate terrain contour segment");
|
|
17633
|
+
const key2 = a < b ? `${a}/${b}` : `${b}/${a}`;
|
|
17634
|
+
if (seen.has(key2))
|
|
17635
|
+
throw new Error("Duplicate terrain contour segment");
|
|
17636
|
+
seen.add(key2);
|
|
17637
|
+
degrees2[a]++;
|
|
17638
|
+
degrees2[b]++;
|
|
17639
|
+
}
|
|
17640
|
+
const vertices = [], resultDegrees = [], levels = [], axes = [];
|
|
17641
|
+
for (let i = 0; i < count; i++) {
|
|
17642
|
+
if (degrees2[i] !== 1 && degrees2[i] <= 2)
|
|
17643
|
+
continue;
|
|
17644
|
+
const x = contours.gridCoordinates[2 * i], y = contours.gridCoordinates[2 * i + 1];
|
|
17645
|
+
if (Math.abs(x) > Number.MAX_SAFE_INTEGER || Math.abs(y) > Number.MAX_SAFE_INTEGER)
|
|
17646
|
+
throw new Error("Terrain contour boundary lattice exceeds safe integer range");
|
|
17647
|
+
const axis = (Number.isSafeInteger(x) && x % (width - 1) === 0 ? TerrainContourBoundaryAxis.COLUMN : 0) | (Number.isSafeInteger(y) && y % (height - 1) === 0 ? TerrainContourBoundaryAxis.ROW : 0);
|
|
17648
|
+
if (!axis)
|
|
17649
|
+
continue;
|
|
17650
|
+
vertices.push(i);
|
|
17651
|
+
resultDegrees.push(degrees2[i]);
|
|
17652
|
+
levels.push(assignments[i]);
|
|
17653
|
+
axes.push(axis);
|
|
17654
|
+
}
|
|
17655
|
+
return {
|
|
17656
|
+
vertexIndices: Uint32Array.from(vertices),
|
|
17657
|
+
degrees: Uint32Array.from(resultDegrees),
|
|
17658
|
+
levelIndices: Uint32Array.from(levels),
|
|
17659
|
+
boundaryAxes: Uint8Array.from(axes)
|
|
17660
|
+
};
|
|
17661
|
+
}
|
|
17662
|
+
|
|
17663
|
+
// dist/terrain/contour-tile-paths.js
|
|
17664
|
+
function stitchTerrainContourTiles(tiles, options) {
|
|
17665
|
+
return stitchTerrainContours(weldTerrainContourTiles(tiles, options), options);
|
|
17666
|
+
}
|
|
17667
|
+
|
|
17668
|
+
// dist/terrain/gradient-pyramid.js
|
|
17669
|
+
function createTerrainGradientPyramid(grid, options = {}) {
|
|
17670
|
+
const { width, height, gradients, statuses } = grid;
|
|
17671
|
+
const count = width * height, limit = options.maxSamples ?? 4e6;
|
|
17672
|
+
if (!Number.isSafeInteger(width) || width < 1 || !Number.isSafeInteger(height) || height < 1 || !Number.isSafeInteger(count) || count > 4294967295 || !Number.isSafeInteger(limit) || limit < count || !(gradients instanceof Float64Array) || gradients.length !== 2 * count || !(statuses instanceof Uint8Array) || statuses.length !== count || grid.method !== "horn" && grid.method !== "zevenbergen-thorne" || grid.registration !== "cell" && grid.registration !== "vertex" || typeof grid.heightReference !== "string" || ![grid.origin, grid.columnStep, grid.rowStep].every((v) => v.length === 2 && v.every(Number.isFinite)))
|
|
17673
|
+
throw new Error("Invalid terrain gradient pyramid input or capacity");
|
|
17674
|
+
const base = {
|
|
17675
|
+
width,
|
|
17676
|
+
height,
|
|
17677
|
+
blockSize: 1,
|
|
17678
|
+
gradients: new Float64Array(2 * count),
|
|
17679
|
+
validCounts: new Uint32Array(count),
|
|
17680
|
+
sampleCounts: new Uint32Array(count).fill(1)
|
|
17681
|
+
};
|
|
17682
|
+
for (let i = 0; i < count; i++) {
|
|
17683
|
+
if (statuses[i] > TerrainSampleStatus.NOT_RESIDENT)
|
|
17684
|
+
throw new Error("Invalid terrain gradient status");
|
|
17685
|
+
if (statuses[i] === TerrainSampleStatus.VALID) {
|
|
17686
|
+
if (!Number.isFinite(gradients[2 * i]) || !Number.isFinite(gradients[2 * i + 1]))
|
|
17687
|
+
throw new Error("Invalid terrain gradient value");
|
|
17688
|
+
base.gradients[2 * i] = gradients[2 * i];
|
|
17689
|
+
base.gradients[2 * i + 1] = gradients[2 * i + 1];
|
|
17690
|
+
base.validCounts[i] = 1;
|
|
17691
|
+
}
|
|
17692
|
+
}
|
|
17693
|
+
const levels = [base];
|
|
17694
|
+
let source = base;
|
|
17695
|
+
while (source.width > 1 || source.height > 1) {
|
|
17696
|
+
const w = Math.ceil(source.width / 2), h = Math.ceil(source.height / 2);
|
|
17697
|
+
const next = {
|
|
17698
|
+
width: w,
|
|
17699
|
+
height: h,
|
|
17700
|
+
blockSize: source.blockSize * 2,
|
|
17701
|
+
gradients: new Float64Array(2 * w * h),
|
|
17702
|
+
validCounts: new Uint32Array(w * h),
|
|
17703
|
+
sampleCounts: new Uint32Array(w * h)
|
|
17704
|
+
};
|
|
17705
|
+
for (let y = 0; y < h; y++)
|
|
17706
|
+
for (let x = 0; x < w; x++) {
|
|
17707
|
+
const out = y * w + x;
|
|
17708
|
+
for (let dy = 0; dy < 2; dy++)
|
|
17709
|
+
for (let dx = 0; dx < 2; dx++) {
|
|
17710
|
+
const sx = 2 * x + dx, sy = 2 * y + dy;
|
|
17711
|
+
if (sx >= source.width || sy >= source.height)
|
|
17712
|
+
continue;
|
|
17713
|
+
const index = sy * source.width + sx, n = source.validCounts[index], old = next.validCounts[out];
|
|
17714
|
+
next.sampleCounts[out] += source.sampleCounts[index];
|
|
17715
|
+
if (n) {
|
|
17716
|
+
const total = old + n;
|
|
17717
|
+
for (let axis = 0; axis < 2; axis++) {
|
|
17718
|
+
const a = next.gradients[2 * out + axis], b = source.gradients[2 * index + axis];
|
|
17719
|
+
next.gradients[2 * out + axis] = old ? a * (old / total) + b * (n / total) : b;
|
|
17720
|
+
}
|
|
17721
|
+
next.validCounts[out] = total;
|
|
17722
|
+
}
|
|
17723
|
+
}
|
|
17724
|
+
}
|
|
17725
|
+
levels.push(next);
|
|
17726
|
+
source = next;
|
|
17727
|
+
}
|
|
17728
|
+
return {
|
|
17729
|
+
levels,
|
|
17730
|
+
method: grid.method,
|
|
17731
|
+
origin: [...grid.origin],
|
|
17732
|
+
columnStep: [...grid.columnStep],
|
|
17733
|
+
rowStep: [...grid.rowStep],
|
|
17734
|
+
registration: grid.registration,
|
|
17735
|
+
heightReference: grid.heightReference
|
|
17736
|
+
};
|
|
17737
|
+
}
|
|
17738
|
+
|
|
17486
17739
|
// dist/terrain/contour-simplify.js
|
|
17487
17740
|
function simplifyTerrainContourPaths(paths, options) {
|
|
17488
17741
|
const limits = contourPathLimits(options), count = validateContourData(paths, limits);
|
|
@@ -17694,6 +17947,156 @@ function weighted(value3, part, total) {
|
|
|
17694
17947
|
return value3 * ratio2;
|
|
17695
17948
|
}
|
|
17696
17949
|
|
|
17950
|
+
// dist/terrain/profile-visibility.js
|
|
17951
|
+
function getTerrainProfileVisibility(profile, options) {
|
|
17952
|
+
const { observerHeight, targetHeight } = options;
|
|
17953
|
+
const limit = options.maxSamples ?? 1e6;
|
|
17954
|
+
const { distances, heights, statuses, length } = profile;
|
|
17955
|
+
const count = distances.length;
|
|
17956
|
+
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)
|
|
17957
|
+
throw new Error("Invalid terrain visibility profile or options");
|
|
17958
|
+
let missingSampleCount = 0;
|
|
17959
|
+
let firstBlockingSample;
|
|
17960
|
+
let minimumClearance = Infinity;
|
|
17961
|
+
for (let i = 0; i < count; i++) {
|
|
17962
|
+
const distance = distances[i], status = statuses[i];
|
|
17963
|
+
if (!Number.isFinite(distance) || i > 0 && distance <= distances[i - 1])
|
|
17964
|
+
throw new Error("Invalid terrain visibility stationing");
|
|
17965
|
+
if (status > TerrainSampleStatus.NOT_RESIDENT)
|
|
17966
|
+
throw new Error("Invalid terrain visibility status");
|
|
17967
|
+
if (status !== TerrainSampleStatus.VALID) {
|
|
17968
|
+
missingSampleCount++;
|
|
17969
|
+
continue;
|
|
17970
|
+
}
|
|
17971
|
+
if (!Number.isFinite(heights[i]))
|
|
17972
|
+
throw new Error("Invalid terrain visibility height");
|
|
17973
|
+
const fraction = distance / length;
|
|
17974
|
+
const lineHeight = observerHeight * (1 - fraction) + targetHeight * fraction;
|
|
17975
|
+
const clearance = lineHeight - heights[i];
|
|
17976
|
+
if (!Number.isFinite(clearance))
|
|
17977
|
+
throw new Error("Terrain visibility arithmetic overflow");
|
|
17978
|
+
minimumClearance = Math.min(minimumClearance, clearance);
|
|
17979
|
+
if (clearance <= 0 && firstBlockingSample === void 0)
|
|
17980
|
+
firstBlockingSample = i;
|
|
17981
|
+
}
|
|
17982
|
+
return {
|
|
17983
|
+
status: firstBlockingSample !== void 0 ? "blocked" : missingSampleCount ? "unknown" : "clear",
|
|
17984
|
+
firstBlockingSample,
|
|
17985
|
+
missingSampleCount,
|
|
17986
|
+
minimumClearance: minimumClearance === Infinity ? void 0 : minimumClearance
|
|
17987
|
+
};
|
|
17988
|
+
}
|
|
17989
|
+
|
|
17990
|
+
// dist/terrain/profile-slope.js
|
|
17991
|
+
function compareTerrainSlopes(a, ad, b, bd) {
|
|
17992
|
+
const as = a / ad;
|
|
17993
|
+
const bs = b / bd;
|
|
17994
|
+
if (as < bs)
|
|
17995
|
+
return -1;
|
|
17996
|
+
if (as > bs)
|
|
17997
|
+
return 1;
|
|
17998
|
+
if (a === 0 || b === 0 || Math.sign(a) !== Math.sign(b))
|
|
17999
|
+
return Math.sign(a) - Math.sign(b);
|
|
18000
|
+
const bytes = new DataView(new ArrayBuffer(8));
|
|
18001
|
+
const parts = (value3) => {
|
|
18002
|
+
bytes.setFloat64(0, Math.abs(value3));
|
|
18003
|
+
const bits = bytes.getBigUint64(0);
|
|
18004
|
+
const exponent = Number(bits >> 52n & 0x7ffn);
|
|
18005
|
+
const fraction = bits & 0xfffffffffffffn;
|
|
18006
|
+
return exponent ? [fraction | 0x10000000000000n, exponent - 1075] : [fraction, -1074];
|
|
18007
|
+
};
|
|
18008
|
+
const [am, ae] = parts(a), [bdm, bde] = parts(bd);
|
|
18009
|
+
const [bm, be] = parts(b), [adm, ade] = parts(ad);
|
|
18010
|
+
let left = am * bdm;
|
|
18011
|
+
let right = bm * adm;
|
|
18012
|
+
const shift2 = ae + bde - be - ade;
|
|
18013
|
+
if (shift2 > 0)
|
|
18014
|
+
left <<= BigInt(shift2);
|
|
18015
|
+
else if (shift2 < 0)
|
|
18016
|
+
right <<= BigInt(-shift2);
|
|
18017
|
+
return (left < right ? -1 : left > right ? 1 : 0) * Math.sign(a);
|
|
18018
|
+
}
|
|
18019
|
+
|
|
18020
|
+
// dist/terrain/profile-horizon.js
|
|
18021
|
+
function getTerrainProfileHorizon(profile, options) {
|
|
18022
|
+
const { distances, heights, statuses, length } = profile;
|
|
18023
|
+
const count = distances.length;
|
|
18024
|
+
const limit = options.maxSamples ?? 1e6;
|
|
18025
|
+
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)
|
|
18026
|
+
throw new Error("Invalid terrain horizon profile or options");
|
|
18027
|
+
let winningRise = 0;
|
|
18028
|
+
let winningDistance = 1;
|
|
18029
|
+
let sampleIndex;
|
|
18030
|
+
let missingSampleCount = 0;
|
|
18031
|
+
for (let i = 0; i < count; i++) {
|
|
18032
|
+
const distance = distances[i];
|
|
18033
|
+
const status = statuses[i];
|
|
18034
|
+
if (!Number.isFinite(distance) || i > 0 && distance <= distances[i - 1])
|
|
18035
|
+
throw new Error("Invalid terrain horizon stationing");
|
|
18036
|
+
if (status > TerrainSampleStatus.NOT_RESIDENT)
|
|
18037
|
+
throw new Error("Invalid terrain horizon status");
|
|
18038
|
+
if (status !== TerrainSampleStatus.VALID) {
|
|
18039
|
+
missingSampleCount++;
|
|
18040
|
+
continue;
|
|
18041
|
+
}
|
|
18042
|
+
if (!Number.isFinite(heights[i]))
|
|
18043
|
+
throw new Error("Invalid terrain horizon height");
|
|
18044
|
+
if (i === 0) {
|
|
18045
|
+
if (options.observerHeight <= heights[i])
|
|
18046
|
+
throw new Error("Terrain horizon observer must be above ground");
|
|
18047
|
+
continue;
|
|
18048
|
+
}
|
|
18049
|
+
const delta = heights[i] - options.observerHeight;
|
|
18050
|
+
if (!Number.isFinite(delta))
|
|
18051
|
+
throw new Error("Terrain horizon arithmetic overflow");
|
|
18052
|
+
if (sampleIndex === void 0 || compareTerrainSlopes(delta, distance, winningRise, winningDistance) > 0) {
|
|
18053
|
+
winningRise = delta;
|
|
18054
|
+
winningDistance = distance;
|
|
18055
|
+
sampleIndex = i;
|
|
18056
|
+
}
|
|
18057
|
+
}
|
|
18058
|
+
return {
|
|
18059
|
+
angle: sampleIndex === void 0 ? void 0 : Math.atan2(winningRise, winningDistance),
|
|
18060
|
+
sampleIndex,
|
|
18061
|
+
missingSampleCount,
|
|
18062
|
+
complete: missingSampleCount === 0
|
|
18063
|
+
};
|
|
18064
|
+
}
|
|
18065
|
+
|
|
18066
|
+
// dist/terrain/profile-viewshed.js
|
|
18067
|
+
var TerrainProfileViewStatus = {
|
|
18068
|
+
OBSERVER: 0,
|
|
18069
|
+
VISIBLE: 1,
|
|
18070
|
+
BLOCKED: 2,
|
|
18071
|
+
UNKNOWN: 3,
|
|
18072
|
+
MISSING: 4
|
|
18073
|
+
};
|
|
18074
|
+
function getTerrainProfileViewshed(profile, options) {
|
|
18075
|
+
getTerrainProfileHorizon(profile, options);
|
|
18076
|
+
const result = new Uint8Array(profile.distances.length);
|
|
18077
|
+
let maxRise = 0;
|
|
18078
|
+
let maxDistance = 1;
|
|
18079
|
+
let hasHorizon = false;
|
|
18080
|
+
let missingBefore = profile.statuses[0] !== TerrainSampleStatus.VALID;
|
|
18081
|
+
for (let i = 1; i < result.length; i++) {
|
|
18082
|
+
if (profile.statuses[i] !== TerrainSampleStatus.VALID) {
|
|
18083
|
+
result[i] = TerrainProfileViewStatus.MISSING;
|
|
18084
|
+
missingBefore = true;
|
|
18085
|
+
continue;
|
|
18086
|
+
}
|
|
18087
|
+
const rise = profile.heights[i] - options.observerHeight;
|
|
18088
|
+
const distance = profile.distances[i];
|
|
18089
|
+
const comparison = hasHorizon ? compareTerrainSlopes(rise, distance, maxRise, maxDistance) : 1;
|
|
18090
|
+
result[i] = comparison <= 0 ? TerrainProfileViewStatus.BLOCKED : missingBefore ? TerrainProfileViewStatus.UNKNOWN : TerrainProfileViewStatus.VISIBLE;
|
|
18091
|
+
if (comparison > 0) {
|
|
18092
|
+
maxRise = rise;
|
|
18093
|
+
maxDistance = distance;
|
|
18094
|
+
hasHorizon = true;
|
|
18095
|
+
}
|
|
18096
|
+
}
|
|
18097
|
+
return result;
|
|
18098
|
+
}
|
|
18099
|
+
|
|
17697
18100
|
// dist/terrain/vertex-tiles.js
|
|
17698
18101
|
function reconcileTerrainVertexTiles(tiles, options) {
|
|
17699
18102
|
const { width, height } = options;
|
|
@@ -17794,6 +18197,221 @@ function reconcileTerrainVertexTiles(tiles, options) {
|
|
|
17794
18197
|
return { tiles: result, sharedVertices, maxHeightDifference };
|
|
17795
18198
|
}
|
|
17796
18199
|
|
|
18200
|
+
// dist/terrain/vertex-halos.js
|
|
18201
|
+
var TerrainVertexHaloStatus = { NOT_RESIDENT: 0, NO_DATA: 1, VALID: 2 };
|
|
18202
|
+
function createTerrainVertexTileHalos(tiles, options) {
|
|
18203
|
+
const { width, height } = options;
|
|
18204
|
+
const paddedWidth = width + 2, paddedHeight = height + 2;
|
|
18205
|
+
const paddedCount = paddedWidth * paddedHeight * tiles.length;
|
|
18206
|
+
if (!Number.isSafeInteger(paddedCount) || paddedCount > (options.maxSamples ?? 4e6))
|
|
18207
|
+
throw new Error("Vertex tile halo sample capacity exceeded");
|
|
18208
|
+
const reconciled = reconcileTerrainVertexTiles(tiles, options);
|
|
18209
|
+
const lattice = /* @__PURE__ */ new Map();
|
|
18210
|
+
for (const tile of reconciled.tiles) {
|
|
18211
|
+
const x = tile.column * (width - 1), y = tile.row * (height - 1);
|
|
18212
|
+
if (![x - 1, y - 1, x + width, y + height].every(Number.isSafeInteger))
|
|
18213
|
+
throw new Error("Vertex tile halo lattice overflow");
|
|
18214
|
+
for (let row = 0; row < height; row++) {
|
|
18215
|
+
for (let col = 0; col < width; col++) {
|
|
18216
|
+
const index = row * width + col;
|
|
18217
|
+
lattice.set(`${x + col},${y + row}`, {
|
|
18218
|
+
height: tile.field.heights[index],
|
|
18219
|
+
valid: tile.field.validity[index] !== 0
|
|
18220
|
+
});
|
|
18221
|
+
}
|
|
18222
|
+
}
|
|
18223
|
+
}
|
|
18224
|
+
const result = reconciled.tiles.map((tile) => {
|
|
18225
|
+
const x = tile.column * (width - 1), y = tile.row * (height - 1);
|
|
18226
|
+
const heights = new Float64Array(paddedWidth * paddedHeight);
|
|
18227
|
+
const validity = new Uint8Array(heights.length);
|
|
18228
|
+
const statuses = new Uint8Array(heights.length);
|
|
18229
|
+
for (let row = 0; row < paddedHeight; row++) {
|
|
18230
|
+
for (let col = 0; col < paddedWidth; col++) {
|
|
18231
|
+
const index = row * paddedWidth + col;
|
|
18232
|
+
const value3 = lattice.get(`${x + col - 1},${y + row - 1}`);
|
|
18233
|
+
if (value3) {
|
|
18234
|
+
statuses[index] = value3.valid ? TerrainVertexHaloStatus.VALID : TerrainVertexHaloStatus.NO_DATA;
|
|
18235
|
+
if (value3.valid) {
|
|
18236
|
+
heights[index] = value3.height;
|
|
18237
|
+
validity[index] = 1;
|
|
18238
|
+
}
|
|
18239
|
+
}
|
|
18240
|
+
}
|
|
18241
|
+
}
|
|
18242
|
+
const origin = tile.field.origin, columnStep = tile.field.columnStep, rowStep = tile.field.rowStep;
|
|
18243
|
+
const paddedOrigin = [
|
|
18244
|
+
origin[0] - columnStep[0] - rowStep[0],
|
|
18245
|
+
origin[1] - columnStep[1] - rowStep[1]
|
|
18246
|
+
];
|
|
18247
|
+
if (!paddedOrigin.every(Number.isFinite))
|
|
18248
|
+
throw new Error("Vertex tile halo coordinate overflow");
|
|
18249
|
+
return {
|
|
18250
|
+
column: tile.column,
|
|
18251
|
+
row: tile.row,
|
|
18252
|
+
statuses,
|
|
18253
|
+
field: {
|
|
18254
|
+
...tile.field,
|
|
18255
|
+
width: paddedWidth,
|
|
18256
|
+
height: paddedHeight,
|
|
18257
|
+
heights,
|
|
18258
|
+
validity,
|
|
18259
|
+
origin: paddedOrigin
|
|
18260
|
+
}
|
|
18261
|
+
};
|
|
18262
|
+
});
|
|
18263
|
+
return {
|
|
18264
|
+
tiles: result,
|
|
18265
|
+
sharedVertices: reconciled.sharedVertices,
|
|
18266
|
+
maxHeightDifference: reconciled.maxHeightDifference
|
|
18267
|
+
};
|
|
18268
|
+
}
|
|
18269
|
+
|
|
18270
|
+
// dist/terrain/vertex-halo-invalidation.js
|
|
18271
|
+
function getTerrainVertexHaloAffectedTiles(resident, changed, options) {
|
|
18272
|
+
const limit = options.maxTiles ?? 4096;
|
|
18273
|
+
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)
|
|
18274
|
+
throw new Error("Invalid vertex halo tile capacity");
|
|
18275
|
+
const addresses = /* @__PURE__ */ new Map();
|
|
18276
|
+
const key2 = (tile) => {
|
|
18277
|
+
if (!Number.isSafeInteger(tile.column) || !Number.isSafeInteger(tile.row))
|
|
18278
|
+
throw new Error("Invalid vertex tile address");
|
|
18279
|
+
return `${tile.column},${tile.row}`;
|
|
18280
|
+
};
|
|
18281
|
+
for (const tile of resident) {
|
|
18282
|
+
const id = key2(tile);
|
|
18283
|
+
if (addresses.has(id))
|
|
18284
|
+
throw new Error("Duplicate resident vertex tile address");
|
|
18285
|
+
addresses.set(id, { column: tile.column, row: tile.row });
|
|
18286
|
+
}
|
|
18287
|
+
const affected = /* @__PURE__ */ new Map();
|
|
18288
|
+
for (const tile of changed) {
|
|
18289
|
+
key2(tile);
|
|
18290
|
+
const rx = options.width === 2 ? 2 : 1, ry = options.height === 2 ? 2 : 1;
|
|
18291
|
+
for (let x = -rx; x <= rx; x++)
|
|
18292
|
+
for (let y = -ry; y <= ry; y++) {
|
|
18293
|
+
const column = tile.column + x, row = tile.row + y;
|
|
18294
|
+
if (!Number.isSafeInteger(column) || !Number.isSafeInteger(row))
|
|
18295
|
+
continue;
|
|
18296
|
+
const id = `${column},${row}`;
|
|
18297
|
+
const target = addresses.get(id);
|
|
18298
|
+
if (target)
|
|
18299
|
+
affected.set(id, target);
|
|
18300
|
+
}
|
|
18301
|
+
}
|
|
18302
|
+
return [...affected.values()].sort((a, b) => a.column - b.column || a.row - b.row);
|
|
18303
|
+
}
|
|
18304
|
+
|
|
18305
|
+
// dist/terrain/vertex-halo-update.js
|
|
18306
|
+
function updateTerrainVertexTileHalos(previous, resident, changed, options) {
|
|
18307
|
+
const prior = options.previousOptions;
|
|
18308
|
+
if (!prior)
|
|
18309
|
+
throw new Error("Previous vertex tile options are required");
|
|
18310
|
+
const paddedCount = (options.width + 2) * (options.height + 2) * resident.length;
|
|
18311
|
+
if (!Number.isSafeInteger(paddedCount) || paddedCount > (options.maxSamples ?? 4e6))
|
|
18312
|
+
throw new Error("Vertex tile halo sample capacity exceeded");
|
|
18313
|
+
const equalPair = (a, b) => a[0] === b[0] && a[1] === b[1];
|
|
18314
|
+
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))
|
|
18315
|
+
throw new Error("Vertex tile options changed; rebuild the full snapshot");
|
|
18316
|
+
const key2 = (t) => `${t.column},${t.row}`;
|
|
18317
|
+
const affected = getTerrainVertexHaloAffectedTiles(resident, changed, options);
|
|
18318
|
+
getTerrainVertexHaloAffectedTiles(previous, [], options);
|
|
18319
|
+
const previousMap = new Map(previous.map((tile) => [key2(tile), tile]));
|
|
18320
|
+
const currentKeys = new Set(resident.map(key2));
|
|
18321
|
+
const changedKeys = new Set(changed.map(key2));
|
|
18322
|
+
for (const tile of resident) {
|
|
18323
|
+
if (!previousMap.has(key2(tile)) && !changedKeys.has(key2(tile)))
|
|
18324
|
+
throw new Error("Unreported vertex tile arrival");
|
|
18325
|
+
}
|
|
18326
|
+
const removed = [];
|
|
18327
|
+
for (const tile of previous) {
|
|
18328
|
+
if (!currentKeys.has(key2(tile))) {
|
|
18329
|
+
if (!changedKeys.has(key2(tile)))
|
|
18330
|
+
throw new Error("Unreported vertex tile eviction");
|
|
18331
|
+
removed.push({ column: tile.column, row: tile.row });
|
|
18332
|
+
}
|
|
18333
|
+
}
|
|
18334
|
+
removed.sort((a, b) => a.column - b.column || a.row - b.row);
|
|
18335
|
+
const affectedKeys = new Set(affected.map(key2));
|
|
18336
|
+
const rx = options.width === 2 ? 2 : 1;
|
|
18337
|
+
const ry = options.height === 2 ? 2 : 1;
|
|
18338
|
+
const needed = /* @__PURE__ */ new Set();
|
|
18339
|
+
for (const tile of affected)
|
|
18340
|
+
for (let x = -rx; x <= rx; x++)
|
|
18341
|
+
for (let y = -ry; y <= ry; y++) {
|
|
18342
|
+
const column = tile.column + x, row = tile.row + y;
|
|
18343
|
+
if (Number.isSafeInteger(column) && Number.isSafeInteger(row))
|
|
18344
|
+
needed.add(`${column},${row}`);
|
|
18345
|
+
}
|
|
18346
|
+
const source = resident.filter((tile) => needed.has(key2(tile)));
|
|
18347
|
+
const rebuilt = createTerrainVertexTileHalos(source, options).tiles;
|
|
18348
|
+
const results = new Map(previous.filter((tile) => currentKeys.has(key2(tile)) && !affectedKeys.has(key2(tile))).map((tile) => [key2(tile), tile]));
|
|
18349
|
+
for (const tile of rebuilt)
|
|
18350
|
+
if (affectedKeys.has(key2(tile)))
|
|
18351
|
+
results.set(key2(tile), tile);
|
|
18352
|
+
if (results.size !== resident.length)
|
|
18353
|
+
throw new Error("Incomplete vertex halo update");
|
|
18354
|
+
return {
|
|
18355
|
+
tiles: [...results.values()].sort((a, b) => a.column - b.column || a.row - b.row),
|
|
18356
|
+
rebuilt: affected,
|
|
18357
|
+
removed
|
|
18358
|
+
};
|
|
18359
|
+
}
|
|
18360
|
+
|
|
18361
|
+
// dist/terrain/filtered-pyramid.js
|
|
18362
|
+
function createTerrainFilteredPyramid(input, options = {}) {
|
|
18363
|
+
const { width, height, heights, validity } = input;
|
|
18364
|
+
const count = width * height;
|
|
18365
|
+
const limit = options.maxSamples ?? 4e6;
|
|
18366
|
+
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))
|
|
18367
|
+
throw new Error("Invalid terrain filtered pyramid input or capacity");
|
|
18368
|
+
const base = {
|
|
18369
|
+
width,
|
|
18370
|
+
height,
|
|
18371
|
+
heights: new Float64Array(count),
|
|
18372
|
+
validCounts: new Uint32Array(count),
|
|
18373
|
+
sampleCounts: new Uint32Array(count).fill(1)
|
|
18374
|
+
};
|
|
18375
|
+
for (let i = 0; i < count; i++)
|
|
18376
|
+
if ((!validity || validity[i] !== 0) && Number.isFinite(heights[i])) {
|
|
18377
|
+
base.heights[i] = heights[i];
|
|
18378
|
+
base.validCounts[i] = 1;
|
|
18379
|
+
}
|
|
18380
|
+
const levels = [base];
|
|
18381
|
+
let source = base;
|
|
18382
|
+
while (source.width > 1 || source.height > 1) {
|
|
18383
|
+
const w = Math.ceil(source.width / 2), h = Math.ceil(source.height / 2);
|
|
18384
|
+
const next = {
|
|
18385
|
+
width: w,
|
|
18386
|
+
height: h,
|
|
18387
|
+
heights: new Float64Array(w * h),
|
|
18388
|
+
validCounts: new Uint32Array(w * h),
|
|
18389
|
+
sampleCounts: new Uint32Array(w * h)
|
|
18390
|
+
};
|
|
18391
|
+
for (let y = 0; y < h; y++)
|
|
18392
|
+
for (let x = 0; x < w; x++) {
|
|
18393
|
+
const out = y * w + x;
|
|
18394
|
+
for (let dy = 0; dy < 2; dy++)
|
|
18395
|
+
for (let dx = 0; dx < 2; dx++) {
|
|
18396
|
+
const sx = x * 2 + dx, sy = y * 2 + dy;
|
|
18397
|
+
if (sx >= source.width || sy >= source.height)
|
|
18398
|
+
continue;
|
|
18399
|
+
const index = sy * source.width + sx;
|
|
18400
|
+
const n = source.validCounts[index], old = next.validCounts[out];
|
|
18401
|
+
next.sampleCounts[out] += source.sampleCounts[index];
|
|
18402
|
+
if (n) {
|
|
18403
|
+
const total = old + n, a = next.heights[out], b = source.heights[index];
|
|
18404
|
+
next.heights[out] = old ? a * (old / total) + b * (n / total) : b;
|
|
18405
|
+
next.validCounts[out] = total;
|
|
18406
|
+
}
|
|
18407
|
+
}
|
|
18408
|
+
}
|
|
18409
|
+
levels.push(next);
|
|
18410
|
+
source = next;
|
|
18411
|
+
}
|
|
18412
|
+
return levels;
|
|
18413
|
+
}
|
|
18414
|
+
|
|
17797
18415
|
// dist/terrain/mesh-stitch.js
|
|
17798
18416
|
function stitchTerrainMeshEdges(a, edgeA, b, edgeB, options = {}) {
|
|
17799
18417
|
const maxVertices = options.maxVertices ?? 2e6, maxTriangles = options.maxTriangles ?? 4e6, maxBoundary = options.maxBoundaryVertices ?? 1e5;
|