@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.
- package/dist/crs/crs-identifier.d.ts +23 -0
- package/dist/crs/crs-identifier.d.ts.map +1 -0
- package/dist/crs/crs-identifier.js +74 -0
- package/dist/crs/crs-identifier.js.map +1 -0
- package/dist/crs/index.cjs +48 -0
- package/dist/crs/index.cjs.map +2 -2
- package/dist/crs/index.d.ts +1 -0
- package/dist/crs/index.d.ts.map +1 -1
- package/dist/crs/index.js +1 -0
- package/dist/crs/index.js.map +1 -1
- package/dist/discontinuous/cap-map.d.ts.map +1 -1
- package/dist/discontinuous/cap-map.js +197 -13
- package/dist/discontinuous/cap-map.js.map +1 -1
- package/dist/discontinuous/elastic/geometry.d.ts +1 -1
- package/dist/discontinuous/elastic/geometry.d.ts.map +1 -1
- package/dist/discontinuous/elastic/geometry.js +7 -7
- package/dist/discontinuous/elastic/geometry.js.map +1 -1
- package/dist/discontinuous/elastic/map.d.ts.map +1 -1
- package/dist/discontinuous/elastic/map.js +263 -23
- package/dist/discontinuous/elastic/map.js.map +1 -1
- package/dist/discontinuous/elastic/source-arc.d.ts +10 -0
- package/dist/discontinuous/elastic/source-arc.d.ts.map +1 -0
- package/dist/discontinuous/elastic/source-arc.js +111 -0
- package/dist/discontinuous/elastic/source-arc.js.map +1 -0
- package/dist/discontinuous/global-polygons.d.ts +1 -1
- package/dist/discontinuous/global-polygons.d.ts.map +1 -1
- package/dist/discontinuous/global-polygons.js +49 -1
- package/dist/discontinuous/global-polygons.js.map +1 -1
- package/dist/discontinuous/map-engine.d.ts +9 -0
- package/dist/discontinuous/map-engine.d.ts.map +1 -1
- package/dist/discontinuous/map-layout.d.ts +21 -0
- package/dist/discontinuous/map-layout.d.ts.map +1 -1
- package/dist/discontinuous/map-layout.js +116 -1
- package/dist/discontinuous/map-layout.js.map +1 -1
- package/dist/discontinuous/map-transition.d.ts.map +1 -1
- package/dist/discontinuous/map-transition.js +66 -3
- package/dist/discontinuous/map-transition.js.map +1 -1
- package/dist/discontinuous/mercator-map.d.ts +2 -2
- package/dist/discontinuous/mercator-map.d.ts.map +1 -1
- package/dist/discontinuous/mercator-map.js +123 -11
- package/dist/discontinuous/mercator-map.js.map +1 -1
- package/dist/discontinuous/polygon-constraints.d.ts +16 -0
- package/dist/discontinuous/polygon-constraints.d.ts.map +1 -0
- package/dist/discontinuous/polygon-constraints.js +157 -0
- package/dist/discontinuous/polygon-constraints.js.map +1 -0
- package/dist/discontinuous/prepare-features.d.ts +27 -0
- package/dist/discontinuous/prepare-features.d.ts.map +1 -1
- package/dist/discontinuous/prepare-features.js +106 -5
- package/dist/discontinuous/prepare-features.js.map +1 -1
- package/dist/discontinuous/rotated-map.d.ts +9 -0
- package/dist/discontinuous/rotated-map.d.ts.map +1 -1
- package/dist/discontinuous/source-arc.d.ts +4 -0
- package/dist/discontinuous/source-arc.d.ts.map +1 -0
- package/dist/discontinuous/source-arc.js +23 -0
- package/dist/discontinuous/source-arc.js.map +1 -0
- package/dist/discontinuous/world-kernels.d.ts +1 -1
- package/dist/discontinuous.cjs +1047 -75
- package/dist/discontinuous.cjs.map +3 -3
- package/dist/index.cjs +422 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- 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 +1223 -191
- 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/dist/turf.cjs +69 -5
- package/dist/turf.cjs.map +2 -2
- package/dist/turf.d.ts +9 -0
- package/dist/turf.d.ts.map +1 -1
- package/dist/turf.js +67 -0
- package/dist/turf.js.map +1 -1
- package/package.json +10 -15
- package/src/crs/crs-identifier.ts +86 -0
- package/src/crs/index.ts +1 -0
- package/src/discontinuous/cap-map.ts +248 -19
- package/src/discontinuous/elastic/geometry.ts +18 -7
- package/src/discontinuous/elastic/map.ts +334 -30
- package/src/discontinuous/elastic/source-arc.ts +129 -0
- package/src/discontinuous/global-polygons.ts +56 -2
- package/src/discontinuous/map-layout.ts +165 -2
- package/src/discontinuous/map-transition.ts +67 -3
- package/src/discontinuous/mercator-map.ts +151 -12
- package/src/discontinuous/polygon-constraints.ts +184 -0
- package/src/discontinuous/prepare-features.ts +154 -6
- package/src/discontinuous/source-arc.ts +31 -0
- package/src/index.ts +13 -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/src/turf.ts +86 -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 -20036
- 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/terrain/index.cjs
CHANGED
|
@@ -34,19 +34,27 @@ __export(index_exports, {
|
|
|
34
34
|
HeightFieldGeometry: () => HeightFieldGeometry,
|
|
35
35
|
HeightFieldMinMax: () => HeightFieldMinMax,
|
|
36
36
|
TERRAIN_BUFFER_VERSION: () => TERRAIN_BUFFER_VERSION,
|
|
37
|
+
TerrainProfileViewStatus: () => TerrainProfileViewStatus,
|
|
37
38
|
TerrainSampleStatus: () => TerrainSampleStatus,
|
|
38
39
|
TerrainSurface: () => TerrainSurface,
|
|
40
|
+
TerrainVertexHaloStatus: () => TerrainVertexHaloStatus,
|
|
39
41
|
TiledHeightField: () => TiledHeightField,
|
|
40
42
|
createDelatinTerrainMesh: () => createDelatinTerrainMesh,
|
|
41
43
|
createMartiniTerrainMesh: () => createMartiniTerrainMesh,
|
|
42
44
|
createTerrainContours: () => createTerrainContours,
|
|
45
|
+
createTerrainFilteredPyramid: () => createTerrainFilteredPyramid,
|
|
43
46
|
createTerrainGradientGrid: () => createTerrainGradientGrid,
|
|
44
47
|
createTerrainMesh: () => createTerrainMesh,
|
|
45
48
|
createTerrainSkirt: () => createTerrainSkirt,
|
|
46
49
|
createTerrainSlopeAspectGrid: () => createTerrainSlopeAspectGrid,
|
|
47
50
|
createTerrainSurface: () => createTerrainSurface,
|
|
51
|
+
createTerrainVertexTileHalos: () => createTerrainVertexTileHalos,
|
|
48
52
|
getTerrainMeshEdge: () => getTerrainMeshEdge,
|
|
53
|
+
getTerrainProfileHorizon: () => getTerrainProfileHorizon,
|
|
54
|
+
getTerrainProfileViewshed: () => getTerrainProfileViewshed,
|
|
55
|
+
getTerrainProfileVisibility: () => getTerrainProfileVisibility,
|
|
49
56
|
getTerrainSlopeAspect: () => getTerrainSlopeAspect,
|
|
57
|
+
getTerrainVertexHaloAffectedTiles: () => getTerrainVertexHaloAffectedTiles,
|
|
50
58
|
measureTerrainMeshError: () => measureTerrainMeshError,
|
|
51
59
|
measureTerrainProfile: () => measureTerrainProfile,
|
|
52
60
|
packTerrainHeightField: () => packTerrainHeightField,
|
|
@@ -55,7 +63,8 @@ __export(index_exports, {
|
|
|
55
63
|
simplifyTerrainContourPaths: () => simplifyTerrainContourPaths,
|
|
56
64
|
stitchTerrainContours: () => stitchTerrainContours,
|
|
57
65
|
stitchTerrainMeshEdges: () => stitchTerrainMeshEdges,
|
|
58
|
-
unpackTerrainHeightField: () => unpackTerrainHeightField
|
|
66
|
+
unpackTerrainHeightField: () => unpackTerrainHeightField,
|
|
67
|
+
updateTerrainVertexTileHalos: () => updateTerrainVertexTileHalos
|
|
59
68
|
});
|
|
60
69
|
module.exports = __toCommonJS(index_exports);
|
|
61
70
|
|
|
@@ -2777,6 +2786,156 @@ function weighted(value, part, total) {
|
|
|
2777
2786
|
return value * ratio;
|
|
2778
2787
|
}
|
|
2779
2788
|
|
|
2789
|
+
// dist/terrain/profile-visibility.js
|
|
2790
|
+
function getTerrainProfileVisibility(profile, options) {
|
|
2791
|
+
const { observerHeight, targetHeight } = options;
|
|
2792
|
+
const limit = options.maxSamples ?? 1e6;
|
|
2793
|
+
const { distances, heights, statuses, length } = profile;
|
|
2794
|
+
const count = distances.length;
|
|
2795
|
+
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)
|
|
2796
|
+
throw new Error("Invalid terrain visibility profile or options");
|
|
2797
|
+
let missingSampleCount = 0;
|
|
2798
|
+
let firstBlockingSample;
|
|
2799
|
+
let minimumClearance = Infinity;
|
|
2800
|
+
for (let i = 0; i < count; i++) {
|
|
2801
|
+
const distance = distances[i], status = statuses[i];
|
|
2802
|
+
if (!Number.isFinite(distance) || i > 0 && distance <= distances[i - 1])
|
|
2803
|
+
throw new Error("Invalid terrain visibility stationing");
|
|
2804
|
+
if (status > TerrainSampleStatus.NOT_RESIDENT)
|
|
2805
|
+
throw new Error("Invalid terrain visibility status");
|
|
2806
|
+
if (status !== TerrainSampleStatus.VALID) {
|
|
2807
|
+
missingSampleCount++;
|
|
2808
|
+
continue;
|
|
2809
|
+
}
|
|
2810
|
+
if (!Number.isFinite(heights[i]))
|
|
2811
|
+
throw new Error("Invalid terrain visibility height");
|
|
2812
|
+
const fraction = distance / length;
|
|
2813
|
+
const lineHeight = observerHeight * (1 - fraction) + targetHeight * fraction;
|
|
2814
|
+
const clearance = lineHeight - heights[i];
|
|
2815
|
+
if (!Number.isFinite(clearance))
|
|
2816
|
+
throw new Error("Terrain visibility arithmetic overflow");
|
|
2817
|
+
minimumClearance = Math.min(minimumClearance, clearance);
|
|
2818
|
+
if (clearance <= 0 && firstBlockingSample === void 0)
|
|
2819
|
+
firstBlockingSample = i;
|
|
2820
|
+
}
|
|
2821
|
+
return {
|
|
2822
|
+
status: firstBlockingSample !== void 0 ? "blocked" : missingSampleCount ? "unknown" : "clear",
|
|
2823
|
+
firstBlockingSample,
|
|
2824
|
+
missingSampleCount,
|
|
2825
|
+
minimumClearance: minimumClearance === Infinity ? void 0 : minimumClearance
|
|
2826
|
+
};
|
|
2827
|
+
}
|
|
2828
|
+
|
|
2829
|
+
// dist/terrain/profile-slope.js
|
|
2830
|
+
function compareTerrainSlopes(a, ad, b, bd) {
|
|
2831
|
+
const as = a / ad;
|
|
2832
|
+
const bs = b / bd;
|
|
2833
|
+
if (as < bs)
|
|
2834
|
+
return -1;
|
|
2835
|
+
if (as > bs)
|
|
2836
|
+
return 1;
|
|
2837
|
+
if (a === 0 || b === 0 || Math.sign(a) !== Math.sign(b))
|
|
2838
|
+
return Math.sign(a) - Math.sign(b);
|
|
2839
|
+
const bytes = new DataView(new ArrayBuffer(8));
|
|
2840
|
+
const parts = (value) => {
|
|
2841
|
+
bytes.setFloat64(0, Math.abs(value));
|
|
2842
|
+
const bits = bytes.getBigUint64(0);
|
|
2843
|
+
const exponent = Number(bits >> 52n & 0x7ffn);
|
|
2844
|
+
const fraction = bits & 0xfffffffffffffn;
|
|
2845
|
+
return exponent ? [fraction | 0x10000000000000n, exponent - 1075] : [fraction, -1074];
|
|
2846
|
+
};
|
|
2847
|
+
const [am, ae] = parts(a), [bdm, bde] = parts(bd);
|
|
2848
|
+
const [bm, be] = parts(b), [adm, ade] = parts(ad);
|
|
2849
|
+
let left = am * bdm;
|
|
2850
|
+
let right = bm * adm;
|
|
2851
|
+
const shift = ae + bde - be - ade;
|
|
2852
|
+
if (shift > 0)
|
|
2853
|
+
left <<= BigInt(shift);
|
|
2854
|
+
else if (shift < 0)
|
|
2855
|
+
right <<= BigInt(-shift);
|
|
2856
|
+
return (left < right ? -1 : left > right ? 1 : 0) * Math.sign(a);
|
|
2857
|
+
}
|
|
2858
|
+
|
|
2859
|
+
// dist/terrain/profile-horizon.js
|
|
2860
|
+
function getTerrainProfileHorizon(profile, options) {
|
|
2861
|
+
const { distances, heights, statuses, length } = profile;
|
|
2862
|
+
const count = distances.length;
|
|
2863
|
+
const limit = options.maxSamples ?? 1e6;
|
|
2864
|
+
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)
|
|
2865
|
+
throw new Error("Invalid terrain horizon profile or options");
|
|
2866
|
+
let winningRise = 0;
|
|
2867
|
+
let winningDistance = 1;
|
|
2868
|
+
let sampleIndex;
|
|
2869
|
+
let missingSampleCount = 0;
|
|
2870
|
+
for (let i = 0; i < count; i++) {
|
|
2871
|
+
const distance = distances[i];
|
|
2872
|
+
const status = statuses[i];
|
|
2873
|
+
if (!Number.isFinite(distance) || i > 0 && distance <= distances[i - 1])
|
|
2874
|
+
throw new Error("Invalid terrain horizon stationing");
|
|
2875
|
+
if (status > TerrainSampleStatus.NOT_RESIDENT)
|
|
2876
|
+
throw new Error("Invalid terrain horizon status");
|
|
2877
|
+
if (status !== TerrainSampleStatus.VALID) {
|
|
2878
|
+
missingSampleCount++;
|
|
2879
|
+
continue;
|
|
2880
|
+
}
|
|
2881
|
+
if (!Number.isFinite(heights[i]))
|
|
2882
|
+
throw new Error("Invalid terrain horizon height");
|
|
2883
|
+
if (i === 0) {
|
|
2884
|
+
if (options.observerHeight <= heights[i])
|
|
2885
|
+
throw new Error("Terrain horizon observer must be above ground");
|
|
2886
|
+
continue;
|
|
2887
|
+
}
|
|
2888
|
+
const delta = heights[i] - options.observerHeight;
|
|
2889
|
+
if (!Number.isFinite(delta))
|
|
2890
|
+
throw new Error("Terrain horizon arithmetic overflow");
|
|
2891
|
+
if (sampleIndex === void 0 || compareTerrainSlopes(delta, distance, winningRise, winningDistance) > 0) {
|
|
2892
|
+
winningRise = delta;
|
|
2893
|
+
winningDistance = distance;
|
|
2894
|
+
sampleIndex = i;
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
return {
|
|
2898
|
+
angle: sampleIndex === void 0 ? void 0 : Math.atan2(winningRise, winningDistance),
|
|
2899
|
+
sampleIndex,
|
|
2900
|
+
missingSampleCount,
|
|
2901
|
+
complete: missingSampleCount === 0
|
|
2902
|
+
};
|
|
2903
|
+
}
|
|
2904
|
+
|
|
2905
|
+
// dist/terrain/profile-viewshed.js
|
|
2906
|
+
var TerrainProfileViewStatus = {
|
|
2907
|
+
OBSERVER: 0,
|
|
2908
|
+
VISIBLE: 1,
|
|
2909
|
+
BLOCKED: 2,
|
|
2910
|
+
UNKNOWN: 3,
|
|
2911
|
+
MISSING: 4
|
|
2912
|
+
};
|
|
2913
|
+
function getTerrainProfileViewshed(profile, options) {
|
|
2914
|
+
getTerrainProfileHorizon(profile, options);
|
|
2915
|
+
const result = new Uint8Array(profile.distances.length);
|
|
2916
|
+
let maxRise = 0;
|
|
2917
|
+
let maxDistance = 1;
|
|
2918
|
+
let hasHorizon = false;
|
|
2919
|
+
let missingBefore = profile.statuses[0] !== TerrainSampleStatus.VALID;
|
|
2920
|
+
for (let i = 1; i < result.length; i++) {
|
|
2921
|
+
if (profile.statuses[i] !== TerrainSampleStatus.VALID) {
|
|
2922
|
+
result[i] = TerrainProfileViewStatus.MISSING;
|
|
2923
|
+
missingBefore = true;
|
|
2924
|
+
continue;
|
|
2925
|
+
}
|
|
2926
|
+
const rise = profile.heights[i] - options.observerHeight;
|
|
2927
|
+
const distance = profile.distances[i];
|
|
2928
|
+
const comparison = hasHorizon ? compareTerrainSlopes(rise, distance, maxRise, maxDistance) : 1;
|
|
2929
|
+
result[i] = comparison <= 0 ? TerrainProfileViewStatus.BLOCKED : missingBefore ? TerrainProfileViewStatus.UNKNOWN : TerrainProfileViewStatus.VISIBLE;
|
|
2930
|
+
if (comparison > 0) {
|
|
2931
|
+
maxRise = rise;
|
|
2932
|
+
maxDistance = distance;
|
|
2933
|
+
hasHorizon = true;
|
|
2934
|
+
}
|
|
2935
|
+
}
|
|
2936
|
+
return result;
|
|
2937
|
+
}
|
|
2938
|
+
|
|
2780
2939
|
// dist/terrain/vertex-tiles.js
|
|
2781
2940
|
function reconcileTerrainVertexTiles(tiles, options) {
|
|
2782
2941
|
const { width, height } = options;
|
|
@@ -2877,6 +3036,221 @@ function reconcileTerrainVertexTiles(tiles, options) {
|
|
|
2877
3036
|
return { tiles: result, sharedVertices, maxHeightDifference };
|
|
2878
3037
|
}
|
|
2879
3038
|
|
|
3039
|
+
// dist/terrain/vertex-halos.js
|
|
3040
|
+
var TerrainVertexHaloStatus = { NOT_RESIDENT: 0, NO_DATA: 1, VALID: 2 };
|
|
3041
|
+
function createTerrainVertexTileHalos(tiles, options) {
|
|
3042
|
+
const { width, height } = options;
|
|
3043
|
+
const paddedWidth = width + 2, paddedHeight = height + 2;
|
|
3044
|
+
const paddedCount = paddedWidth * paddedHeight * tiles.length;
|
|
3045
|
+
if (!Number.isSafeInteger(paddedCount) || paddedCount > (options.maxSamples ?? 4e6))
|
|
3046
|
+
throw new Error("Vertex tile halo sample capacity exceeded");
|
|
3047
|
+
const reconciled = reconcileTerrainVertexTiles(tiles, options);
|
|
3048
|
+
const lattice = /* @__PURE__ */ new Map();
|
|
3049
|
+
for (const tile of reconciled.tiles) {
|
|
3050
|
+
const x = tile.column * (width - 1), y = tile.row * (height - 1);
|
|
3051
|
+
if (![x - 1, y - 1, x + width, y + height].every(Number.isSafeInteger))
|
|
3052
|
+
throw new Error("Vertex tile halo lattice overflow");
|
|
3053
|
+
for (let row = 0; row < height; row++) {
|
|
3054
|
+
for (let col = 0; col < width; col++) {
|
|
3055
|
+
const index = row * width + col;
|
|
3056
|
+
lattice.set(`${x + col},${y + row}`, {
|
|
3057
|
+
height: tile.field.heights[index],
|
|
3058
|
+
valid: tile.field.validity[index] !== 0
|
|
3059
|
+
});
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
const result = reconciled.tiles.map((tile) => {
|
|
3064
|
+
const x = tile.column * (width - 1), y = tile.row * (height - 1);
|
|
3065
|
+
const heights = new Float64Array(paddedWidth * paddedHeight);
|
|
3066
|
+
const validity = new Uint8Array(heights.length);
|
|
3067
|
+
const statuses = new Uint8Array(heights.length);
|
|
3068
|
+
for (let row = 0; row < paddedHeight; row++) {
|
|
3069
|
+
for (let col = 0; col < paddedWidth; col++) {
|
|
3070
|
+
const index = row * paddedWidth + col;
|
|
3071
|
+
const value = lattice.get(`${x + col - 1},${y + row - 1}`);
|
|
3072
|
+
if (value) {
|
|
3073
|
+
statuses[index] = value.valid ? TerrainVertexHaloStatus.VALID : TerrainVertexHaloStatus.NO_DATA;
|
|
3074
|
+
if (value.valid) {
|
|
3075
|
+
heights[index] = value.height;
|
|
3076
|
+
validity[index] = 1;
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
const origin = tile.field.origin, columnStep = tile.field.columnStep, rowStep = tile.field.rowStep;
|
|
3082
|
+
const paddedOrigin = [
|
|
3083
|
+
origin[0] - columnStep[0] - rowStep[0],
|
|
3084
|
+
origin[1] - columnStep[1] - rowStep[1]
|
|
3085
|
+
];
|
|
3086
|
+
if (!paddedOrigin.every(Number.isFinite))
|
|
3087
|
+
throw new Error("Vertex tile halo coordinate overflow");
|
|
3088
|
+
return {
|
|
3089
|
+
column: tile.column,
|
|
3090
|
+
row: tile.row,
|
|
3091
|
+
statuses,
|
|
3092
|
+
field: {
|
|
3093
|
+
...tile.field,
|
|
3094
|
+
width: paddedWidth,
|
|
3095
|
+
height: paddedHeight,
|
|
3096
|
+
heights,
|
|
3097
|
+
validity,
|
|
3098
|
+
origin: paddedOrigin
|
|
3099
|
+
}
|
|
3100
|
+
};
|
|
3101
|
+
});
|
|
3102
|
+
return {
|
|
3103
|
+
tiles: result,
|
|
3104
|
+
sharedVertices: reconciled.sharedVertices,
|
|
3105
|
+
maxHeightDifference: reconciled.maxHeightDifference
|
|
3106
|
+
};
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
// dist/terrain/vertex-halo-invalidation.js
|
|
3110
|
+
function getTerrainVertexHaloAffectedTiles(resident, changed, options) {
|
|
3111
|
+
const limit = options.maxTiles ?? 4096;
|
|
3112
|
+
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)
|
|
3113
|
+
throw new Error("Invalid vertex halo tile capacity");
|
|
3114
|
+
const addresses = /* @__PURE__ */ new Map();
|
|
3115
|
+
const key = (tile) => {
|
|
3116
|
+
if (!Number.isSafeInteger(tile.column) || !Number.isSafeInteger(tile.row))
|
|
3117
|
+
throw new Error("Invalid vertex tile address");
|
|
3118
|
+
return `${tile.column},${tile.row}`;
|
|
3119
|
+
};
|
|
3120
|
+
for (const tile of resident) {
|
|
3121
|
+
const id = key(tile);
|
|
3122
|
+
if (addresses.has(id))
|
|
3123
|
+
throw new Error("Duplicate resident vertex tile address");
|
|
3124
|
+
addresses.set(id, { column: tile.column, row: tile.row });
|
|
3125
|
+
}
|
|
3126
|
+
const affected = /* @__PURE__ */ new Map();
|
|
3127
|
+
for (const tile of changed) {
|
|
3128
|
+
key(tile);
|
|
3129
|
+
const rx = options.width === 2 ? 2 : 1, ry = options.height === 2 ? 2 : 1;
|
|
3130
|
+
for (let x = -rx; x <= rx; x++)
|
|
3131
|
+
for (let y = -ry; y <= ry; y++) {
|
|
3132
|
+
const column = tile.column + x, row = tile.row + y;
|
|
3133
|
+
if (!Number.isSafeInteger(column) || !Number.isSafeInteger(row))
|
|
3134
|
+
continue;
|
|
3135
|
+
const id = `${column},${row}`;
|
|
3136
|
+
const target = addresses.get(id);
|
|
3137
|
+
if (target)
|
|
3138
|
+
affected.set(id, target);
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
3141
|
+
return [...affected.values()].sort((a, b) => a.column - b.column || a.row - b.row);
|
|
3142
|
+
}
|
|
3143
|
+
|
|
3144
|
+
// dist/terrain/vertex-halo-update.js
|
|
3145
|
+
function updateTerrainVertexTileHalos(previous, resident, changed, options) {
|
|
3146
|
+
const prior = options.previousOptions;
|
|
3147
|
+
if (!prior)
|
|
3148
|
+
throw new Error("Previous vertex tile options are required");
|
|
3149
|
+
const paddedCount = (options.width + 2) * (options.height + 2) * resident.length;
|
|
3150
|
+
if (!Number.isSafeInteger(paddedCount) || paddedCount > (options.maxSamples ?? 4e6))
|
|
3151
|
+
throw new Error("Vertex tile halo sample capacity exceeded");
|
|
3152
|
+
const equalPair = (a, b) => a[0] === b[0] && a[1] === b[1];
|
|
3153
|
+
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))
|
|
3154
|
+
throw new Error("Vertex tile options changed; rebuild the full snapshot");
|
|
3155
|
+
const key = (t) => `${t.column},${t.row}`;
|
|
3156
|
+
const affected = getTerrainVertexHaloAffectedTiles(resident, changed, options);
|
|
3157
|
+
getTerrainVertexHaloAffectedTiles(previous, [], options);
|
|
3158
|
+
const previousMap = new Map(previous.map((tile) => [key(tile), tile]));
|
|
3159
|
+
const currentKeys = new Set(resident.map(key));
|
|
3160
|
+
const changedKeys = new Set(changed.map(key));
|
|
3161
|
+
for (const tile of resident) {
|
|
3162
|
+
if (!previousMap.has(key(tile)) && !changedKeys.has(key(tile)))
|
|
3163
|
+
throw new Error("Unreported vertex tile arrival");
|
|
3164
|
+
}
|
|
3165
|
+
const removed = [];
|
|
3166
|
+
for (const tile of previous) {
|
|
3167
|
+
if (!currentKeys.has(key(tile))) {
|
|
3168
|
+
if (!changedKeys.has(key(tile)))
|
|
3169
|
+
throw new Error("Unreported vertex tile eviction");
|
|
3170
|
+
removed.push({ column: tile.column, row: tile.row });
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
removed.sort((a, b) => a.column - b.column || a.row - b.row);
|
|
3174
|
+
const affectedKeys = new Set(affected.map(key));
|
|
3175
|
+
const rx = options.width === 2 ? 2 : 1;
|
|
3176
|
+
const ry = options.height === 2 ? 2 : 1;
|
|
3177
|
+
const needed = /* @__PURE__ */ new Set();
|
|
3178
|
+
for (const tile of affected)
|
|
3179
|
+
for (let x = -rx; x <= rx; x++)
|
|
3180
|
+
for (let y = -ry; y <= ry; y++) {
|
|
3181
|
+
const column = tile.column + x, row = tile.row + y;
|
|
3182
|
+
if (Number.isSafeInteger(column) && Number.isSafeInteger(row))
|
|
3183
|
+
needed.add(`${column},${row}`);
|
|
3184
|
+
}
|
|
3185
|
+
const source = resident.filter((tile) => needed.has(key(tile)));
|
|
3186
|
+
const rebuilt = createTerrainVertexTileHalos(source, options).tiles;
|
|
3187
|
+
const results = new Map(previous.filter((tile) => currentKeys.has(key(tile)) && !affectedKeys.has(key(tile))).map((tile) => [key(tile), tile]));
|
|
3188
|
+
for (const tile of rebuilt)
|
|
3189
|
+
if (affectedKeys.has(key(tile)))
|
|
3190
|
+
results.set(key(tile), tile);
|
|
3191
|
+
if (results.size !== resident.length)
|
|
3192
|
+
throw new Error("Incomplete vertex halo update");
|
|
3193
|
+
return {
|
|
3194
|
+
tiles: [...results.values()].sort((a, b) => a.column - b.column || a.row - b.row),
|
|
3195
|
+
rebuilt: affected,
|
|
3196
|
+
removed
|
|
3197
|
+
};
|
|
3198
|
+
}
|
|
3199
|
+
|
|
3200
|
+
// dist/terrain/filtered-pyramid.js
|
|
3201
|
+
function createTerrainFilteredPyramid(input, options = {}) {
|
|
3202
|
+
const { width, height, heights, validity } = input;
|
|
3203
|
+
const count = width * height;
|
|
3204
|
+
const limit = options.maxSamples ?? 4e6;
|
|
3205
|
+
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))
|
|
3206
|
+
throw new Error("Invalid terrain filtered pyramid input or capacity");
|
|
3207
|
+
const base = {
|
|
3208
|
+
width,
|
|
3209
|
+
height,
|
|
3210
|
+
heights: new Float64Array(count),
|
|
3211
|
+
validCounts: new Uint32Array(count),
|
|
3212
|
+
sampleCounts: new Uint32Array(count).fill(1)
|
|
3213
|
+
};
|
|
3214
|
+
for (let i = 0; i < count; i++)
|
|
3215
|
+
if ((!validity || validity[i] !== 0) && Number.isFinite(heights[i])) {
|
|
3216
|
+
base.heights[i] = heights[i];
|
|
3217
|
+
base.validCounts[i] = 1;
|
|
3218
|
+
}
|
|
3219
|
+
const levels = [base];
|
|
3220
|
+
let source = base;
|
|
3221
|
+
while (source.width > 1 || source.height > 1) {
|
|
3222
|
+
const w = Math.ceil(source.width / 2), h = Math.ceil(source.height / 2);
|
|
3223
|
+
const next = {
|
|
3224
|
+
width: w,
|
|
3225
|
+
height: h,
|
|
3226
|
+
heights: new Float64Array(w * h),
|
|
3227
|
+
validCounts: new Uint32Array(w * h),
|
|
3228
|
+
sampleCounts: new Uint32Array(w * h)
|
|
3229
|
+
};
|
|
3230
|
+
for (let y = 0; y < h; y++)
|
|
3231
|
+
for (let x = 0; x < w; x++) {
|
|
3232
|
+
const out = y * w + x;
|
|
3233
|
+
for (let dy = 0; dy < 2; dy++)
|
|
3234
|
+
for (let dx = 0; dx < 2; dx++) {
|
|
3235
|
+
const sx = x * 2 + dx, sy = y * 2 + dy;
|
|
3236
|
+
if (sx >= source.width || sy >= source.height)
|
|
3237
|
+
continue;
|
|
3238
|
+
const index = sy * source.width + sx;
|
|
3239
|
+
const n = source.validCounts[index], old = next.validCounts[out];
|
|
3240
|
+
next.sampleCounts[out] += source.sampleCounts[index];
|
|
3241
|
+
if (n) {
|
|
3242
|
+
const total = old + n, a = next.heights[out], b = source.heights[index];
|
|
3243
|
+
next.heights[out] = old ? a * (old / total) + b * (n / total) : b;
|
|
3244
|
+
next.validCounts[out] = total;
|
|
3245
|
+
}
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
3248
|
+
levels.push(next);
|
|
3249
|
+
source = next;
|
|
3250
|
+
}
|
|
3251
|
+
return levels;
|
|
3252
|
+
}
|
|
3253
|
+
|
|
2880
3254
|
// dist/terrain/mesh-stitch.js
|
|
2881
3255
|
function stitchTerrainMeshEdges(a, edgeA, b, edgeB, options = {}) {
|
|
2882
3256
|
const maxVertices = options.maxVertices ?? 2e6, maxTriangles = options.maxTriangles ?? 4e6, maxBoundary = options.maxBoundaryVertices ?? 1e5;
|