@math.gl/geospatial 5.0.0-beta.10 → 5.0.0-beta.11
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/index.cjs +54 -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/crs/spatial-reference-metadata.d.ts +20 -0
- package/dist/crs/spatial-reference-metadata.d.ts.map +1 -0
- package/dist/crs/spatial-reference-metadata.js +86 -0
- package/dist/crs/spatial-reference-metadata.js.map +1 -0
- package/dist/expressions.d.ts +1 -1
- package/dist/expressions.d.ts.map +1 -1
- package/dist/index.cjs +1030 -104
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/tasks/index.cjs +181 -84
- package/dist/tasks/index.cjs.map +2 -2
- package/dist/tasks/terrain-residency.d.ts.map +1 -1
- package/dist/tasks/terrain-residency.js +80 -18
- package/dist/tasks/terrain-residency.js.map +1 -1
- package/dist/terrain/cutout-skirts.d.ts +34 -0
- package/dist/terrain/cutout-skirts.d.ts.map +1 -0
- package/dist/terrain/cutout-skirts.js +29 -0
- package/dist/terrain/cutout-skirts.js.map +1 -0
- package/dist/terrain/depression-fill.d.ts +25 -0
- package/dist/terrain/depression-fill.d.ts.map +1 -0
- package/dist/terrain/depression-fill.js +106 -0
- package/dist/terrain/depression-fill.js.map +1 -0
- package/dist/terrain/hydrology.d.ts +42 -0
- package/dist/terrain/hydrology.d.ts.map +1 -0
- package/dist/terrain/hydrology.js +112 -0
- package/dist/terrain/hydrology.js.map +1 -0
- package/dist/terrain/index.cjs +1014 -88
- package/dist/terrain/index.cjs.map +3 -3
- package/dist/terrain/index.d.ts +10 -1
- package/dist/terrain/index.d.ts.map +1 -1
- package/dist/terrain/index.js +9 -0
- package/dist/terrain/index.js.map +1 -1
- package/dist/terrain/lod-screen-error.d.ts +28 -0
- package/dist/terrain/lod-screen-error.d.ts.map +1 -0
- package/dist/terrain/lod-screen-error.js +95 -0
- package/dist/terrain/lod-screen-error.js.map +1 -0
- package/dist/terrain/lod-select.d.ts +26 -10
- package/dist/terrain/lod-select.d.ts.map +1 -1
- package/dist/terrain/lod-select.js +27 -14
- package/dist/terrain/lod-select.js.map +1 -1
- package/dist/terrain/mesh-cutout.d.ts +40 -0
- package/dist/terrain/mesh-cutout.d.ts.map +1 -0
- package/dist/terrain/mesh-cutout.js +294 -0
- package/dist/terrain/mesh-cutout.js.map +1 -0
- package/dist/terrain/mesh-skirts.d.ts +8 -2
- package/dist/terrain/mesh-skirts.d.ts.map +1 -1
- package/dist/terrain/mesh-skirts.js +5 -4
- package/dist/terrain/mesh-skirts.js.map +1 -1
- package/dist/terrain/mixed-halo-update.d.ts.map +1 -1
- package/dist/terrain/mixed-halo-update.js +58 -23
- package/dist/terrain/mixed-halo-update.js.map +1 -1
- package/dist/terrain/mixed-vertex-halos.d.ts +24 -1
- package/dist/terrain/mixed-vertex-halos.d.ts.map +1 -1
- package/dist/terrain/mixed-vertex-halos.js +75 -58
- package/dist/terrain/mixed-vertex-halos.js.map +1 -1
- package/dist/terrain/regional-viewshed.d.ts +55 -0
- package/dist/terrain/regional-viewshed.d.ts.map +1 -0
- package/dist/terrain/regional-viewshed.js +119 -0
- package/dist/terrain/regional-viewshed.js.map +1 -0
- package/dist/terrain/sweep-polytope.d.ts +4 -0
- package/dist/terrain/sweep-polytope.d.ts.map +1 -1
- package/dist/terrain/sweep-polytope.js +15 -5
- package/dist/terrain/sweep-polytope.js.map +1 -1
- package/dist/terrain/sweep-rotating-capsule.d.ts +17 -0
- package/dist/terrain/sweep-rotating-capsule.d.ts.map +1 -0
- package/dist/terrain/sweep-rotating-capsule.js +118 -0
- package/dist/terrain/sweep-rotating-capsule.js.map +1 -0
- package/dist/terrain/sweep-rotation.d.ts +35 -0
- package/dist/terrain/sweep-rotation.d.ts.map +1 -0
- package/dist/terrain/sweep-rotation.js +114 -0
- package/dist/terrain/sweep-rotation.js.map +1 -0
- package/dist/terrain/watershed-accumulation.d.ts +20 -0
- package/dist/terrain/watershed-accumulation.d.ts.map +1 -0
- package/dist/terrain/watershed-accumulation.js +53 -0
- package/dist/terrain/watershed-accumulation.js.map +1 -0
- package/dist/turf/expressions.d.ts +1 -1
- package/dist/turf/expressions.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/crs/index.ts +7 -0
- package/src/crs/spatial-reference-metadata.ts +118 -0
- package/src/expressions.ts +1 -1
- package/src/index.ts +57 -0
- package/src/tasks/terrain-residency.ts +86 -21
- package/src/terrain/cutout-skirts.ts +52 -0
- package/src/terrain/depression-fill.ts +125 -0
- package/src/terrain/hydrology.ts +149 -0
- package/src/terrain/index.ts +61 -1
- package/src/terrain/lod-screen-error.ts +128 -0
- package/src/terrain/lod-select.ts +65 -31
- package/src/terrain/mesh-cutout.ts +358 -0
- package/src/terrain/mesh-skirts.ts +10 -7
- package/src/terrain/mixed-halo-update.ts +54 -20
- package/src/terrain/mixed-vertex-halos.ts +94 -78
- package/src/terrain/regional-viewshed.ts +177 -0
- package/src/terrain/sweep-polytope.ts +49 -25
- package/src/terrain/sweep-rotating-capsule.ts +139 -0
- package/src/terrain/sweep-rotation.ts +149 -0
- package/src/terrain/watershed-accumulation.ts +67 -0
- package/src/turf/expressions.ts +1 -1
|
@@ -81,20 +81,29 @@ export function updateTerrainMixedVertexTileHalos(
|
|
|
81
81
|
const budget = options.maxDependencyTests ?? 10_000_000;
|
|
82
82
|
if (!Number.isSafeInteger(budget) || budget < 0)
|
|
83
83
|
throw new Error('Invalid mixed halo dependency budget');
|
|
84
|
-
const old = new Map(previous?.sources.map(t => [key(t), t]));
|
|
85
|
-
const current = new Map(resident.map(t => [key(t), t]));
|
|
86
|
-
const cached = new Map(previous?.tiles.map(t => [key(t), t]));
|
|
87
|
-
const targets = new Set<string>();
|
|
88
84
|
const unchangedLayout =
|
|
89
85
|
previous?.sources.length === resident.length &&
|
|
90
86
|
resident.every((tile, i) => {
|
|
91
87
|
const prior = previous.sources[i];
|
|
92
88
|
return (
|
|
93
|
-
|
|
94
|
-
prior.
|
|
95
|
-
|
|
89
|
+
prior === tile ||
|
|
90
|
+
(prior.column === tile.column &&
|
|
91
|
+
prior.row === tile.row &&
|
|
92
|
+
prior.spacing === tile.spacing &&
|
|
93
|
+
prior.field.width === tile.field.width &&
|
|
94
|
+
prior.field.height === tile.field.height)
|
|
96
95
|
);
|
|
97
96
|
});
|
|
97
|
+
const old = unchangedLayout ? undefined : new Map(previous?.sources.map(t => [key(t), t]));
|
|
98
|
+
const targets = new Set<string>();
|
|
99
|
+
const initialized = previous !== null && preparations.has(previous);
|
|
100
|
+
if (!initialized) {
|
|
101
|
+
const cached = new Set(previous?.tiles.map(key));
|
|
102
|
+
for (const tile of resident) {
|
|
103
|
+
const address = key(tile);
|
|
104
|
+
if (!cached.has(address)) targets.add(address);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
98
107
|
let index = unchangedLayout && previous ? targetIndexes.get(previous) : undefined;
|
|
99
108
|
let tests = 0;
|
|
100
109
|
const charge = () => {
|
|
@@ -104,11 +113,12 @@ export function updateTerrainMixedVertexTileHalos(
|
|
|
104
113
|
index ??= createTerrainBoxIndex(resident.map(tile => bounds(tile, tile.spacing)));
|
|
105
114
|
for (const id of index(box, charge)) targets.add(key(resident[id]));
|
|
106
115
|
}
|
|
107
|
-
for (
|
|
108
|
-
const
|
|
109
|
-
const prior = old
|
|
110
|
-
if (
|
|
111
|
-
|
|
116
|
+
for (let i = 0; i < resident.length; i++) {
|
|
117
|
+
const tile = resident[i];
|
|
118
|
+
const prior = unchangedLayout ? previous!.sources[i] : old?.get(key(tile));
|
|
119
|
+
if (prior === tile) continue;
|
|
120
|
+
targets.add(key(tile));
|
|
121
|
+
if (!previous) continue;
|
|
112
122
|
if (!prior) {
|
|
113
123
|
invalidate(bounds(tile));
|
|
114
124
|
} else if (prior.field.width !== tile.field.width || prior.field.height !== tile.field.height) {
|
|
@@ -119,24 +129,48 @@ export function updateTerrainMixedVertexTileHalos(
|
|
|
119
129
|
if (dirty) invalidate(dirty);
|
|
120
130
|
}
|
|
121
131
|
}
|
|
122
|
-
|
|
123
|
-
|
|
132
|
+
const removed: string[] = [];
|
|
133
|
+
if (old?.size) {
|
|
134
|
+
const current = new Set(resident.map(key));
|
|
135
|
+
for (const [address, tile] of old) {
|
|
136
|
+
if (current.has(address)) continue;
|
|
137
|
+
removed.push(address);
|
|
138
|
+
if (resident.length) invalidate(bounds(tile));
|
|
139
|
+
}
|
|
124
140
|
}
|
|
125
141
|
const priorPreparation = previous && preparations.get(previous);
|
|
126
142
|
const preparation: MixedHaloPreparation = {
|
|
127
|
-
|
|
143
|
+
tiles: priorPreparation?.tiles ?? new WeakMap(),
|
|
128
144
|
layout: priorPreparation?.layout
|
|
129
145
|
};
|
|
130
146
|
const built = buildMixedVertexTileHalos(resident, options, targets, preparation).tiles;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
147
|
+
let tiles: TerrainMixedHaloSnapshot['tiles'];
|
|
148
|
+
if (unchangedLayout && initialized) {
|
|
149
|
+
// Built halos form a sorted subsequence of the previous output.
|
|
150
|
+
let cursor = 0;
|
|
151
|
+
tiles = previous!.tiles.map(tile => {
|
|
152
|
+
const replacement = built[cursor];
|
|
153
|
+
if (
|
|
154
|
+
replacement?.spacing !== tile.spacing ||
|
|
155
|
+
replacement.column !== tile.column ||
|
|
156
|
+
replacement.row !== tile.row
|
|
157
|
+
)
|
|
158
|
+
return tile;
|
|
159
|
+
cursor++;
|
|
160
|
+
return replacement;
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
const cached = new Map(previous?.tiles.map(tile => [key(tile), tile]));
|
|
164
|
+
for (const tile of built) cached.set(key(tile), tile);
|
|
165
|
+
tiles = resident
|
|
166
|
+
.map(tile => cached.get(key(tile))!)
|
|
167
|
+
.sort((a, b) => a.spacing - b.spacing || a.column - b.column || a.row - b.row);
|
|
168
|
+
}
|
|
135
169
|
const snapshot = {
|
|
136
170
|
sources: resident.slice(),
|
|
137
171
|
tiles,
|
|
138
172
|
rebuilt: built.map(key),
|
|
139
|
-
removed:
|
|
173
|
+
removed: removed.sort()
|
|
140
174
|
};
|
|
141
175
|
preparations.set(snapshot, preparation);
|
|
142
176
|
if (index) targetIndexes.set(snapshot, index);
|
|
@@ -37,7 +37,7 @@ export function createTerrainMixedVertexTileHalos(
|
|
|
37
37
|
|
|
38
38
|
/** Internal preparation shared only by immutable incremental snapshots. */
|
|
39
39
|
export type MixedHaloPreparation = {
|
|
40
|
-
|
|
40
|
+
tiles: WeakMap<TerrainMixedVertexTile, ReturnType<typeof prepareMixedHaloTile>>;
|
|
41
41
|
layout?: {keys: string[]; query: ReturnType<typeof createTerrainBoxIndex>};
|
|
42
42
|
};
|
|
43
43
|
|
|
@@ -53,89 +53,74 @@ export function buildMixedVertexTileHalos(
|
|
|
53
53
|
if (![maxSamples, maxTests].every(v => Number.isSafeInteger(v) && v >= 0))
|
|
54
54
|
throw new Error('Invalid mixed halo capacity');
|
|
55
55
|
let count = 0;
|
|
56
|
-
|
|
56
|
+
let previousKey: string | undefined;
|
|
57
57
|
let frame:
|
|
58
58
|
| {origin: number[]; column: number[]; row: number[]; reference: string; scale: number[]}
|
|
59
59
|
| undefined;
|
|
60
60
|
const sources = [...tiles]
|
|
61
61
|
.sort((a, b) => a.spacing - b.spacing || a.column - b.column || a.row - b.row)
|
|
62
62
|
.map(tile => {
|
|
63
|
-
if (
|
|
64
|
-
![tile.column, tile.row, tile.spacing].every(Number.isSafeInteger) ||
|
|
65
|
-
tile.spacing < 1 ||
|
|
66
|
-
2 ** Math.round(Math.log2(tile.spacing)) !== tile.spacing
|
|
67
|
-
)
|
|
68
|
-
throw new Error('Invalid mixed halo lattice');
|
|
69
|
-
const key = `${tile.spacing}/${tile.column}/${tile.row}`;
|
|
70
|
-
if (addresses.has(key)) throw new Error('Duplicate mixed halo tile');
|
|
71
|
-
addresses.add(key);
|
|
72
63
|
count += (tile.field.width + 2) * (tile.field.height + 2);
|
|
73
64
|
if (!Number.isSafeInteger(count) || count > maxSamples)
|
|
74
65
|
throw new Error('Mixed halo sample capacity exceeded');
|
|
75
|
-
let
|
|
76
|
-
if (!
|
|
77
|
-
|
|
78
|
-
preparation?.
|
|
66
|
+
let prepared = preparation?.tiles.get(tile);
|
|
67
|
+
if (!prepared) {
|
|
68
|
+
prepared = prepareMixedHaloTile(tile);
|
|
69
|
+
preparation?.tiles.set(tile, prepared);
|
|
70
|
+
}
|
|
71
|
+
const {
|
|
72
|
+
key,
|
|
73
|
+
source: field,
|
|
74
|
+
columnStep: column,
|
|
75
|
+
rowStep: row,
|
|
76
|
+
frameOrigin: origin,
|
|
77
|
+
scale
|
|
78
|
+
} = prepared;
|
|
79
|
+
// Address sorting makes duplicate tiles adjacent; no per-build Set is needed.
|
|
80
|
+
if (previousKey === key) throw new Error('Duplicate mixed halo tile');
|
|
81
|
+
previousKey = key;
|
|
82
|
+
if (frame) {
|
|
83
|
+
if (frame.reference !== field.heightReference)
|
|
84
|
+
throw new Error('Mixed halo frames or height references differ');
|
|
85
|
+
for (let i = 0; i < 2; i++) {
|
|
86
|
+
if (
|
|
87
|
+
column[i] !== frame.column[i] ||
|
|
88
|
+
row[i] !== frame.row[i] ||
|
|
89
|
+
(origin[i] !== frame.origin[i] &&
|
|
90
|
+
Math.abs(origin[i] - frame.origin[i]) >
|
|
91
|
+
Math.min(
|
|
92
|
+
16 * Number.EPSILON * Math.max(scale[i], frame.scale[i]),
|
|
93
|
+
1e-9 * Math.max(Math.abs(column[i]), Math.abs(row[i]))
|
|
94
|
+
))
|
|
95
|
+
)
|
|
96
|
+
throw new Error('Mixed halo frames or height references differ');
|
|
97
|
+
}
|
|
79
98
|
}
|
|
80
|
-
if (field.registration !== 'vertex')
|
|
81
|
-
throw new Error('Mixed halos require vertex registration');
|
|
82
|
-
const column = field.columnStep.map(v => v / tile.spacing);
|
|
83
|
-
const row = field.rowStep.map(v => v / tile.spacing);
|
|
84
|
-
const origin = field.origin.map(
|
|
85
|
-
(v, axis) => v - tile.column * column[axis] - tile.row * row[axis]
|
|
86
|
-
);
|
|
87
|
-
const scale = field.origin.map((v, i) =>
|
|
88
|
-
Math.max(1, Math.abs(v), Math.abs(tile.column * column[i]), Math.abs(tile.row * row[i]))
|
|
89
|
-
);
|
|
90
|
-
if (!origin.every(Number.isFinite)) throw new Error('Mixed halo coordinate overflow');
|
|
91
|
-
if (
|
|
92
|
-
frame &&
|
|
93
|
-
(frame.reference !== field.heightReference ||
|
|
94
|
-
column.some((v, i) => v !== frame!.column[i]) ||
|
|
95
|
-
row.some((v, i) => v !== frame!.row[i]) ||
|
|
96
|
-
origin.some(
|
|
97
|
-
(v, i) =>
|
|
98
|
-
Math.abs(v - frame!.origin[i]) >
|
|
99
|
-
Math.min(
|
|
100
|
-
16 * Number.EPSILON * Math.max(scale[i], frame!.scale[i]),
|
|
101
|
-
1e-9 * Math.max(Math.abs(column[i]), Math.abs(row[i]))
|
|
102
|
-
)
|
|
103
|
-
))
|
|
104
|
-
)
|
|
105
|
-
throw new Error('Mixed halo frames or height references differ');
|
|
106
99
|
frame ??= {origin, column, row, reference: field.heightReference, scale};
|
|
107
|
-
return
|
|
100
|
+
return prepared;
|
|
108
101
|
});
|
|
109
102
|
// Bound the full lattice span so relative coordinates remain exact integers.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
if (sources.length && !Number.isSafeInteger(max - min))
|
|
122
|
-
throw new Error('Mixed halo lattice span overflow');
|
|
103
|
+
let minX = Infinity,
|
|
104
|
+
minY = Infinity,
|
|
105
|
+
maxX = -Infinity,
|
|
106
|
+
maxY = -Infinity;
|
|
107
|
+
for (let i = 0; i < sources.length; i++) {
|
|
108
|
+
const {haloBounds} = sources[i];
|
|
109
|
+
minX = Math.min(minX, haloBounds.minX);
|
|
110
|
+
minY = Math.min(minY, haloBounds.minY);
|
|
111
|
+
maxX = Math.max(maxX, haloBounds.maxX);
|
|
112
|
+
maxY = Math.max(maxY, haloBounds.maxY);
|
|
123
113
|
}
|
|
114
|
+
if (sources.length && (!Number.isSafeInteger(maxX - minX) || !Number.isSafeInteger(maxY - minY)))
|
|
115
|
+
throw new Error('Mixed halo lattice span overflow');
|
|
124
116
|
if (targets && targets.size === 0) return {tiles: []};
|
|
125
117
|
let index: ReturnType<typeof createTerrainBoxIndex> | undefined;
|
|
126
118
|
if (sources.length > 8) {
|
|
127
|
-
const keys =
|
|
128
|
-
preparation &&
|
|
129
|
-
sources.map(
|
|
130
|
-
tile =>
|
|
131
|
-
`${tile.spacing}/${tile.column}/${tile.row}/${tile.source.width}/${tile.source.height}`
|
|
132
|
-
);
|
|
133
119
|
const cached = preparation?.layout;
|
|
134
120
|
if (
|
|
135
|
-
keys &&
|
|
136
121
|
cached &&
|
|
137
|
-
|
|
138
|
-
|
|
122
|
+
sources.length === cached.keys.length &&
|
|
123
|
+
sources.every((tile, i) => tile.layoutKey === cached.keys[i])
|
|
139
124
|
) {
|
|
140
125
|
index = cached.query;
|
|
141
126
|
} else {
|
|
@@ -147,7 +132,8 @@ export function buildMixedVertexTileHalos(
|
|
|
147
132
|
maxY: tile.row + (tile.source.height - 1) * tile.spacing
|
|
148
133
|
}))
|
|
149
134
|
);
|
|
150
|
-
if (preparation
|
|
135
|
+
if (preparation)
|
|
136
|
+
preparation.layout = {keys: sources.map(tile => tile.layoutKey), query: index};
|
|
151
137
|
}
|
|
152
138
|
}
|
|
153
139
|
let tests = 0;
|
|
@@ -156,7 +142,7 @@ export function buildMixedVertexTileHalos(
|
|
|
156
142
|
};
|
|
157
143
|
return {
|
|
158
144
|
tiles: sources
|
|
159
|
-
.filter(tile => !targets || targets.has(
|
|
145
|
+
.filter(tile => !targets || targets.has(tile.key))
|
|
160
146
|
.map(tile => {
|
|
161
147
|
const source = tile.source,
|
|
162
148
|
width = source.width + 2,
|
|
@@ -164,23 +150,15 @@ export function buildMixedVertexTileHalos(
|
|
|
164
150
|
const heights = new Float64Array(width * height),
|
|
165
151
|
validity = new Uint8Array(heights.length),
|
|
166
152
|
statuses = new Uint8Array(heights.length);
|
|
167
|
-
const candidates =
|
|
168
|
-
index?.(
|
|
169
|
-
{
|
|
170
|
-
minX: tile.column - tile.spacing,
|
|
171
|
-
minY: tile.row - tile.spacing,
|
|
172
|
-
maxX: tile.column + source.width * tile.spacing,
|
|
173
|
-
maxY: tile.row + source.height * tile.spacing
|
|
174
|
-
},
|
|
175
|
-
charge
|
|
176
|
-
).map(id => sources[id]) ?? sources;
|
|
153
|
+
const candidates = index?.(tile.haloBounds, charge).map(id => sources[id]) ?? sources;
|
|
177
154
|
for (let y = 0; y < height; y++)
|
|
178
155
|
for (let x = 0; x < width; x++) {
|
|
179
156
|
const gx = tile.column + (x - 1) * tile.spacing,
|
|
180
157
|
gy = tile.row + (y - 1) * tile.spacing;
|
|
181
|
-
if (!
|
|
158
|
+
if (!Number.isSafeInteger(gx) || !Number.isSafeInteger(gy))
|
|
182
159
|
throw new Error('Mixed halo lattice overflow');
|
|
183
|
-
for (
|
|
160
|
+
for (let candidateIndex = 0; candidateIndex < candidates.length; candidateIndex++) {
|
|
161
|
+
const candidate = candidates[candidateIndex];
|
|
184
162
|
charge();
|
|
185
163
|
const cx = (gx - candidate.column) / candidate.spacing,
|
|
186
164
|
cy = (gy - candidate.row) / candidate.spacing;
|
|
@@ -222,3 +200,41 @@ export function buildMixedVertexTileHalos(
|
|
|
222
200
|
})
|
|
223
201
|
};
|
|
224
202
|
}
|
|
203
|
+
|
|
204
|
+
/** Prepare immutable geometry and normalized data once per source descriptor. */
|
|
205
|
+
function prepareMixedHaloTile(tile: TerrainMixedVertexTile) {
|
|
206
|
+
const {column, row, spacing} = tile;
|
|
207
|
+
if (
|
|
208
|
+
![column, row, spacing].every(Number.isSafeInteger) ||
|
|
209
|
+
spacing < 1 ||
|
|
210
|
+
2 ** Math.round(Math.log2(spacing)) !== spacing
|
|
211
|
+
)
|
|
212
|
+
throw new Error('Invalid mixed halo lattice');
|
|
213
|
+
const source = new HeightField(tile.field);
|
|
214
|
+
if (source.registration !== 'vertex') throw new Error('Mixed halos require vertex registration');
|
|
215
|
+
const columnStep = source.columnStep.map(v => v / spacing);
|
|
216
|
+
const rowStep = source.rowStep.map(v => v / spacing);
|
|
217
|
+
const frameOrigin = source.origin.map((v, i) => v - column * columnStep[i] - row * rowStep[i]);
|
|
218
|
+
const scale = source.origin.map((v, i) =>
|
|
219
|
+
Math.max(1, Math.abs(v), Math.abs(column * columnStep[i]), Math.abs(row * rowStep[i]))
|
|
220
|
+
);
|
|
221
|
+
if (!frameOrigin.every(Number.isFinite)) throw new Error('Mixed halo coordinate overflow');
|
|
222
|
+
const minX = column - spacing,
|
|
223
|
+
minY = row - spacing;
|
|
224
|
+
const maxX = column + source.width * spacing,
|
|
225
|
+
maxY = row + source.height * spacing;
|
|
226
|
+
if (![minX, minY, maxX, maxY].every(Number.isSafeInteger))
|
|
227
|
+
throw new Error('Mixed halo lattice overflow');
|
|
228
|
+
const key = `${spacing}/${column}/${row}`;
|
|
229
|
+
return {
|
|
230
|
+
...tile,
|
|
231
|
+
source,
|
|
232
|
+
columnStep,
|
|
233
|
+
rowStep,
|
|
234
|
+
frameOrigin,
|
|
235
|
+
scale,
|
|
236
|
+
key,
|
|
237
|
+
layoutKey: `${key}/${source.width}/${source.height}`,
|
|
238
|
+
haloBounds: {minX, minY, maxX, maxY}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {compareTerrainSlopes} from './profile-slope';
|
|
6
|
+
import {TerrainSampleStatus, type TerrainSample} from './types';
|
|
7
|
+
|
|
8
|
+
/** Classification at each target grid node. */
|
|
9
|
+
export const TerrainRegionalViewStatus = {
|
|
10
|
+
VISIBLE: 0,
|
|
11
|
+
BLOCKED: 1,
|
|
12
|
+
UNKNOWN: 2,
|
|
13
|
+
MISSING_TARGET: 3,
|
|
14
|
+
OBSERVER: 4
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
/** Axis-aligned target grid in a local Cartesian or observer-centered distance frame. */
|
|
18
|
+
export type TerrainViewshedGrid = {
|
|
19
|
+
/** Number of target columns. */
|
|
20
|
+
width: number;
|
|
21
|
+
/** Number of target rows. */
|
|
22
|
+
height: number;
|
|
23
|
+
/** Coordinates of the first target in meters. */
|
|
24
|
+
origin: readonly [number, number];
|
|
25
|
+
/** Positive spacings in meters. */
|
|
26
|
+
spacing: readonly [number, number];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** Observer geometry and sampling limits. */
|
|
30
|
+
export type TerrainRegionalViewshedOptions = {
|
|
31
|
+
/** Observer XY and absolute eye elevation, in meters. */
|
|
32
|
+
observer: readonly [number, number, number];
|
|
33
|
+
/** Maximum spacing of sampled stations on each ray, in meters. */
|
|
34
|
+
sampleStep: number;
|
|
35
|
+
/** Height above terrain at each target, in meters. Defaults to zero. */
|
|
36
|
+
targetOffset?: number;
|
|
37
|
+
/** Spherical radius in meters. Distances from the observer are surface arc lengths. */
|
|
38
|
+
radius?: number;
|
|
39
|
+
/** Maximum target grid size. Defaults to 100,000. */
|
|
40
|
+
maxTargets?: number;
|
|
41
|
+
/** Total callback invocations allowed, including observer and targets. Defaults to 4,000,000. */
|
|
42
|
+
maxSamples?: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** Row-major viewshed and coverage diagnostics. */
|
|
46
|
+
export type TerrainRegionalViewshed = {
|
|
47
|
+
/** View statuses from TerrainRegionalViewStatus. */
|
|
48
|
+
statuses: Uint8Array;
|
|
49
|
+
/** Target sample statuses from TerrainSampleStatus. */
|
|
50
|
+
targetStatuses: Uint8Array;
|
|
51
|
+
/** One when every sampled station including both endpoints was valid, otherwise zero. */
|
|
52
|
+
sampledCoverage: Uint8Array;
|
|
53
|
+
/** Total elevation callback invocations. */
|
|
54
|
+
samples: number;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Classify a regional raster of target nodes along sampled radial profiles.
|
|
59
|
+
* A known obstruction (including grazing) blocks even when other stations are missing.
|
|
60
|
+
* Missing support otherwise gives UNKNOWN. Results describe sampled stations only.
|
|
61
|
+
* Without a radius, XY and elevation use a local flat metric frame. With a radius,
|
|
62
|
+
* radial distance is spherical arc length and elevations are radial offsets from that sphere.
|
|
63
|
+
*/
|
|
64
|
+
export function createTerrainRegionalViewshed(
|
|
65
|
+
grid: TerrainViewshedGrid,
|
|
66
|
+
sample: (x: number, y: number) => Pick<TerrainSample, 'height' | 'status'>,
|
|
67
|
+
options: TerrainRegionalViewshedOptions
|
|
68
|
+
): TerrainRegionalViewshed {
|
|
69
|
+
const {width, height, origin, spacing} = grid;
|
|
70
|
+
const {
|
|
71
|
+
observer,
|
|
72
|
+
sampleStep,
|
|
73
|
+
radius,
|
|
74
|
+
targetOffset = 0,
|
|
75
|
+
maxTargets = 100_000,
|
|
76
|
+
maxSamples = 4_000_000
|
|
77
|
+
} = options;
|
|
78
|
+
const count = width * height;
|
|
79
|
+
if (
|
|
80
|
+
![width, height, count, maxTargets, maxSamples].every(Number.isSafeInteger) ||
|
|
81
|
+
width < 1 ||
|
|
82
|
+
height < 1 ||
|
|
83
|
+
count > maxTargets ||
|
|
84
|
+
maxSamples < 1 ||
|
|
85
|
+
origin.length !== 2 ||
|
|
86
|
+
spacing.length !== 2 ||
|
|
87
|
+
observer.length !== 3 ||
|
|
88
|
+
![...origin, ...spacing, ...observer, sampleStep, targetOffset].every(Number.isFinite) ||
|
|
89
|
+
spacing.some(value => value <= 0) ||
|
|
90
|
+
sampleStep <= 0 ||
|
|
91
|
+
targetOffset < 0 ||
|
|
92
|
+
(radius !== undefined && (!Number.isFinite(radius) || radius <= 0 || observer[2] <= -radius))
|
|
93
|
+
)
|
|
94
|
+
throw new RangeError('Invalid regional viewshed grid or options');
|
|
95
|
+
|
|
96
|
+
const statuses = new Uint8Array(count);
|
|
97
|
+
const targetStatuses = new Uint8Array(count);
|
|
98
|
+
const sampledCoverage = new Uint8Array(count);
|
|
99
|
+
let samples = 0;
|
|
100
|
+
/** Read one station, preserving the source coverage reason. */
|
|
101
|
+
function read(x: number, y: number) {
|
|
102
|
+
if (samples >= maxSamples) throw new RangeError('Regional viewshed sample budget exceeded');
|
|
103
|
+
samples++;
|
|
104
|
+
const result = sample(x, y);
|
|
105
|
+
if (
|
|
106
|
+
!Number.isInteger(result.status) ||
|
|
107
|
+
result.status < 0 ||
|
|
108
|
+
result.status > TerrainSampleStatus.NOT_RESIDENT ||
|
|
109
|
+
(result.status === TerrainSampleStatus.VALID &&
|
|
110
|
+
(!Number.isFinite(result.height) || (radius !== undefined && result.height <= -radius)))
|
|
111
|
+
)
|
|
112
|
+
throw new RangeError('Invalid regional viewshed sample');
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Express an elevation in the observer tangent frame without subtracting large radii. */
|
|
117
|
+
function sight(distance: number, elevation: number): readonly [number, number] {
|
|
118
|
+
let rise = elevation - observer[2];
|
|
119
|
+
let run = distance;
|
|
120
|
+
if (radius !== undefined) {
|
|
121
|
+
const theta = distance / radius;
|
|
122
|
+
const radial = radius + elevation;
|
|
123
|
+
const halfSine = Math.sin(theta / 2);
|
|
124
|
+
rise -= radial * (2 * halfSine * halfSine);
|
|
125
|
+
run = radial * Math.sin(theta);
|
|
126
|
+
}
|
|
127
|
+
if (!Number.isFinite(rise) || !Number.isFinite(run) || run <= 0)
|
|
128
|
+
throw new RangeError('Regional viewshed sight calculation overflow');
|
|
129
|
+
return [rise, run];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const observerSample = {...read(observer[0], observer[1])};
|
|
133
|
+
const observerValid = observerSample.status === TerrainSampleStatus.VALID;
|
|
134
|
+
for (let i = 0; i < count; i++) {
|
|
135
|
+
const x = origin[0] + (i % width) * spacing[0];
|
|
136
|
+
const y = origin[1] + Math.floor(i / width) * spacing[1];
|
|
137
|
+
const dx = x - observer[0];
|
|
138
|
+
const dy = y - observer[1];
|
|
139
|
+
const distance = Math.hypot(dx, dy);
|
|
140
|
+
if (!Number.isFinite(distance) || (radius !== undefined && distance / radius >= Math.PI))
|
|
141
|
+
throw new RangeError('Regional viewshed distance outside supported range');
|
|
142
|
+
const target = distance === 0 ? observerSample : read(x, y);
|
|
143
|
+
targetStatuses[i] = target.status;
|
|
144
|
+
if (target.status !== TerrainSampleStatus.VALID) {
|
|
145
|
+
statuses[i] = TerrainRegionalViewStatus.MISSING_TARGET;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (distance === 0) {
|
|
149
|
+
statuses[i] = TerrainRegionalViewStatus.OBSERVER;
|
|
150
|
+
sampledCoverage[i] = 1;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const [targetRise, targetRun] = sight(distance, target.height + targetOffset);
|
|
154
|
+
const segments = Math.max(1, Math.ceil(distance / sampleStep));
|
|
155
|
+
if (!Number.isSafeInteger(segments) || segments - 1 > maxSamples - samples)
|
|
156
|
+
throw new RangeError('Regional viewshed sample budget exceeded');
|
|
157
|
+
let complete = observerValid;
|
|
158
|
+
let blocked = observerValid && observerSample.height > observer[2];
|
|
159
|
+
for (let j = 1; j < segments; j++) {
|
|
160
|
+
const fraction = j / segments;
|
|
161
|
+
const station = read(observer[0] + dx * fraction, observer[1] + dy * fraction);
|
|
162
|
+
if (station.status !== TerrainSampleStatus.VALID) {
|
|
163
|
+
complete = false;
|
|
164
|
+
} else if (!blocked) {
|
|
165
|
+
const [rise, run] = sight(distance * fraction, station.height);
|
|
166
|
+
blocked = compareTerrainSlopes(rise, run, targetRise, targetRun) >= 0;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
sampledCoverage[i] = complete ? 1 : 0;
|
|
170
|
+
statuses[i] = blocked
|
|
171
|
+
? TerrainRegionalViewStatus.BLOCKED
|
|
172
|
+
: complete
|
|
173
|
+
? TerrainRegionalViewStatus.VISIBLE
|
|
174
|
+
: TerrainRegionalViewStatus.UNKNOWN;
|
|
175
|
+
}
|
|
176
|
+
return {statuses, targetStatuses, sampledCoverage, samples};
|
|
177
|
+
}
|
|
@@ -36,6 +36,18 @@ export function sweepTerrainPolytope(
|
|
|
36
36
|
collider: TerrainPolytope,
|
|
37
37
|
translation: Point,
|
|
38
38
|
{maxWork = 100_000}: {maxWork?: number} = {}
|
|
39
|
+
): TerrainPolytopeSweepResult {
|
|
40
|
+
return queryTerrainPolytope(surface.copyData(), surface.origin, collider, translation, maxWork);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @internal Test a conservative projection expansion along each separating axis. */
|
|
44
|
+
export function queryTerrainPolytope(
|
|
45
|
+
data: ReturnType<TerrainSurface['copyData']>,
|
|
46
|
+
origin: Point,
|
|
47
|
+
collider: TerrainPolytope,
|
|
48
|
+
translation: Point,
|
|
49
|
+
maxWork: number,
|
|
50
|
+
padding = 0
|
|
39
51
|
): TerrainPolytopeSweepResult {
|
|
40
52
|
if (
|
|
41
53
|
!Number.isSafeInteger(maxWork) ||
|
|
@@ -47,7 +59,7 @@ export function sweepTerrainPolytope(
|
|
|
47
59
|
collider.vertices.some(point => point.length !== 3 || !point.every(Number.isFinite))
|
|
48
60
|
)
|
|
49
61
|
throw new RangeError('Invalid terrain polytope sweep');
|
|
50
|
-
const vertices = collider.vertices.map(point => sub(point,
|
|
62
|
+
const vertices = collider.vertices.map(point => sub(point, origin));
|
|
51
63
|
const normals: Point[] = [];
|
|
52
64
|
const directions: Point[] = [];
|
|
53
65
|
for (const face of collider.faces) {
|
|
@@ -60,7 +72,16 @@ export function sweepTerrainPolytope(
|
|
|
60
72
|
normals.push(normal);
|
|
61
73
|
directions.push(...side);
|
|
62
74
|
}
|
|
63
|
-
return sweepTriangles(
|
|
75
|
+
return sweepTriangles(
|
|
76
|
+
data,
|
|
77
|
+
vertices,
|
|
78
|
+
normals,
|
|
79
|
+
directions,
|
|
80
|
+
translation,
|
|
81
|
+
maxWork,
|
|
82
|
+
undefined,
|
|
83
|
+
padding
|
|
84
|
+
);
|
|
64
85
|
}
|
|
65
86
|
|
|
66
87
|
/** Sweep a two-sided triangle mesh under translation. A finite plane can be
|
|
@@ -121,7 +142,8 @@ function sweepTriangles(
|
|
|
121
142
|
directions: readonly Point[],
|
|
122
143
|
translation: Point,
|
|
123
144
|
maxWork: number,
|
|
124
|
-
movingTriangleNormal?: Point
|
|
145
|
+
movingTriangleNormal?: Point,
|
|
146
|
+
padding = 0
|
|
125
147
|
): TerrainPolytopeSweepResult {
|
|
126
148
|
let work = 0;
|
|
127
149
|
let best: Extract<TerrainPolytopeSweepResult, {status: 'hit'}> | undefined;
|
|
@@ -161,6 +183,8 @@ function sweepTriangles(
|
|
|
161
183
|
min = Math.min(min, projection);
|
|
162
184
|
max = Math.max(max, projection);
|
|
163
185
|
}
|
|
186
|
+
min -= padding;
|
|
187
|
+
max += padding;
|
|
164
188
|
const speed = dot(translation, unit);
|
|
165
189
|
if (![low, high, min, max, speed, length].every(Number.isFinite))
|
|
166
190
|
throw new RangeError('Terrain polytope projection overflow');
|
|
@@ -194,6 +218,11 @@ export function sweepTerrainBox(
|
|
|
194
218
|
translation: Point,
|
|
195
219
|
options?: {maxWork?: number}
|
|
196
220
|
): TerrainPolytopeSweepResult {
|
|
221
|
+
return sweepTerrainPolytope(surface, createSweepBox(center, halfExtents), translation, options);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** @internal */
|
|
225
|
+
export function createSweepBox(center: Point, halfExtents: Point): TerrainPolytope {
|
|
197
226
|
if (halfExtents.length !== 3 || halfExtents.some(value => !(value > 0)))
|
|
198
227
|
throw new RangeError('Terrain box half extents must be positive');
|
|
199
228
|
const vertices = Array.from(
|
|
@@ -204,26 +233,21 @@ export function sweepTerrainBox(
|
|
|
204
233
|
center[2] + (i & 4 ? 1 : -1) * halfExtents[2]
|
|
205
234
|
]
|
|
206
235
|
);
|
|
207
|
-
return
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
]
|
|
225
|
-
},
|
|
226
|
-
translation,
|
|
227
|
-
options
|
|
228
|
-
);
|
|
236
|
+
return {
|
|
237
|
+
vertices,
|
|
238
|
+
faces: [
|
|
239
|
+
[0, 1, 3],
|
|
240
|
+
[0, 3, 2],
|
|
241
|
+
[4, 6, 7],
|
|
242
|
+
[4, 7, 5],
|
|
243
|
+
[0, 4, 5],
|
|
244
|
+
[0, 5, 1],
|
|
245
|
+
[2, 3, 7],
|
|
246
|
+
[2, 7, 6],
|
|
247
|
+
[0, 2, 6],
|
|
248
|
+
[0, 6, 4],
|
|
249
|
+
[1, 5, 7],
|
|
250
|
+
[1, 7, 3]
|
|
251
|
+
]
|
|
252
|
+
};
|
|
229
253
|
}
|