@math.gl/geospatial 5.0.0-beta.11 → 5.0.0-beta.12
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/README.md +3 -3
- package/dist/index.cjs +725 -229
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/projection/experimental/core.cjs.map +1 -1
- package/dist/projection/experimental/crs/spatial-reference.d.ts.map +1 -1
- package/dist/projection/experimental/crs/spatial-reference.js.map +1 -1
- package/dist/projection/experimental/crs/types.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/aea.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/aea.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/aea.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/aea.js +4 -1
- package/dist/projection/experimental/lazy-projections/aea.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/bonne.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/bonne.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/bonne.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/bonne.js +4 -1
- package/dist/projection/experimental/lazy-projections/bonne.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/cass.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/cass.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/cass.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/cass.js +4 -1
- package/dist/projection/experimental/lazy-projections/cass.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/eck6.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/eck6.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/eck6.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/eck6.js +4 -1
- package/dist/projection/experimental/lazy-projections/eck6.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/eqdc.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/eqdc.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/eqdc.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/eqdc.js +4 -1
- package/dist/projection/experimental/lazy-projections/eqdc.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/eqearth.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/eqearth.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/eqearth.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/eqearth.js +4 -1
- package/dist/projection/experimental/lazy-projections/eqearth.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/equi.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/equi.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/equi.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/equi.js +4 -1
- package/dist/projection/experimental/lazy-projections/equi.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/geocent.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/geocent.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/geocent.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/geocent.js +4 -1
- package/dist/projection/experimental/lazy-projections/geocent.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/geos.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/geos.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/geos.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/geos.js +4 -1
- package/dist/projection/experimental/lazy-projections/geos.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/gnom.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/gnom.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/gnom.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/gnom.js +4 -1
- package/dist/projection/experimental/lazy-projections/gnom.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/index.cjs +92 -23
- package/dist/projection/experimental/lazy-projections/index.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/krovak.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/krovak.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/krovak.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/krovak.js +4 -1
- package/dist/projection/experimental/lazy-projections/krovak.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/merc.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/merc.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/merc.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/merc.js +4 -1
- package/dist/projection/experimental/lazy-projections/merc.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/mill.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/mill.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/mill.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/mill.js +4 -1
- package/dist/projection/experimental/lazy-projections/mill.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/moll.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/moll.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/moll.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/moll.js +4 -1
- package/dist/projection/experimental/lazy-projections/moll.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/nzmg.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/nzmg.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/nzmg.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/nzmg.js +4 -1
- package/dist/projection/experimental/lazy-projections/nzmg.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/omerc.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/omerc.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/omerc.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/omerc.js +4 -1
- package/dist/projection/experimental/lazy-projections/omerc.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/ortho.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/ortho.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/ortho.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/ortho.js +4 -1
- package/dist/projection/experimental/lazy-projections/ortho.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/poly.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/poly.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/poly.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/poly.js +4 -1
- package/dist/projection/experimental/lazy-projections/poly.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/robin.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/robin.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/robin.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/robin.js +4 -1
- package/dist/projection/experimental/lazy-projections/robin.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/sinu.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/sinu.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/sinu.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/sinu.js +4 -1
- package/dist/projection/experimental/lazy-projections/sinu.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/stere.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/stere.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/stere.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/stere.js +4 -1
- package/dist/projection/experimental/lazy-projections/stere.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/tpers.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/tpers.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/tpers.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/tpers.js +4 -1
- package/dist/projection/experimental/lazy-projections/tpers.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/vandg.cjs +4 -1
- package/dist/projection/experimental/lazy-projections/vandg.cjs.map +1 -1
- package/dist/projection/experimental/lazy-projections/vandg.d.ts.map +1 -1
- package/dist/projection/experimental/lazy-projections/vandg.js +4 -1
- package/dist/projection/experimental/lazy-projections/vandg.js.map +1 -1
- package/dist/projection/index.cjs.map +1 -1
- package/dist/projection/index.d.ts.map +1 -1
- package/dist/projection/index.js.map +1 -1
- package/dist/projection/lib/projection.js.map +1 -1
- package/dist/projection/pipeline.cjs.map +1 -1
- package/dist/projection/transform-analysis.cjs.map +1 -1
- package/dist/tasks/index.cjs.map +1 -1
- package/dist/terrain/cutout-polygons.d.ts +21 -0
- package/dist/terrain/cutout-polygons.d.ts.map +1 -0
- package/dist/terrain/cutout-polygons.js +172 -0
- package/dist/terrain/cutout-polygons.js.map +1 -0
- package/dist/terrain/cutout-region.d.ts +34 -0
- package/dist/terrain/cutout-region.d.ts.map +1 -0
- package/dist/terrain/cutout-region.js +33 -0
- package/dist/terrain/cutout-region.js.map +1 -0
- package/dist/terrain/geographic-cutout.d.ts +38 -0
- package/dist/terrain/geographic-cutout.d.ts.map +1 -0
- package/dist/terrain/geographic-cutout.js +120 -0
- package/dist/terrain/geographic-cutout.js.map +1 -0
- package/dist/terrain/index.cjs +532 -36
- package/dist/terrain/index.cjs.map +3 -3
- package/dist/terrain/index.d.ts +5 -0
- package/dist/terrain/index.d.ts.map +1 -1
- package/dist/terrain/index.js +4 -0
- package/dist/terrain/index.js.map +1 -1
- package/dist/terrain/mesh-cutout.d.ts +10 -5
- package/dist/terrain/mesh-cutout.d.ts.map +1 -1
- package/dist/terrain/mesh-cutout.js +62 -20
- package/dist/terrain/mesh-cutout.js.map +1 -1
- package/dist/terrain/tile-cutout-update.d.ts +73 -0
- package/dist/terrain/tile-cutout-update.d.ts.map +1 -0
- package/dist/terrain/tile-cutout-update.js +181 -0
- package/dist/terrain/tile-cutout-update.js.map +1 -0
- package/dist/terrain/tile-cutout.d.ts +33 -0
- package/dist/terrain/tile-cutout.d.ts.map +1 -0
- package/dist/terrain/tile-cutout.js +93 -0
- package/dist/terrain/tile-cutout.js.map +1 -0
- package/dist/turf/expressions.cjs +4 -4
- package/dist/turf/expressions.cjs.map +2 -2
- package/dist/turf/expressions.d.ts +1 -1
- package/dist/turf/expressions.d.ts.map +1 -1
- package/dist/turf/expressions.js +2 -2
- package/dist/turf/expressions.js.map +1 -1
- package/dist/turf.cjs +25 -25
- package/dist/turf.cjs.map +2 -2
- package/dist/turf.d.ts +1 -1
- package/dist/turf.d.ts.map +1 -1
- package/dist/turf.js +2 -2
- package/dist/turf.js.map +1 -1
- package/dist/web-mercator/assert.d.ts +2 -0
- package/dist/web-mercator/assert.d.ts.map +1 -0
- package/dist/web-mercator/assert.js +12 -0
- package/dist/web-mercator/assert.js.map +1 -0
- package/dist/web-mercator/fit-bounds.d.ts +52 -0
- package/dist/web-mercator/fit-bounds.d.ts.map +1 -0
- package/dist/web-mercator/fit-bounds.js +70 -0
- package/dist/web-mercator/fit-bounds.js.map +1 -0
- package/dist/web-mercator/fly-to-viewport.d.ts +19 -0
- package/dist/web-mercator/fly-to-viewport.d.ts.map +1 -0
- package/dist/web-mercator/fly-to-viewport.js +94 -0
- package/dist/web-mercator/fly-to-viewport.js.map +1 -0
- package/dist/web-mercator/get-bounds.d.ts +3 -0
- package/dist/web-mercator/get-bounds.d.ts.map +1 -0
- package/dist/web-mercator/get-bounds.js +56 -0
- package/dist/web-mercator/get-bounds.js.map +1 -0
- package/dist/web-mercator/index.cjs +705 -0
- package/dist/web-mercator/index.cjs.map +6 -0
- package/dist/web-mercator/index.d.ts +14 -0
- package/dist/web-mercator/index.d.ts.map +1 -0
- package/dist/web-mercator/index.js +14 -0
- package/dist/web-mercator/index.js.map +1 -0
- package/dist/web-mercator/math-utils.d.ts +7 -0
- package/dist/web-mercator/math-utils.d.ts.map +1 -0
- package/dist/web-mercator/math-utils.js +30 -0
- package/dist/web-mercator/math-utils.js.map +1 -0
- package/dist/web-mercator/mercator-meters.d.ts +29 -0
- package/dist/web-mercator/mercator-meters.d.ts.map +1 -0
- package/dist/web-mercator/mercator-meters.js +61 -0
- package/dist/web-mercator/mercator-meters.js.map +1 -0
- package/dist/web-mercator/normalize-viewport-props.d.ts +16 -0
- package/dist/web-mercator/normalize-viewport-props.d.ts.map +1 -0
- package/dist/web-mercator/normalize-viewport-props.js +45 -0
- package/dist/web-mercator/normalize-viewport-props.js.map +1 -0
- package/dist/web-mercator/web-mercator-utils.d.ts +192 -0
- package/dist/web-mercator/web-mercator-utils.d.ts.map +1 -0
- package/dist/web-mercator/web-mercator-utils.js +321 -0
- package/dist/web-mercator/web-mercator-utils.js.map +1 -0
- package/dist/web-mercator/web-mercator-viewport.d.ts +177 -0
- package/dist/web-mercator/web-mercator-viewport.d.ts.map +1 -0
- package/dist/web-mercator/web-mercator-viewport.js +276 -0
- package/dist/web-mercator/web-mercator-viewport.js.map +1 -0
- package/dist/web-mercator.d.ts +1 -1
- package/dist/web-mercator.d.ts.map +1 -1
- package/dist/web-mercator.js +1 -1
- package/dist/web-mercator.js.map +1 -1
- package/package.json +19 -458
- package/src/index.ts +36 -5
- package/src/projection/experimental/crs/spatial-reference.ts +1 -6
- package/src/projection/experimental/crs/types.ts +1 -1
- package/src/projection/experimental/crs/wkt.ts +1 -1
- package/src/projection/experimental/crs-descriptor.ts +1 -1
- package/src/projection/experimental/lazy-projections/aea.ts +4 -1
- package/src/projection/experimental/lazy-projections/bonne.ts +4 -1
- package/src/projection/experimental/lazy-projections/cass.ts +4 -1
- package/src/projection/experimental/lazy-projections/eck6.ts +4 -1
- package/src/projection/experimental/lazy-projections/eqdc.ts +4 -1
- package/src/projection/experimental/lazy-projections/eqearth.ts +4 -1
- package/src/projection/experimental/lazy-projections/equi.ts +4 -1
- package/src/projection/experimental/lazy-projections/geocent.ts +4 -1
- package/src/projection/experimental/lazy-projections/geos.ts +4 -1
- package/src/projection/experimental/lazy-projections/gnom.ts +4 -1
- package/src/projection/experimental/lazy-projections/krovak.ts +4 -1
- package/src/projection/experimental/lazy-projections/merc.ts +4 -1
- package/src/projection/experimental/lazy-projections/mill.ts +4 -1
- package/src/projection/experimental/lazy-projections/moll.ts +4 -1
- package/src/projection/experimental/lazy-projections/nzmg.ts +4 -1
- package/src/projection/experimental/lazy-projections/omerc.ts +4 -1
- package/src/projection/experimental/lazy-projections/ortho.ts +4 -1
- package/src/projection/experimental/lazy-projections/poly.ts +4 -1
- package/src/projection/experimental/lazy-projections/robin.ts +4 -1
- package/src/projection/experimental/lazy-projections/sinu.ts +4 -1
- package/src/projection/experimental/lazy-projections/stere.ts +4 -1
- package/src/projection/experimental/lazy-projections/tpers.ts +4 -1
- package/src/projection/experimental/lazy-projections/vandg.ts +4 -1
- package/src/projection/index.ts +1 -1
- package/src/projection/lib/projection.ts +1 -1
- package/src/terrain/cutout-polygons.ts +202 -0
- package/src/terrain/cutout-region.ts +54 -0
- package/src/terrain/geographic-cutout.ts +154 -0
- package/src/terrain/index.ts +24 -0
- package/src/terrain/mesh-cutout.ts +85 -23
- package/src/terrain/tile-cutout-update.ts +293 -0
- package/src/terrain/tile-cutout.ts +123 -0
- package/src/turf/expressions.ts +2 -2
- package/src/turf.ts +3 -7
- package/src/web-mercator/assert.ts +11 -0
- package/src/web-mercator/fit-bounds.ts +132 -0
- package/src/web-mercator/fly-to-viewport.ts +157 -0
- package/src/web-mercator/get-bounds.ts +62 -0
- package/src/web-mercator/index.ts +49 -0
- package/src/web-mercator/math-utils.ts +35 -0
- package/src/web-mercator/mercator-meters.ts +83 -0
- package/src/web-mercator/normalize-viewport-props.ts +58 -0
- package/src/web-mercator/web-mercator-utils.ts +468 -0
- package/src/web-mercator/web-mercator-viewport.ts +406 -0
- package/src/web-mercator.ts +1 -1
- package/dist/projection/experimental/index.cjs +0 -11707
- package/dist/projection/experimental/index.cjs.map +0 -6
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** A spherical gnomonic chart with terrain height retained as the third ordinate. */
|
|
6
|
+
export type GeographicTerrainCutoutFrame = {
|
|
7
|
+
/** Central longitude/latitude in degrees. Longitude is normalized to [-180,180). */
|
|
8
|
+
center: readonly [number, number];
|
|
9
|
+
/** Sphere radius in meters; default WGS84 semi-major axis (6378137). */
|
|
10
|
+
radius: number;
|
|
11
|
+
/** Maximum angular distance from the center in degrees; must be below 90. */
|
|
12
|
+
maxAngularRadius: number;
|
|
13
|
+
};
|
|
14
|
+
/** Explicit chart choice for regional terrain cutting. */
|
|
15
|
+
export type GeographicTerrainCutoutFrameOptions = {
|
|
16
|
+
/** Center longitude/latitude in degrees; polar centers are supported. */
|
|
17
|
+
center: readonly [number, number];
|
|
18
|
+
/** Spherical radius in meters. This is not an ellipsoidal distance certificate. */
|
|
19
|
+
radius?: number;
|
|
20
|
+
/** Angular cap in degrees, default 30; positive and at most 80. */
|
|
21
|
+
maxAngularRadius?: number;
|
|
22
|
+
};
|
|
23
|
+
/** Degrees to radians. */
|
|
24
|
+
const RAD = Math.PI / 180;
|
|
25
|
+
|
|
26
|
+
/** Create a bounded chart that has no antimeridian cut and supports either pole.
|
|
27
|
+
* Great-circle segments project to straight lines. Mesh connectivity must
|
|
28
|
+
* already describe the intended local surface (polar fans rather than duplicate
|
|
29
|
+
* pole rows). Heights retain their input datum; Z is not ECEF or tangent-plane up.
|
|
30
|
+
*/
|
|
31
|
+
export function createGeographicTerrainCutoutFrame(
|
|
32
|
+
options: GeographicTerrainCutoutFrameOptions
|
|
33
|
+
): GeographicTerrainCutoutFrame {
|
|
34
|
+
if (options.center.length !== 2) throw new RangeError('Invalid geographic terrain cutout center');
|
|
35
|
+
const frame = {
|
|
36
|
+
center: [wrap(options.center[0]), options.center[1]] as const,
|
|
37
|
+
radius: options.radius ?? 6378137,
|
|
38
|
+
maxAngularRadius: options.maxAngularRadius ?? 30
|
|
39
|
+
};
|
|
40
|
+
validateFrame(frame);
|
|
41
|
+
return Object.freeze({...frame, center: Object.freeze(frame.center)});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Project packed longitude/latitude/height to chart X/Y/height in Float64.
|
|
45
|
+
* Longitude aliases are normalized relative to the chart center. Vertices at
|
|
46
|
+
* the same pole project identically regardless of longitude. No connectivity,
|
|
47
|
+
* height filling, edge densification or geographic winding repair is performed.
|
|
48
|
+
* Triangle edges and cut edges mean straight segments in this chart (minor
|
|
49
|
+
* great-circle arcs horizontally); interpolate terrain height in chart space.
|
|
50
|
+
*/
|
|
51
|
+
export function projectGeographicTerrainCutout(
|
|
52
|
+
positions: Float32Array | Float64Array,
|
|
53
|
+
frame: GeographicTerrainCutoutFrame
|
|
54
|
+
): Float64Array {
|
|
55
|
+
validateFrame(frame);
|
|
56
|
+
validatePositions(positions);
|
|
57
|
+
const result = new Float64Array(positions.length);
|
|
58
|
+
const [sin0, cos0] = latitude(frame.center[1]);
|
|
59
|
+
const maximum = chartLimit(frame);
|
|
60
|
+
for (let i = 0; i < positions.length; i += 3) {
|
|
61
|
+
const lon = positions[i],
|
|
62
|
+
lat = positions[i + 1];
|
|
63
|
+
if (lat < -90 || lat > 90) throw new RangeError('Invalid geographic terrain latitude');
|
|
64
|
+
const sin = Math.sin(lat * RAD);
|
|
65
|
+
const cos = Math.abs(lat) === 90 ? 0 : Math.cos(lat * RAD);
|
|
66
|
+
const delta = wrap(wrap(lon) - frame.center[0]) * RAD;
|
|
67
|
+
const dot = sin0 * sin + cos0 * cos * Math.cos(delta);
|
|
68
|
+
const x = (cos * Math.sin(delta)) / dot;
|
|
69
|
+
const y = (cos0 * sin - sin0 * cos * Math.cos(delta)) / dot;
|
|
70
|
+
if (!(dot > 0) || Math.hypot(x, y) > maximum)
|
|
71
|
+
throw new RangeError('Terrain coordinate exceeds geographic cutout chart');
|
|
72
|
+
result[i] = frame.radius * x;
|
|
73
|
+
result[i + 1] = frame.radius * y;
|
|
74
|
+
result[i] ||= 0;
|
|
75
|
+
result[i + 1] ||= 0;
|
|
76
|
+
result[i + 2] = positions[i + 2];
|
|
77
|
+
}
|
|
78
|
+
if (!result.every(Number.isFinite))
|
|
79
|
+
throw new RangeError('Geographic terrain projection overflow');
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Invert chart X/Y/height to canonical longitude/latitude/height.
|
|
84
|
+
* Points outside the declared cap are rejected. At the exact pole, longitude
|
|
85
|
+
* is the chart center's longitude. Height and vertical datum are unchanged.
|
|
86
|
+
*/
|
|
87
|
+
export function unprojectGeographicTerrainCutout(
|
|
88
|
+
positions: Float32Array | Float64Array,
|
|
89
|
+
frame: GeographicTerrainCutoutFrame
|
|
90
|
+
): Float64Array {
|
|
91
|
+
validateFrame(frame);
|
|
92
|
+
validatePositions(positions);
|
|
93
|
+
const result = new Float64Array(positions.length);
|
|
94
|
+
const [sin0, cos0] = latitude(frame.center[1]);
|
|
95
|
+
const maximum = chartLimit(frame);
|
|
96
|
+
for (let i = 0; i < positions.length; i += 3) {
|
|
97
|
+
const x = positions[i] / frame.radius,
|
|
98
|
+
y = positions[i + 1] / frame.radius;
|
|
99
|
+
const distance = Math.hypot(x, y);
|
|
100
|
+
if (!Number.isFinite(distance) || distance > maximum)
|
|
101
|
+
throw new RangeError('Terrain coordinate exceeds geographic cutout chart');
|
|
102
|
+
const horizontal = cos0 - y * sin0;
|
|
103
|
+
const vertical = sin0 + y * cos0;
|
|
104
|
+
const lat = Math.atan2(vertical, Math.hypot(horizontal, x)) / RAD;
|
|
105
|
+
result[i] =
|
|
106
|
+
Math.abs(lat) === 90
|
|
107
|
+
? frame.center[0]
|
|
108
|
+
: wrap(frame.center[0] + Math.atan2(x, horizontal) / RAD);
|
|
109
|
+
result[i + 1] = lat;
|
|
110
|
+
result[i + 2] = positions[i + 2];
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Normalize aliases before subtraction to avoid overflow and inconsistent seams. */
|
|
116
|
+
function wrap(longitude: number) {
|
|
117
|
+
const result = longitude % 360;
|
|
118
|
+
return result >= 180 ? result - 360 : result < -180 ? result + 360 : result;
|
|
119
|
+
}
|
|
120
|
+
/** Exact pole cosines prevent longitude-dependent roundoff at the poles. */
|
|
121
|
+
function latitude(degrees: number): readonly [number, number] {
|
|
122
|
+
return [Math.sin(degrees * RAD), Math.abs(degrees) === 90 ? 0 : Math.cos(degrees * RAD)];
|
|
123
|
+
}
|
|
124
|
+
/** Validate frames even when callers supply a structural object. */
|
|
125
|
+
function validateFrame(frame: GeographicTerrainCutoutFrame) {
|
|
126
|
+
if (
|
|
127
|
+
frame.center.length !== 2 ||
|
|
128
|
+
!frame.center.every(Number.isFinite) ||
|
|
129
|
+
frame.center[0] < -180 ||
|
|
130
|
+
frame.center[0] >= 180 ||
|
|
131
|
+
Math.abs(frame.center[1]) > 90 ||
|
|
132
|
+
!Number.isFinite(frame.radius) ||
|
|
133
|
+
frame.radius <= 0 ||
|
|
134
|
+
!Number.isFinite(frame.maxAngularRadius) ||
|
|
135
|
+
frame.maxAngularRadius <= 0 ||
|
|
136
|
+
frame.maxAngularRadius > 80
|
|
137
|
+
)
|
|
138
|
+
throw new RangeError('Invalid geographic terrain cutout frame');
|
|
139
|
+
}
|
|
140
|
+
/** Reject malformed or nonfinite packed XYZ before allocating output. */
|
|
141
|
+
function validatePositions(positions: Float32Array | Float64Array) {
|
|
142
|
+
if (
|
|
143
|
+
!(positions instanceof Float32Array || positions instanceof Float64Array) ||
|
|
144
|
+
positions.length % 3 ||
|
|
145
|
+
!positions.every(Number.isFinite)
|
|
146
|
+
)
|
|
147
|
+
throw new RangeError('Invalid geographic terrain cutout positions');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Shared roundoff allowance for inclusive forward/inverse angular caps. */
|
|
151
|
+
function chartLimit(frame: GeographicTerrainCutoutFrame) {
|
|
152
|
+
const distance = Math.tan(frame.maxAngularRadius * RAD);
|
|
153
|
+
return distance + 16 * Number.EPSILON * (1 + distance);
|
|
154
|
+
}
|
package/src/terrain/index.ts
CHANGED
|
@@ -302,3 +302,27 @@ export {
|
|
|
302
302
|
type TerrainWatershedAccumulation,
|
|
303
303
|
type TerrainWatershedAccumulationOptions
|
|
304
304
|
} from './watershed-accumulation';
|
|
305
|
+
|
|
306
|
+
export {splitTerrainMeshTiles, type TerrainCutoutTile, type TerrainTileCutout} from './tile-cutout';
|
|
307
|
+
|
|
308
|
+
export {
|
|
309
|
+
updateTerrainTileCutouts,
|
|
310
|
+
type TerrainCutoutResident,
|
|
311
|
+
type TerrainTileCutoutUpdateOptions,
|
|
312
|
+
type TerrainTileCutoutCache,
|
|
313
|
+
type TerrainTileCutoutUpdate
|
|
314
|
+
} from './tile-cutout-update';
|
|
315
|
+
export {
|
|
316
|
+
createGeographicTerrainCutoutFrame,
|
|
317
|
+
projectGeographicTerrainCutout,
|
|
318
|
+
unprojectGeographicTerrainCutout,
|
|
319
|
+
type GeographicTerrainCutoutFrame,
|
|
320
|
+
type GeographicTerrainCutoutFrameOptions
|
|
321
|
+
} from './geographic-cutout';
|
|
322
|
+
|
|
323
|
+
export {prepareTerrainCutoutPolygons, type TerrainCutoutPolygonOptions} from './cutout-polygons';
|
|
324
|
+
export type {
|
|
325
|
+
TerrainCutoutPolygon,
|
|
326
|
+
TerrainCutoutPolygonSet,
|
|
327
|
+
TerrainCutoutRegion
|
|
328
|
+
} from './cutout-region';
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import {getTerrainCutoutPlan, type TerrainCutoutRegion} from './cutout-region';
|
|
6
|
+
|
|
5
7
|
type XY = readonly [number, number];
|
|
6
8
|
type XYZ = readonly [number, number, number];
|
|
7
9
|
type Face = [number, number, number];
|
|
@@ -25,6 +27,10 @@ export type TerrainCutoutPiece = {
|
|
|
25
27
|
sourceFaces: Uint32Array;
|
|
26
28
|
/** Directed boundary edges paired with the other piece in reverse order. */
|
|
27
29
|
cutEdges: Uint32Array;
|
|
30
|
+
/** Input polygon index per output face; 0 for raw convex rings, 0xffffffff for remainder. */
|
|
31
|
+
polygonIndices: Uint32Array;
|
|
32
|
+
/** Patch polygon index per directed cut edge, also present on the paired remainder edge. */
|
|
33
|
+
cutPolygonIndices: Uint32Array;
|
|
28
34
|
};
|
|
29
35
|
|
|
30
36
|
/** Bounds for the splitter's working storage and pair/fragment checks. */
|
|
@@ -37,11 +43,19 @@ export type TerrainCutoutOptions = {
|
|
|
37
43
|
maxTriangles?: number;
|
|
38
44
|
};
|
|
39
45
|
|
|
40
|
-
/** Both sides of a
|
|
46
|
+
/** Both sides of a terrain cut, with matching directed edges along the opening. */
|
|
41
47
|
export type TerrainCutout = {patch: TerrainCutoutPiece; remainder: TerrainCutoutPiece};
|
|
42
48
|
|
|
43
49
|
type Fragment = {ids: number[]; inside: boolean};
|
|
44
|
-
|
|
50
|
+
/** Edge incidence and owning polygon while assembling one output piece. */
|
|
51
|
+
type Boundary = {
|
|
52
|
+
/** Directed output vertex IDs. */
|
|
53
|
+
edge: Edge;
|
|
54
|
+
/** Number of incident output faces. */
|
|
55
|
+
count: number;
|
|
56
|
+
/** Input polygon index of the incident face, or -1 for the remainder. */
|
|
57
|
+
polygon: number;
|
|
58
|
+
};
|
|
45
59
|
type PieceBuilder = {
|
|
46
60
|
ids: Map<number, number>;
|
|
47
61
|
positions: number[];
|
|
@@ -51,15 +65,19 @@ type PieceBuilder = {
|
|
|
51
65
|
sourceFaces: number[];
|
|
52
66
|
boundary: Map<string, Boundary>;
|
|
53
67
|
cutEdges: number[];
|
|
68
|
+
/** One input polygon index per face; remainder -1 converts to Uint32 0xffffffff. */
|
|
69
|
+
polygonIndices: number[];
|
|
70
|
+
/** One owning patch polygon index per directed cut edge, on both sides. */
|
|
71
|
+
cutPolygonIndices: number[];
|
|
54
72
|
};
|
|
55
73
|
|
|
56
|
-
/** Split
|
|
74
|
+
/** Split conforming 2.5D terrain by a convex ring or prepared polygon set in local XY.
|
|
57
75
|
* Either ring winding is accepted. Ring vertices must omit a closing duplicate.
|
|
58
76
|
* Rejects overlapping sheets, nonconforming edges and unrepresentable slivers.
|
|
59
77
|
*/
|
|
60
78
|
export function splitTerrainMesh(
|
|
61
79
|
mesh: TerrainCutoutInput,
|
|
62
|
-
polygon:
|
|
80
|
+
polygon: TerrainCutoutRegion,
|
|
63
81
|
{maxWork = 4_000_000, maxVertices = 500_000, maxTriangles = 500_000}: TerrainCutoutOptions = {}
|
|
64
82
|
): TerrainCutout {
|
|
65
83
|
if (
|
|
@@ -83,7 +101,9 @@ export function splitTerrainMesh(
|
|
|
83
101
|
if (work > maxWork) throw new RangeError('Terrain cutout work budget exceeded');
|
|
84
102
|
}
|
|
85
103
|
|
|
86
|
-
const
|
|
104
|
+
const prepared = getTerrainCutoutPlan(polygon);
|
|
105
|
+
const ring = prepared ? undefined : validatePolygon(polygon as readonly XY[], charge);
|
|
106
|
+
const lines = prepared?.lines ?? ring!.map((p, i) => [p, ring![(i + 1) % ring!.length]] as const);
|
|
87
107
|
const vertices: XYZ[] = [];
|
|
88
108
|
for (let i = 0; i < mesh.positions.length; i += 3)
|
|
89
109
|
vertices.push([mesh.positions[i], mesh.positions[i + 1], mesh.positions[i + 2]]);
|
|
@@ -99,7 +119,7 @@ export function splitTerrainMesh(
|
|
|
99
119
|
|
|
100
120
|
const patch = createPiece();
|
|
101
121
|
const remainder = createPiece();
|
|
102
|
-
const intersections =
|
|
122
|
+
const intersections = lines.map(() => new Map<string, number>());
|
|
103
123
|
let fragmentCount = 0;
|
|
104
124
|
|
|
105
125
|
/** Allocate a vertex once for both pieces and every incident fragment. */
|
|
@@ -115,6 +135,17 @@ export function splitTerrainMesh(
|
|
|
115
135
|
const cache = intersections[line];
|
|
116
136
|
const saved = cache.get(key);
|
|
117
137
|
if (saved !== undefined) return saved;
|
|
138
|
+
// Canonical coordinate order also makes independently clipped tile edges
|
|
139
|
+
// bit-identical, regardless of their local vertex IDs or face traversal.
|
|
140
|
+
const pa = vertices[a],
|
|
141
|
+
pb = vertices[b];
|
|
142
|
+
if (
|
|
143
|
+
pa[0] > pb[0] ||
|
|
144
|
+
(pa[0] === pb[0] && (pa[1] > pb[1] || (pa[1] === pb[1] && pa[2] > pb[2])))
|
|
145
|
+
) {
|
|
146
|
+
[a, b] = [b, a];
|
|
147
|
+
[da, db] = [db, da];
|
|
148
|
+
}
|
|
118
149
|
const t = Math.abs(da) / (Math.abs(da) + Math.abs(db));
|
|
119
150
|
if (!(t > 0 && t < 1)) throw new RangeError('Unrepresentable terrain cut intersection');
|
|
120
151
|
const u = vertices[a];
|
|
@@ -132,10 +163,9 @@ export function splitTerrainMesh(
|
|
|
132
163
|
let fragments: Fragment[] = [{ids: faces[source], inside: true}];
|
|
133
164
|
// Split both sides by every supporting line. This preserves matching
|
|
134
165
|
// subdivisions on remainder edges beyond the finite polygon segments.
|
|
135
|
-
for (let line = 0; line <
|
|
166
|
+
for (let line = 0; line < lines.length; line++) {
|
|
136
167
|
const next: Fragment[] = [];
|
|
137
|
-
const a =
|
|
138
|
-
const b = ring[(line + 1) % ring.length];
|
|
168
|
+
const [a, b] = lines[line];
|
|
139
169
|
for (const fragment of fragments) {
|
|
140
170
|
const {ids} = fragment;
|
|
141
171
|
charge(ids.length);
|
|
@@ -168,25 +198,35 @@ export function splitTerrainMesh(
|
|
|
168
198
|
}
|
|
169
199
|
fragmentCount += fragments.length;
|
|
170
200
|
for (const {ids, inside} of fragments) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const center = [...vertices[ids[0]]] as [number, number, number];
|
|
201
|
+
// A strict interior point classifies each arrangement cell. Its artificial
|
|
202
|
+
// subdivision edges disappear when same-piece boundary incidences cancel.
|
|
203
|
+
let center: [number, number, number] | undefined;
|
|
204
|
+
if (prepared || ids.length > 3) {
|
|
205
|
+
center = [...vertices[ids[0]]] as [number, number, number];
|
|
177
206
|
for (const id of ids) {
|
|
178
207
|
for (let k = 0; k < 3; k++)
|
|
179
208
|
center[k] += (vertices[id][k] - vertices[ids[0]][k]) / ids.length;
|
|
180
209
|
}
|
|
181
|
-
|
|
210
|
+
}
|
|
211
|
+
const polygonIndex = prepared
|
|
212
|
+
? prepared.classify([center![0], center![1]], charge)
|
|
213
|
+
: inside
|
|
214
|
+
? 0
|
|
215
|
+
: -1;
|
|
216
|
+
const piece = polygonIndex >= 0 ? patch : remainder;
|
|
217
|
+
if (ids.length === 3) emit(piece, ids as Face, source, polygonIndex);
|
|
218
|
+
else {
|
|
219
|
+
// A center fan retains collinear boundary vertices and therefore pairs
|
|
220
|
+
// every constrained boundary segment with its neighbor.
|
|
221
|
+
const hub = addVertex(center!);
|
|
182
222
|
for (let i = 0; i < ids.length; i++)
|
|
183
|
-
emit(piece, [ids[i], ids[(i + 1) % ids.length], hub], source);
|
|
223
|
+
emit(piece, [ids[i], ids[(i + 1) % ids.length], hub], source, polygonIndex);
|
|
184
224
|
}
|
|
185
225
|
}
|
|
186
226
|
}
|
|
187
227
|
|
|
188
228
|
/** Emit a triangle and weld all of its edges by their shared topology IDs. */
|
|
189
|
-
function emit(piece: PieceBuilder, face: Face, source: number) {
|
|
229
|
+
function emit(piece: PieceBuilder, face: Face, source: number, polygonIndex: number) {
|
|
190
230
|
if (patch.sourceFaces.length + remainder.sourceFaces.length >= maxTriangles)
|
|
191
231
|
throw new RangeError('Terrain cutout triangle budget exceeded');
|
|
192
232
|
checkTriangle(vertices[face[0]], vertices[face[1]], vertices[face[2]]);
|
|
@@ -208,9 +248,10 @@ export function splitTerrainMesh(
|
|
|
208
248
|
);
|
|
209
249
|
}
|
|
210
250
|
piece.indices.push(piece.ids.get(id)!);
|
|
211
|
-
addEdge(piece.boundary, id, face[(i + 1) % 3]);
|
|
251
|
+
addEdge(piece.boundary, id, face[(i + 1) % 3], polygonIndex);
|
|
212
252
|
}
|
|
213
253
|
piece.sourceFaces.push(source);
|
|
254
|
+
piece.polygonIndices.push(polygonIndex);
|
|
214
255
|
}
|
|
215
256
|
|
|
216
257
|
for (const [key, inside] of patch.boundary) {
|
|
@@ -221,6 +262,8 @@ export function splitTerrainMesh(
|
|
|
221
262
|
throw new Error('Nonconforming terrain cut boundary');
|
|
222
263
|
patch.cutEdges.push(patch.ids.get(a)!, patch.ids.get(b)!);
|
|
223
264
|
remainder.cutEdges.push(remainder.ids.get(b)!, remainder.ids.get(a)!);
|
|
265
|
+
patch.cutPolygonIndices.push(inside.polygon);
|
|
266
|
+
remainder.cutPolygonIndices.push(inside.polygon);
|
|
224
267
|
}
|
|
225
268
|
return {patch: finish(patch), remainder: finish(remainder)};
|
|
226
269
|
}
|
|
@@ -310,10 +353,10 @@ function checkJunctions(a: Face, b: Face, vertices: XYZ[]) {
|
|
|
310
353
|
}
|
|
311
354
|
|
|
312
355
|
/** Track the first direction and incidence count of an indexed edge. */
|
|
313
|
-
function addEdge(edges: Map<string, Boundary>, a: number, b: number) {
|
|
356
|
+
function addEdge(edges: Map<string, Boundary>, a: number, b: number, polygon = -1) {
|
|
314
357
|
const key = edgeKey(a, b);
|
|
315
358
|
const entry = edges.get(key);
|
|
316
|
-
if (!entry) edges.set(key, {edge: [a, b], count: 1});
|
|
359
|
+
if (!entry) edges.set(key, {edge: [a, b], count: 1, polygon});
|
|
317
360
|
else {
|
|
318
361
|
if (entry.count !== 1 || entry.edge[0] !== b)
|
|
319
362
|
throw new RangeError('Terrain cut mesh has inconsistent or nonmanifold edges');
|
|
@@ -341,7 +384,9 @@ function createPiece(): PieceBuilder {
|
|
|
341
384
|
sourceWeights: [],
|
|
342
385
|
sourceFaces: [],
|
|
343
386
|
boundary: new Map(),
|
|
344
|
-
cutEdges: []
|
|
387
|
+
cutEdges: [],
|
|
388
|
+
polygonIndices: [],
|
|
389
|
+
cutPolygonIndices: []
|
|
345
390
|
};
|
|
346
391
|
}
|
|
347
392
|
|
|
@@ -353,6 +398,23 @@ function finish(piece: PieceBuilder): TerrainCutoutPiece {
|
|
|
353
398
|
sourceTriangles: Uint32Array.from(piece.sourceTriangles),
|
|
354
399
|
sourceWeights: Float64Array.from(piece.sourceWeights),
|
|
355
400
|
sourceFaces: Uint32Array.from(piece.sourceFaces),
|
|
356
|
-
cutEdges: Uint32Array.from(piece.cutEdges)
|
|
401
|
+
cutEdges: Uint32Array.from(piece.cutEdges),
|
|
402
|
+
polygonIndices: Uint32Array.from(piece.polygonIndices),
|
|
403
|
+
cutPolygonIndices: Uint32Array.from(piece.cutPolygonIndices)
|
|
357
404
|
};
|
|
358
405
|
}
|
|
406
|
+
|
|
407
|
+
/** @internal Check topology of already range-validated assembled tile inputs. */
|
|
408
|
+
export function validateTerrainCutoutTopology(mesh: TerrainCutoutInput, maxWork: number) {
|
|
409
|
+
const vertices: XYZ[] = [];
|
|
410
|
+
const faces: Face[] = [];
|
|
411
|
+
for (let i = 0; i < mesh.positions.length; i += 3)
|
|
412
|
+
vertices.push([mesh.positions[i], mesh.positions[i + 1], mesh.positions[i + 2]]);
|
|
413
|
+
for (let i = 0; i < mesh.indices.length; i += 3)
|
|
414
|
+
faces.push([mesh.indices[i], mesh.indices[i + 1], mesh.indices[i + 2]]);
|
|
415
|
+
let work = 0;
|
|
416
|
+
validateTopology(vertices, faces, amount => {
|
|
417
|
+
work += amount;
|
|
418
|
+
if (work > maxWork) throw new RangeError('Terrain cutout topology work budget exceeded');
|
|
419
|
+
});
|
|
420
|
+
}
|