@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,118 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import { sweepTerrainCapsule } from "./sweep-capsule.js";
|
|
5
|
+
/**
|
|
6
|
+
* Bracket first contact for a capsule under linear pivot translation and shortest-arc
|
|
7
|
+
* rotation. Coincident axis endpoints describe a sphere, including an off-pivot
|
|
8
|
+
* sphere whose center follows a curved path. Unresolved tangency returns incomplete.
|
|
9
|
+
* The witness is an axis/triangle pair within the radius at the upper fraction.
|
|
10
|
+
*/
|
|
11
|
+
export function sweepTerrainRotatingCapsule(surface, start, end, radius, { pivot, translation, rotation }, { maxWork = 100000, fractionTolerance = 1e-5 } = {}) {
|
|
12
|
+
const norm = Math.hypot(...rotation);
|
|
13
|
+
if (![start, end, pivot, translation].every(p => p.length === 3 && p.every(Number.isFinite)) ||
|
|
14
|
+
rotation.length !== 4 ||
|
|
15
|
+
!(norm > 0 && Number.isFinite(norm)) ||
|
|
16
|
+
!Number.isFinite(radius) ||
|
|
17
|
+
radius < 0 ||
|
|
18
|
+
!Number.isSafeInteger(maxWork) ||
|
|
19
|
+
maxWork < 0 ||
|
|
20
|
+
!(fractionTolerance >= Number.EPSILON && fractionTolerance <= 1))
|
|
21
|
+
throw new RangeError('Invalid terrain capsule rigid motion');
|
|
22
|
+
const sign = rotation[3] < 0 ? -1 : 1;
|
|
23
|
+
const axisLength = Math.hypot(rotation[0], rotation[1], rotation[2]);
|
|
24
|
+
const angle = 2 * Math.atan2(axisLength, Math.abs(rotation[3]));
|
|
25
|
+
if (angle === 0) {
|
|
26
|
+
return sweepTerrainCapsule(surface, start, end, translation, radius, {
|
|
27
|
+
maxWork,
|
|
28
|
+
fractionTolerance
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const x = (rotation[0] / axisLength) * sign;
|
|
32
|
+
const y = (rotation[1] / axisLength) * sign;
|
|
33
|
+
const z = (rotation[2] / axisLength) * sign;
|
|
34
|
+
const offsets = [start, end].map(p => p.map((v, i) => v - pivot[i]));
|
|
35
|
+
// A segment is a convex combination of its endpoints. The capsule's spherical
|
|
36
|
+
// dilation is rotation invariant, so only the axis motion contributes here.
|
|
37
|
+
const reach = Math.max(...offsets.map(p => Math.hypot(...p)));
|
|
38
|
+
const speed = Math.hypot(...translation) + angle * reach;
|
|
39
|
+
const scale = Math.max(Math.hypot(...pivot), reach, speed, radius);
|
|
40
|
+
if (!Number.isFinite(scale))
|
|
41
|
+
throw new RangeError('Terrain capsule rigid motion overflow');
|
|
42
|
+
let work = 0;
|
|
43
|
+
/** Query the axis at an exact pose, charging both the probe and index work. */
|
|
44
|
+
function probe(t) {
|
|
45
|
+
if (work >= maxWork)
|
|
46
|
+
return null;
|
|
47
|
+
work++;
|
|
48
|
+
const sin = Math.sin(angle * t);
|
|
49
|
+
const cos = Math.cos(angle * t);
|
|
50
|
+
const [a, b] = t === 0
|
|
51
|
+
? [start, end]
|
|
52
|
+
: offsets.map(([u, v, w]) => {
|
|
53
|
+
const d = (x * u + y * v + z * w) * (1 - cos);
|
|
54
|
+
const pos = [
|
|
55
|
+
pivot[0] + (translation[0] * t + u * cos + (y * w - z * v) * sin + x * d),
|
|
56
|
+
pivot[1] + (translation[1] * t + v * cos + (z * u - x * w) * sin + y * d),
|
|
57
|
+
pivot[2] + (translation[2] * t + w * cos + (x * v - y * u) * sin + z * d)
|
|
58
|
+
];
|
|
59
|
+
if (!pos.every(Number.isFinite))
|
|
60
|
+
throw new RangeError('Terrain capsule pose overflow');
|
|
61
|
+
return pos;
|
|
62
|
+
});
|
|
63
|
+
const query = surface.nearestSegmentQuery(a, b, { maxWork: maxWork - work });
|
|
64
|
+
work += query.work;
|
|
65
|
+
return query;
|
|
66
|
+
}
|
|
67
|
+
const initial = probe(0);
|
|
68
|
+
if (initial?.result && initial.result.distance <= radius)
|
|
69
|
+
return { status: 'hit', fraction: 0, lowerFraction: 0, work, contact: initial.result };
|
|
70
|
+
if (!initial?.complete)
|
|
71
|
+
return { status: 'incomplete', work };
|
|
72
|
+
if (!initial.result || speed === 0)
|
|
73
|
+
return { status: 'miss', work };
|
|
74
|
+
let clearUntil = 0;
|
|
75
|
+
let witness;
|
|
76
|
+
const pending = [[0, 1]];
|
|
77
|
+
while (pending.length) {
|
|
78
|
+
if (witness && witness.fraction - clearUntil <= fractionTolerance)
|
|
79
|
+
return { status: 'hit', lowerFraction: clearUntil, work, ...witness };
|
|
80
|
+
const [lo, hi] = pending.pop();
|
|
81
|
+
const mid = lo + (hi - lo) / 2;
|
|
82
|
+
const query = probe(mid);
|
|
83
|
+
const contact = query?.result;
|
|
84
|
+
if (contact && contact.distance <= radius) {
|
|
85
|
+
witness = { fraction: mid, contact };
|
|
86
|
+
if (mid - clearUntil <= fractionTolerance)
|
|
87
|
+
return { status: 'hit', lowerFraction: clearUntil, work, ...witness };
|
|
88
|
+
if (mid === lo || mid === hi)
|
|
89
|
+
return { status: 'incomplete', work };
|
|
90
|
+
pending.push([lo, mid]);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (!query?.complete)
|
|
94
|
+
return { status: 'incomplete', work };
|
|
95
|
+
const travel = speed * Math.max(mid - lo, hi - mid);
|
|
96
|
+
const allowance = 16 * Number.EPSILON * Math.max(scale, contact?.distance ?? 0);
|
|
97
|
+
if (!contact || contact.distance - radius > travel + allowance) {
|
|
98
|
+
clearUntil = hi;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (hi - clearUntil <= fractionTolerance) {
|
|
102
|
+
const final = witness?.fraction === hi ? witness.contact : probe(hi)?.result;
|
|
103
|
+
if (final && final.distance <= radius)
|
|
104
|
+
return { status: 'hit', fraction: hi, lowerFraction: clearUntil, work, contact: final };
|
|
105
|
+
}
|
|
106
|
+
if (mid === lo || mid === hi || hi - lo <= fractionTolerance / 4)
|
|
107
|
+
return { status: 'incomplete', work };
|
|
108
|
+
pending.push([mid, hi], [lo, mid]);
|
|
109
|
+
}
|
|
110
|
+
return witness
|
|
111
|
+
? { status: 'hit', lowerFraction: clearUntil, work, ...witness }
|
|
112
|
+
: { status: 'miss', work };
|
|
113
|
+
}
|
|
114
|
+
/** Sweep a sphere whose center may orbit an offset rigid-motion pivot. */
|
|
115
|
+
export function sweepTerrainRotatingSphere(surface, center, radius, motion, options) {
|
|
116
|
+
return sweepTerrainRotatingCapsule(surface, center, center, radius, motion, options);
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=sweep-rotating-capsule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sweep-rotating-capsule.js","sourceRoot":"","sources":["../../src/terrain/sweep-rotating-capsule.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EAAC,mBAAmB,EAAiC,2BAAwB;AAQpF;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CACzC,OAAoD,EACpD,KAAY,EACZ,GAAU,EACV,MAAc,EACd,EAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAqB,EAClD,EAAC,OAAO,GAAG,MAAO,EAAE,iBAAiB,GAAG,IAAI,KAA+B,EAAE;IAE7E,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAC;IACrC,IACE,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACxF,QAAQ,CAAC,MAAM,KAAK,CAAC;QACrB,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QACxB,MAAM,GAAG,CAAC;QACV,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC;QAC9B,OAAO,GAAG,CAAC;QACX,CAAC,CAAC,iBAAiB,IAAI,MAAM,CAAC,OAAO,IAAI,iBAAiB,IAAI,CAAC,CAAC;QAEhE,MAAM,IAAI,UAAU,CAAC,sCAAsC,CAAC,CAAC;IAE/D,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CA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D,CAAC,CAAC,EAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAC,CAAC;AAC7B,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,0BAA0B,CACxC,OAAoD,EACpD,MAAa,EACb,MAAc,EACd,MAA0B,EAC1B,OAAmC;IAEnC,OAAO,2BAA2B,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACvF,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type TerrainPolytope, type TerrainPolytopeSweepResult } from "./sweep-polytope.js";
|
|
2
|
+
import type { TerrainSurface } from "./surface.js";
|
|
3
|
+
type Point = readonly [number, number, number];
|
|
4
|
+
type Surface = Pick<TerrainSurface, 'copyData' | 'origin'>;
|
|
5
|
+
export type TerrainRigidMotion = {
|
|
6
|
+
/** Pivot in the same Cartesian frame as the collider vertices. */
|
|
7
|
+
pivot: Point;
|
|
8
|
+
translation: Point;
|
|
9
|
+
/** Quaternion [x,y,z,w] relative to the initial pose. The shortest arc is used. */
|
|
10
|
+
rotation: readonly [number, number, number, number];
|
|
11
|
+
};
|
|
12
|
+
export type TerrainRotationalSweepResult = {
|
|
13
|
+
status: 'miss' | 'incomplete';
|
|
14
|
+
work: number;
|
|
15
|
+
} | (Extract<TerrainPolytopeSweepResult, {
|
|
16
|
+
status: 'hit';
|
|
17
|
+
}> & {
|
|
18
|
+
lowerFraction: number;
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Sweep a convex hull along linear translation and shortest-arc rotation.
|
|
22
|
+
* An expanded midpoint SAT can exclude an interval. An unexpanded pose supplies
|
|
23
|
+
* a hit witness. Unresolved grazing or exhausted work yields incomplete.
|
|
24
|
+
*/
|
|
25
|
+
export declare function sweepTerrainRotatingPolytope(surface: Surface, collider: TerrainPolytope, { pivot, translation, rotation }: TerrainRigidMotion, { maxWork, fractionTolerance }?: {
|
|
26
|
+
maxWork?: number;
|
|
27
|
+
fractionTolerance?: number;
|
|
28
|
+
}): TerrainRotationalSweepResult;
|
|
29
|
+
/** Rotational sweep of a box that starts axis-aligned. */
|
|
30
|
+
export declare function sweepTerrainRotatingBox(surface: Surface, center: Point, halfExtents: Point, motion: TerrainRigidMotion, options?: {
|
|
31
|
+
maxWork?: number;
|
|
32
|
+
fractionTolerance?: number;
|
|
33
|
+
}): TerrainRotationalSweepResult;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=sweep-rotation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sweep-rotation.d.ts","sourceRoot":"","sources":["../../src/terrain/sweep-rotation.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,0BAA0B,EAChC,4BAAyB;AAC1B,OAAO,KAAK,EAAC,cAAc,EAAC,qBAAkB;AAE9C,KAAK,KAAK,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAC/C,KAAK,OAAO,GAAG,IAAI,CAAC,cAAc,EAAE,UAAU,GAAG,QAAQ,CAAC,CAAC;AAE3D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,kEAAkE;IAClE,KAAK,EAAE,KAAK,CAAC;IACb,WAAW,EAAE,KAAK,CAAC;IACnB,mFAAmF;IACnF,QAAQ,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,4BAA4B,GACpC;IAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,GAC7C,CAAC,OAAO,CAAC,0BAA0B,EAAE;IAAC,MAAM,EAAE,KAAK,CAAA;CAAC,CAAC,GAAG;IAAC,aAAa,EAAE,MAAM,CAAA;CAAC,CAAC,CAAC;AAErF;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,eAAe,EACzB,EAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAC,EAAE,kBAAkB,EAClD,EAAC,OAAiB,EAAE,iBAAwB,EAAC,GAAE;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAAM,GACjG,4BAA4B,CA+F9B;AAED,0DAA0D;AAC1D,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,KAAK,EACb,WAAW,EAAE,KAAK,EAClB,MAAM,EAAE,kBAAkB,EAC1B,OAAO,CAAC,EAAE;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAAC,GACvD,4BAA4B,CAO9B"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import { createSweepBox, queryTerrainPolytope } from "./sweep-polytope.js";
|
|
5
|
+
/**
|
|
6
|
+
* Sweep a convex hull along linear translation and shortest-arc rotation.
|
|
7
|
+
* An expanded midpoint SAT can exclude an interval. An unexpanded pose supplies
|
|
8
|
+
* a hit witness. Unresolved grazing or exhausted work yields incomplete.
|
|
9
|
+
*/
|
|
10
|
+
export function sweepTerrainRotatingPolytope(surface, collider, { pivot, translation, rotation }, { maxWork = 100000, fractionTolerance = 1e-5 } = {}) {
|
|
11
|
+
const norm = Math.hypot(...rotation);
|
|
12
|
+
if (pivot.length !== 3 ||
|
|
13
|
+
translation.length !== 3 ||
|
|
14
|
+
rotation.length !== 4 ||
|
|
15
|
+
!pivot.every(Number.isFinite) ||
|
|
16
|
+
!translation.every(Number.isFinite) ||
|
|
17
|
+
!(norm > 0 && Number.isFinite(norm)) ||
|
|
18
|
+
!Number.isSafeInteger(maxWork) ||
|
|
19
|
+
maxWork < 0 ||
|
|
20
|
+
!(fractionTolerance >= Number.EPSILON && fractionTolerance <= 1))
|
|
21
|
+
throw new RangeError('Invalid terrain rigid motion');
|
|
22
|
+
// Work in the surface frame before interpolating to preserve small offsets.
|
|
23
|
+
const localPivot = pivot.map((v, i) => v - surface.origin[i]);
|
|
24
|
+
const offsets = collider.vertices.map(v => v.map((x, i) => x - pivot[i]));
|
|
25
|
+
const radius = offsets.reduce((r, v) => Math.max(r, Math.hypot(...v)), 0);
|
|
26
|
+
const sign = rotation[3] < 0 ? -1 : 1;
|
|
27
|
+
const vectorNorm = Math.hypot(rotation[0], rotation[1], rotation[2]);
|
|
28
|
+
const angle = 2 * Math.atan2(vectorNorm, Math.abs(rotation[3]));
|
|
29
|
+
const speed = Math.hypot(...translation) + angle * radius;
|
|
30
|
+
if (!Number.isFinite(speed))
|
|
31
|
+
throw new RangeError('Terrain rigid motion overflow');
|
|
32
|
+
const data = surface.copyData();
|
|
33
|
+
if (angle === 0) {
|
|
34
|
+
const result = queryTerrainPolytope(data, surface.origin, collider, translation, maxWork);
|
|
35
|
+
return result.status === 'hit' ? { ...result, lowerFraction: result.fraction } : result;
|
|
36
|
+
}
|
|
37
|
+
const [x, y, z] = rotation.slice(0, 3).map(v => (v / vectorNorm) * sign);
|
|
38
|
+
const zero = [0, 0, 0];
|
|
39
|
+
let work = 0;
|
|
40
|
+
const pose = (t) => {
|
|
41
|
+
const sin = Math.sin(angle * t);
|
|
42
|
+
const cos = Math.cos(angle * t);
|
|
43
|
+
return {
|
|
44
|
+
faces: collider.faces,
|
|
45
|
+
vertices: offsets.map(([a, b, c]) => {
|
|
46
|
+
const projection = (x * a + y * b + z * c) * (1 - cos);
|
|
47
|
+
return [
|
|
48
|
+
localPivot[0] + translation[0] * t + a * cos + (y * c - z * b) * sin + x * projection,
|
|
49
|
+
localPivot[1] + translation[1] * t + b * cos + (z * a - x * c) * sin + y * projection,
|
|
50
|
+
localPivot[2] + translation[2] * t + c * cos + (x * b - y * a) * sin + z * projection
|
|
51
|
+
];
|
|
52
|
+
})
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const probe = (shape, padding = 0) => {
|
|
56
|
+
if (work >= maxWork)
|
|
57
|
+
return { status: 'incomplete', work: 0 };
|
|
58
|
+
work++;
|
|
59
|
+
const result = queryTerrainPolytope(data, zero, shape, zero, maxWork - work, padding);
|
|
60
|
+
work += result.work;
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
const initial = probe(pose(0));
|
|
64
|
+
if (initial.status === 'hit')
|
|
65
|
+
return { ...initial, lowerFraction: 0, work };
|
|
66
|
+
if (initial.status === 'incomplete')
|
|
67
|
+
return { status: 'incomplete', work };
|
|
68
|
+
let clearUntil = 0;
|
|
69
|
+
let witness;
|
|
70
|
+
const pending = [[0, 1]];
|
|
71
|
+
while (pending.length) {
|
|
72
|
+
if (witness && witness.fraction - clearUntil <= fractionTolerance)
|
|
73
|
+
return { ...witness, lowerFraction: clearUntil, work };
|
|
74
|
+
const [lo, hi] = pending.pop();
|
|
75
|
+
const mid = lo + (hi - lo) / 2;
|
|
76
|
+
const shape = pose(mid);
|
|
77
|
+
const padding = speed * Math.max(mid - lo, hi - mid);
|
|
78
|
+
const expanded = probe(shape, padding + 8 * Number.EPSILON * (radius + padding));
|
|
79
|
+
if (expanded.status === 'miss') {
|
|
80
|
+
clearUntil = hi;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (expanded.status === 'incomplete')
|
|
84
|
+
return { status: 'incomplete', work };
|
|
85
|
+
const hit = probe(shape);
|
|
86
|
+
if (hit.status === 'incomplete')
|
|
87
|
+
return { status: 'incomplete', work };
|
|
88
|
+
if (hit.status === 'hit') {
|
|
89
|
+
witness = { ...hit, fraction: mid };
|
|
90
|
+
if (mid - clearUntil <= fractionTolerance)
|
|
91
|
+
return { ...witness, lowerFraction: clearUntil, work };
|
|
92
|
+
pending.push([lo, mid]);
|
|
93
|
+
}
|
|
94
|
+
else if (hi - clearUntil <= fractionTolerance) {
|
|
95
|
+
const end = witness?.fraction === hi ? witness : probe(pose(hi));
|
|
96
|
+
if (end?.status === 'hit')
|
|
97
|
+
return { ...end, fraction: hi, lowerFraction: clearUntil, work };
|
|
98
|
+
if (hi - lo <= fractionTolerance / 4)
|
|
99
|
+
return { status: 'incomplete', work };
|
|
100
|
+
pending.push([mid, hi], [lo, mid]);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
if (mid === lo || mid === hi || hi - lo <= fractionTolerance / 4)
|
|
104
|
+
return { status: 'incomplete', work };
|
|
105
|
+
pending.push([mid, hi], [lo, mid]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return witness ? { ...witness, lowerFraction: clearUntil, work } : { status: 'miss', work };
|
|
109
|
+
}
|
|
110
|
+
/** Rotational sweep of a box that starts axis-aligned. */
|
|
111
|
+
export function sweepTerrainRotatingBox(surface, center, halfExtents, motion, options) {
|
|
112
|
+
return sweepTerrainRotatingPolytope(surface, createSweepBox(center, halfExtents), motion, options);
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=sweep-rotation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sweep-rotation.js","sourceRoot":"","sources":["../../src/terrain/sweep-rotation.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EACL,cAAc,EACd,oBAAoB,EAGrB,4BAAyB;AAkB1B;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAC1C,OAAgB,EAChB,QAAyB,EACzB,EAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAqB,EAClD,EAAC,OAAO,GAAG,MAAO,EAAE,iBAAiB,GAAG,IAAI,KAAoD,EAAE;IAElG,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAC;IACrC,IACE,KAAK,CAAC,MAAM,KAAK,CAAC;QAClB,WAAW,CAAC,MAA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AAY,EAAE,IAAI,EAAC,CAAC;YAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;QACrC,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,KAAK,EAAE,IAAI,GAAG,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,iBAAiB,GAAG,CAAC;gBAC9D,OAAO,EAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAC,CAAC;YACtC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC,CAAC,CAAC,EAAC,GAAG,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,IAAI,EAAC,CAAC,CAAC,CAAC,EAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAC,CAAC;AAC1F,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,uBAAuB,CACrC,OAAgB,EAChB,MAAa,EACb,WAAkB,EAClB,MAA0B,EAC1B,OAAwD;IAExD,OAAO,4BAA4B,CACjC,OAAO,EACP,cAAc,CAAC,MAAM,EAAE,WAAW,CAAC,EACnC,MAAM,EACN,OAAO,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Outlet labels and upstream counts for a terrain receiver forest. */
|
|
2
|
+
export type TerrainWatershedAccumulation = {
|
|
3
|
+
/** Row-major outlet index, or -1 for excluded cells. */
|
|
4
|
+
terminal: Int32Array;
|
|
5
|
+
/** Number of contributing cells, including the cell itself. Excluded cells have zero. */
|
|
6
|
+
contributingCells: Uint32Array;
|
|
7
|
+
};
|
|
8
|
+
/** Controls allocation for watershed accumulation. */
|
|
9
|
+
export type TerrainWatershedAccumulationOptions = {
|
|
10
|
+
/** Limit before allocating working buffers. */
|
|
11
|
+
maxCells?: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Accumulates a receiver forest such as that returned by fillTerrainDepressions.
|
|
15
|
+
* Each entry is a receiver index, -1 for an outlet, or -2 for an excluded cell.
|
|
16
|
+
* createTerrainDrainage uses -1 for nodata. Map nodata cells to -2 before calling.
|
|
17
|
+
* Rejects cycles and links to excluded cells. Time and storage are O(cell count).
|
|
18
|
+
*/
|
|
19
|
+
export declare function accumulateTerrainWatersheds(receiver: Int32Array, { maxCells }?: TerrainWatershedAccumulationOptions): TerrainWatershedAccumulation;
|
|
20
|
+
//# sourceMappingURL=watershed-accumulation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watershed-accumulation.d.ts","sourceRoot":"","sources":["../../src/terrain/watershed-accumulation.ts"],"names":[],"mappings":"AAIA,uEAAuE;AACvE,MAAM,MAAM,4BAA4B,GAAG;IACzC,wDAAwD;IACxD,QAAQ,EAAE,UAAU,CAAC;IACrB,yFAAyF;IACzF,iBAAiB,EAAE,WAAW,CAAC;CAChC,CAAC;AAEF,sDAAsD;AACtD,MAAM,MAAM,mCAAmC,GAAG;IAChD,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,UAAU,EACpB,EAAC,QAAoB,EAAC,GAAE,mCAAwC,GAC/D,4BAA4B,CAuC9B"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
/**
|
|
5
|
+
* Accumulates a receiver forest such as that returned by fillTerrainDepressions.
|
|
6
|
+
* Each entry is a receiver index, -1 for an outlet, or -2 for an excluded cell.
|
|
7
|
+
* createTerrainDrainage uses -1 for nodata. Map nodata cells to -2 before calling.
|
|
8
|
+
* Rejects cycles and links to excluded cells. Time and storage are O(cell count).
|
|
9
|
+
*/
|
|
10
|
+
export function accumulateTerrainWatersheds(receiver, { maxCells = 4194304 } = {}) {
|
|
11
|
+
const count = receiver.length;
|
|
12
|
+
if (!Number.isSafeInteger(maxCells) || maxCells < 0 || count > maxCells || count > 0x7fffffff)
|
|
13
|
+
throw new RangeError('Terrain watershed accumulation exceeds its cell budget');
|
|
14
|
+
const incoming = new Uint32Array(count);
|
|
15
|
+
const contributingCells = new Uint32Array(count);
|
|
16
|
+
const terminal = new Int32Array(count).fill(-1);
|
|
17
|
+
const queue = new Int32Array(count);
|
|
18
|
+
let active = 0;
|
|
19
|
+
for (let i = 0; i < count; i++) {
|
|
20
|
+
const next = receiver[i];
|
|
21
|
+
if (next === -2)
|
|
22
|
+
continue;
|
|
23
|
+
if (next < -1 || next >= count || (next >= 0 && receiver[next] === -2))
|
|
24
|
+
throw new RangeError('Invalid terrain watershed receiver');
|
|
25
|
+
active++;
|
|
26
|
+
contributingCells[i] = 1;
|
|
27
|
+
if (next >= 0)
|
|
28
|
+
incoming[next]++;
|
|
29
|
+
}
|
|
30
|
+
let end = 0;
|
|
31
|
+
for (let i = 0; i < count; i++) {
|
|
32
|
+
if (contributingCells[i] && !incoming[i])
|
|
33
|
+
queue[end++] = i;
|
|
34
|
+
}
|
|
35
|
+
for (let cursor = 0; cursor < end; cursor++) {
|
|
36
|
+
const i = queue[cursor];
|
|
37
|
+
const next = receiver[i];
|
|
38
|
+
if (next < 0)
|
|
39
|
+
continue;
|
|
40
|
+
contributingCells[next] += contributingCells[i];
|
|
41
|
+
if (--incoming[next] === 0)
|
|
42
|
+
queue[end++] = next;
|
|
43
|
+
}
|
|
44
|
+
if (end !== active)
|
|
45
|
+
throw new RangeError('Terrain watershed receiver graph contains a cycle');
|
|
46
|
+
for (let cursor = end - 1; cursor >= 0; cursor--) {
|
|
47
|
+
const i = queue[cursor];
|
|
48
|
+
const next = receiver[i];
|
|
49
|
+
terminal[i] = next < 0 ? i : terminal[next];
|
|
50
|
+
}
|
|
51
|
+
return { terminal, contributingCells };
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=watershed-accumulation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watershed-accumulation.js","sourceRoot":"","sources":["../../src/terrain/watershed-accumulation.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAgB5D;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CACzC,QAAoB,EACpB,EAAC,QAAQ,GAAG,OAAS,KAAyC,EAAE;IAEhE,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC9B,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,IAAI,KAAK,GAAG,QAAQ,IAAI,KAAK,GAAG,UAAU;QAC3F,MAAM,IAAI,UAAU,CAAC,wDAAwD,CAAC,CAAC;IAEjF,MAAM,QAAQ,GAAG,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;IACxC,MAAM,iBAAiB,GAAG,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,IAAI,KAAK,CAAC,CAAC;YAAE,SAAS;QAC1B,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,QAAQ,CAAC,IAA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,CAAC;QACzB,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,EAAC,QAAQ,EAAE,iBAAiB,EAAC,CAAC;AACvC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Field } from 'apache-arrow';
|
|
2
|
-
import type { ArrowTableFunction } from '@math.gl/
|
|
2
|
+
import type { ArrowTableFunction } from '@math.gl/sql/arrow';
|
|
3
3
|
import { type GeoArrowColumn } from '@math.gl/arrow/geoarrow-utils';
|
|
4
4
|
import type { TurfBatchResult } from "../turf.js";
|
|
5
5
|
/** Adapter for row-preserving numeric/Boolean functions from @math.gl/geospatial/turf. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../../src/turf/expressions.ts"],"names":[],"mappings":"AAIA,OAAO,EAA4C,KAAK,KAAK,EAAC,MAAM,cAAc,CAAC;AACnF,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../../src/turf/expressions.ts"],"names":[],"mappings":"AAIA,OAAO,EAA4C,KAAK,KAAK,EAAC,MAAM,cAAc,CAAC;AACnF,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAuB,KAAK,cAAc,EAAC,MAAM,+BAA+B,CAAC;AACxF,OAAO,KAAK,EAAC,eAAe,EAAC,mBAAgB;AAE7C,0FAA0F;AAC1F,MAAM,MAAM,wBAAwB,CAAC,MAAM,SAAS,SAAS,KAAK,EAAE,GAAG,SAAS,KAAK,EAAE,IAAI;IACzF,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,uFAAuF;IACvF,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,MAAM,EAAE,KAAK,CAAC;IACd,+FAA+F;IAC/F,QAAQ,EAAE,CACR,GAAG,OAAO,EAAE;SAAE,KAAK,IAAI,MAAM,MAAM,GAAG,cAAc;KAAC,KAClD,eAAe,CAAC,YAAY,GAAG,UAAU,CAAC,CAAC;CACjD,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,CAAC,MAAM,SAAS,SAAS,KAAK,EAAE,EAC3E,OAAO,EAAE,wBAAwB,CAAC,MAAM,CAAC,GACxC,kBAAkB,CAiEpB"}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
-
"version": "5.0.0-beta.
|
|
9
|
+
"version": "5.0.0-beta.11",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"webgl",
|
|
12
12
|
"javascript",
|
|
@@ -1062,12 +1062,12 @@
|
|
|
1062
1062
|
],
|
|
1063
1063
|
"dependencies": {
|
|
1064
1064
|
"@mapbox/martini": "0.2.0",
|
|
1065
|
-
"@math.gl/arrow": "5.0.0-beta.
|
|
1066
|
-
"@math.gl/core": "5.0.0-beta.
|
|
1067
|
-
"@math.gl/
|
|
1068
|
-
"@math.gl/
|
|
1069
|
-
"@math.gl/tasks": "5.0.0-beta.
|
|
1070
|
-
"@math.gl/web-mercator": "5.0.0-beta.
|
|
1065
|
+
"@math.gl/arrow": "5.0.0-beta.11",
|
|
1066
|
+
"@math.gl/core": "5.0.0-beta.11",
|
|
1067
|
+
"@math.gl/geometry": "5.0.0-beta.11",
|
|
1068
|
+
"@math.gl/sql": "5.0.0-beta.11",
|
|
1069
|
+
"@math.gl/tasks": "5.0.0-beta.11",
|
|
1070
|
+
"@math.gl/web-mercator": "5.0.0-beta.11",
|
|
1071
1071
|
"cdt2d": "1.0.0",
|
|
1072
1072
|
"polygon-clipping": "0.15.7"
|
|
1073
1073
|
},
|
|
@@ -1080,5 +1080,5 @@
|
|
|
1080
1080
|
"proj4": "2.22.0"
|
|
1081
1081
|
},
|
|
1082
1082
|
"sideEffects": false,
|
|
1083
|
-
"gitHead": "
|
|
1083
|
+
"gitHead": "5f2da3c1b2c7ee38c4175c35698891ccaabaa668"
|
|
1084
1084
|
}
|
package/src/crs/index.ts
CHANGED
|
@@ -100,3 +100,10 @@ export type {
|
|
|
100
100
|
|
|
101
101
|
export {createCRSExecutionIdentity, getCRSExecutionKey} from './execution-identity';
|
|
102
102
|
export type {CRSExecutionIdentity} from './execution-identity';
|
|
103
|
+
|
|
104
|
+
export {
|
|
105
|
+
SPATIAL_REFERENCE_METADATA_KEY,
|
|
106
|
+
getSpatialReferenceMetadata,
|
|
107
|
+
setSpatialReferenceMetadata,
|
|
108
|
+
resolveSpatialReferenceMetadata
|
|
109
|
+
} from './spatial-reference-metadata';
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {createSpatialReference} from './spatial-reference';
|
|
6
|
+
import type {SpatialReference} from './spatial-reference';
|
|
7
|
+
|
|
8
|
+
/** JSON spatial reference for current coordinate values in schema or field metadata. */
|
|
9
|
+
export const SPATIAL_REFERENCE_METADATA_KEY = 'vis.gl:spatial_reference';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns a copy of metadata containing the spatial reference for current coordinate values.
|
|
13
|
+
* Other entries and caller-owned objects are preserved. Invalid descriptors throw.
|
|
14
|
+
*/
|
|
15
|
+
export function setSpatialReferenceMetadata(
|
|
16
|
+
metadata: ReadonlyMap<string, string> | undefined,
|
|
17
|
+
spatialReference: SpatialReference
|
|
18
|
+
): Map<string, string> {
|
|
19
|
+
validateSpatialReference(spatialReference);
|
|
20
|
+
const result = new Map(metadata);
|
|
21
|
+
result.set(SPATIAL_REFERENCE_METADATA_KEY, JSON.stringify(spatialReference));
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Reads an immutable spatial reference, or undefined when the metadata key is missing.
|
|
27
|
+
* Malformed JSON or descriptors throw; CRS definitions are not parsed or resolved.
|
|
28
|
+
*/
|
|
29
|
+
export function getSpatialReferenceMetadata(
|
|
30
|
+
metadata: ReadonlyMap<string, string> | undefined
|
|
31
|
+
): SpatialReference | undefined {
|
|
32
|
+
const value = metadata?.get(SPATIAL_REFERENCE_METADATA_KEY);
|
|
33
|
+
if (value === undefined) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
const reference: unknown = JSON.parse(value);
|
|
37
|
+
validateSpatialReference(reference);
|
|
38
|
+
return createSpatialReference(reference);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Resolves a coordinate field's declaration before the schema default.
|
|
43
|
+
* Explicit unknown or absent field references block inheritance. The caller identifies coordinate
|
|
44
|
+
* fields and handles format-specific metadata such as GeoArrow before using this convention.
|
|
45
|
+
*/
|
|
46
|
+
export function resolveSpatialReferenceMetadata(
|
|
47
|
+
schemaMetadata: ReadonlyMap<string, string> | undefined,
|
|
48
|
+
fieldMetadata?: ReadonlyMap<string, string>
|
|
49
|
+
): SpatialReference | undefined {
|
|
50
|
+
return getSpatialReferenceMetadata(fieldMetadata) ?? getSpatialReferenceMetadata(schemaMetadata);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Validate the descriptor envelope without importing a CRS parser or projection engine. */
|
|
54
|
+
function validateSpatialReference(value: unknown): asserts value is SpatialReference {
|
|
55
|
+
if (
|
|
56
|
+
!isObject(value) ||
|
|
57
|
+
!isReference(value['crs']) ||
|
|
58
|
+
(value['vertical'] !== undefined && !isReference(value['vertical'])) ||
|
|
59
|
+
!['geographic', 'geocentric', 'projected', 'local', 'unknown'].includes(
|
|
60
|
+
value['coordinateFrame'] as string
|
|
61
|
+
) ||
|
|
62
|
+
!isStringArray(value['coordinateOrder']) ||
|
|
63
|
+
(value['units'] !== undefined && !isStringArray(value['units'])) ||
|
|
64
|
+
(value['coordinateEpoch'] !== undefined &&
|
|
65
|
+
(typeof value['coordinateEpoch'] !== 'number' || !Number.isFinite(value['coordinateEpoch'])))
|
|
66
|
+
) {
|
|
67
|
+
throw new Error('Invalid spatial reference metadata');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Check known and unresolved reference variants, including alternate representations. */
|
|
72
|
+
function isReference(value: unknown): boolean {
|
|
73
|
+
if (
|
|
74
|
+
!isObject(value) ||
|
|
75
|
+
!['metadata', 'format-default', 'caller-override', 'legacy-assumption', 'unknown'].includes(
|
|
76
|
+
value['provenance'] as string
|
|
77
|
+
)
|
|
78
|
+
) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (value['state'] === 'unknown' || value['state'] === 'absent') {
|
|
82
|
+
return (
|
|
83
|
+
value['definition'] === undefined &&
|
|
84
|
+
value['representation'] === undefined &&
|
|
85
|
+
value['alternatives'] === undefined
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return (
|
|
89
|
+
(value['state'] === 'explicit' || value['state'] === 'default') &&
|
|
90
|
+
isDefinition(value) &&
|
|
91
|
+
(value['alternatives'] === undefined ||
|
|
92
|
+
(Array.isArray(value['alternatives']) && value['alternatives'].every(isDefinition)))
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Check representation and serialized value shape without validating CRS semantics. */
|
|
97
|
+
function isDefinition(value: unknown): boolean {
|
|
98
|
+
if (!isObject(value)) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
if (value['representation'] === 'projjson') {
|
|
102
|
+
return isObject(value['definition']);
|
|
103
|
+
}
|
|
104
|
+
return (
|
|
105
|
+
['identifier', 'wkt', 'proj-string', 'opaque'].includes(value['representation'] as string) &&
|
|
106
|
+
typeof value['definition'] === 'string'
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Exclude arrays and null from JSON objects. */
|
|
111
|
+
function isObject(value: unknown): value is Record<string, unknown> {
|
|
112
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Check coordinate order and unit arrays. */
|
|
116
|
+
function isStringArray(value: unknown): value is string[] {
|
|
117
|
+
return Array.isArray(value) && value['every'](item => typeof item === 'string');
|
|
118
|
+
}
|
package/src/expressions.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {eastNorthUpToFixedFrame} from './ellipsoid-transforms';
|
|
|
7
7
|
import {Ellipsoid} from './ellipsoid';
|
|
8
8
|
import {isWGS84} from './type-utils';
|
|
9
9
|
import {toDegrees, toRadians} from '@math.gl/core';
|
|
10
|
-
import type {ExpressionFunctionLibrary} from '@math.gl/expressions';
|
|
10
|
+
import type {ExpressionFunctionLibrary} from '@math.gl/sql/expressions';
|
|
11
11
|
|
|
12
12
|
/** WGS84 ellipsoid helpers available to the expression evaluator. */
|
|
13
13
|
export const GEOSPATIAL_FUNCTION_LIBRARY: ExpressionFunctionLibrary = {
|
package/src/index.ts
CHANGED
|
@@ -392,6 +392,7 @@ export {
|
|
|
392
392
|
export {
|
|
393
393
|
selectTerrainLod,
|
|
394
394
|
type TerrainLodCandidate,
|
|
395
|
+
type TerrainLodCertifiedView,
|
|
395
396
|
type TerrainLodView
|
|
396
397
|
} from './terrain/lod-select';
|
|
397
398
|
export {stitchTerrainLodCut, type TerrainLodSeam} from './terrain/lod-stitch';
|
|
@@ -433,6 +434,10 @@ export {
|
|
|
433
434
|
type TerrainPolytopeSweepResult
|
|
434
435
|
} from './terrain/sweep-polytope';
|
|
435
436
|
|
|
437
|
+
export {
|
|
438
|
+
sweepTerrainRotatingCapsule,
|
|
439
|
+
sweepTerrainRotatingSphere
|
|
440
|
+
} from './terrain/sweep-rotating-capsule';
|
|
436
441
|
export {sweepTerrainCylinder} from './terrain/sweep-cylinder';
|
|
437
442
|
|
|
438
443
|
export {sweepTerrainPlane} from './terrain/sweep-plane';
|
|
@@ -443,3 +448,55 @@ export {
|
|
|
443
448
|
type TerrainPoleIncidence,
|
|
444
449
|
type TerrainPoleCoverage
|
|
445
450
|
} from './terrain/geographic-poles';
|
|
451
|
+
|
|
452
|
+
export {
|
|
453
|
+
sweepTerrainRotatingBox,
|
|
454
|
+
sweepTerrainRotatingPolytope,
|
|
455
|
+
type TerrainRigidMotion,
|
|
456
|
+
type TerrainRotationalSweepResult
|
|
457
|
+
} from './terrain/sweep-rotation';
|
|
458
|
+
|
|
459
|
+
export {
|
|
460
|
+
boundTerrainLodScreenError,
|
|
461
|
+
type TerrainLodErrorBounds,
|
|
462
|
+
type TerrainLodProjection
|
|
463
|
+
} from './terrain/lod-screen-error';
|
|
464
|
+
|
|
465
|
+
export {
|
|
466
|
+
createTerrainRegionalViewshed,
|
|
467
|
+
TerrainRegionalViewStatus,
|
|
468
|
+
type TerrainRegionalViewshed,
|
|
469
|
+
type TerrainRegionalViewshedOptions,
|
|
470
|
+
type TerrainViewshedGrid
|
|
471
|
+
} from './terrain/regional-viewshed';
|
|
472
|
+
|
|
473
|
+
export {
|
|
474
|
+
createTerrainDrainage,
|
|
475
|
+
getTerrainCellMetrics,
|
|
476
|
+
type TerrainCellMetrics,
|
|
477
|
+
type TerrainDrainage,
|
|
478
|
+
type TerrainDrainageOptions
|
|
479
|
+
} from './terrain/hydrology';
|
|
480
|
+
|
|
481
|
+
export {
|
|
482
|
+
fillTerrainDepressions,
|
|
483
|
+
type TerrainDepressionFill,
|
|
484
|
+
type TerrainDepressionFillOptions
|
|
485
|
+
} from './terrain/depression-fill';
|
|
486
|
+
|
|
487
|
+
export {
|
|
488
|
+
splitTerrainMesh,
|
|
489
|
+
createTerrainCutoutSkirts,
|
|
490
|
+
type TerrainCutout,
|
|
491
|
+
type TerrainCutoutInput,
|
|
492
|
+
type TerrainCutoutOptions,
|
|
493
|
+
type TerrainCutoutPiece,
|
|
494
|
+
type SkirtedTerrainCutout,
|
|
495
|
+
type TerrainCutoutSkirtOptions
|
|
496
|
+
} from './terrain/index';
|
|
497
|
+
|
|
498
|
+
export {
|
|
499
|
+
accumulateTerrainWatersheds,
|
|
500
|
+
type TerrainWatershedAccumulation,
|
|
501
|
+
type TerrainWatershedAccumulationOptions
|
|
502
|
+
} from './terrain/watershed-accumulation';
|