@loaders.gl/raster 5.0.0-beta.5 → 5.0.0-beta.6
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/geotiff/advanced.cjs +4 -4
- package/dist/geotiff/geotiff-loader-types.js +1 -1
- package/dist/geotiff/geotiff-raster-loader-types.js +1 -1
- package/dist/geotiff/geotiff-source-loader.js +1 -1
- package/dist/geotiff/loaders.js +1 -1
- package/dist/geotiff/ometiff-source-loader.js +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lerc/lerc-loader-types.js +1 -1
- package/dist/quantized-mesh-worker.js +4379 -4481
- package/dist/terrain/heightmap.cjs +2 -333
- package/dist/terrain/heightmap.cjs.map +4 -4
- package/dist/terrain/heightmap.d.ts +1 -5
- package/dist/terrain/heightmap.d.ts.map +1 -1
- package/dist/terrain/heightmap.js +0 -3
- package/dist/terrain/heightmap.js.map +1 -1
- package/dist/terrain/index.cjs +35 -76
- package/dist/terrain/index.cjs.map +3 -3
- package/dist/terrain/index.d.ts +1 -2
- package/dist/terrain/index.d.ts.map +1 -1
- package/dist/terrain/index.js.map +1 -1
- package/dist/terrain/lib/helpers/skirt.d.ts +2 -9
- package/dist/terrain/lib/helpers/skirt.d.ts.map +1 -1
- package/dist/terrain/lib/helpers/skirt.js +30 -114
- package/dist/terrain/lib/helpers/skirt.js.map +1 -1
- package/dist/terrain/lib/terrain-contracts.d.ts +0 -15
- package/dist/terrain/lib/terrain-contracts.d.ts.map +1 -1
- package/dist/terrain/lib/utils/version.js +1 -1
- package/dist/terrain-worker.js +131 -117
- package/package.json +5 -17
- package/src/index.ts +0 -7
- package/src/terrain/heightmap.ts +0 -10
- package/src/terrain/index.ts +0 -7
- package/src/terrain/lib/helpers/skirt.ts +41 -151
- package/src/terrain/lib/terrain-contracts.ts +0 -19
- package/dist/terrain/lib/terrain-height-field.d.ts +0 -51
- package/dist/terrain/lib/terrain-height-field.d.ts.map +0 -1
- package/dist/terrain/lib/terrain-height-field.js +0 -260
- package/dist/terrain/lib/terrain-height-field.js.map +0 -1
- package/dist/terrain/lib/terrain-height-grid.d.ts +0 -14
- package/dist/terrain/lib/terrain-height-grid.d.ts.map +0 -1
- package/dist/terrain/lib/terrain-height-grid.js +0 -104
- package/dist/terrain/lib/terrain-height-grid.js.map +0 -1
- package/dist/terrain/lib/terrain-neighborhood.d.ts +0 -15
- package/dist/terrain/lib/terrain-neighborhood.d.ts.map +0 -1
- package/dist/terrain/lib/terrain-neighborhood.js +0 -58
- package/dist/terrain/lib/terrain-neighborhood.js.map +0 -1
- package/src/terrain/lib/terrain-height-field.ts +0 -355
- package/src/terrain/lib/terrain-height-grid.ts +0 -157
- package/src/terrain/lib/terrain-neighborhood.ts +0 -69
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
/**
|
|
5
|
-
* Detach a decoded heightmap and its explicit georeferencing/validity into a physical grid.
|
|
6
|
-
* Never derives missing data from alpha, fills holes, converts datums or exaggerates heights.
|
|
7
|
-
*/
|
|
8
|
-
export function createTerrainHeightGrid(heightmap, metadata, validity) {
|
|
9
|
-
const { width, height } = heightmap;
|
|
10
|
-
const { bounds, registration, verticalDatum } = metadata;
|
|
11
|
-
if (!Number.isSafeInteger(width) ||
|
|
12
|
-
!Number.isSafeInteger(height) ||
|
|
13
|
-
width < 2 ||
|
|
14
|
-
height < 2 ||
|
|
15
|
-
!Number.isSafeInteger(width * height) ||
|
|
16
|
-
heightmap.heights.length !== width * height) {
|
|
17
|
-
throw new RangeError('Terrain grid requires a complete heightmap of at least 2 by 2');
|
|
18
|
-
}
|
|
19
|
-
if (bounds.length !== 4 ||
|
|
20
|
-
!bounds.every(Number.isFinite) ||
|
|
21
|
-
bounds[0] >= bounds[2] ||
|
|
22
|
-
bounds[1] >= bounds[3] ||
|
|
23
|
-
!Number.isFinite(bounds[2] - bounds[0]) ||
|
|
24
|
-
!Number.isFinite(bounds[3] - bounds[1])) {
|
|
25
|
-
throw new RangeError('Terrain grid bounds must have finite positive extent');
|
|
26
|
-
}
|
|
27
|
-
if (!['pixel-center', 'grid-node'].includes(registration) ||
|
|
28
|
-
!['ellipsoidal', 'orthometric', 'unknown'].includes(verticalDatum)) {
|
|
29
|
-
throw new RangeError('Terrain grid registration and vertical datum must be explicit');
|
|
30
|
-
}
|
|
31
|
-
if (validity && validity.length !== width * height)
|
|
32
|
-
throw new RangeError('Terrain grid validity must match samples');
|
|
33
|
-
const heights = new Float32Array(width * height);
|
|
34
|
-
const valid = new Uint8Array(width * height);
|
|
35
|
-
for (let index = 0; index < heights.length; index++) {
|
|
36
|
-
valid[index] = validity ? Number(validity[index] !== 0) : 1;
|
|
37
|
-
heights[index] = valid[index] ? heightmap.heights[index] : NaN;
|
|
38
|
-
if (valid[index] && !Number.isFinite(heights[index]))
|
|
39
|
-
throw new RangeError('Valid terrain heights must be finite');
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
width,
|
|
43
|
-
height,
|
|
44
|
-
heights,
|
|
45
|
-
valid,
|
|
46
|
-
bounds: [bounds[0], bounds[1], bounds[2], bounds[3]],
|
|
47
|
-
registration,
|
|
48
|
-
verticalDatum
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Bilinear sample of a valid physical grid. Closed footprint edges clamp to the nearest
|
|
53
|
-
* pixel center. Outside points and missing nonzero-weight support return null, never zero.
|
|
54
|
-
* The caller must not mutate the grid while it is shared with consumers.
|
|
55
|
-
*/
|
|
56
|
-
export function sampleTerrainHeightGrid(grid, position) {
|
|
57
|
-
const [west, south, east, north] = grid.bounds;
|
|
58
|
-
if (position.length !== 2 ||
|
|
59
|
-
!position.every(Number.isFinite) ||
|
|
60
|
-
position[0] < west ||
|
|
61
|
-
position[0] > east ||
|
|
62
|
-
position[1] < south ||
|
|
63
|
-
position[1] > north)
|
|
64
|
-
return null;
|
|
65
|
-
const centered = grid.registration === 'pixel-center';
|
|
66
|
-
const column = snapTerrainSample(Math.max(0, Math.min(grid.width - 1, ((position[0] - west) / (east - west)) * (centered ? grid.width : grid.width - 1) -
|
|
67
|
-
(centered ? 0.5 : 0))), position[0], west, east, grid.width);
|
|
68
|
-
const row = snapTerrainSample(Math.max(0, Math.min(grid.height - 1, ((north - position[1]) / (north - south)) * (centered ? grid.height : grid.height - 1) -
|
|
69
|
-
(centered ? 0.5 : 0))), position[1], south, north, grid.height);
|
|
70
|
-
const left = Math.floor(column), top = Math.floor(row);
|
|
71
|
-
const horizontal = column - left, vertical = row - top;
|
|
72
|
-
const samples = [
|
|
73
|
-
top * grid.width + left,
|
|
74
|
-
top * grid.width + Math.min(left + 1, grid.width - 1),
|
|
75
|
-
Math.min(top + 1, grid.height - 1) * grid.width + left,
|
|
76
|
-
Math.min(top + 1, grid.height - 1) * grid.width + Math.min(left + 1, grid.width - 1)
|
|
77
|
-
];
|
|
78
|
-
const weights = [
|
|
79
|
-
(1 - horizontal) * (1 - vertical),
|
|
80
|
-
horizontal * (1 - vertical),
|
|
81
|
-
(1 - horizontal) * vertical,
|
|
82
|
-
horizontal * vertical
|
|
83
|
-
];
|
|
84
|
-
let height = 0;
|
|
85
|
-
for (let index = 0; index < samples.length; index++) {
|
|
86
|
-
if (weights[index] === 0)
|
|
87
|
-
continue;
|
|
88
|
-
if (!grid.valid[samples[index]])
|
|
89
|
-
return null;
|
|
90
|
-
height += grid.heights[samples[index]] * weights[index];
|
|
91
|
-
}
|
|
92
|
-
return height;
|
|
93
|
-
}
|
|
94
|
-
/** Remove coordinate roundoff at exact samples, without broadening support by more than 1e-6 pixels. */
|
|
95
|
-
function snapTerrainSample(value, coordinate, minimum, maximum, size) {
|
|
96
|
-
const nearest = Math.round(value);
|
|
97
|
-
const tolerance = Math.min(1e-6, ((8 *
|
|
98
|
-
Number.EPSILON *
|
|
99
|
-
Math.max(1, Math.abs(coordinate), Math.abs(minimum), Math.abs(maximum))) /
|
|
100
|
-
(maximum - minimum)) *
|
|
101
|
-
size);
|
|
102
|
-
return Math.abs(value - nearest) <= tolerance ? nearest : value;
|
|
103
|
-
}
|
|
104
|
-
//# sourceMappingURL=terrain-height-grid.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"terrain-height-grid.js","sourceRoot":"","sources":["../../../src/terrain/lib/terrain-height-grid.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAKpC;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CACrC,SAA2B,EAC3B,QAA6B,EAC7B,QAAqB;IAErB,MAAM,EAAC,KAAK,EAAE,MAAM,EAAC,GAAG,SAAS,CAAC;IAClC,MAAM,EAAC,MAAM,EAAE,YAAY,EAAE,aAAa,EAAC,GAAG,QAAQ,CAAC;IACvD,IACE,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC;QAC5B,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC;QAC7B,KAAK,GAAG,CAAC;QACT,MAAM,GAAG,CAAC;QACV,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,GAAG,MAAM,CAAC;QACrC,SAAS,CAAC,OAAO,CAAC,MAAM,KAAK,KAAK,GAAG,MAAM,EAC3C,CAAC;QACD,MAAM,IAAI,UAAU,CAAC,+DAA+D,CAAC,CAAC;IACxF,CAAC;IACD,IACE,MAAM,CAAC,MAAM,KAAK,CAAC;QACnB,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC9B,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC;QACtB,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC;QACtB,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM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AC,CAAC,CAAC;QACxE,CAAC,OAAO,GAAG,OAAO,CAAC,CAAC;QACpB,IAAI,CACP,CAAC;IACF,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;AAClE,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { TerrainHeightGrid } from "./terrain-contracts.js";
|
|
2
|
-
/**
|
|
3
|
-
* Sample physical meters across closed neighboring footprints, averaging shared edges.
|
|
4
|
-
* Any contributing hole returns null. Datums must match; no wrapping or reprojection occurs.
|
|
5
|
-
* Reuse TerrainHeightField rather than this convenience function for repeated queries.
|
|
6
|
-
*/
|
|
7
|
-
export declare function sampleTerrainNeighborhood(grids: readonly TerrainHeightGrid[], position: readonly [number, number]): number | null;
|
|
8
|
-
/**
|
|
9
|
-
* Reconstruct explicit edge nodes from a pixel-centered grid and equal-resolution neighbors.
|
|
10
|
-
* Pixel-centered inputs become (width + 1) by (height + 1); grid-node inputs retain dimensions.
|
|
11
|
-
* Missing neighbors clamp to the source edge. Touching holes remain invalid, never filled.
|
|
12
|
-
* Arrays are detached; heights remain physical source meters with the original vertical datum.
|
|
13
|
-
*/
|
|
14
|
-
export declare function resampleTerrainNodes(grid: TerrainHeightGrid, neighbors?: readonly TerrainHeightGrid[]): TerrainHeightGrid;
|
|
15
|
-
//# sourceMappingURL=terrain-neighborhood.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"terrain-neighborhood.d.ts","sourceRoot":"","sources":["../../../src/terrain/lib/terrain-neighborhood.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,iBAAiB,EAAC,+BAA4B;AAG3D;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,SAAS,iBAAiB,EAAE,EACnC,QAAQ,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,MAAM,GAAG,IAAI,CAEf;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,iBAAiB,EACvB,SAAS,GAAE,SAAS,iBAAiB,EAAO,GAC3C,iBAAiB,CAwCnB"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { TerrainHeightField } from "./terrain-height-field.js";
|
|
5
|
-
/**
|
|
6
|
-
* Sample physical meters across closed neighboring footprints, averaging shared edges.
|
|
7
|
-
* Any contributing hole returns null. Datums must match; no wrapping or reprojection occurs.
|
|
8
|
-
* Reuse TerrainHeightField rather than this convenience function for repeated queries.
|
|
9
|
-
*/
|
|
10
|
-
export function sampleTerrainNeighborhood(grids, position) {
|
|
11
|
-
return new TerrainHeightField(grids).sampleHeight(position);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Reconstruct explicit edge nodes from a pixel-centered grid and equal-resolution neighbors.
|
|
15
|
-
* Pixel-centered inputs become (width + 1) by (height + 1); grid-node inputs retain dimensions.
|
|
16
|
-
* Missing neighbors clamp to the source edge. Touching holes remain invalid, never filled.
|
|
17
|
-
* Arrays are detached; heights remain physical source meters with the original vertical datum.
|
|
18
|
-
*/
|
|
19
|
-
export function resampleTerrainNodes(grid, neighbors = []) {
|
|
20
|
-
const grids = [grid, ...new Set(neighbors.filter(neighbor => neighbor !== grid))];
|
|
21
|
-
const field = new TerrainHeightField(grids);
|
|
22
|
-
const [west, south, east, north] = grid.bounds;
|
|
23
|
-
for (const neighbor of grids) {
|
|
24
|
-
if (neighbor.registration !== grid.registration ||
|
|
25
|
-
neighbor.width !== grid.width ||
|
|
26
|
-
neighbor.height !== grid.height ||
|
|
27
|
-
Math.abs((neighbor.bounds[2] - neighbor.bounds[0]) / (east - west) - 1) > 1e-8 ||
|
|
28
|
-
Math.abs((neighbor.bounds[3] - neighbor.bounds[1]) / (north - south) - 1) > 1e-8)
|
|
29
|
-
throw new RangeError('Terrain neighbors require matching resolution and registration');
|
|
30
|
-
}
|
|
31
|
-
const columns = grid.registration === 'pixel-center' ? grid.width : grid.width - 1;
|
|
32
|
-
const rows = grid.registration === 'pixel-center' ? grid.height : grid.height - 1;
|
|
33
|
-
const width = columns + 1;
|
|
34
|
-
const height = rows + 1;
|
|
35
|
-
const heights = new Float32Array(width * height);
|
|
36
|
-
const valid = new Uint8Array(width * height);
|
|
37
|
-
for (let row = 0; row < height; row++) {
|
|
38
|
-
for (let column = 0; column < width; column++) {
|
|
39
|
-
const value = field.sampleHeight([
|
|
40
|
-
west + (column / columns) * (east - west),
|
|
41
|
-
north - (row / rows) * (north - south)
|
|
42
|
-
]);
|
|
43
|
-
const index = row * width + column;
|
|
44
|
-
heights[index] = value ?? NaN;
|
|
45
|
-
valid[index] = Number(value !== null);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
width,
|
|
50
|
-
height,
|
|
51
|
-
heights,
|
|
52
|
-
valid,
|
|
53
|
-
bounds: [west, south, east, north],
|
|
54
|
-
registration: 'grid-node',
|
|
55
|
-
verticalDatum: grid.verticalDatum
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=terrain-neighborhood.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"terrain-neighborhood.js","sourceRoot":"","sources":["../../../src/terrain/lib/terrain-neighborhood.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EAAC,kBAAkB,EAAC,kCAA+B;AAE1D;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,KAAmC,EACnC,QAAmC;IAEnC,OAAO,IAAI,kBAAkB,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAA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ifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {sampleTerrainHeightGrid} from './terrain-height-grid';
|
|
6
|
-
import type {TerrainHeightGrid} from './terrain-contracts';
|
|
7
|
-
|
|
8
|
-
/** Absolute EPSG:3857 [west, south, east, north], including zero-width probe bounds. */
|
|
9
|
-
export type TerrainFieldBounds = readonly [number, number, number, number];
|
|
10
|
-
|
|
11
|
-
/** Retained mask admission; geometry, source arrays and JavaScript metadata are separate. */
|
|
12
|
-
export interface TerrainHeightFieldOptions {
|
|
13
|
-
/** Maximum retained summed-area mask bytes; default 8 MiB. Zero uses exact sample scans. */
|
|
14
|
-
maxMaskBytes?: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Detached operation counts, suitable for deterministic performance tests rather than FPS estimates. */
|
|
18
|
-
export interface TerrainHeightFieldStatistics {
|
|
19
|
-
/** Number of retained immutable source references. */
|
|
20
|
-
grids: number;
|
|
21
|
-
/** Retained summed-area mask bytes, excluding source arrays and tree metadata. */
|
|
22
|
-
maskBytes: number;
|
|
23
|
-
/** Admitted mask constructions, each built at most once per grid. */
|
|
24
|
-
maskBuilds: number;
|
|
25
|
-
/** Validity samples read during mask construction or exact fallback scans. */
|
|
26
|
-
maskSamples: number;
|
|
27
|
-
/** Spatial tree envelopes tested by sampling and coverage queries. */
|
|
28
|
-
boundsTests: number;
|
|
29
|
-
/** Candidate grid footprints visited after tree pruning. */
|
|
30
|
-
candidateGrids: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Private source identity, detached footprint and lazy mask state. */
|
|
34
|
-
interface FieldEntry {
|
|
35
|
-
/** Detached descriptor sharing immutable sample arrays. */
|
|
36
|
-
grid: TerrainHeightGrid;
|
|
37
|
-
/** Original accumulation order, independent of spatial sorting. */
|
|
38
|
-
index: number;
|
|
39
|
-
/** Exact source footprint. */
|
|
40
|
-
bounds: TerrainFieldBounds;
|
|
41
|
-
/** Legacy touching-edge tolerance envelope. */
|
|
42
|
-
sampleBounds: TerrainFieldBounds;
|
|
43
|
-
/** Lazy prefix; null means fully valid, undefined means unprepared/unadmitted. */
|
|
44
|
-
mask?: Uint32Array | null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Balanced spatial envelope; leaves contain exactly one source. */
|
|
48
|
-
interface FieldNode {
|
|
49
|
-
/** Closed union of every descendant sampling envelope. */
|
|
50
|
-
bounds: TerrainFieldBounds;
|
|
51
|
-
/** Source owner on a leaf. */
|
|
52
|
-
entry?: FieldEntry;
|
|
53
|
-
/** Median-partitioned child envelopes on an internal node. */
|
|
54
|
-
children?: readonly [FieldNode, FieldNode];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Immutable-source physical height sampling and conservative footprint admission.
|
|
59
|
-
* Snapshots membership/bounds, not height arrays: do not mutate shared grids.
|
|
60
|
-
* No provider, worker, deck view, GPU resource or implicit longitude wrapping is owned.
|
|
61
|
-
*/
|
|
62
|
-
export class TerrainHeightField {
|
|
63
|
-
/** Original order for small-field direct sampling, avoiding tree/sort overhead. */
|
|
64
|
-
private readonly entries: readonly FieldEntry[];
|
|
65
|
-
/** Immutable spatial tree built once per admitted field. */
|
|
66
|
-
private readonly root: FieldNode | null;
|
|
67
|
-
/** Fixed retained summed-area mask admission limit. */
|
|
68
|
-
private readonly maxMaskBytes: number;
|
|
69
|
-
/** Mutable counters never exposed by reference. */
|
|
70
|
-
private readonly statistics: TerrainHeightFieldStatistics;
|
|
71
|
-
|
|
72
|
-
/** Retain structurally valid decoded grids with one datum; overlaps preserve ordered sample averaging. */
|
|
73
|
-
constructor(grids: readonly TerrainHeightGrid[], options: TerrainHeightFieldOptions = {}) {
|
|
74
|
-
this.maxMaskBytes = options.maxMaskBytes ?? 8 * 1024 * 1024;
|
|
75
|
-
if (!Number.isSafeInteger(this.maxMaskBytes) || this.maxMaskBytes < 0)
|
|
76
|
-
throw new Error('Invalid terrain field mask budget');
|
|
77
|
-
this.statistics = {
|
|
78
|
-
grids: grids.length,
|
|
79
|
-
maskBytes: 0,
|
|
80
|
-
maskBuilds: 0,
|
|
81
|
-
maskSamples: 0,
|
|
82
|
-
boundsTests: 0,
|
|
83
|
-
candidateGrids: 0
|
|
84
|
-
};
|
|
85
|
-
const entries = grids.map((grid, index): FieldEntry => {
|
|
86
|
-
const [west, south, east, north] = grid.bounds;
|
|
87
|
-
if (
|
|
88
|
-
grid.bounds.length !== 4 ||
|
|
89
|
-
!grid.bounds.every(Number.isFinite) ||
|
|
90
|
-
west >= east ||
|
|
91
|
-
south >= north ||
|
|
92
|
-
!Number.isFinite(east - west) ||
|
|
93
|
-
!Number.isFinite(north - south) ||
|
|
94
|
-
!Number.isSafeInteger(grid.width) ||
|
|
95
|
-
!Number.isSafeInteger(grid.height) ||
|
|
96
|
-
grid.width < 2 ||
|
|
97
|
-
grid.height < 2 ||
|
|
98
|
-
!Number.isSafeInteger(grid.width * grid.height) ||
|
|
99
|
-
grid.heights.length !== grid.width * grid.height ||
|
|
100
|
-
grid.valid.length !== grid.heights.length ||
|
|
101
|
-
!['pixel-center', 'grid-node'].includes(grid.registration) ||
|
|
102
|
-
!['unknown', 'ellipsoidal', 'orthometric'].includes(grid.verticalDatum) ||
|
|
103
|
-
grid.verticalDatum !== grids[0].verticalDatum
|
|
104
|
-
)
|
|
105
|
-
throw new Error('Invalid terrain field grid or datum');
|
|
106
|
-
const bounds: TerrainFieldBounds = [west, south, east, north];
|
|
107
|
-
const tolerance = Math.max(east - west, north - south) * 1e-10;
|
|
108
|
-
return {
|
|
109
|
-
grid: {...grid, bounds},
|
|
110
|
-
index,
|
|
111
|
-
bounds,
|
|
112
|
-
sampleBounds: [west - tolerance, south - tolerance, east + tolerance, north + tolerance]
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
|
-
this.entries = entries;
|
|
116
|
-
this.root = entries.length ? buildFieldNode([...entries]) : null;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** Sample physical meters in original source order; any contributing no-data support remains a hole. */
|
|
120
|
-
sampleHeight(position: readonly [number, number]): number | null {
|
|
121
|
-
if (position.length !== 2 || !position.every(Number.isFinite)) return null;
|
|
122
|
-
const direct = this.entries.length <= 16;
|
|
123
|
-
const bounds: TerrainFieldBounds = [position[0], position[1], position[0], position[1]];
|
|
124
|
-
const candidates = direct ? this.entries : this.findEntries(bounds);
|
|
125
|
-
let sum = 0,
|
|
126
|
-
count = 0;
|
|
127
|
-
for (const entry of candidates) {
|
|
128
|
-
if (direct) this.statistics.boundsTests++;
|
|
129
|
-
if (!intersectsBounds(entry.sampleBounds, bounds)) continue;
|
|
130
|
-
if (direct) this.statistics.candidateGrids++;
|
|
131
|
-
const [west, south, east, north] = entry.bounds;
|
|
132
|
-
const height = sampleTerrainHeightGrid(entry.grid, [
|
|
133
|
-
Math.max(west, Math.min(east, position[0])),
|
|
134
|
-
Math.max(south, Math.min(north, position[1]))
|
|
135
|
-
]);
|
|
136
|
-
if (height === null) return null;
|
|
137
|
-
sum += height;
|
|
138
|
-
count++;
|
|
139
|
-
}
|
|
140
|
-
return count ? sum / count : null;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/** Require complete rectangular footprint coverage and no invalid bilinear-support sample; not an exact triangle mask. */
|
|
144
|
-
coversBounds(bounds: TerrainFieldBounds): boolean {
|
|
145
|
-
if (
|
|
146
|
-
bounds.length !== 4 ||
|
|
147
|
-
!bounds.every(Number.isFinite) ||
|
|
148
|
-
bounds[0] > bounds[2] ||
|
|
149
|
-
bounds[1] > bounds[3] ||
|
|
150
|
-
!Number.isFinite(bounds[2] - bounds[0]) ||
|
|
151
|
-
!Number.isFinite(bounds[3] - bounds[1])
|
|
152
|
-
)
|
|
153
|
-
throw new Error('Invalid terrain field probe bounds');
|
|
154
|
-
const width = bounds[2] - bounds[0],
|
|
155
|
-
height = bounds[3] - bounds[1];
|
|
156
|
-
if (!Number.isFinite(width * height) || (width > 0 && height > 0 && width * height === 0))
|
|
157
|
-
throw new Error('Terrain field probe area must be finite and representable');
|
|
158
|
-
if (!width && !height) return this.sampleHeight([bounds[0], bounds[1]]) !== null;
|
|
159
|
-
const clipped: TerrainFieldBounds[] = [];
|
|
160
|
-
for (const entry of this.findEntries(bounds)) {
|
|
161
|
-
// Sampling admits a small roundoff halo. Check its clamped source support
|
|
162
|
-
// even when the exact footprint lies just outside the probe.
|
|
163
|
-
const support: TerrainFieldBounds = [
|
|
164
|
-
Math.max(
|
|
165
|
-
entry.bounds[0],
|
|
166
|
-
Math.min(entry.bounds[2], Math.max(bounds[0], entry.sampleBounds[0]))
|
|
167
|
-
),
|
|
168
|
-
Math.max(
|
|
169
|
-
entry.bounds[1],
|
|
170
|
-
Math.min(entry.bounds[3], Math.max(bounds[1], entry.sampleBounds[1]))
|
|
171
|
-
),
|
|
172
|
-
Math.max(
|
|
173
|
-
entry.bounds[0],
|
|
174
|
-
Math.min(entry.bounds[2], Math.min(bounds[2], entry.sampleBounds[2]))
|
|
175
|
-
),
|
|
176
|
-
Math.max(
|
|
177
|
-
entry.bounds[1],
|
|
178
|
-
Math.min(entry.bounds[3], Math.min(bounds[3], entry.sampleBounds[3]))
|
|
179
|
-
)
|
|
180
|
-
];
|
|
181
|
-
if (this.hasMissingSamples(entry, support)) return false;
|
|
182
|
-
const left = Math.max(bounds[0], entry.bounds[0]),
|
|
183
|
-
right = Math.min(bounds[2], entry.bounds[2]);
|
|
184
|
-
const bottom = Math.max(bounds[1], entry.bounds[1]),
|
|
185
|
-
top = Math.min(bounds[3], entry.bounds[3]);
|
|
186
|
-
if (left > right || bottom > top) continue;
|
|
187
|
-
// Closed neighboring footprints still contribute holes on a probe's edge,
|
|
188
|
-
// even though their zero-area contact cannot add union coverage.
|
|
189
|
-
if ((width && left === right) || (height && bottom === top)) continue;
|
|
190
|
-
clipped.push([left, bottom, right, top]);
|
|
191
|
-
}
|
|
192
|
-
// Exact slab/interval coverage: an arbitrarily narrow representable gap stays a gap.
|
|
193
|
-
if (!width || !height) {
|
|
194
|
-
return coversInterval(
|
|
195
|
-
clipped.map(rectangle =>
|
|
196
|
-
width ? [rectangle[0], rectangle[2]] : [rectangle[1], rectangle[3]]
|
|
197
|
-
),
|
|
198
|
-
width ? bounds[0] : bounds[1],
|
|
199
|
-
width ? bounds[2] : bounds[3]
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
const columns = [
|
|
203
|
-
...new Set([
|
|
204
|
-
bounds[0],
|
|
205
|
-
bounds[2],
|
|
206
|
-
...clipped.flatMap(rectangle => [rectangle[0], rectangle[2]])
|
|
207
|
-
])
|
|
208
|
-
].sort((first, second) => first - second);
|
|
209
|
-
for (let column = 1; column < columns.length; column++) {
|
|
210
|
-
const left = columns[column - 1],
|
|
211
|
-
right = columns[column];
|
|
212
|
-
const intervals: [number, number][] = clipped
|
|
213
|
-
.filter(rectangle => rectangle[0] <= left && rectangle[2] >= right)
|
|
214
|
-
.map(rectangle => [rectangle[1], rectangle[3]]);
|
|
215
|
-
if (!coversInterval(intervals, bounds[1], bounds[3])) return false;
|
|
216
|
-
}
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/** Scalar counters only; callers cannot mutate cache ownership through diagnostics. */
|
|
221
|
-
getStatistics(): TerrainHeightFieldStatistics {
|
|
222
|
-
return {...this.statistics};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/** Traverse closed envelopes, then preserve original source order for floating-point accumulation. */
|
|
226
|
-
private findEntries(bounds: TerrainFieldBounds): FieldEntry[] {
|
|
227
|
-
const entries: FieldEntry[] = [],
|
|
228
|
-
pending = this.root ? [this.root] : [];
|
|
229
|
-
while (pending.length) {
|
|
230
|
-
const node = pending.pop()!;
|
|
231
|
-
this.statistics.boundsTests++;
|
|
232
|
-
if (!intersectsBounds(node.bounds, bounds)) continue;
|
|
233
|
-
if (node.entry) {
|
|
234
|
-
entries.push(node.entry);
|
|
235
|
-
this.statistics.candidateGrids++;
|
|
236
|
-
} else if (node.children) pending.push(...node.children);
|
|
237
|
-
}
|
|
238
|
-
return entries.sort((first, second) => first.index - second.index);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/** Admit a lazy reusable prefix or scan the same support rectangle exactly when it does not fit. */
|
|
242
|
-
private hasMissingSamples(entry: FieldEntry, bounds: TerrainFieldBounds): boolean {
|
|
243
|
-
const {grid} = entry,
|
|
244
|
-
stride = grid.width + 1;
|
|
245
|
-
const required = stride * (grid.height + 1) * Uint32Array.BYTES_PER_ELEMENT;
|
|
246
|
-
if (entry.mask === undefined && required <= this.maxMaskBytes - this.statistics.maskBytes) {
|
|
247
|
-
let hasMissing = false;
|
|
248
|
-
for (const valid of grid.valid) {
|
|
249
|
-
this.statistics.maskSamples++;
|
|
250
|
-
if (!valid) {
|
|
251
|
-
hasMissing = true;
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
if (!hasMissing) {
|
|
256
|
-
entry.mask = null;
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
const prefix = new Uint32Array(stride * (grid.height + 1));
|
|
260
|
-
for (let row = 0; row < grid.height; row++)
|
|
261
|
-
for (let column = 0; column < grid.width; column++) {
|
|
262
|
-
const offset = (row + 1) * stride + column + 1,
|
|
263
|
-
invalid = Number(!grid.valid[row * grid.width + column]);
|
|
264
|
-
prefix[offset] =
|
|
265
|
-
invalid + prefix[offset - 1] + prefix[offset - stride] - prefix[offset - stride - 1];
|
|
266
|
-
}
|
|
267
|
-
this.statistics.maskSamples += grid.valid.length;
|
|
268
|
-
entry.mask = prefix;
|
|
269
|
-
this.statistics.maskBytes += required;
|
|
270
|
-
this.statistics.maskBuilds++;
|
|
271
|
-
}
|
|
272
|
-
if (entry.mask === null) return false;
|
|
273
|
-
const pixel = grid.registration === 'pixel-center';
|
|
274
|
-
const column = (x: number) =>
|
|
275
|
-
Math.max(
|
|
276
|
-
0,
|
|
277
|
-
Math.min(
|
|
278
|
-
grid.width - 1,
|
|
279
|
-
((x - grid.bounds[0]) / (grid.bounds[2] - grid.bounds[0])) *
|
|
280
|
-
(pixel ? grid.width : grid.width - 1) -
|
|
281
|
-
(pixel ? 0.5 : 0)
|
|
282
|
-
)
|
|
283
|
-
);
|
|
284
|
-
const row = (y: number) =>
|
|
285
|
-
Math.max(
|
|
286
|
-
0,
|
|
287
|
-
Math.min(
|
|
288
|
-
grid.height - 1,
|
|
289
|
-
((grid.bounds[3] - y) / (grid.bounds[3] - grid.bounds[1])) *
|
|
290
|
-
(pixel ? grid.height : grid.height - 1) -
|
|
291
|
-
(pixel ? 0.5 : 0)
|
|
292
|
-
)
|
|
293
|
-
);
|
|
294
|
-
const firstColumn = Math.floor(column(bounds[0])),
|
|
295
|
-
lastColumn = Math.ceil(column(bounds[2]));
|
|
296
|
-
const firstRow = Math.floor(row(bounds[3])),
|
|
297
|
-
lastRow = Math.ceil(row(bounds[1]));
|
|
298
|
-
if (entry.mask)
|
|
299
|
-
return Boolean(
|
|
300
|
-
entry.mask[(lastRow + 1) * stride + lastColumn + 1] -
|
|
301
|
-
entry.mask[firstRow * stride + lastColumn + 1] -
|
|
302
|
-
entry.mask[(lastRow + 1) * stride + firstColumn] +
|
|
303
|
-
entry.mask[firstRow * stride + firstColumn]
|
|
304
|
-
);
|
|
305
|
-
for (let row = firstRow; row <= lastRow; row++)
|
|
306
|
-
for (let column = firstColumn; column <= lastColumn; column++) {
|
|
307
|
-
this.statistics.maskSamples++;
|
|
308
|
-
if (!grid.valid[row * grid.width + column]) return true;
|
|
309
|
-
}
|
|
310
|
-
return false;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/** Closed rectangle intersection, including tolerance-expanded sampling envelopes. */
|
|
315
|
-
function intersectsBounds(first: TerrainFieldBounds, second: TerrainFieldBounds): boolean {
|
|
316
|
-
return (
|
|
317
|
-
first[0] <= second[2] && first[2] >= second[0] && first[1] <= second[3] && first[3] >= second[1]
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/** Median split on the longest axis; no external spatial-index dependency is needed. */
|
|
322
|
-
function buildFieldNode(entries: FieldEntry[]): FieldNode {
|
|
323
|
-
const bounds: [number, number, number, number] = [Infinity, Infinity, -Infinity, -Infinity];
|
|
324
|
-
for (const entry of entries) {
|
|
325
|
-
bounds[0] = Math.min(bounds[0], entry.sampleBounds[0]);
|
|
326
|
-
bounds[1] = Math.min(bounds[1], entry.sampleBounds[1]);
|
|
327
|
-
bounds[2] = Math.max(bounds[2], entry.sampleBounds[2]);
|
|
328
|
-
bounds[3] = Math.max(bounds[3], entry.sampleBounds[3]);
|
|
329
|
-
}
|
|
330
|
-
if (entries.length === 1) return {bounds, entry: entries[0]};
|
|
331
|
-
const axis = bounds[2] - bounds[0] >= bounds[3] - bounds[1] ? 0 : 1;
|
|
332
|
-
entries.sort(
|
|
333
|
-
(first, second) =>
|
|
334
|
-
first.bounds[axis] / 2 +
|
|
335
|
-
first.bounds[axis + 2] / 2 -
|
|
336
|
-
(second.bounds[axis] / 2 + second.bounds[axis + 2] / 2) || first.index - second.index
|
|
337
|
-
);
|
|
338
|
-
const middle = Math.floor(entries.length / 2);
|
|
339
|
-
return {
|
|
340
|
-
bounds,
|
|
341
|
-
children: [buildFieldNode(entries.slice(0, middle)), buildFieldNode(entries.slice(middle))]
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/** Merge closed intervals without using an area/length tolerance that could conceal holes. */
|
|
346
|
-
function coversInterval(intervals: [number, number][], minimum: number, maximum: number): boolean {
|
|
347
|
-
intervals.sort((first, second) => first[0] - second[0]);
|
|
348
|
-
let covered = minimum;
|
|
349
|
-
for (const [left, right] of intervals) {
|
|
350
|
-
if (left > covered) return false;
|
|
351
|
-
covered = Math.max(covered, right);
|
|
352
|
-
if (covered >= maximum) return true;
|
|
353
|
-
}
|
|
354
|
-
return false;
|
|
355
|
-
}
|