@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terrain-residency.d.ts","sourceRoot":"","sources":["../../src/tasks/terrain-residency.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,wBAAwB,EAAC,wCAAqC;AAC3E,OAAO,KAAK,EAAC,sBAAsB,EAAC,yCAAsC;
|
|
1
|
+
{"version":3,"file":"terrain-residency.d.ts","sourceRoot":"","sources":["../../src/tasks/terrain-residency.ts"],"names":[],"mappings":"AAKA,OAAO,K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Aa,CAAC,EAAE,OAAO,CAAA;KAAC,GACnF;QAAC,IAAI,EAAE,UAAU,CAAA;KAAC,CAAC;IACvB,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,YAAY,EAAE,CAAC;QACtB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,uBAAuB,CAAC;KACnC,CAAC;CACH,CAAC;AA0EF,mFAAmF;AACnF,eAAO,MAAM,oBAAoB;;;qBA3FD,MAAM;uBAAiB,MAAM;6BAAuB,MAAM;QA6FpE,qBAAqB,CAAC,OAAO,CAAC;;kBAtFnC,MAAM;eAAS,SAAS,oBAAoB,EAAE;wBAAkB,OAAO;;cAC3E,UAAU;;gBANX,qBAAqB,CAAC,gBAAgB,CAAC;kBACrC,wBAAwB,GAAG,IAAI;kBAC/B,MAAM;SA4FuB,OAAO,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;CA6H5C,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// math.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
/** Address lookup retained with an immutable source layout, not rebuilt per sample batch. */
|
|
5
|
+
const sourceIndexes = new WeakMap();
|
|
4
6
|
const addressKey = ({ spacing, column, row }) => `${spacing}/${column}/${row}`;
|
|
5
7
|
function sameArray(a, b) {
|
|
6
8
|
if (a.length !== b.length)
|
|
@@ -26,6 +28,44 @@ function sameHalo(a, b) {
|
|
|
26
28
|
}) &&
|
|
27
29
|
sameArray(a.statuses, b.statuses));
|
|
28
30
|
}
|
|
31
|
+
/** Copy already validated resident samples once, preserving precision and nodata normalization. */
|
|
32
|
+
function copyResidentSamples(field) {
|
|
33
|
+
const { width, height, offset = 0, stride = width } = field;
|
|
34
|
+
const heights = field.heights instanceof Float64Array
|
|
35
|
+
? new Float64Array(width * height)
|
|
36
|
+
: new Float32Array(width * height);
|
|
37
|
+
const validity = new Uint8Array(heights.length);
|
|
38
|
+
for (let y = 0; y < height; y++) {
|
|
39
|
+
for (let x = 0; x < width; x++) {
|
|
40
|
+
const input = offset + y * stride + x;
|
|
41
|
+
const output = y * width + x;
|
|
42
|
+
const value = field.heights[input];
|
|
43
|
+
if (Number.isFinite(value) && (!field.validity || field.validity[input] !== 0)) {
|
|
44
|
+
heights[output] = value;
|
|
45
|
+
validity[output] = 1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { heights, validity };
|
|
50
|
+
}
|
|
51
|
+
/** Compare halo addresses in the order used by the incremental builder. */
|
|
52
|
+
function compareAddress(a, b) {
|
|
53
|
+
return a.spacing - b.spacing || a.column - b.column || a.row - b.row;
|
|
54
|
+
}
|
|
55
|
+
/** Compute changed outputs with a linear merge over sorted snapshots. */
|
|
56
|
+
function changedHalos(previous, next) {
|
|
57
|
+
const changed = [];
|
|
58
|
+
let index = 0;
|
|
59
|
+
for (let i = 0; i < next.length; i++) {
|
|
60
|
+
const tile = next[i];
|
|
61
|
+
while (index < previous.length && compareAddress(previous[index], tile) < 0)
|
|
62
|
+
index++;
|
|
63
|
+
const prior = previous[index];
|
|
64
|
+
if (!prior || (prior !== tile && (compareAddress(prior, tile) !== 0 || !sameHalo(prior, tile))))
|
|
65
|
+
changed.push(tile);
|
|
66
|
+
}
|
|
67
|
+
return changed;
|
|
68
|
+
}
|
|
29
69
|
/** Keep mixed halo sources and outputs resident across serialized edit batches. */
|
|
30
70
|
export const TerrainResidencyTask = {
|
|
31
71
|
id: 'terrain-residency',
|
|
@@ -47,40 +87,64 @@ export const TerrainResidencyTask = {
|
|
|
47
87
|
try {
|
|
48
88
|
if (input.revision !== state.revision)
|
|
49
89
|
throw new Error('Stale terrain residency revision');
|
|
50
|
-
const
|
|
51
|
-
import("../terrain/mixed-halo-update.js"),
|
|
52
|
-
import("../terrain/height-field.js")
|
|
53
|
-
]);
|
|
90
|
+
const { updateTerrainMixedVertexTileHalos } = await import("../terrain/mixed-halo-update.js");
|
|
54
91
|
context.throwIfAborted();
|
|
55
|
-
const
|
|
92
|
+
const priorSources = state.snapshot?.sources ?? [];
|
|
93
|
+
let sourceIndex = state.snapshot && sourceIndexes.get(state.snapshot);
|
|
94
|
+
if (!sourceIndex) {
|
|
95
|
+
sourceIndex = new Map();
|
|
96
|
+
for (let i = 0; i < priorSources.length; i++)
|
|
97
|
+
sourceIndex.set(addressKey(priorSources[i]), i);
|
|
98
|
+
}
|
|
99
|
+
// Sample-only transactions copy one reference array. Structural edits lazily
|
|
100
|
+
// create a map; neither path mutates the committed snapshot on rejection.
|
|
101
|
+
const resident = priorSources.slice();
|
|
102
|
+
let structural;
|
|
103
|
+
const getSource = (key) => structural ? structural.get(key) : resident[sourceIndex.get(key)];
|
|
104
|
+
const setSource = (key, tile) => {
|
|
105
|
+
if (structural)
|
|
106
|
+
structural.set(key, tile);
|
|
107
|
+
else
|
|
108
|
+
resident[sourceIndex.get(key)] = tile;
|
|
109
|
+
};
|
|
110
|
+
const editLayout = () => {
|
|
111
|
+
if (!structural) {
|
|
112
|
+
structural = new Map();
|
|
113
|
+
for (const tile of resident)
|
|
114
|
+
structural.set(addressKey(tile), tile);
|
|
115
|
+
}
|
|
116
|
+
return structural;
|
|
117
|
+
};
|
|
56
118
|
// Several edits to a tile in one batch share one private copy.
|
|
57
119
|
const writable = new Map();
|
|
58
120
|
for (const edit of input.edits) {
|
|
59
121
|
if (edit.type === 'upsert') {
|
|
60
122
|
const key = addressKey(edit.tile);
|
|
61
|
-
|
|
123
|
+
editLayout().set(key, structuredClone(edit.tile));
|
|
62
124
|
writable.delete(key);
|
|
63
125
|
continue;
|
|
64
126
|
}
|
|
65
127
|
const key = addressKey(edit.address);
|
|
66
128
|
if (edit.type === 'remove') {
|
|
67
|
-
|
|
129
|
+
editLayout().delete(key);
|
|
68
130
|
writable.delete(key);
|
|
69
131
|
continue;
|
|
70
132
|
}
|
|
71
133
|
if (edit.type !== 'samples')
|
|
72
134
|
throw new Error('Unknown terrain residency edit');
|
|
73
|
-
const source =
|
|
135
|
+
const source = getSource(key);
|
|
74
136
|
if (!source)
|
|
75
137
|
throw new Error('Terrain sample edit requires a resident tile');
|
|
76
138
|
if (!edit.samples.length)
|
|
77
139
|
continue;
|
|
78
140
|
let data = writable.get(key);
|
|
79
141
|
if (!data) {
|
|
80
|
-
|
|
81
|
-
data =
|
|
142
|
+
// Upserts in this transaction have not passed halo validation yet.
|
|
143
|
+
data = structural
|
|
144
|
+
? new (await import("../terrain/height-field.js")).HeightField(source.field).copyData()
|
|
145
|
+
: copyResidentSamples(source.field);
|
|
82
146
|
writable.set(key, data);
|
|
83
|
-
|
|
147
|
+
setSource(key, {
|
|
84
148
|
...source,
|
|
85
149
|
field: { ...source.field, ...data, offset: 0, stride: source.field.width }
|
|
86
150
|
});
|
|
@@ -99,15 +163,13 @@ export const TerrainResidencyTask = {
|
|
|
99
163
|
}
|
|
100
164
|
}
|
|
101
165
|
const applied = input.measureStages ? performance.now() : 0;
|
|
102
|
-
const next = updateTerrainMixedVertexTileHalos(state.snapshot, [...
|
|
166
|
+
const next = updateTerrainMixedVertexTileHalos(state.snapshot, structural ? [...structural.values()] : resident, state.limits);
|
|
103
167
|
const updated = input.measureStages ? performance.now() : 0;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const tiles = structuredClone(next.tiles.filter(tile => {
|
|
107
|
-
const prior = old.get(addressKey(tile));
|
|
108
|
-
return !prior || !sameHalo(prior, tile);
|
|
109
|
-
}));
|
|
168
|
+
// Both snapshots are in address order. Unchanged halos retain object identity.
|
|
169
|
+
const tiles = structuredClone(changedHalos(state.snapshot?.tiles ?? [], next.tiles));
|
|
110
170
|
context.throwIfAborted();
|
|
171
|
+
if (!structural)
|
|
172
|
+
sourceIndexes.set(next, sourceIndex);
|
|
111
173
|
state.snapshot = next;
|
|
112
174
|
state.revision++;
|
|
113
175
|
const result = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terrain-residency.js","sourceRoot":"","sources":["../../src/tasks/terrain-residency.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;
|
|
1
|
+
{"version":3,"file":"terrain-residency.js","sourceRoot":"","sources":["../../src/tasks/terrain-residency.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AA4C5D,6FAA6F;AAC7F,MAAM,aAAa,GAAG,IAAI,OAAO,EAAiD,CAAC;AAEnF,MAAM,UAAU,GAAG,CAAC,EAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAc,EAAE,EAAE,CAAC,GAAG,OAAO,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;AAE1F,SAAS,SAAS,CAAC,CAAoB,EAAE,CAAoB;IAC3D,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IAC5E,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,CAAe,EAAE,CAAe;IAChD,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC;IACnB,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC;IACnB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAwB,CAAC;IACpD,OAAO,CACL,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM;QACtC,IAAI,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AAC,QAAQ;gBACxB,KAAK,EAAE,EAAE;gBACT,OAAO,EAAE,EAAE;gBACX,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC9D,CAAC;QACJ,CAAC;IACH,CAAC;CACoC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { TerrainCutout, TerrainCutoutPiece } from "./mesh-cutout.js";
|
|
2
|
+
import { type TerrainSkirtMesh, type TerrainSkirtOptions } from "./mesh-skirts.js";
|
|
3
|
+
/** Select wall height or a local base, without allowing arbitrary edge selection. */
|
|
4
|
+
type WallOptions = Pick<TerrainSkirtOptions, 'maxVertices' | 'maxTriangles'> & ({
|
|
5
|
+
height: number;
|
|
6
|
+
baseZ?: never;
|
|
7
|
+
} | {
|
|
8
|
+
baseZ: number;
|
|
9
|
+
height?: never;
|
|
10
|
+
});
|
|
11
|
+
/** Lift and wall settings for a terrain split. */
|
|
12
|
+
export type TerrainCutoutSkirtOptions = {
|
|
13
|
+
/** Amount added to the patch's local Z coordinates. Defaults to zero. */
|
|
14
|
+
lift?: number;
|
|
15
|
+
/** Wall options for the lifted patch. */
|
|
16
|
+
patch: WallOptions;
|
|
17
|
+
/** Wall options for the unchanged remainder. */
|
|
18
|
+
remainder: WallOptions;
|
|
19
|
+
};
|
|
20
|
+
/** Raised and stationary surfaces with optional visual skirts. */
|
|
21
|
+
export type SkirtedTerrainCutout = {
|
|
22
|
+
patch: {
|
|
23
|
+
surface: TerrainCutoutPiece;
|
|
24
|
+
skirt?: TerrainSkirtMesh;
|
|
25
|
+
};
|
|
26
|
+
remainder: {
|
|
27
|
+
surface: TerrainCutoutPiece;
|
|
28
|
+
skirt?: TerrainSkirtMesh;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/** Translate the patch and build both walls from the paired cut edges only. */
|
|
32
|
+
export declare function createTerrainCutoutSkirts(cutout: TerrainCutout, { lift, patch, remainder }: TerrainCutoutSkirtOptions): SkirtedTerrainCutout;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=cutout-skirts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cutout-skirts.d.ts","sourceRoot":"","sources":["../../src/terrain/cutout-skirts.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,aAAa,EAAE,kBAAkB,EAAC,yBAAsB;AACrE,OAAO,EAAqB,KAAK,gBAAgB,EAAE,KAAK,mBAAmB,EAAC,yBAAsB;AAElG,qFAAqF;AACrF,KAAK,WAAW,GAAG,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,cAAc,CAAC,GAC1E,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAC,GAAG;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,KAAK,CAAA;CAAC,CAAC,CAAC;AAEtE,kDAAkD;AAClD,MAAM,MAAM,yBAAyB,GAAG;IACtC,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,KAAK,EAAE,WAAW,CAAC;IACnB,gDAAgD;IAChD,SAAS,EAAE,WAAW,CAAC;CACxB,CAAC;AAEF,kEAAkE;AAClE,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE;QAAC,OAAO,EAAE,kBAAkB,CAAC;QAAC,KAAK,CAAC,EAAE,gBAAgB,CAAA;KAAC,CAAC;IAC/D,SAAS,EAAE;QAAC,OAAO,EAAE,kBAAkB,CAAC;QAAC,KAAK,CAAC,EAAE,gBAAgB,CAAA;KAAC,CAAC;CACpE,CAAC;AAEF,+EAA+E;AAC/E,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,aAAa,EACrB,EAAC,IAAQ,EAAE,KAAK,EAAE,SAAS,EAAC,EAAE,yBAAyB,GACtD,oBAAoB,CAWtB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import { createTerrainSkirt } from "./mesh-skirts.js";
|
|
5
|
+
/** Translate the patch and build both walls from the paired cut edges only. */
|
|
6
|
+
export function createTerrainCutoutSkirts(cutout, { lift = 0, patch, remainder }) {
|
|
7
|
+
if (!Number.isFinite(lift))
|
|
8
|
+
throw new RangeError('Invalid terrain cutout lift');
|
|
9
|
+
const positions = cutout.patch.positions.slice();
|
|
10
|
+
for (let i = 2; i < positions.length; i += 3) {
|
|
11
|
+
positions[i] += lift;
|
|
12
|
+
if (!Number.isFinite(positions[i]))
|
|
13
|
+
throw new RangeError('Terrain cutout lift overflow');
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
patch: skirtPiece({ ...cutout.patch, positions }, patch),
|
|
17
|
+
remainder: skirtPiece(cutout.remainder, remainder)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Compose on a nonempty paired boundary only. */
|
|
21
|
+
function skirtPiece(surface, options) {
|
|
22
|
+
if (!surface.cutEdges.length)
|
|
23
|
+
return { surface };
|
|
24
|
+
return {
|
|
25
|
+
surface,
|
|
26
|
+
skirt: createTerrainSkirt(surface, { ...options, edges: surface.cutEdges })
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=cutout-skirts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cutout-skirts.js","sourceRoot":"","sources":["../../src/terrain/cutout-skirts.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAG5D,OAAO,EAAC,kBAAkB,EAAkD,yBAAsB;AAsBlG,+EAA+E;AAC/E,MAAM,UAAU,yBAAyB,CACvC,MAAqB,EACrB,EAAC,IAAI,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,EAA4B;IAEvD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,6BAA6B,CAAC,CAAC;IAChF,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7C,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAAE,MAAM,IAAI,UAAU,CAAC,8BAA8B,CAAC,CAAC;IAC3F,CAAC;IACD,OAAO;QACL,KAAK,EAAE,UAAU,CAAC,EAAC,GAAG,MAAM,CAAC,KAAK,EAAE,SAAS,EAAC,EAAE,KAAK,CAAC;QACtD,SAAS,EAAE,UAAU,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC;KACnD,CAAC;AACJ,CAAC;AAED,kDAAkD;AAClD,SAAS,UAAU,CAAC,OAA2B,EAAE,OAAoB;IACnE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM;QAAE,OAAO,EAAC,OAAO,EAAC,CAAC;IAC/C,OAAO;QACL,OAAO;QACP,KAAK,EAAE,kBAAkB,CAAC,OAAO,EAAE,EAAC,GAAG,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAC,CAAC;KAC1E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { HeightField } from "./height-field.js";
|
|
2
|
+
/** Outlet and allocation policy for four-neighbor terrain conditioning. */
|
|
3
|
+
export type TerrainDepressionFillOptions = {
|
|
4
|
+
/** Valid row-major cell indices that can drain. Exterior and nodata are closed. */
|
|
5
|
+
outlets: readonly number[];
|
|
6
|
+
/** Maximum grid cells before allocating buffers. Defaults to 4,194,304. */
|
|
7
|
+
maxCells?: number;
|
|
8
|
+
};
|
|
9
|
+
/** Conditioned terrain and its outlet-connected drainage forest. */
|
|
10
|
+
export type TerrainDepressionFill = {
|
|
11
|
+
/** Derived field, including the original heights of outlet-disconnected cells. */
|
|
12
|
+
field: HeightField;
|
|
13
|
+
/** Next face neighbor toward an outlet, -1 at outlets, -2 for nodata or disconnected cells. */
|
|
14
|
+
receiver: Int32Array;
|
|
15
|
+
/** Number of valid cells with no face-connected path to an outlet. */
|
|
16
|
+
disconnectedCells: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Raise each outlet-connected cell to the lowest spill elevation needed to reach
|
|
20
|
+
* a declared outlet by face neighbors. The returned forest routes across flats.
|
|
21
|
+
* Nodata blocks flow and disconnected components retain their source heights.
|
|
22
|
+
* The source is immutable. Time is O(cells log cells) and storage is O(cells).
|
|
23
|
+
*/
|
|
24
|
+
export declare function fillTerrainDepressions(field: HeightField, { outlets, maxCells }: TerrainDepressionFillOptions): TerrainDepressionFill;
|
|
25
|
+
//# sourceMappingURL=depression-fill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"depression-fill.d.ts","sourceRoot":"","sources":["../../src/terrain/depression-fill.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,WAAW,EAAC,0BAAuB;AAE3C,2EAA2E;AAC3E,MAAM,MAAM,4BAA4B,GAAG;IACzC,mFAAmF;IACnF,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,oEAAoE;AACpE,MAAM,MAAM,qBAAqB,GAAG;IAClC,kFAAkF;IAClF,KAAK,EAAE,WAAW,CAAC;IACnB,+FAA+F;IAC/F,QAAQ,EAAE,UAAU,CAAC;IACrB,sEAAsE;IACtE,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,WAAW,EAClB,EAAC,OAAO,EAAE,QAAoB,EAAC,EAAE,4BAA4B,GAC5D,qBAAqB,CA2FvB"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import { HeightField } from "./height-field.js";
|
|
5
|
+
/**
|
|
6
|
+
* Raise each outlet-connected cell to the lowest spill elevation needed to reach
|
|
7
|
+
* a declared outlet by face neighbors. The returned forest routes across flats.
|
|
8
|
+
* Nodata blocks flow and disconnected components retain their source heights.
|
|
9
|
+
* The source is immutable. Time is O(cells log cells) and storage is O(cells).
|
|
10
|
+
*/
|
|
11
|
+
export function fillTerrainDepressions(field, { outlets, maxCells = 4194304 }) {
|
|
12
|
+
if (field.registration !== 'cell')
|
|
13
|
+
throw new Error('Terrain depression fill requires cell registration');
|
|
14
|
+
const { width, height } = field;
|
|
15
|
+
const count = width * height;
|
|
16
|
+
if (!Number.isSafeInteger(maxCells) || maxCells < 0 || count > maxCells || count > 0x7fffffff)
|
|
17
|
+
throw new RangeError('Terrain depression fill exceeds its cell budget');
|
|
18
|
+
if (!outlets.length)
|
|
19
|
+
throw new RangeError('Terrain depression fill requires an outlet');
|
|
20
|
+
for (const i of outlets) {
|
|
21
|
+
if (!Number.isInteger(i) ||
|
|
22
|
+
i < 0 ||
|
|
23
|
+
i >= count ||
|
|
24
|
+
field.getHeight(i % width, Math.floor(i / width)) === undefined)
|
|
25
|
+
throw new RangeError('Terrain outlet must identify a valid cell');
|
|
26
|
+
}
|
|
27
|
+
const { heights, validity } = field.copyData();
|
|
28
|
+
const receiver = new Int32Array(count).fill(-2);
|
|
29
|
+
const heap = new Int32Array(count);
|
|
30
|
+
let size = 0;
|
|
31
|
+
let disconnectedCells = field.validCount;
|
|
32
|
+
/** Sort by spill elevation, then by cell index for reproducible flat routing. */
|
|
33
|
+
const before = (a, b) => heights[a] < heights[b] || (heights[a] === heights[b] && a < b);
|
|
34
|
+
/** Insert a newly reached cell. Its finalized spill height never changes. */
|
|
35
|
+
function push(cell) {
|
|
36
|
+
let slot = size++;
|
|
37
|
+
while (slot > 0) {
|
|
38
|
+
const parent = Math.floor((slot - 1) / 2);
|
|
39
|
+
if (!before(cell, heap[parent]))
|
|
40
|
+
break;
|
|
41
|
+
heap[slot] = heap[parent];
|
|
42
|
+
slot = parent;
|
|
43
|
+
}
|
|
44
|
+
heap[slot] = cell;
|
|
45
|
+
}
|
|
46
|
+
/** Remove the cell with the lowest known spill elevation. */
|
|
47
|
+
function pop() {
|
|
48
|
+
const first = heap[0];
|
|
49
|
+
const tail = heap[--size];
|
|
50
|
+
let slot = 0;
|
|
51
|
+
let child = 1;
|
|
52
|
+
while (child < size) {
|
|
53
|
+
if (child + 1 < size && before(heap[child + 1], heap[child]))
|
|
54
|
+
child++;
|
|
55
|
+
if (!before(heap[child], tail))
|
|
56
|
+
break;
|
|
57
|
+
heap[slot] = heap[child];
|
|
58
|
+
slot = child;
|
|
59
|
+
child = slot * 2 + 1;
|
|
60
|
+
}
|
|
61
|
+
if (size)
|
|
62
|
+
heap[slot] = tail;
|
|
63
|
+
return first;
|
|
64
|
+
}
|
|
65
|
+
/** First discovery from the minimum frontier finalizes the minimax path cost. */
|
|
66
|
+
function visit(cell, parent) {
|
|
67
|
+
if (!validity[cell] || receiver[cell] !== -2)
|
|
68
|
+
return;
|
|
69
|
+
receiver[cell] = parent;
|
|
70
|
+
disconnectedCells--;
|
|
71
|
+
if (parent >= 0)
|
|
72
|
+
heights[cell] = Math.max(heights[cell], heights[parent]);
|
|
73
|
+
push(cell);
|
|
74
|
+
}
|
|
75
|
+
for (const outlet of outlets)
|
|
76
|
+
visit(outlet, -1);
|
|
77
|
+
while (size) {
|
|
78
|
+
const cell = pop();
|
|
79
|
+
const column = cell % width;
|
|
80
|
+
if (column > 0)
|
|
81
|
+
visit(cell - 1, cell);
|
|
82
|
+
if (column + 1 < width)
|
|
83
|
+
visit(cell + 1, cell);
|
|
84
|
+
if (cell >= width)
|
|
85
|
+
visit(cell - width, cell);
|
|
86
|
+
if (cell < count - width)
|
|
87
|
+
visit(cell + width, cell);
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
field: new HeightField({
|
|
91
|
+
width,
|
|
92
|
+
height,
|
|
93
|
+
heights,
|
|
94
|
+
validity,
|
|
95
|
+
origin: field.origin,
|
|
96
|
+
columnStep: field.columnStep,
|
|
97
|
+
rowStep: field.rowStep,
|
|
98
|
+
registration: field.registration,
|
|
99
|
+
diagonal: field.diagonal,
|
|
100
|
+
heightReference: field.heightReference
|
|
101
|
+
}),
|
|
102
|
+
receiver,
|
|
103
|
+
disconnectedCells
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=depression-fill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"depression-fill.js","sourceRoot":"","sources":["../../src/terrain/depression-fill.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EAAC,WAAW,EAAC,0BAAuB;AAoB3C;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAAkB,EAClB,EAAC,OAAO,EAAE,QAAQ,GAAG,OAAS,EAA+B;IAE7D,IAAI,KAAK,CAAC,YAAY,KAAK,MAAM;QAC/B,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,MAAM,EAAC,KAAK,EAAE,MAAM,EAAC,GAAG,KAAK,CAAC;IAC9B,MAAM,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;IAC7B,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,IAAI,KAAK,GAAG,QAAQ,IAAI,KAAK,GAAG,UAAU;QAC3F,MAAM,IAAI,UAAU,CAA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,42 @@
|
|
|
1
|
+
import type { HeightField } from "./height-field.js";
|
|
2
|
+
/** Uniform horizontal finite-volume metrics for an affine cell-centered grid. */
|
|
3
|
+
export type TerrainCellMetrics = {
|
|
4
|
+
/** Horizontal area of one cell, in square meters. */
|
|
5
|
+
area: number;
|
|
6
|
+
/** Face lengths ordered by negative column, positive column, negative row, positive row. */
|
|
7
|
+
faceLengths: readonly [number, number, number, number];
|
|
8
|
+
/** Outward horizontal unit normals in the same order as the face lengths. */
|
|
9
|
+
faceNormals: readonly [
|
|
10
|
+
readonly [number, number],
|
|
11
|
+
readonly [number, number],
|
|
12
|
+
readonly [number, number],
|
|
13
|
+
readonly [number, number]
|
|
14
|
+
];
|
|
15
|
+
};
|
|
16
|
+
/** Derive projected cell area and face geometry, including shear and reflected grids. */
|
|
17
|
+
export declare function getTerrainCellMetrics(field: Pick<HeightField, 'registration' | 'columnStep' | 'rowStep'>): TerrainCellMetrics;
|
|
18
|
+
/** Drainage options for the unconditioned cell grid. */
|
|
19
|
+
export type TerrainDrainageOptions = {
|
|
20
|
+
/** Valid row-major cell indices where flow terminates, even if lower neighbors exist. */
|
|
21
|
+
outlets?: readonly number[];
|
|
22
|
+
/** Maximum grid cells before allocating drainage buffers. Defaults to 4,194,304. */
|
|
23
|
+
maxCells?: number;
|
|
24
|
+
};
|
|
25
|
+
/** Row-major routing, catchments and accumulation for a single affine cell grid. */
|
|
26
|
+
export type TerrainDrainage = {
|
|
27
|
+
/** Receiver index, or -1 for nodata and terminal cells. */
|
|
28
|
+
receiver: Int32Array;
|
|
29
|
+
/** Terminal cell index for the catchment, or -1 for nodata. */
|
|
30
|
+
terminal: Int32Array;
|
|
31
|
+
/** Upstream cell count including the cell itself. Zero denotes nodata. */
|
|
32
|
+
contributingCells: Uint32Array;
|
|
33
|
+
/** Multiply by contributingCells to get contributing area in square meters. */
|
|
34
|
+
cellArea: number;
|
|
35
|
+
};
|
|
36
|
+
/** Route each valid cell to its steepest strictly lower neighbor in projected XY.
|
|
37
|
+
* Equal slopes select the lower row-major index. Diagonal flow requires both
|
|
38
|
+
* intervening side cells to be valid. The exterior and nodata block flow.
|
|
39
|
+
* Flats, pits and declared outlets terminate flow. Accumulation is O(cells).
|
|
40
|
+
*/
|
|
41
|
+
export declare function createTerrainDrainage(field: HeightField, { outlets, maxCells }?: TerrainDrainageOptions): TerrainDrainage;
|
|
42
|
+
//# sourceMappingURL=hydrology.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydrology.d.ts","sourceRoot":"","sources":["../../src/terrain/hydrology.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,0BAAuB;AAEhD,iFAAiF;AACjF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,4FAA4F;IAC5F,WAAW,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACvD,6EAA6E;IAC7E,WAAW,EAAE,SAAS;QACpB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;QACzB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;QACzB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;QACzB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH,CAAC;AAEF,yFAAyF;AACzF,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,cAAc,GAAG,YAAY,GAAG,SAAS,CAAC,GAClE,kBAAkB,CAmBpB;AAED,wDAAwD;AACxD,MAAM,MAAM,sBAAsB,GAAG;IACnC,yFAAyF;IACzF,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,oFAAoF;IACpF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,oFAAoF;AACpF,MAAM,MAAM,eAAe,GAAG;IAC5B,2DAA2D;IAC3D,QAAQ,EAAE,UAAU,CAAC;IACrB,+DAA+D;IAC/D,QAAQ,EAAE,UAAU,CAAC;IACrB,0EAA0E;IAC1E,iBAAiB,EAAE,WAAW,CAAC;IAC/B,+EAA+E;IAC/E,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,WAAW,EAClB,EAAC,OAAY,EAAE,QAAoB,EAAC,GAAE,sBAA2B,GAChE,eAAe,CA2EjB"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
/** Derive projected cell area and face geometry, including shear and reflected grids. */
|
|
5
|
+
export function getTerrainCellMetrics(field) {
|
|
6
|
+
if (field.registration !== 'cell')
|
|
7
|
+
throw new Error('Terrain cell metrics require cell registration');
|
|
8
|
+
const [cx, cy] = field.columnStep;
|
|
9
|
+
const [rx, ry] = field.rowStep;
|
|
10
|
+
const determinant = cx * ry - cy * rx;
|
|
11
|
+
const columnLength = Math.hypot(cx, cy);
|
|
12
|
+
const rowLength = Math.hypot(rx, ry);
|
|
13
|
+
const area = Math.abs(determinant);
|
|
14
|
+
if (!(area > 0 && Number.isFinite(area) && Number.isFinite(columnLength + rowLength)))
|
|
15
|
+
throw new RangeError('Invalid terrain cell geometry');
|
|
16
|
+
const sign = Math.sign(determinant);
|
|
17
|
+
const east = [(sign * ry) / rowLength, (-sign * rx) / rowLength];
|
|
18
|
+
const south = [(-sign * cy) / columnLength, (sign * cx) / columnLength];
|
|
19
|
+
return {
|
|
20
|
+
area,
|
|
21
|
+
faceLengths: [rowLength, rowLength, columnLength, columnLength],
|
|
22
|
+
faceNormals: [[-east[0], -east[1]], east, [-south[0], -south[1]], south]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Route each valid cell to its steepest strictly lower neighbor in projected XY.
|
|
26
|
+
* Equal slopes select the lower row-major index. Diagonal flow requires both
|
|
27
|
+
* intervening side cells to be valid. The exterior and nodata block flow.
|
|
28
|
+
* Flats, pits and declared outlets terminate flow. Accumulation is O(cells).
|
|
29
|
+
*/
|
|
30
|
+
export function createTerrainDrainage(field, { outlets = [], maxCells = 4194304 } = {}) {
|
|
31
|
+
const { width, height, columnStep, rowStep } = field;
|
|
32
|
+
const count = width * height;
|
|
33
|
+
if (!Number.isSafeInteger(maxCells) || maxCells < 0 || count > maxCells || count > 0x7fffffff)
|
|
34
|
+
throw new RangeError('Terrain drainage exceeds its cell budget');
|
|
35
|
+
const { area: cellArea } = getTerrainCellMetrics(field);
|
|
36
|
+
for (const i of outlets) {
|
|
37
|
+
if (!Number.isInteger(i) ||
|
|
38
|
+
i < 0 ||
|
|
39
|
+
i >= count ||
|
|
40
|
+
field.getHeight(i % width, Math.floor(i / width)) === undefined)
|
|
41
|
+
throw new RangeError('Terrain outlet must identify a valid cell');
|
|
42
|
+
}
|
|
43
|
+
const { heights, validity } = field.copyData();
|
|
44
|
+
const receiver = new Int32Array(count).fill(-1);
|
|
45
|
+
const terminal = new Int32Array(count).fill(-1);
|
|
46
|
+
const contributingCells = new Uint32Array(count);
|
|
47
|
+
const incoming = new Uint8Array(count);
|
|
48
|
+
const queue = new Int32Array(count);
|
|
49
|
+
const outletSet = new Set(outlets);
|
|
50
|
+
const offsets = [];
|
|
51
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
52
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
53
|
+
if (!dx && !dy)
|
|
54
|
+
continue;
|
|
55
|
+
const distance = Math.hypot(dx * columnStep[0] + dy * rowStep[0], dx * columnStep[1] + dy * rowStep[1]);
|
|
56
|
+
if (!(distance > 0 && Number.isFinite(distance)))
|
|
57
|
+
throw new RangeError('Invalid terrain neighbor distance');
|
|
58
|
+
offsets.push({ dx, dy, distance });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
for (let i = 0; i < count; i++) {
|
|
62
|
+
if (!validity[i])
|
|
63
|
+
continue;
|
|
64
|
+
contributingCells[i] = 1;
|
|
65
|
+
if (outletSet.has(i))
|
|
66
|
+
continue;
|
|
67
|
+
const col = i % width;
|
|
68
|
+
const row = Math.floor(i / width);
|
|
69
|
+
let steepest = 0;
|
|
70
|
+
for (const { dx, dy, distance } of offsets) {
|
|
71
|
+
if (col + dx < 0 || col + dx >= width || row + dy < 0 || row + dy >= height)
|
|
72
|
+
continue;
|
|
73
|
+
const j = i + dx + dy * width;
|
|
74
|
+
if (!validity[j] || heights[j] >= heights[i])
|
|
75
|
+
continue;
|
|
76
|
+
if (dx && dy && (!validity[i + dx] || !validity[i + dy * width]))
|
|
77
|
+
continue;
|
|
78
|
+
const slope = (heights[i] - heights[j]) / distance;
|
|
79
|
+
if (!Number.isFinite(slope) || slope === 0)
|
|
80
|
+
throw new RangeError('Terrain drainage slope is outside the representable range');
|
|
81
|
+
// Offsets visit neighbors in ascending row-major order.
|
|
82
|
+
if (slope > steepest) {
|
|
83
|
+
steepest = slope;
|
|
84
|
+
receiver[i] = j;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (receiver[i] >= 0)
|
|
88
|
+
incoming[receiver[i]]++;
|
|
89
|
+
}
|
|
90
|
+
let end = 0;
|
|
91
|
+
for (let i = 0; i < count; i++)
|
|
92
|
+
if (validity[i] && !incoming[i])
|
|
93
|
+
queue[end++] = i;
|
|
94
|
+
// Strict descent makes the graph acyclic. Topological order permits one
|
|
95
|
+
// accumulation pass and one backward catchment pass without sorting heights.
|
|
96
|
+
for (let cursor = 0; cursor < end; cursor++) {
|
|
97
|
+
const i = queue[cursor];
|
|
98
|
+
const next = receiver[i];
|
|
99
|
+
if (next < 0)
|
|
100
|
+
continue;
|
|
101
|
+
contributingCells[next] += contributingCells[i];
|
|
102
|
+
if (--incoming[next] === 0)
|
|
103
|
+
queue[end++] = next;
|
|
104
|
+
}
|
|
105
|
+
for (let cursor = end - 1; cursor >= 0; cursor--) {
|
|
106
|
+
const i = queue[cursor];
|
|
107
|
+
const next = receiver[i];
|
|
108
|
+
terminal[i] = next < 0 ? i : terminal[next];
|
|
109
|
+
}
|
|
110
|
+
return { receiver, terminal, contributingCells, cellArea };
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=hydrology.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydrology.js","sourceRoot":"","sources":["../../src/terrain/hydrology.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAmB5D,yFAAyF;AACzF,MAAM,UAAU,qBAAqB,CACnC,KAAmE;IAEnE,IAAI,KAAK,CAAC,YAAY,KAAK,MAAM;QAC/B,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC;IAClC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;IAC/B,MAAM,WAAW,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IACtC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACxC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACnC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;QACnF,MAAM,IAAI,UAAU,CAAC,+BAA+B,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,CA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