@math.gl/geospatial 5.0.0-beta.1 → 5.0.0-beta.3
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/crs-identifier.d.ts +23 -0
- package/dist/crs/crs-identifier.d.ts.map +1 -0
- package/dist/crs/crs-identifier.js +74 -0
- package/dist/crs/crs-identifier.js.map +1 -0
- package/dist/crs/index.cjs +48 -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/discontinuous/cap-map.d.ts.map +1 -1
- package/dist/discontinuous/cap-map.js +197 -13
- package/dist/discontinuous/cap-map.js.map +1 -1
- package/dist/discontinuous/elastic/geometry.d.ts +1 -1
- package/dist/discontinuous/elastic/geometry.d.ts.map +1 -1
- package/dist/discontinuous/elastic/geometry.js +7 -7
- package/dist/discontinuous/elastic/geometry.js.map +1 -1
- package/dist/discontinuous/elastic/map.d.ts.map +1 -1
- package/dist/discontinuous/elastic/map.js +263 -23
- package/dist/discontinuous/elastic/map.js.map +1 -1
- package/dist/discontinuous/elastic/source-arc.d.ts +10 -0
- package/dist/discontinuous/elastic/source-arc.d.ts.map +1 -0
- package/dist/discontinuous/elastic/source-arc.js +111 -0
- package/dist/discontinuous/elastic/source-arc.js.map +1 -0
- package/dist/discontinuous/global-polygons.d.ts +1 -1
- package/dist/discontinuous/global-polygons.d.ts.map +1 -1
- package/dist/discontinuous/global-polygons.js +49 -1
- package/dist/discontinuous/global-polygons.js.map +1 -1
- package/dist/discontinuous/map-engine.d.ts +9 -0
- package/dist/discontinuous/map-engine.d.ts.map +1 -1
- package/dist/discontinuous/map-layout.d.ts +21 -0
- package/dist/discontinuous/map-layout.d.ts.map +1 -1
- package/dist/discontinuous/map-layout.js +116 -1
- package/dist/discontinuous/map-layout.js.map +1 -1
- package/dist/discontinuous/map-transition.d.ts.map +1 -1
- package/dist/discontinuous/map-transition.js +66 -3
- package/dist/discontinuous/map-transition.js.map +1 -1
- package/dist/discontinuous/mercator-map.d.ts +2 -2
- package/dist/discontinuous/mercator-map.d.ts.map +1 -1
- package/dist/discontinuous/mercator-map.js +123 -11
- package/dist/discontinuous/mercator-map.js.map +1 -1
- package/dist/discontinuous/polygon-constraints.d.ts +16 -0
- package/dist/discontinuous/polygon-constraints.d.ts.map +1 -0
- package/dist/discontinuous/polygon-constraints.js +157 -0
- package/dist/discontinuous/polygon-constraints.js.map +1 -0
- package/dist/discontinuous/prepare-features.d.ts +27 -0
- package/dist/discontinuous/prepare-features.d.ts.map +1 -1
- package/dist/discontinuous/prepare-features.js +106 -5
- package/dist/discontinuous/prepare-features.js.map +1 -1
- package/dist/discontinuous/rotated-map.d.ts +9 -0
- package/dist/discontinuous/rotated-map.d.ts.map +1 -1
- package/dist/discontinuous/source-arc.d.ts +4 -0
- package/dist/discontinuous/source-arc.d.ts.map +1 -0
- package/dist/discontinuous/source-arc.js +23 -0
- package/dist/discontinuous/source-arc.js.map +1 -0
- package/dist/discontinuous/world-kernels.d.ts +1 -1
- package/dist/discontinuous.cjs +1047 -75
- package/dist/discontinuous.cjs.map +3 -3
- package/dist/index.cjs +422 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/tasks/definitions.d.ts +90 -0
- package/dist/tasks/definitions.d.ts.map +1 -0
- package/dist/tasks/definitions.js +54 -0
- package/dist/tasks/definitions.js.map +1 -0
- package/dist/{workers → tasks}/index.cjs +1223 -191
- package/dist/tasks/index.cjs.map +6 -0
- package/dist/tasks/index.d.ts +12 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +30 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/{workers → tasks}/map-worker.d.ts.map +1 -1
- package/dist/tasks/map-worker.js +7 -0
- package/dist/tasks/map-worker.js.map +1 -0
- package/dist/{workers → tasks}/operations.d.ts +6 -4
- package/dist/tasks/operations.d.ts.map +1 -0
- package/dist/{workers → tasks}/operations.js +3 -5
- package/dist/tasks/operations.js.map +1 -0
- package/dist/tasks/projection-worker.d.ts.map +1 -0
- package/dist/tasks/projection-worker.js +7 -0
- package/dist/tasks/projection-worker.js.map +1 -0
- package/dist/terrain/filtered-pyramid.d.ts +22 -0
- package/dist/terrain/filtered-pyramid.d.ts.map +1 -0
- package/dist/terrain/filtered-pyramid.js +71 -0
- package/dist/terrain/filtered-pyramid.js.map +1 -0
- package/dist/terrain/index.cjs +375 -1
- package/dist/terrain/index.cjs.map +2 -2
- package/dist/terrain/index.d.ts +12 -0
- package/dist/terrain/index.d.ts.map +1 -1
- package/dist/terrain/index.js +7 -0
- package/dist/terrain/index.js.map +1 -1
- package/dist/terrain/profile-horizon.d.ts +20 -0
- package/dist/terrain/profile-horizon.d.ts.map +1 -0
- package/dist/terrain/profile-horizon.js +69 -0
- package/dist/terrain/profile-horizon.js.map +1 -0
- package/dist/terrain/profile-slope.d.ts +3 -0
- package/dist/terrain/profile-slope.d.ts.map +1 -0
- package/dist/terrain/profile-slope.js +35 -0
- package/dist/terrain/profile-slope.js.map +1 -0
- package/dist/terrain/profile-viewshed.d.ts +17 -0
- package/dist/terrain/profile-viewshed.d.ts.map +1 -0
- package/dist/terrain/profile-viewshed.js +51 -0
- package/dist/terrain/profile-viewshed.js.map +1 -0
- package/dist/terrain/profile-visibility.d.ts +21 -0
- package/dist/terrain/profile-visibility.d.ts.map +1 -0
- package/dist/terrain/profile-visibility.js +61 -0
- package/dist/terrain/profile-visibility.js.map +1 -0
- package/dist/terrain/vertex-halo-invalidation.d.ts +16 -0
- package/dist/terrain/vertex-halo-invalidation.d.ts.map +1 -0
- package/dist/terrain/vertex-halo-invalidation.js +50 -0
- package/dist/terrain/vertex-halo-invalidation.js.map +1 -0
- package/dist/terrain/vertex-halo-update.d.ts +18 -0
- package/dist/terrain/vertex-halo-update.d.ts.map +1 -0
- package/dist/terrain/vertex-halo-update.js +76 -0
- package/dist/terrain/vertex-halo-update.js.map +1 -0
- package/dist/terrain/vertex-halos.d.ts +26 -0
- package/dist/terrain/vertex-halos.d.ts.map +1 -0
- package/dist/terrain/vertex-halos.js +80 -0
- package/dist/terrain/vertex-halos.js.map +1 -0
- package/dist/turf.cjs +69 -5
- package/dist/turf.cjs.map +2 -2
- package/dist/turf.d.ts +9 -0
- package/dist/turf.d.ts.map +1 -1
- package/dist/turf.js +67 -0
- package/dist/turf.js.map +1 -1
- package/package.json +10 -15
- package/src/crs/crs-identifier.ts +86 -0
- package/src/crs/index.ts +1 -0
- package/src/discontinuous/cap-map.ts +248 -19
- package/src/discontinuous/elastic/geometry.ts +18 -7
- package/src/discontinuous/elastic/map.ts +334 -30
- package/src/discontinuous/elastic/source-arc.ts +129 -0
- package/src/discontinuous/global-polygons.ts +56 -2
- package/src/discontinuous/map-layout.ts +165 -2
- package/src/discontinuous/map-transition.ts +67 -3
- package/src/discontinuous/mercator-map.ts +151 -12
- package/src/discontinuous/polygon-constraints.ts +184 -0
- package/src/discontinuous/prepare-features.ts +154 -6
- package/src/discontinuous/source-arc.ts +31 -0
- package/src/index.ts +13 -0
- package/src/tasks/definitions.ts +89 -0
- package/src/tasks/index.ts +39 -0
- package/src/tasks/map-worker.ts +6 -0
- package/src/{workers → tasks}/operations.ts +11 -7
- package/src/tasks/projection-worker.ts +6 -0
- package/src/terrain/filtered-pyramid.ts +95 -0
- package/src/terrain/index.ts +12 -0
- package/src/terrain/profile-horizon.ts +86 -0
- package/src/terrain/profile-slope.ts +32 -0
- package/src/terrain/profile-viewshed.ts +57 -0
- package/src/terrain/profile-visibility.ts +81 -0
- package/src/terrain/vertex-halo-invalidation.ts +57 -0
- package/src/terrain/vertex-halo-update.ts +91 -0
- package/src/terrain/vertex-halos.ts +101 -0
- package/src/turf.ts +86 -0
- package/dist/workers/index.cjs.map +0 -6
- package/dist/workers/index.d.ts +0 -12
- package/dist/workers/index.d.ts.map +0 -1
- package/dist/workers/index.js +0 -41
- package/dist/workers/index.js.map +0 -1
- package/dist/workers/map-worker.js +0 -7
- package/dist/workers/map-worker.js.map +0 -1
- package/dist/workers/operations.cjs +0 -20036
- package/dist/workers/operations.cjs.map +0 -6
- package/dist/workers/operations.d.ts.map +0 -1
- package/dist/workers/operations.js.map +0 -1
- package/dist/workers/projection-worker.d.ts.map +0 -1
- package/dist/workers/projection-worker.js +0 -7
- package/dist/workers/projection-worker.js.map +0 -1
- package/src/workers/index.ts +0 -59
- package/src/workers/map-worker.ts +0 -7
- package/src/workers/projection-worker.ts +0 -7
- /package/dist/{workers → tasks}/map-worker.d.ts +0 -0
- /package/dist/{workers → tasks}/projection-worker.d.ts +0 -0
|
@@ -48,18 +48,45 @@ export type PreparedMapGeometry = {
|
|
|
48
48
|
regionIds: string[];
|
|
49
49
|
/** One vertex per part. Point ownership follows MapEngine.projectPoint(). */
|
|
50
50
|
points: PreparedMapVertices & {parts: PreparedMapPart[]};
|
|
51
|
-
paths: PreparedMapVertices & {
|
|
51
|
+
paths: PreparedMapVertices & {
|
|
52
|
+
parts: PreparedMapPathPart[];
|
|
53
|
+
pathStarts: Uint32Array;
|
|
54
|
+
provenance?: {
|
|
55
|
+
sourceSegmentIndices?: Uint32Array;
|
|
56
|
+
sourceSegmentParameters?: Float64Array;
|
|
57
|
+
sourceVertexIndices?: Uint32Array;
|
|
58
|
+
sourceDistances?: Float64Array;
|
|
59
|
+
distanceRadius?: number;
|
|
60
|
+
/** Per part: source endpoint, coverage boundary, cut, or continuous join. */
|
|
61
|
+
startReasons?: string[];
|
|
62
|
+
endReasons?: string[];
|
|
63
|
+
};
|
|
64
|
+
};
|
|
52
65
|
polygons: PreparedMapVertices & {
|
|
53
66
|
parts: PreparedMapPart[];
|
|
54
67
|
/** Vertex offsets for all rings, with a terminal sentinel. Rings repeat their first vertex. */
|
|
55
68
|
ringStarts: Uint32Array;
|
|
56
69
|
/** Ring offsets for polygon parts, with a terminal sentinel. Outer ring comes first. */
|
|
57
70
|
polygonStarts: Uint32Array;
|
|
71
|
+
/** One edge from each vertex to the next; repeated closing vertices have kind 0. */
|
|
72
|
+
edgeProvenance?: {
|
|
73
|
+
kinds: Uint8Array;
|
|
74
|
+
sourceRingIndices: Uint32Array;
|
|
75
|
+
sourceSegmentIndices: Uint32Array;
|
|
76
|
+
sourceParameterRanges: Float64Array;
|
|
77
|
+
};
|
|
58
78
|
};
|
|
59
79
|
};
|
|
60
80
|
/** Static preparation controls. This does not triangulate, interpolate attributes or pose meshes. */
|
|
61
81
|
export type MapPrepareFeaturesOptions = {
|
|
62
82
|
sampling?: MapSamplingOptions;
|
|
83
|
+
provenance?: {
|
|
84
|
+
sourceSegments?: boolean;
|
|
85
|
+
boundaries?: boolean;
|
|
86
|
+
polygonEdges?: boolean;
|
|
87
|
+
/** Source minor-great-circle distance in meters on the declared sphere. */
|
|
88
|
+
distances?: {metric: 'spherical'; radius: number};
|
|
89
|
+
};
|
|
63
90
|
/** Project original polygon boundaries separately; default true. */
|
|
64
91
|
polygonOutlines?: boolean;
|
|
65
92
|
/** Directed global spherical polygons; original outlines never include atlas connectors. */
|
|
@@ -108,6 +135,45 @@ export function prepareMapFeatures(
|
|
|
108
135
|
if (!Array.isArray(features)) throw new Error('Expected a feature array');
|
|
109
136
|
if (options.polygonOutlines !== undefined && typeof options.polygonOutlines !== 'boolean')
|
|
110
137
|
throw new Error('polygonOutlines must be boolean');
|
|
138
|
+
const provenance = options.provenance;
|
|
139
|
+
if (
|
|
140
|
+
provenance !== undefined &&
|
|
141
|
+
(!provenance || typeof provenance !== 'object' || Array.isArray(provenance))
|
|
142
|
+
)
|
|
143
|
+
throw new Error('Unsupported provenance policy');
|
|
144
|
+
if (
|
|
145
|
+
provenance?.distances !== undefined &&
|
|
146
|
+
(!provenance.distances || typeof provenance.distances !== 'object')
|
|
147
|
+
)
|
|
148
|
+
throw new Error('Unsupported provenance distance policy');
|
|
149
|
+
if (
|
|
150
|
+
provenance &&
|
|
151
|
+
(typeof provenance !== 'object' ||
|
|
152
|
+
Object.keys(provenance).some(
|
|
153
|
+
k => !['sourceSegments', 'boundaries', 'distances', 'polygonEdges'].includes(k)
|
|
154
|
+
) ||
|
|
155
|
+
[provenance.sourceSegments, provenance.boundaries, provenance.polygonEdges].some(
|
|
156
|
+
v => v !== undefined && typeof v !== 'boolean'
|
|
157
|
+
) ||
|
|
158
|
+
(provenance.distances &&
|
|
159
|
+
(provenance.distances.metric !== 'spherical' ||
|
|
160
|
+
!Number.isFinite(provenance.distances.radius) ||
|
|
161
|
+
provenance.distances.radius <= 0)))
|
|
162
|
+
)
|
|
163
|
+
throw new Error('Unsupported provenance policy');
|
|
164
|
+
const edgeKinds: number[] = [],
|
|
165
|
+
edgeRings: number[] = [],
|
|
166
|
+
edgeSegments: number[] = [],
|
|
167
|
+
edgeParameters: number[] = [];
|
|
168
|
+
const lineage = Boolean(
|
|
169
|
+
provenance?.sourceSegments || provenance?.boundaries || provenance?.distances
|
|
170
|
+
);
|
|
171
|
+
const segments: number[] = [],
|
|
172
|
+
parameters: number[] = [],
|
|
173
|
+
originalVertices: number[] = [],
|
|
174
|
+
distances: number[] = [],
|
|
175
|
+
startReasons: string[] = [],
|
|
176
|
+
endReasons: string[] = [];
|
|
111
177
|
const regionIds = map.regions.map(r => r.id),
|
|
112
178
|
regionIndices = new Map(regionIds.map((id, i) => [id, i]));
|
|
113
179
|
const points = vertices(),
|
|
@@ -140,7 +206,28 @@ export function prepareMapFeatures(
|
|
|
140
206
|
if (line.length < 2) throw new Error('A line needs at least two positions');
|
|
141
207
|
const isRing = ringIndex !== undefined;
|
|
142
208
|
if (isRing && !closed(line)) line.push([...line[0]]);
|
|
143
|
-
for (const p of map.projectLine(line,
|
|
209
|
+
for (const p of map.projectLine(line, {
|
|
210
|
+
...options.sampling,
|
|
211
|
+
pathProvenance: lineage,
|
|
212
|
+
pathDistances: Boolean(provenance?.distances),
|
|
213
|
+
pathBoundaries: Boolean(provenance?.boundaries)
|
|
214
|
+
})) {
|
|
215
|
+
if (lineage) {
|
|
216
|
+
if (!p.provenance) throw new Error('Map backend does not support path provenance');
|
|
217
|
+
if (provenance?.sourceSegments) {
|
|
218
|
+
segments.push(...p.provenance.segments);
|
|
219
|
+
parameters.push(...p.provenance.parameters);
|
|
220
|
+
originalVertices.push(...p.provenance.vertices);
|
|
221
|
+
}
|
|
222
|
+
if (provenance?.distances)
|
|
223
|
+
distances.push(
|
|
224
|
+
...p.provenance.angularDistances.map(d => d * provenance.distances!.radius)
|
|
225
|
+
);
|
|
226
|
+
if (provenance?.boundaries) {
|
|
227
|
+
startReasons.push(p.provenance.startReason!);
|
|
228
|
+
endReasons.push(p.provenance.endReason!);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
144
231
|
append(paths, p.coordinates, p.sourceCoordinates);
|
|
145
232
|
pathParts.push({
|
|
146
233
|
...part(featureIndex, geometryPath, p.regionId),
|
|
@@ -159,10 +246,37 @@ export function prepareMapFeatures(
|
|
|
159
246
|
if (!input.length) return;
|
|
160
247
|
const rings = input.map(r => r.map(position));
|
|
161
248
|
const parts = options.sphericalCuts
|
|
162
|
-
? map.projectGlobalPolygon(rings, {
|
|
163
|
-
|
|
249
|
+
? map.projectGlobalPolygon(rings, {
|
|
250
|
+
...options.sampling,
|
|
251
|
+
...options.sphericalCuts,
|
|
252
|
+
polygonEdgeProvenance: provenance?.polygonEdges
|
|
253
|
+
})
|
|
254
|
+
: map.projectPolygon(rings, {
|
|
255
|
+
...options.sampling,
|
|
256
|
+
polygonEdgeProvenance: provenance?.polygonEdges
|
|
257
|
+
});
|
|
164
258
|
for (const p of parts) {
|
|
165
259
|
for (let i = 0; i < p.coordinates.length; i++) {
|
|
260
|
+
if (provenance?.polygonEdges) {
|
|
261
|
+
const edges = p.edgeProvenance?.[i];
|
|
262
|
+
if (!edges) throw new Error('Map backend does not support polygon edge provenance');
|
|
263
|
+
const kinds = [
|
|
264
|
+
'source-boundary',
|
|
265
|
+
'coverage-boundary',
|
|
266
|
+
'chart-cut',
|
|
267
|
+
'continuous-chart-join'
|
|
268
|
+
];
|
|
269
|
+
for (const edge of edges) {
|
|
270
|
+
edgeKinds.push(kinds.indexOf(edge.kind) + 1);
|
|
271
|
+
edgeRings.push(edge.ring);
|
|
272
|
+
edgeSegments.push(edge.segment);
|
|
273
|
+
edgeParameters.push(edge.t0, edge.t1);
|
|
274
|
+
}
|
|
275
|
+
edgeKinds.push(0);
|
|
276
|
+
edgeRings.push(0xffffffff);
|
|
277
|
+
edgeSegments.push(0xffffffff);
|
|
278
|
+
edgeParameters.push(0, 0);
|
|
279
|
+
}
|
|
166
280
|
append(polygons, p.coordinates[i], p.sourceCoordinates[i]);
|
|
167
281
|
ringStarts.push(polygons.positions.length / 2);
|
|
168
282
|
}
|
|
@@ -234,12 +348,46 @@ export function prepareMapFeatures(
|
|
|
234
348
|
featureIds,
|
|
235
349
|
regionIds,
|
|
236
350
|
points: {...pack(points), parts: pointParts},
|
|
237
|
-
paths: {
|
|
351
|
+
paths: {
|
|
352
|
+
...pack(paths),
|
|
353
|
+
parts: pathParts,
|
|
354
|
+
pathStarts: new Uint32Array(pathStarts),
|
|
355
|
+
...(lineage
|
|
356
|
+
? {
|
|
357
|
+
provenance: {
|
|
358
|
+
...(provenance?.sourceSegments
|
|
359
|
+
? {
|
|
360
|
+
sourceSegmentIndices: new Uint32Array(segments),
|
|
361
|
+
sourceSegmentParameters: new Float64Array(parameters),
|
|
362
|
+
sourceVertexIndices: new Uint32Array(originalVertices)
|
|
363
|
+
}
|
|
364
|
+
: {}),
|
|
365
|
+
...(provenance?.distances
|
|
366
|
+
? {
|
|
367
|
+
sourceDistances: new Float64Array(distances),
|
|
368
|
+
distanceRadius: provenance.distances.radius
|
|
369
|
+
}
|
|
370
|
+
: {}),
|
|
371
|
+
...(provenance?.boundaries ? {startReasons, endReasons} : {})
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
: {})
|
|
375
|
+
},
|
|
238
376
|
polygons: {
|
|
239
377
|
...pack(polygons),
|
|
240
378
|
parts: polygonParts,
|
|
241
379
|
ringStarts: new Uint32Array(ringStarts),
|
|
242
|
-
polygonStarts: new Uint32Array(polygonStarts)
|
|
380
|
+
polygonStarts: new Uint32Array(polygonStarts),
|
|
381
|
+
...(provenance?.polygonEdges
|
|
382
|
+
? {
|
|
383
|
+
edgeProvenance: {
|
|
384
|
+
kinds: new Uint8Array(edgeKinds),
|
|
385
|
+
sourceRingIndices: new Uint32Array(edgeRings),
|
|
386
|
+
sourceSegmentIndices: new Uint32Array(edgeSegments),
|
|
387
|
+
sourceParameterRanges: new Float64Array(edgeParameters)
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
: {})
|
|
243
391
|
}
|
|
244
392
|
};
|
|
245
393
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import {angle, coordinates, geographic, unit, type Position, type Vector} from './math';
|
|
5
|
+
|
|
6
|
+
/** Preserve the source minor arc, including each owning chart's longitude side. */
|
|
7
|
+
export function sourceArc(a: Position, b: Position) {
|
|
8
|
+
const va = geographic(a),
|
|
9
|
+
vb = geographic(b),
|
|
10
|
+
length = angle(va, vb);
|
|
11
|
+
const poleA = Math.abs(a[1]) === 90,
|
|
12
|
+
poleB = Math.abs(b[1]) === 90;
|
|
13
|
+
const start: Position = poleA && !poleB ? [b[0], a[1]] : [...a],
|
|
14
|
+
end: Position = poleB && !poleA ? [a[0], b[1]] : [...b];
|
|
15
|
+
return (t: number): Position => {
|
|
16
|
+
if (t === 0) return [...start];
|
|
17
|
+
if (t === 1) return [...end];
|
|
18
|
+
if (length < 1e-14) return [a[0] + t * (b[0] - a[0]), a[1] + t * (b[1] - a[1])];
|
|
19
|
+
const p = coordinates(
|
|
20
|
+
unit(
|
|
21
|
+
va.map(
|
|
22
|
+
(v, k) =>
|
|
23
|
+
(Math.sin((1 - t) * length) * v + Math.sin(t * length) * vb[k]) / Math.sin(length)
|
|
24
|
+
) as Vector
|
|
25
|
+
)
|
|
26
|
+
);
|
|
27
|
+
const reference = start[0] + t * (end[0] - start[0]);
|
|
28
|
+
p[0] += 360 * Math.round((reference - p[0]) / 360);
|
|
29
|
+
return p;
|
|
30
|
+
};
|
|
31
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ export {
|
|
|
16
16
|
createCRSExecutionIdentity,
|
|
17
17
|
getCRSExecutionKey,
|
|
18
18
|
inferCRSRepresentation,
|
|
19
|
+
normalizeCRSIdentifier,
|
|
19
20
|
encodeWKTCRS,
|
|
20
21
|
parseWKTCRS,
|
|
21
22
|
validateWKTCRS,
|
|
@@ -376,8 +377,20 @@ export type {TerrainContourPaths, TerrainContourPathLimits} from './terrain/cont
|
|
|
376
377
|
export {simplifyTerrainContourPaths} from './terrain/contour-simplify';
|
|
377
378
|
export type {TerrainSimplifiedContourPaths} from './terrain/contour-simplify';
|
|
378
379
|
export {measureTerrainProfile} from './terrain/profile-measure';
|
|
380
|
+
export {getTerrainProfileVisibility} from './terrain/profile-visibility';
|
|
381
|
+
export type {TerrainProfileVisibility} from './terrain/profile-visibility';
|
|
382
|
+
export {getTerrainProfileHorizon} from './terrain/profile-horizon';
|
|
383
|
+
export type {TerrainProfileHorizon, TerrainProfileHorizonOptions} from './terrain/profile-horizon';
|
|
384
|
+
export {getTerrainProfileViewshed, TerrainProfileViewStatus} from './terrain/profile-viewshed';
|
|
379
385
|
export type {TerrainProfileMeasurements} from './terrain/profile-measure';
|
|
380
386
|
export {reconcileTerrainVertexTiles} from './terrain/vertex-tiles';
|
|
387
|
+
export {createTerrainVertexTileHalos, TerrainVertexHaloStatus} from './terrain/vertex-halos';
|
|
388
|
+
export type {TerrainVertexHaloTile} from './terrain/vertex-halos';
|
|
389
|
+
export {getTerrainVertexHaloAffectedTiles} from './terrain/vertex-halo-invalidation';
|
|
390
|
+
export type {TerrainVertexTileAddress} from './terrain/vertex-halo-invalidation';
|
|
391
|
+
export {updateTerrainVertexTileHalos} from './terrain/vertex-halo-update';
|
|
392
|
+
export {createTerrainFilteredPyramid} from './terrain/filtered-pyramid';
|
|
393
|
+
export type {TerrainFilteredLevel} from './terrain/filtered-pyramid';
|
|
381
394
|
export type {
|
|
382
395
|
TerrainVertexTile,
|
|
383
396
|
TerrainVertexTileOptions,
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import type {Task} from '@math.gl/core/tasks';
|
|
5
|
+
import type {CreateProjectionOptions, Projection, ProjectionArray} from '../projection/types';
|
|
6
|
+
import type {MapDescription, PreparedMap} from '../discontinuous/map-engine';
|
|
7
|
+
export type ProjectCoordinatesTypes = {
|
|
8
|
+
initialization: {projection?: CreateProjectionOptions};
|
|
9
|
+
state: {projection?: Projection; key?: string; defaultOptions?: CreateProjectionOptions};
|
|
10
|
+
input: {
|
|
11
|
+
projection?: CreateProjectionOptions;
|
|
12
|
+
coordinates: ProjectionArray;
|
|
13
|
+
dimension?: number;
|
|
14
|
+
inverse?: boolean;
|
|
15
|
+
};
|
|
16
|
+
output: {coordinates: ProjectionArray};
|
|
17
|
+
options: {chunkSize?: number};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const processCoordinates: NonNullable<Task<ProjectCoordinatesTypes>['process']> = async (
|
|
21
|
+
input,
|
|
22
|
+
options,
|
|
23
|
+
context
|
|
24
|
+
) => {
|
|
25
|
+
const projection = input.projection ?? context.state.defaultOptions;
|
|
26
|
+
if (!projection) throw new Error('Provide projection in the input or initializeTask');
|
|
27
|
+
await prepareProjection(context.state, projection);
|
|
28
|
+
const {projectBulk} = await import('./operations');
|
|
29
|
+
const coordinates = await projectBulk(
|
|
30
|
+
{...input, projection, chunkSize: options.chunkSize},
|
|
31
|
+
context,
|
|
32
|
+
context.state.projection
|
|
33
|
+
);
|
|
34
|
+
return {coordinates};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** Reproject packed coordinates, retaining the prepared projection for each task lifetime. */
|
|
38
|
+
export const ProjectCoordinatesTask = {
|
|
39
|
+
id: 'project-coordinates',
|
|
40
|
+
async preload() {
|
|
41
|
+
await Promise.all([import('./operations'), import('../projection/lib/projection')]);
|
|
42
|
+
},
|
|
43
|
+
async initialize({projection}) {
|
|
44
|
+
const state: ProjectCoordinatesTypes['state'] = {defaultOptions: projection};
|
|
45
|
+
if (projection) await prepareProjection(state, projection);
|
|
46
|
+
return state;
|
|
47
|
+
},
|
|
48
|
+
destroy(state) {
|
|
49
|
+
state.projection = undefined;
|
|
50
|
+
state.defaultOptions = undefined;
|
|
51
|
+
state.key = undefined;
|
|
52
|
+
},
|
|
53
|
+
process: processCoordinates,
|
|
54
|
+
async *processInBatches(inputs, options, context) {
|
|
55
|
+
for await (const input of inputs) {
|
|
56
|
+
yield await processCoordinates(input, options, context);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} satisfies Task<ProjectCoordinatesTypes>;
|
|
60
|
+
|
|
61
|
+
export type PrepareMapTypes = {
|
|
62
|
+
input: {description: MapDescription};
|
|
63
|
+
output: {map: PreparedMap};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** Build a portable map snapshot for MapEngine.fromPrepared without blocking the UI. */
|
|
67
|
+
export const PrepareMapTask = {
|
|
68
|
+
id: 'prepare-map',
|
|
69
|
+
async preload() {
|
|
70
|
+
await import('./operations');
|
|
71
|
+
},
|
|
72
|
+
async process({description}, _options, context) {
|
|
73
|
+
const {setupMap} = await import('./operations');
|
|
74
|
+
return {map: setupMap(description, context).toPrepared()};
|
|
75
|
+
}
|
|
76
|
+
} satisfies Task<PrepareMapTypes>;
|
|
77
|
+
|
|
78
|
+
async function prepareProjection(
|
|
79
|
+
state: ProjectCoordinatesTypes['state'],
|
|
80
|
+
options: CreateProjectionOptions
|
|
81
|
+
): Promise<void> {
|
|
82
|
+
const key = JSON.stringify(options);
|
|
83
|
+
if (!state.projection || state.key !== key) {
|
|
84
|
+
const {FullProjectionEngine} = await import('../projection/lib/projection');
|
|
85
|
+
const projection = new FullProjectionEngine().createProjection(options);
|
|
86
|
+
state.projection = projection;
|
|
87
|
+
state.key = key;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import type {TaskWorker} from '@math.gl/core/tasks';
|
|
5
|
+
import {ProjectCoordinatesTask as projectionTask, PrepareMapTask as mapTask} from './definitions';
|
|
6
|
+
export type {ProjectCoordinatesTypes, PrepareMapTypes} from './definitions';
|
|
7
|
+
declare const __filename: string;
|
|
8
|
+
|
|
9
|
+
// Resolve compiled worker modules in both ESM and CommonJS package entries.
|
|
10
|
+
const isBrowser = !(globalThis as {process?: {versions?: {node?: string}}}).process?.versions?.node;
|
|
11
|
+
const path = typeof __filename === 'string' ? __filename.replace(/\\/g, '/') : '';
|
|
12
|
+
const moduleUrl = path
|
|
13
|
+
? `file://${path.startsWith('/') ? '' : '/'}${encodeURI(path).replace(/#/g, '%23').replace(/\?/g, '%3F')}`
|
|
14
|
+
: import.meta.url;
|
|
15
|
+
|
|
16
|
+
/** Reproject coordinates with an automatic or explicitly retained worker. */
|
|
17
|
+
export const ProjectCoordinatesTask: typeof projectionTask & {worker: TaskWorker} = {
|
|
18
|
+
...projectionTask,
|
|
19
|
+
worker: {
|
|
20
|
+
...(!isBrowser
|
|
21
|
+
? {url: /* @__PURE__ */ (() => new URL('./projection-worker.js', moduleUrl).href)()}
|
|
22
|
+
: {
|
|
23
|
+
create: () =>
|
|
24
|
+
new Worker(new URL('./projection-worker.js', import.meta.url), {type: 'module'})
|
|
25
|
+
}),
|
|
26
|
+
capabilities: {atomic: true, streaming: true}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** Prepare a portable map snapshot in a worker. */
|
|
31
|
+
export const PrepareMapTask: typeof mapTask & {worker: TaskWorker} = {
|
|
32
|
+
...mapTask,
|
|
33
|
+
worker: {
|
|
34
|
+
...(!isBrowser
|
|
35
|
+
? {url: /* @__PURE__ */ (() => new URL('./map-worker.js', moduleUrl).href)()}
|
|
36
|
+
: {create: () => new Worker(new URL('./map-worker.js', import.meta.url), {type: 'module'})}),
|
|
37
|
+
capabilities: {atomic: true, streaming: false}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
import {MapEngine, type MapDescription, type MapEngineOptions} from '../discontinuous/map-engine';
|
|
5
|
-
import type {CreateProjectionOptions, ProjectionArray} from '../projection/types';
|
|
6
|
-
import type {
|
|
5
|
+
import type {CreateProjectionOptions, ProjectionArray, Projection} from '../projection/types';
|
|
6
|
+
import type {TaskContext} from '@math.gl/core/tasks';
|
|
7
|
+
type OperationContext = Partial<Omit<TaskContext<unknown>, 'state'>>;
|
|
7
8
|
|
|
8
9
|
export type BulkProjectionTask = {
|
|
9
10
|
projection: CreateProjectionOptions;
|
|
@@ -16,7 +17,7 @@ export type BulkProjectionTask = {
|
|
|
16
17
|
/** Setup callbacks belong in the worker and cannot be sent in a request. */
|
|
17
18
|
export function setupMap(
|
|
18
19
|
description: MapDescription,
|
|
19
|
-
context:
|
|
20
|
+
context: OperationContext,
|
|
20
21
|
options?: MapEngineOptions
|
|
21
22
|
): MapEngine {
|
|
22
23
|
context.reportProgress?.({phase: 'map-setup', completed: 0, total: 1, unit: 'tasks'});
|
|
@@ -29,7 +30,8 @@ export function setupMap(
|
|
|
29
30
|
/** Process worker-owned storage in chunks. Failed jobs return no partial result. */
|
|
30
31
|
export async function projectBulk(
|
|
31
32
|
input: BulkProjectionTask,
|
|
32
|
-
context:
|
|
33
|
+
context: OperationContext,
|
|
34
|
+
preparedProjection?: Projection
|
|
33
35
|
): Promise<ProjectionArray> {
|
|
34
36
|
const {coordinates, dimension = 2, chunkSize = 4096} = input;
|
|
35
37
|
if (
|
|
@@ -45,8 +47,11 @@ export async function projectBulk(
|
|
|
45
47
|
'Expected ordinary floating-point buffers, complete records and positive chunk size'
|
|
46
48
|
);
|
|
47
49
|
context.reportProgress?.({phase: 'projection-setup', completed: 0, total: 1, unit: 'tasks'});
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
+
const projection =
|
|
51
|
+
preparedProjection ??
|
|
52
|
+
new (await import('../projection/lib/projection')).FullProjectionEngine().createProjection(
|
|
53
|
+
input.projection
|
|
54
|
+
);
|
|
50
55
|
context.reportProgress?.({phase: 'projection-setup', completed: 1, total: 1, unit: 'tasks'});
|
|
51
56
|
const total = coordinates.length / dimension;
|
|
52
57
|
context.reportProgress?.({phase: 'bulk-projection', completed: 0, total, unit: 'records'});
|
|
@@ -57,7 +62,6 @@ export async function projectBulk(
|
|
|
57
62
|
const chunk = coordinates.subarray(start * dimension, end * dimension);
|
|
58
63
|
if (input.inverse) projection.unprojectFlatSync(chunk, dimension);
|
|
59
64
|
else projection.projectFlatSync(chunk, dimension);
|
|
60
|
-
if (total <= 0x7fffffff) context.sharedState?.setProgress(end, total);
|
|
61
65
|
context.reportProgress?.({phase: 'bulk-projection', completed: end, total, unit: 'records'});
|
|
62
66
|
await new Promise(resolve => setTimeout(resolve, 0));
|
|
63
67
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import {initializeTaskWorker} from '@math.gl/core/tasks';
|
|
5
|
+
import {ProjectCoordinatesTask} from './definitions';
|
|
6
|
+
void initializeTaskWorker(ProjectCoordinatesTask);
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
export type TerrainFilteredLevel = {
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
/** Mean of valid original samples, or zero when validCounts is zero. */
|
|
9
|
+
heights: Float64Array;
|
|
10
|
+
validCounts: Uint32Array;
|
|
11
|
+
/** Original sample count represented, including missing samples. */
|
|
12
|
+
sampleCounts: Uint32Array;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** Box-filter a cell raster into a weighted pyramid. Odd edges retain their true
|
|
16
|
+
* source counts. Missing data is excluded from means but remains visible in counts.
|
|
17
|
+
* These averages are not conservative collision bounds or vertex-registered meshes.
|
|
18
|
+
*/
|
|
19
|
+
export function createTerrainFilteredPyramid(
|
|
20
|
+
input: {
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
heights: Float32Array | Float64Array;
|
|
24
|
+
validity?: Uint8Array;
|
|
25
|
+
},
|
|
26
|
+
options: {maxSamples?: number} = {}
|
|
27
|
+
): TerrainFilteredLevel[] {
|
|
28
|
+
const {width, height, heights, validity} = input;
|
|
29
|
+
const count = width * height;
|
|
30
|
+
const limit = options.maxSamples ?? 4_000_000;
|
|
31
|
+
if (
|
|
32
|
+
!Number.isSafeInteger(width) ||
|
|
33
|
+
width < 1 ||
|
|
34
|
+
!Number.isSafeInteger(height) ||
|
|
35
|
+
height < 1 ||
|
|
36
|
+
!Number.isSafeInteger(count) ||
|
|
37
|
+
count > 0xffffffff ||
|
|
38
|
+
!Number.isSafeInteger(limit) ||
|
|
39
|
+
limit < count ||
|
|
40
|
+
!(heights instanceof Float32Array || heights instanceof Float64Array) ||
|
|
41
|
+
heights.length !== count ||
|
|
42
|
+
(validity !== undefined && (!(validity instanceof Uint8Array) || validity.length !== count))
|
|
43
|
+
)
|
|
44
|
+
throw new Error('Invalid terrain filtered pyramid input or capacity');
|
|
45
|
+
const base: TerrainFilteredLevel = {
|
|
46
|
+
width,
|
|
47
|
+
height,
|
|
48
|
+
heights: new Float64Array(count),
|
|
49
|
+
validCounts: new Uint32Array(count),
|
|
50
|
+
sampleCounts: new Uint32Array(count).fill(1)
|
|
51
|
+
};
|
|
52
|
+
for (let i = 0; i < count; i++)
|
|
53
|
+
if ((!validity || validity[i] !== 0) && Number.isFinite(heights[i])) {
|
|
54
|
+
base.heights[i] = heights[i];
|
|
55
|
+
base.validCounts[i] = 1;
|
|
56
|
+
}
|
|
57
|
+
const levels = [base];
|
|
58
|
+
let source = base;
|
|
59
|
+
while (source.width > 1 || source.height > 1) {
|
|
60
|
+
const w = Math.ceil(source.width / 2),
|
|
61
|
+
h = Math.ceil(source.height / 2);
|
|
62
|
+
const next: TerrainFilteredLevel = {
|
|
63
|
+
width: w,
|
|
64
|
+
height: h,
|
|
65
|
+
heights: new Float64Array(w * h),
|
|
66
|
+
validCounts: new Uint32Array(w * h),
|
|
67
|
+
sampleCounts: new Uint32Array(w * h)
|
|
68
|
+
};
|
|
69
|
+
for (let y = 0; y < h; y++)
|
|
70
|
+
for (let x = 0; x < w; x++) {
|
|
71
|
+
const out = y * w + x;
|
|
72
|
+
for (let dy = 0; dy < 2; dy++)
|
|
73
|
+
for (let dx = 0; dx < 2; dx++) {
|
|
74
|
+
const sx = x * 2 + dx,
|
|
75
|
+
sy = y * 2 + dy;
|
|
76
|
+
if (sx >= source.width || sy >= source.height) continue;
|
|
77
|
+
const index = sy * source.width + sx;
|
|
78
|
+
const n = source.validCounts[index],
|
|
79
|
+
old = next.validCounts[out];
|
|
80
|
+
next.sampleCounts[out] += source.sampleCounts[index];
|
|
81
|
+
if (n) {
|
|
82
|
+
const total = old + n,
|
|
83
|
+
a = next.heights[out],
|
|
84
|
+
b = source.heights[index];
|
|
85
|
+
// Convex combination avoids overflow when values have opposite signs.
|
|
86
|
+
next.heights[out] = old ? a * (old / total) + b * (n / total) : b;
|
|
87
|
+
next.validCounts[out] = total;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
levels.push(next);
|
|
92
|
+
source = next;
|
|
93
|
+
}
|
|
94
|
+
return levels;
|
|
95
|
+
}
|
package/src/terrain/index.ts
CHANGED
|
@@ -71,8 +71,20 @@ export type {TerrainContourPaths, TerrainContourPathLimits} from './contour-path
|
|
|
71
71
|
export {simplifyTerrainContourPaths} from './contour-simplify';
|
|
72
72
|
export type {TerrainSimplifiedContourPaths} from './contour-simplify';
|
|
73
73
|
export {measureTerrainProfile} from './profile-measure';
|
|
74
|
+
export {getTerrainProfileVisibility} from './profile-visibility';
|
|
75
|
+
export type {TerrainProfileVisibility} from './profile-visibility';
|
|
76
|
+
export {getTerrainProfileHorizon} from './profile-horizon';
|
|
77
|
+
export type {TerrainProfileHorizon, TerrainProfileHorizonOptions} from './profile-horizon';
|
|
78
|
+
export {getTerrainProfileViewshed, TerrainProfileViewStatus} from './profile-viewshed';
|
|
74
79
|
export type {TerrainProfileMeasurements} from './profile-measure';
|
|
75
80
|
export {reconcileTerrainVertexTiles} from './vertex-tiles';
|
|
81
|
+
export {createTerrainVertexTileHalos, TerrainVertexHaloStatus} from './vertex-halos';
|
|
82
|
+
export type {TerrainVertexHaloTile} from './vertex-halos';
|
|
83
|
+
export {getTerrainVertexHaloAffectedTiles} from './vertex-halo-invalidation';
|
|
84
|
+
export type {TerrainVertexTileAddress} from './vertex-halo-invalidation';
|
|
85
|
+
export {updateTerrainVertexTileHalos} from './vertex-halo-update';
|
|
86
|
+
export {createTerrainFilteredPyramid} from './filtered-pyramid';
|
|
87
|
+
export type {TerrainFilteredLevel} from './filtered-pyramid';
|
|
76
88
|
export type {
|
|
77
89
|
TerrainVertexTile,
|
|
78
90
|
TerrainVertexTileOptions,
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {TerrainProfile} from './profile';
|
|
6
|
+
import {TerrainSampleStatus} from './types';
|
|
7
|
+
import {compareTerrainSlopes} from './profile-slope';
|
|
8
|
+
|
|
9
|
+
/** Horizon of known samples. Missing coverage means the true horizon may be higher. */
|
|
10
|
+
export type TerrainProfileHorizon = {
|
|
11
|
+
angle: number | undefined;
|
|
12
|
+
sampleIndex: number | undefined;
|
|
13
|
+
missingSampleCount: number;
|
|
14
|
+
complete: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type TerrainProfileHorizonOptions = {observerHeight: number; maxSamples?: number};
|
|
18
|
+
|
|
19
|
+
/** Calculate the maximum elevation angle in radians of a straight, sampled profile.
|
|
20
|
+
* The observer is at station zero, and its absolute height must be above known terrain
|
|
21
|
+
* there. Values describe a local Cartesian piecewise-linear profile, not unsampled
|
|
22
|
+
* terrain, curvature, refraction or a geographic path. Missing samples leave the
|
|
23
|
+
* maximum of known samples as a lower bound rather than a complete horizon.
|
|
24
|
+
*/
|
|
25
|
+
export function getTerrainProfileHorizon(
|
|
26
|
+
profile: TerrainProfile,
|
|
27
|
+
options: TerrainProfileHorizonOptions
|
|
28
|
+
): TerrainProfileHorizon {
|
|
29
|
+
const {distances, heights, statuses, length} = profile;
|
|
30
|
+
const count = distances.length;
|
|
31
|
+
const limit = options.maxSamples ?? 1_000_000;
|
|
32
|
+
if (
|
|
33
|
+
!(distances instanceof Float64Array) ||
|
|
34
|
+
!(heights instanceof Float64Array) ||
|
|
35
|
+
!(statuses instanceof Uint8Array) ||
|
|
36
|
+
count < 2 ||
|
|
37
|
+
heights.length !== count ||
|
|
38
|
+
statuses.length !== count ||
|
|
39
|
+
!Number.isSafeInteger(limit) ||
|
|
40
|
+
limit < count ||
|
|
41
|
+
!Number.isFinite(options.observerHeight) ||
|
|
42
|
+
!Number.isFinite(length) ||
|
|
43
|
+
length <= 0 ||
|
|
44
|
+
distances[0] !== 0 ||
|
|
45
|
+
distances[count - 1] !== length
|
|
46
|
+
)
|
|
47
|
+
throw new Error('Invalid terrain horizon profile or options');
|
|
48
|
+
let winningRise = 0;
|
|
49
|
+
let winningDistance = 1;
|
|
50
|
+
let sampleIndex: number | undefined;
|
|
51
|
+
let missingSampleCount = 0;
|
|
52
|
+
for (let i = 0; i < count; i++) {
|
|
53
|
+
const distance = distances[i];
|
|
54
|
+
const status = statuses[i];
|
|
55
|
+
if (!Number.isFinite(distance) || (i > 0 && distance <= distances[i - 1]))
|
|
56
|
+
throw new Error('Invalid terrain horizon stationing');
|
|
57
|
+
if (status > TerrainSampleStatus.NOT_RESIDENT)
|
|
58
|
+
throw new Error('Invalid terrain horizon status');
|
|
59
|
+
if (status !== TerrainSampleStatus.VALID) {
|
|
60
|
+
missingSampleCount++;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (!Number.isFinite(heights[i])) throw new Error('Invalid terrain horizon height');
|
|
64
|
+
if (i === 0) {
|
|
65
|
+
if (options.observerHeight <= heights[i])
|
|
66
|
+
throw new Error('Terrain horizon observer must be above ground');
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const delta = heights[i] - options.observerHeight;
|
|
70
|
+
if (!Number.isFinite(delta)) throw new Error('Terrain horizon arithmetic overflow');
|
|
71
|
+
if (
|
|
72
|
+
sampleIndex === undefined ||
|
|
73
|
+
compareTerrainSlopes(delta, distance, winningRise, winningDistance) > 0
|
|
74
|
+
) {
|
|
75
|
+
winningRise = delta;
|
|
76
|
+
winningDistance = distance;
|
|
77
|
+
sampleIndex = i;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
angle: sampleIndex === undefined ? undefined : Math.atan2(winningRise, winningDistance),
|
|
82
|
+
sampleIndex,
|
|
83
|
+
missingSampleCount,
|
|
84
|
+
complete: missingSampleCount === 0
|
|
85
|
+
};
|
|
86
|
+
}
|