@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
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {sweepTerrainCapsule, type TerrainCapsuleSweepResult} from './sweep-capsule';
|
|
6
|
+
import type {TerrainRigidMotion} from './sweep-rotation';
|
|
7
|
+
import type {TerrainSphereSweepOptions} from './sweep-sphere';
|
|
8
|
+
import type {TerrainSegmentHit, TerrainSurface} from './surface';
|
|
9
|
+
|
|
10
|
+
/** Cartesian point in the terrain surface frame. */
|
|
11
|
+
type Point = readonly [number, number, number];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Bracket first contact for a capsule under linear pivot translation and shortest-arc
|
|
15
|
+
* rotation. Coincident axis endpoints describe a sphere, including an off-pivot
|
|
16
|
+
* sphere whose center follows a curved path. Unresolved tangency returns incomplete.
|
|
17
|
+
* The witness is an axis/triangle pair within the radius at the upper fraction.
|
|
18
|
+
*/
|
|
19
|
+
export function sweepTerrainRotatingCapsule(
|
|
20
|
+
surface: Pick<TerrainSurface, 'nearestSegmentQuery'>,
|
|
21
|
+
start: Point,
|
|
22
|
+
end: Point,
|
|
23
|
+
radius: number,
|
|
24
|
+
{pivot, translation, rotation}: TerrainRigidMotion,
|
|
25
|
+
{maxWork = 100_000, fractionTolerance = 1e-5}: TerrainSphereSweepOptions = {}
|
|
26
|
+
): TerrainCapsuleSweepResult {
|
|
27
|
+
const norm = Math.hypot(...rotation);
|
|
28
|
+
if (
|
|
29
|
+
![start, end, pivot, translation].every(p => p.length === 3 && p.every(Number.isFinite)) ||
|
|
30
|
+
rotation.length !== 4 ||
|
|
31
|
+
!(norm > 0 && Number.isFinite(norm)) ||
|
|
32
|
+
!Number.isFinite(radius) ||
|
|
33
|
+
radius < 0 ||
|
|
34
|
+
!Number.isSafeInteger(maxWork) ||
|
|
35
|
+
maxWork < 0 ||
|
|
36
|
+
!(fractionTolerance >= Number.EPSILON && fractionTolerance <= 1)
|
|
37
|
+
)
|
|
38
|
+
throw new RangeError('Invalid terrain capsule rigid motion');
|
|
39
|
+
|
|
40
|
+
const sign = rotation[3] < 0 ? -1 : 1;
|
|
41
|
+
const axisLength = Math.hypot(rotation[0], rotation[1], rotation[2]);
|
|
42
|
+
const angle = 2 * Math.atan2(axisLength, Math.abs(rotation[3]));
|
|
43
|
+
if (angle === 0) {
|
|
44
|
+
return sweepTerrainCapsule(surface, start, end, translation, radius, {
|
|
45
|
+
maxWork,
|
|
46
|
+
fractionTolerance
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const x = (rotation[0] / axisLength) * sign;
|
|
50
|
+
const y = (rotation[1] / axisLength) * sign;
|
|
51
|
+
const z = (rotation[2] / axisLength) * sign;
|
|
52
|
+
const offsets = [start, end].map(p => p.map((v, i) => v - pivot[i]));
|
|
53
|
+
// A segment is a convex combination of its endpoints. The capsule's spherical
|
|
54
|
+
// dilation is rotation invariant, so only the axis motion contributes here.
|
|
55
|
+
const reach = Math.max(...offsets.map(p => Math.hypot(...p)));
|
|
56
|
+
const speed = Math.hypot(...translation) + angle * reach;
|
|
57
|
+
const scale = Math.max(Math.hypot(...pivot), reach, speed, radius);
|
|
58
|
+
if (!Number.isFinite(scale)) throw new RangeError('Terrain capsule rigid motion overflow');
|
|
59
|
+
|
|
60
|
+
let work = 0;
|
|
61
|
+
/** Query the axis at an exact pose, charging both the probe and index work. */
|
|
62
|
+
function probe(t: number) {
|
|
63
|
+
if (work >= maxWork) return null;
|
|
64
|
+
work++;
|
|
65
|
+
const sin = Math.sin(angle * t);
|
|
66
|
+
const cos = Math.cos(angle * t);
|
|
67
|
+
const [a, b] =
|
|
68
|
+
t === 0
|
|
69
|
+
? [start, end]
|
|
70
|
+
: offsets.map(([u, v, w]): Point => {
|
|
71
|
+
const d = (x * u + y * v + z * w) * (1 - cos);
|
|
72
|
+
const pos: Point = [
|
|
73
|
+
pivot[0] + (translation[0] * t + u * cos + (y * w - z * v) * sin + x * d),
|
|
74
|
+
pivot[1] + (translation[1] * t + v * cos + (z * u - x * w) * sin + y * d),
|
|
75
|
+
pivot[2] + (translation[2] * t + w * cos + (x * v - y * u) * sin + z * d)
|
|
76
|
+
];
|
|
77
|
+
if (!pos.every(Number.isFinite)) throw new RangeError('Terrain capsule pose overflow');
|
|
78
|
+
return pos;
|
|
79
|
+
});
|
|
80
|
+
const query = surface.nearestSegmentQuery(a, b, {maxWork: maxWork - work});
|
|
81
|
+
work += query.work;
|
|
82
|
+
return query;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const initial = probe(0);
|
|
86
|
+
if (initial?.result && initial.result.distance <= radius)
|
|
87
|
+
return {status: 'hit', fraction: 0, lowerFraction: 0, work, contact: initial.result};
|
|
88
|
+
if (!initial?.complete) return {status: 'incomplete', work};
|
|
89
|
+
if (!initial.result || speed === 0) return {status: 'miss', work};
|
|
90
|
+
|
|
91
|
+
let clearUntil = 0;
|
|
92
|
+
let witness: {fraction: number; contact: TerrainSegmentHit} | undefined;
|
|
93
|
+
const pending: [number, number][] = [[0, 1]];
|
|
94
|
+
while (pending.length) {
|
|
95
|
+
if (witness && witness.fraction - clearUntil <= fractionTolerance)
|
|
96
|
+
return {status: 'hit', lowerFraction: clearUntil, work, ...witness};
|
|
97
|
+
const [lo, hi] = pending.pop()!;
|
|
98
|
+
const mid = lo + (hi - lo) / 2;
|
|
99
|
+
const query = probe(mid);
|
|
100
|
+
const contact = query?.result;
|
|
101
|
+
if (contact && contact.distance <= radius) {
|
|
102
|
+
witness = {fraction: mid, contact};
|
|
103
|
+
if (mid - clearUntil <= fractionTolerance)
|
|
104
|
+
return {status: 'hit', lowerFraction: clearUntil, work, ...witness};
|
|
105
|
+
if (mid === lo || mid === hi) return {status: 'incomplete', work};
|
|
106
|
+
pending.push([lo, mid]);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (!query?.complete) return {status: 'incomplete', work};
|
|
110
|
+
const travel = speed * Math.max(mid - lo, hi - mid);
|
|
111
|
+
const allowance = 16 * Number.EPSILON * Math.max(scale, contact?.distance ?? 0);
|
|
112
|
+
if (!contact || contact.distance - radius > travel + allowance) {
|
|
113
|
+
clearUntil = hi;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (hi - clearUntil <= fractionTolerance) {
|
|
117
|
+
const final = witness?.fraction === hi ? witness.contact : probe(hi)?.result;
|
|
118
|
+
if (final && final.distance <= radius)
|
|
119
|
+
return {status: 'hit', fraction: hi, lowerFraction: clearUntil, work, contact: final};
|
|
120
|
+
}
|
|
121
|
+
if (mid === lo || mid === hi || hi - lo <= fractionTolerance / 4)
|
|
122
|
+
return {status: 'incomplete', work};
|
|
123
|
+
pending.push([mid, hi], [lo, mid]);
|
|
124
|
+
}
|
|
125
|
+
return witness
|
|
126
|
+
? {status: 'hit', lowerFraction: clearUntil, work, ...witness}
|
|
127
|
+
: {status: 'miss', work};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Sweep a sphere whose center may orbit an offset rigid-motion pivot. */
|
|
131
|
+
export function sweepTerrainRotatingSphere(
|
|
132
|
+
surface: Pick<TerrainSurface, 'nearestSegmentQuery'>,
|
|
133
|
+
center: Point,
|
|
134
|
+
radius: number,
|
|
135
|
+
motion: TerrainRigidMotion,
|
|
136
|
+
options?: TerrainSphereSweepOptions
|
|
137
|
+
): TerrainCapsuleSweepResult {
|
|
138
|
+
return sweepTerrainRotatingCapsule(surface, center, center, radius, motion, options);
|
|
139
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
createSweepBox,
|
|
7
|
+
queryTerrainPolytope,
|
|
8
|
+
type TerrainPolytope,
|
|
9
|
+
type TerrainPolytopeSweepResult
|
|
10
|
+
} from './sweep-polytope';
|
|
11
|
+
import type {TerrainSurface} from './surface';
|
|
12
|
+
|
|
13
|
+
type Point = readonly [number, number, number];
|
|
14
|
+
type Surface = Pick<TerrainSurface, 'copyData' | 'origin'>;
|
|
15
|
+
|
|
16
|
+
export type TerrainRigidMotion = {
|
|
17
|
+
/** Pivot in the same Cartesian frame as the collider vertices. */
|
|
18
|
+
pivot: Point;
|
|
19
|
+
translation: Point;
|
|
20
|
+
/** Quaternion [x,y,z,w] relative to the initial pose. The shortest arc is used. */
|
|
21
|
+
rotation: readonly [number, number, number, number];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type TerrainRotationalSweepResult =
|
|
25
|
+
| {status: 'miss' | 'incomplete'; work: number}
|
|
26
|
+
| (Extract<TerrainPolytopeSweepResult, {status: 'hit'}> & {lowerFraction: number});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Sweep a convex hull along linear translation and shortest-arc rotation.
|
|
30
|
+
* An expanded midpoint SAT can exclude an interval. An unexpanded pose supplies
|
|
31
|
+
* a hit witness. Unresolved grazing or exhausted work yields incomplete.
|
|
32
|
+
*/
|
|
33
|
+
export function sweepTerrainRotatingPolytope(
|
|
34
|
+
surface: Surface,
|
|
35
|
+
collider: TerrainPolytope,
|
|
36
|
+
{pivot, translation, rotation}: TerrainRigidMotion,
|
|
37
|
+
{maxWork = 100_000, fractionTolerance = 1e-5}: {maxWork?: number; fractionTolerance?: number} = {}
|
|
38
|
+
): TerrainRotationalSweepResult {
|
|
39
|
+
const norm = Math.hypot(...rotation);
|
|
40
|
+
if (
|
|
41
|
+
pivot.length !== 3 ||
|
|
42
|
+
translation.length !== 3 ||
|
|
43
|
+
rotation.length !== 4 ||
|
|
44
|
+
!pivot.every(Number.isFinite) ||
|
|
45
|
+
!translation.every(Number.isFinite) ||
|
|
46
|
+
!(norm > 0 && Number.isFinite(norm)) ||
|
|
47
|
+
!Number.isSafeInteger(maxWork) ||
|
|
48
|
+
maxWork < 0 ||
|
|
49
|
+
!(fractionTolerance >= Number.EPSILON && fractionTolerance <= 1)
|
|
50
|
+
)
|
|
51
|
+
throw new RangeError('Invalid terrain rigid motion');
|
|
52
|
+
|
|
53
|
+
// Work in the surface frame before interpolating to preserve small offsets.
|
|
54
|
+
const localPivot = pivot.map((v, i) => v - surface.origin[i]);
|
|
55
|
+
const offsets = collider.vertices.map(v => v.map((x, i) => x - pivot[i]));
|
|
56
|
+
const radius = offsets.reduce((r, v) => Math.max(r, Math.hypot(...v)), 0);
|
|
57
|
+
const sign = rotation[3] < 0 ? -1 : 1;
|
|
58
|
+
const vectorNorm = Math.hypot(rotation[0], rotation[1], rotation[2]);
|
|
59
|
+
const angle = 2 * Math.atan2(vectorNorm, Math.abs(rotation[3]));
|
|
60
|
+
const speed = Math.hypot(...translation) + angle * radius;
|
|
61
|
+
if (!Number.isFinite(speed)) throw new RangeError('Terrain rigid motion overflow');
|
|
62
|
+
|
|
63
|
+
const data = surface.copyData();
|
|
64
|
+
if (angle === 0) {
|
|
65
|
+
const result = queryTerrainPolytope(data, surface.origin, collider, translation, maxWork);
|
|
66
|
+
return result.status === 'hit' ? {...result, lowerFraction: result.fraction} : result;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const [x, y, z] = rotation.slice(0, 3).map(v => (v / vectorNorm) * sign);
|
|
70
|
+
const zero = [0, 0, 0] as const;
|
|
71
|
+
let work = 0;
|
|
72
|
+
const pose = (t: number): TerrainPolytope => {
|
|
73
|
+
const sin = Math.sin(angle * t);
|
|
74
|
+
const cos = Math.cos(angle * t);
|
|
75
|
+
return {
|
|
76
|
+
faces: collider.faces,
|
|
77
|
+
vertices: offsets.map(([a, b, c]): Point => {
|
|
78
|
+
const projection = (x * a + y * b + z * c) * (1 - cos);
|
|
79
|
+
return [
|
|
80
|
+
localPivot[0] + translation[0] * t + a * cos + (y * c - z * b) * sin + x * projection,
|
|
81
|
+
localPivot[1] + translation[1] * t + b * cos + (z * a - x * c) * sin + y * projection,
|
|
82
|
+
localPivot[2] + translation[2] * t + c * cos + (x * b - y * a) * sin + z * projection
|
|
83
|
+
];
|
|
84
|
+
})
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
const probe = (shape: TerrainPolytope, padding = 0) => {
|
|
88
|
+
if (work >= maxWork) return {status: 'incomplete', work: 0} as const;
|
|
89
|
+
work++;
|
|
90
|
+
const result = queryTerrainPolytope(data, zero, shape, zero, maxWork - work, padding);
|
|
91
|
+
work += result.work;
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
const initial = probe(pose(0));
|
|
95
|
+
if (initial.status === 'hit') return {...initial, lowerFraction: 0, work};
|
|
96
|
+
if (initial.status === 'incomplete') return {status: 'incomplete', work};
|
|
97
|
+
|
|
98
|
+
let clearUntil = 0;
|
|
99
|
+
let witness: Extract<TerrainPolytopeSweepResult, {status: 'hit'}> | undefined;
|
|
100
|
+
const pending: [number, number][] = [[0, 1]];
|
|
101
|
+
while (pending.length) {
|
|
102
|
+
if (witness && witness.fraction - clearUntil <= fractionTolerance)
|
|
103
|
+
return {...witness, lowerFraction: clearUntil, work};
|
|
104
|
+
const [lo, hi] = pending.pop()!;
|
|
105
|
+
const mid = lo + (hi - lo) / 2;
|
|
106
|
+
const shape = pose(mid);
|
|
107
|
+
const padding = speed * Math.max(mid - lo, hi - mid);
|
|
108
|
+
const expanded = probe(shape, padding + 8 * Number.EPSILON * (radius + padding));
|
|
109
|
+
if (expanded.status === 'miss') {
|
|
110
|
+
clearUntil = hi;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (expanded.status === 'incomplete') return {status: 'incomplete', work};
|
|
114
|
+
const hit = probe(shape);
|
|
115
|
+
if (hit.status === 'incomplete') return {status: 'incomplete', work};
|
|
116
|
+
if (hit.status === 'hit') {
|
|
117
|
+
witness = {...hit, fraction: mid};
|
|
118
|
+
if (mid - clearUntil <= fractionTolerance)
|
|
119
|
+
return {...witness, lowerFraction: clearUntil, work};
|
|
120
|
+
pending.push([lo, mid]);
|
|
121
|
+
} else if (hi - clearUntil <= fractionTolerance) {
|
|
122
|
+
const end = witness?.fraction === hi ? witness : probe(pose(hi));
|
|
123
|
+
if (end?.status === 'hit') return {...end, fraction: hi, lowerFraction: clearUntil, work};
|
|
124
|
+
if (hi - lo <= fractionTolerance / 4) return {status: 'incomplete', work};
|
|
125
|
+
pending.push([mid, hi], [lo, mid]);
|
|
126
|
+
} else {
|
|
127
|
+
if (mid === lo || mid === hi || hi - lo <= fractionTolerance / 4)
|
|
128
|
+
return {status: 'incomplete', work};
|
|
129
|
+
pending.push([mid, hi], [lo, mid]);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return witness ? {...witness, lowerFraction: clearUntil, work} : {status: 'miss', work};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Rotational sweep of a box that starts axis-aligned. */
|
|
136
|
+
export function sweepTerrainRotatingBox(
|
|
137
|
+
surface: Surface,
|
|
138
|
+
center: Point,
|
|
139
|
+
halfExtents: Point,
|
|
140
|
+
motion: TerrainRigidMotion,
|
|
141
|
+
options?: {maxWork?: number; fractionTolerance?: number}
|
|
142
|
+
): TerrainRotationalSweepResult {
|
|
143
|
+
return sweepTerrainRotatingPolytope(
|
|
144
|
+
surface,
|
|
145
|
+
createSweepBox(center, halfExtents),
|
|
146
|
+
motion,
|
|
147
|
+
options
|
|
148
|
+
);
|
|
149
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** Outlet labels and upstream counts for a terrain receiver forest. */
|
|
6
|
+
export type TerrainWatershedAccumulation = {
|
|
7
|
+
/** Row-major outlet index, or -1 for excluded cells. */
|
|
8
|
+
terminal: Int32Array;
|
|
9
|
+
/** Number of contributing cells, including the cell itself. Excluded cells have zero. */
|
|
10
|
+
contributingCells: Uint32Array;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** Controls allocation for watershed accumulation. */
|
|
14
|
+
export type TerrainWatershedAccumulationOptions = {
|
|
15
|
+
/** Limit before allocating working buffers. */
|
|
16
|
+
maxCells?: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Accumulates a receiver forest such as that returned by fillTerrainDepressions.
|
|
21
|
+
* Each entry is a receiver index, -1 for an outlet, or -2 for an excluded cell.
|
|
22
|
+
* createTerrainDrainage uses -1 for nodata. Map nodata cells to -2 before calling.
|
|
23
|
+
* Rejects cycles and links to excluded cells. Time and storage are O(cell count).
|
|
24
|
+
*/
|
|
25
|
+
export function accumulateTerrainWatersheds(
|
|
26
|
+
receiver: Int32Array,
|
|
27
|
+
{maxCells = 4_194_304}: TerrainWatershedAccumulationOptions = {}
|
|
28
|
+
): TerrainWatershedAccumulation {
|
|
29
|
+
const count = receiver.length;
|
|
30
|
+
if (!Number.isSafeInteger(maxCells) || maxCells < 0 || count > maxCells || count > 0x7fffffff)
|
|
31
|
+
throw new RangeError('Terrain watershed accumulation exceeds its cell budget');
|
|
32
|
+
|
|
33
|
+
const incoming = new Uint32Array(count);
|
|
34
|
+
const contributingCells = new Uint32Array(count);
|
|
35
|
+
const terminal = new Int32Array(count).fill(-1);
|
|
36
|
+
const queue = new Int32Array(count);
|
|
37
|
+
let active = 0;
|
|
38
|
+
for (let i = 0; i < count; i++) {
|
|
39
|
+
const next = receiver[i];
|
|
40
|
+
if (next === -2) continue;
|
|
41
|
+
if (next < -1 || next >= count || (next >= 0 && receiver[next] === -2))
|
|
42
|
+
throw new RangeError('Invalid terrain watershed receiver');
|
|
43
|
+
active++;
|
|
44
|
+
contributingCells[i] = 1;
|
|
45
|
+
if (next >= 0) incoming[next]++;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let end = 0;
|
|
49
|
+
for (let i = 0; i < count; i++) {
|
|
50
|
+
if (contributingCells[i] && !incoming[i]) queue[end++] = i;
|
|
51
|
+
}
|
|
52
|
+
for (let cursor = 0; cursor < end; cursor++) {
|
|
53
|
+
const i = queue[cursor];
|
|
54
|
+
const next = receiver[i];
|
|
55
|
+
if (next < 0) continue;
|
|
56
|
+
contributingCells[next] += contributingCells[i];
|
|
57
|
+
if (--incoming[next] === 0) queue[end++] = next;
|
|
58
|
+
}
|
|
59
|
+
if (end !== active) throw new RangeError('Terrain watershed receiver graph contains a cycle');
|
|
60
|
+
|
|
61
|
+
for (let cursor = end - 1; cursor >= 0; cursor--) {
|
|
62
|
+
const i = queue[cursor];
|
|
63
|
+
const next = receiver[i];
|
|
64
|
+
terminal[i] = next < 0 ? i : terminal[next];
|
|
65
|
+
}
|
|
66
|
+
return {terminal, contributingCells};
|
|
67
|
+
}
|
package/src/turf/expressions.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {DataType, Precision, makeData, makeVector, type Field} from 'apache-arrow';
|
|
6
|
-
import type {ArrowTableFunction} from '@math.gl/
|
|
6
|
+
import type {ArrowTableFunction} from '@math.gl/sql/arrow';
|
|
7
7
|
import {makeGeoArrowColumnFromArrowVector} from '@math.gl/arrow/geoarrow';
|
|
8
8
|
import {isGeoArrowValueValid, type GeoArrowColumn} from '@math.gl/arrow/geoarrow-utils';
|
|
9
9
|
import type {TurfBatchResult} from '../turf';
|