@math.gl/geospatial 5.0.0-beta.9 → 5.0.0-rc.2
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/crs/crs-descriptor-types.d.ts +2 -1
- package/dist/crs/crs-descriptor-types.d.ts.map +1 -1
- 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/ellipsoid-helpers/ellipsoid-transform.d.ts +1 -1
- package/dist/ellipsoid-helpers/ellipsoid-transform.d.ts.map +1 -1
- package/dist/ellipsoid-helpers/ellipsoid-transform.js +2 -2
- package/dist/ellipsoid-helpers/ellipsoid-transform.js.map +1 -1
- package/dist/ellipsoid-helpers/scale-to-geodetic-surface.js +1 -1
- package/dist/ellipsoid-helpers/scale-to-geodetic-surface.js.map +1 -1
- package/dist/ellipsoid-helpers/tangent-plane-numerics.d.ts +1 -1
- package/dist/ellipsoid-helpers/tangent-plane-numerics.d.ts.map +1 -1
- package/dist/ellipsoid-tangent-plane.d.ts +2 -2
- package/dist/ellipsoid-tangent-plane.d.ts.map +1 -1
- package/dist/ellipsoid-tangent-plane.js +1 -1
- package/dist/ellipsoid-tangent-plane.js.map +1 -1
- package/dist/ellipsoid-transforms.d.ts +2 -2
- package/dist/ellipsoid-transforms.d.ts.map +1 -1
- package/dist/ellipsoid-transforms.js +1 -1
- package/dist/ellipsoid-transforms.js.map +1 -1
- package/dist/ellipsoid.d.ts +2 -2
- package/dist/ellipsoid.d.ts.map +1 -1
- package/dist/ellipsoid.js +2 -2
- package/dist/ellipsoid.js.map +1 -1
- package/dist/expressions.d.ts +1 -1
- package/dist/expressions.d.ts.map +1 -1
- package/dist/expressions.js +1 -1
- package/dist/expressions.js.map +1 -1
- package/dist/geodesic-buffer.d.ts +1 -1
- package/dist/geodesic-buffer.d.ts.map +1 -1
- package/dist/geodesic-path.d.ts +1 -1
- package/dist/geodesic-path.d.ts.map +1 -1
- package/dist/geometry-constructors.d.ts +6 -0
- package/dist/geometry-constructors.d.ts.map +1 -0
- package/dist/geometry-constructors.js +37 -0
- package/dist/geometry-constructors.js.map +1 -0
- package/dist/geometry-inspection.d.ts +8 -0
- package/dist/geometry-inspection.d.ts.map +1 -0
- package/dist/geometry-inspection.js +61 -0
- package/dist/geometry-inspection.js.map +1 -0
- package/dist/index.cjs +2514 -558
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +164 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +106 -0
- package/dist/index.js.map +1 -1
- package/dist/line-simplification.d.ts +4 -0
- package/dist/line-simplification.d.ts.map +1 -0
- package/dist/line-simplification.js +83 -0
- package/dist/line-simplification.js.map +1 -0
- package/dist/linear-referencing.d.ts +6 -0
- package/dist/linear-referencing.d.ts.map +1 -0
- package/dist/linear-referencing.js +74 -0
- package/dist/linear-referencing.js.map +1 -0
- package/dist/lng-lat-rectangle.d.ts +1 -1
- package/dist/lng-lat-rectangle.d.ts.map +1 -1
- package/dist/lng-lat-rectangle.js +1 -1
- package/dist/lng-lat-rectangle.js.map +1 -1
- package/dist/local-reference-frame.d.ts +3 -3
- package/dist/local-reference-frame.d.ts.map +1 -1
- package/dist/local-reference-frame.js +2 -2
- package/dist/local-reference-frame.js.map +1 -1
- package/dist/make-obb-from-region.d.ts +1 -1
- package/dist/make-obb-from-region.d.ts.map +1 -1
- package/dist/make-obb-from-region.js +1 -1
- package/dist/make-obb-from-region.js.map +1 -1
- package/dist/maps/air-ocean-mesh.js +1 -1
- package/dist/maps/air-ocean-mesh.js.map +1 -1
- package/dist/maps/myriahedral/unfold.d.ts +1 -1
- package/dist/maps/myriahedral/unfold.d.ts.map +1 -1
- package/dist/maps/myriahedral/unfold.js +1 -1
- package/dist/maps/myriahedral/unfold.js.map +1 -1
- package/dist/maps/presets.cjs +6 -6
- package/dist/maps/presets.cjs.map +2 -2
- package/dist/maps.cjs +6 -6
- package/dist/maps.cjs.map +2 -2
- package/dist/projection/deformation.cjs +5 -5
- package/dist/projection/deformation.cjs.map +2 -2
- package/dist/projection/experimental/core.cjs +8 -4
- 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 +1 -1
- package/dist/projection/experimental/crs/types.d.ts.map +1 -1
- package/dist/projection/experimental/crs-rendering-scale.d.ts.map +1 -1
- package/dist/projection/experimental/crs-rendering-scale.js +13 -2
- package/dist/projection/experimental/crs-rendering-scale.js.map +1 -1
- package/dist/projection/experimental/datum.js +1 -1
- package/dist/projection/experimental/datum.js.map +1 -1
- package/dist/projection/experimental/entries/projections/geocent.cjs +3 -3
- package/dist/projection/experimental/entries/projections/geocent.cjs.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 +100 -27
- 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/experimental/spatial-deformation.js +1 -1
- package/dist/projection/experimental/spatial-deformation.js.map +1 -1
- package/dist/projection/index.cjs +8 -4
- 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 +3 -3
- package/dist/projection/pipeline.cjs.map +1 -1
- package/dist/projection/temporal.cjs +5 -5
- package/dist/projection/temporal.cjs.map +2 -2
- package/dist/projection/transform-analysis.cjs +3 -3
- package/dist/projection/transform-analysis.cjs.map +1 -1
- package/dist/rhumb-path.d.ts +1 -1
- package/dist/rhumb-path.d.ts.map +1 -1
- package/dist/spatial-planar-intersects.d.ts +4 -0
- package/dist/spatial-planar-intersects.d.ts.map +1 -0
- package/dist/spatial-planar-intersects.js +108 -0
- package/dist/spatial-planar-intersects.js.map +1 -0
- package/dist/spatial-planar.d.ts +16 -0
- package/dist/spatial-planar.d.ts.map +1 -0
- package/dist/spatial-planar.js +240 -0
- package/dist/spatial-planar.js.map +1 -0
- package/dist/spatial-sql.d.ts +45 -0
- package/dist/spatial-sql.d.ts.map +1 -0
- package/dist/spatial-sql.js +192 -0
- package/dist/spatial-sql.js.map +1 -0
- package/dist/st-functions.cjs +1616 -0
- package/dist/st-functions.cjs.map +6 -0
- package/dist/st-functions.d.ts +307 -0
- package/dist/st-functions.d.ts.map +1 -0
- package/dist/st-functions.js +593 -0
- package/dist/st-functions.js.map +1 -0
- package/dist/subdivide-globe-mesh.js +1 -1
- package/dist/subdivide-globe-mesh.js.map +1 -1
- package/dist/tasks/index.cjs +216 -98
- package/dist/tasks/index.cjs.map +2 -2
- package/dist/tasks/terrain-residency.d.ts +9 -0
- package/dist/tasks/terrain-residency.d.ts.map +1 -1
- package/dist/tasks/terrain-residency.js +98 -19
- package/dist/tasks/terrain-residency.js.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/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/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/geographic-lod-seams.d.ts +10 -0
- package/dist/terrain/geographic-lod-seams.d.ts.map +1 -0
- package/dist/terrain/geographic-lod-seams.js +100 -0
- package/dist/terrain/geographic-lod-seams.js.map +1 -0
- package/dist/terrain/geographic-neighbor.d.ts +18 -0
- package/dist/terrain/geographic-neighbor.d.ts.map +1 -0
- package/dist/terrain/geographic-neighbor.js +44 -0
- package/dist/terrain/geographic-neighbor.js.map +1 -0
- package/dist/terrain/geographic-poles.d.ts +24 -0
- package/dist/terrain/geographic-poles.d.ts.map +1 -0
- package/dist/terrain/geographic-poles.js +34 -0
- package/dist/terrain/geographic-poles.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 +2135 -161
- package/dist/terrain/index.cjs.map +3 -3
- package/dist/terrain/index.d.ts +23 -1
- package/dist/terrain/index.d.ts.map +1 -1
- package/dist/terrain/index.js +21 -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/lod-stitch.d.ts +2 -0
- package/dist/terrain/lod-stitch.d.ts.map +1 -1
- package/dist/terrain/lod-stitch.js +21 -6
- package/dist/terrain/lod-stitch.js.map +1 -1
- package/dist/terrain/mesh-cutout.d.ts +45 -0
- package/dist/terrain/mesh-cutout.d.ts.map +1 -0
- package/dist/terrain/mesh-cutout.js +336 -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/surface.d.ts +1 -1
- package/dist/terrain/surface.d.ts.map +1 -1
- package/dist/terrain/surface.js +1 -1
- package/dist/terrain/surface.js.map +1 -1
- package/dist/terrain/sweep-capsule.d.ts +27 -0
- package/dist/terrain/sweep-capsule.d.ts.map +1 -0
- package/dist/terrain/sweep-capsule.js +104 -0
- package/dist/terrain/sweep-capsule.js.map +1 -0
- package/dist/terrain/sweep-cylinder.d.ts +16 -0
- package/dist/terrain/sweep-cylinder.d.ts.map +1 -0
- package/dist/terrain/sweep-cylinder.js +52 -0
- package/dist/terrain/sweep-cylinder.js.map +1 -0
- package/dist/terrain/sweep-plane.d.ts +9 -0
- package/dist/terrain/sweep-plane.d.ts.map +1 -0
- package/dist/terrain/sweep-plane.js +52 -0
- package/dist/terrain/sweep-plane.js.map +1 -0
- package/dist/terrain/sweep-polytope.d.ts +42 -0
- package/dist/terrain/sweep-polytope.d.ts.map +1 -0
- package/dist/terrain/sweep-polytope.js +189 -0
- package/dist/terrain/sweep-polytope.js.map +1 -0
- 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/sweep-sphere.d.ts +27 -0
- package/dist/terrain/sweep-sphere.d.ts.map +1 -0
- package/dist/terrain/sweep-sphere.js +69 -0
- package/dist/terrain/sweep-sphere.js.map +1 -0
- 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/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/triaxial.d.ts +1 -1
- package/dist/triaxial.d.ts.map +1 -1
- package/dist/turf-expressions.cjs +1997 -0
- package/dist/turf-expressions.cjs.map +6 -0
- package/dist/turf-expressions.d.ts +3 -0
- package/dist/turf-expressions.d.ts.map +1 -0
- package/dist/turf-expressions.js +7 -0
- package/dist/turf-expressions.js.map +1 -0
- package/dist/turf-functions.cjs +743 -0
- package/dist/turf-functions.cjs.map +6 -0
- package/dist/turf-functions.d.ts +90 -0
- package/dist/turf-functions.d.ts.map +1 -0
- package/dist/{turf/expressions.js → turf-functions.js} +51 -5
- package/dist/turf-functions.js.map +1 -0
- 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/type-utils.d.ts +1 -1
- package/dist/type-utils.d.ts.map +1 -1
- package/dist/type-utils.js +1 -1
- package/dist/type-utils.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 +34 -462
- package/src/crs/crs-descriptor-types.ts +2 -1
- package/src/crs/index.ts +7 -0
- package/src/crs/spatial-reference-metadata.ts +118 -0
- package/src/ellipsoid-helpers/ellipsoid-transform.ts +3 -3
- package/src/ellipsoid-helpers/scale-to-geodetic-surface.ts +1 -1
- package/src/ellipsoid-helpers/tangent-plane-numerics.ts +1 -1
- package/src/ellipsoid-tangent-plane.ts +2 -2
- package/src/ellipsoid-transforms.ts +2 -2
- package/src/ellipsoid.ts +7 -3
- package/src/expressions.ts +2 -2
- package/src/geodesic-buffer.ts +1 -1
- package/src/geodesic-path.ts +1 -1
- package/src/geometry-constructors.ts +36 -0
- package/src/geometry-inspection.ts +66 -0
- package/src/index.ts +271 -4
- package/src/line-simplification.ts +97 -0
- package/src/linear-referencing.ts +94 -0
- package/src/lng-lat-rectangle.ts +1 -1
- package/src/local-reference-frame.ts +4 -4
- package/src/make-obb-from-region.ts +9 -1
- package/src/maps/air-ocean-mesh.ts +1 -1
- package/src/maps/myriahedral/unfold.ts +1 -1
- package/src/projection/experimental/crs/spatial-reference.ts +1 -6
- package/src/projection/experimental/crs/types.ts +2 -2
- package/src/projection/experimental/crs/wkt.ts +1 -1
- package/src/projection/experimental/crs-descriptor.ts +1 -1
- package/src/projection/experimental/crs-rendering-scale.ts +16 -4
- package/src/projection/experimental/datum.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/experimental/spatial-deformation.ts +1 -1
- package/src/projection/index.ts +1 -1
- package/src/projection/lib/projection.ts +1 -1
- package/src/rhumb-path.ts +1 -1
- package/src/spatial-planar-intersects.ts +134 -0
- package/src/spatial-planar.ts +266 -0
- package/src/spatial-sql.ts +276 -0
- package/src/st-functions.ts +852 -0
- package/src/subdivide-globe-mesh.ts +1 -1
- package/src/tasks/terrain-residency.ts +120 -24
- package/src/terrain/cutout-polygons.ts +202 -0
- package/src/terrain/cutout-region.ts +54 -0
- package/src/terrain/cutout-skirts.ts +52 -0
- package/src/terrain/depression-fill.ts +125 -0
- package/src/terrain/geographic-cutout.ts +154 -0
- package/src/terrain/geographic-lod-seams.ts +109 -0
- package/src/terrain/geographic-neighbor.ts +58 -0
- package/src/terrain/geographic-poles.ts +52 -0
- package/src/terrain/hydrology.ts +149 -0
- package/src/terrain/index.ts +122 -1
- package/src/terrain/lod-screen-error.ts +128 -0
- package/src/terrain/lod-select.ts +65 -31
- package/src/terrain/lod-stitch.ts +25 -7
- package/src/terrain/mesh-cutout.ts +420 -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/surface.ts +1 -1
- package/src/terrain/sweep-capsule.ts +148 -0
- package/src/terrain/sweep-cylinder.ts +64 -0
- package/src/terrain/sweep-plane.ts +61 -0
- package/src/terrain/sweep-polytope.ts +253 -0
- package/src/terrain/sweep-rotating-capsule.ts +139 -0
- package/src/terrain/sweep-rotation.ts +149 -0
- package/src/terrain/sweep-sphere.ts +100 -0
- package/src/terrain/tile-cutout-update.ts +293 -0
- package/src/terrain/tile-cutout.ts +123 -0
- package/src/terrain/watershed-accumulation.ts +67 -0
- package/src/triaxial.ts +1 -1
- package/src/turf-expressions.ts +7 -0
- package/src/{turf/expressions.ts → turf-functions.ts} +121 -6
- package/src/turf.ts +3 -7
- package/src/type-utils.ts +2 -2
- 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
- package/dist/turf/expressions.cjs +0 -87
- package/dist/turf/expressions.cjs.map +0 -6
- package/dist/turf/expressions.d.ts +0 -24
- package/dist/turf/expressions.d.ts.map +0 -1
- package/dist/turf/expressions.js.map +0 -1
package/dist/terrain/index.cjs
CHANGED
|
@@ -37,17 +37,23 @@ __export(index_exports, {
|
|
|
37
37
|
TerrainContourBoundaryAxis: () => TerrainContourBoundaryAxis,
|
|
38
38
|
TerrainMorphStatus: () => TerrainMorphStatus,
|
|
39
39
|
TerrainProfileViewStatus: () => TerrainProfileViewStatus,
|
|
40
|
+
TerrainRegionalViewStatus: () => TerrainRegionalViewStatus,
|
|
40
41
|
TerrainSampleStatus: () => TerrainSampleStatus,
|
|
41
42
|
TerrainSurface: () => TerrainSurface,
|
|
42
43
|
TerrainVertexHaloStatus: () => TerrainVertexHaloStatus,
|
|
43
44
|
TiledHeightField: () => TiledHeightField,
|
|
45
|
+
accumulateTerrainWatersheds: () => accumulateTerrainWatersheds,
|
|
46
|
+
boundTerrainLodScreenError: () => boundTerrainLodScreenError,
|
|
44
47
|
boundTerrainMeshError: () => boundTerrainMeshError,
|
|
45
48
|
certifyTerrainMeshCoverage: () => certifyTerrainMeshCoverage,
|
|
46
49
|
coordinateTerrainLodMorphs: () => coordinateTerrainLodMorphs,
|
|
47
50
|
createBreaklineTerrainMesh: () => createBreaklineTerrainMesh,
|
|
48
51
|
createDelatinTerrainMesh: () => createDelatinTerrainMesh,
|
|
52
|
+
createGeographicTerrainCutoutFrame: () => createGeographicTerrainCutoutFrame,
|
|
49
53
|
createMartiniTerrainMesh: () => createMartiniTerrainMesh,
|
|
50
54
|
createTerrainContours: () => createTerrainContours,
|
|
55
|
+
createTerrainCutoutSkirts: () => createTerrainCutoutSkirts,
|
|
56
|
+
createTerrainDrainage: () => createTerrainDrainage,
|
|
51
57
|
createTerrainFilteredPyramid: () => createTerrainFilteredPyramid,
|
|
52
58
|
createTerrainGradientGrid: () => createTerrainGradientGrid,
|
|
53
59
|
createTerrainGradientPyramid: () => createTerrainGradientPyramid,
|
|
@@ -56,13 +62,19 @@ __export(index_exports, {
|
|
|
56
62
|
createTerrainMesh: () => createTerrainMesh,
|
|
57
63
|
createTerrainMixedIsobands: () => createTerrainMixedIsobands,
|
|
58
64
|
createTerrainMixedVertexTileHalos: () => createTerrainMixedVertexTileHalos,
|
|
65
|
+
createTerrainRegionalViewshed: () => createTerrainRegionalViewshed,
|
|
59
66
|
createTerrainSkirt: () => createTerrainSkirt,
|
|
60
67
|
createTerrainSlopeAspectGrid: () => createTerrainSlopeAspectGrid,
|
|
61
68
|
createTerrainSurface: () => createTerrainSurface,
|
|
62
69
|
createTerrainVertexTileHalos: () => createTerrainVertexTileHalos,
|
|
63
70
|
createValidDomainTerrainMesh: () => createValidDomainTerrainMesh,
|
|
64
71
|
diagnoseTerrainContourBoundaries: () => diagnoseTerrainContourBoundaries,
|
|
72
|
+
discoverGeographicTerrainLodSeams: () => discoverGeographicTerrainLodSeams,
|
|
73
|
+
discoverGeographicTerrainPoles: () => discoverGeographicTerrainPoles,
|
|
65
74
|
evaluateTerrainLodMorph: () => evaluateTerrainLodMorph,
|
|
75
|
+
fillTerrainDepressions: () => fillTerrainDepressions,
|
|
76
|
+
getGeographicTerrainNeighbor: () => getGeographicTerrainNeighbor,
|
|
77
|
+
getTerrainCellMetrics: () => getTerrainCellMetrics,
|
|
66
78
|
getTerrainHierarchyNode: () => getTerrainHierarchyNode,
|
|
67
79
|
getTerrainMeshEdge: () => getTerrainMeshEdge,
|
|
68
80
|
getTerrainProfileHorizon: () => getTerrainProfileHorizon,
|
|
@@ -74,17 +86,34 @@ __export(index_exports, {
|
|
|
74
86
|
measureTerrainMeshError: () => measureTerrainMeshError,
|
|
75
87
|
measureTerrainProfile: () => measureTerrainProfile,
|
|
76
88
|
packTerrainHeightField: () => packTerrainHeightField,
|
|
89
|
+
prepareTerrainCutoutPolygons: () => prepareTerrainCutoutPolygons,
|
|
90
|
+
projectGeographicTerrainCutout: () => projectGeographicTerrainCutout,
|
|
77
91
|
reconcileTerrainVertexTiles: () => reconcileTerrainVertexTiles,
|
|
78
92
|
sampleTerrainProfile: () => sampleTerrainProfile,
|
|
79
93
|
selectTerrainLod: () => selectTerrainLod,
|
|
80
94
|
simplifyTerrainContourPaths: () => simplifyTerrainContourPaths,
|
|
81
95
|
simplifyTerrainContourPathsTopology: () => simplifyTerrainContourPathsTopology,
|
|
82
96
|
splitTerrainBreaklines: () => splitTerrainBreaklines,
|
|
97
|
+
splitTerrainMesh: () => splitTerrainMesh,
|
|
98
|
+
splitTerrainMeshTiles: () => splitTerrainMeshTiles,
|
|
83
99
|
stitchTerrainContourTiles: () => stitchTerrainContourTiles,
|
|
84
100
|
stitchTerrainContours: () => stitchTerrainContours,
|
|
85
101
|
stitchTerrainLodCut: () => stitchTerrainLodCut,
|
|
86
102
|
stitchTerrainMeshEdges: () => stitchTerrainMeshEdges,
|
|
103
|
+
sweepTerrainBox: () => sweepTerrainBox,
|
|
104
|
+
sweepTerrainCapsule: () => sweepTerrainCapsule,
|
|
105
|
+
sweepTerrainCylinder: () => sweepTerrainCylinder,
|
|
106
|
+
sweepTerrainPlane: () => sweepTerrainPlane,
|
|
107
|
+
sweepTerrainPolytope: () => sweepTerrainPolytope,
|
|
108
|
+
sweepTerrainRotatingBox: () => sweepTerrainRotatingBox,
|
|
109
|
+
sweepTerrainRotatingCapsule: () => sweepTerrainRotatingCapsule,
|
|
110
|
+
sweepTerrainRotatingPolytope: () => sweepTerrainRotatingPolytope,
|
|
111
|
+
sweepTerrainRotatingSphere: () => sweepTerrainRotatingSphere,
|
|
112
|
+
sweepTerrainSphere: () => sweepTerrainSphere,
|
|
113
|
+
sweepTerrainTaperedCapsule: () => sweepTerrainTaperedCapsule,
|
|
114
|
+
sweepTerrainTriangleMesh: () => sweepTerrainTriangleMesh,
|
|
87
115
|
unpackTerrainHeightField: () => unpackTerrainHeightField,
|
|
116
|
+
unprojectGeographicTerrainCutout: () => unprojectGeographicTerrainCutout,
|
|
88
117
|
updateTerrainBounds: () => updateTerrainBounds,
|
|
89
118
|
updateTerrainBoundsRegions: () => updateTerrainBoundsRegions,
|
|
90
119
|
updateTerrainDelatinMeshRegions: () => updateTerrainDelatinMeshRegions,
|
|
@@ -97,6 +126,7 @@ __export(index_exports, {
|
|
|
97
126
|
updateTerrainMixedVertexTileHalos: () => updateTerrainMixedVertexTileHalos,
|
|
98
127
|
updateTerrainPersistentBounds: () => updateTerrainPersistentBounds,
|
|
99
128
|
updateTerrainPersistentGradients: () => updateTerrainPersistentGradients,
|
|
129
|
+
updateTerrainTileCutouts: () => updateTerrainTileCutouts,
|
|
100
130
|
updateTerrainValidDomainMeshRegions: () => updateTerrainValidDomainMeshRegions,
|
|
101
131
|
updateTerrainVertexTileHalos: () => updateTerrainVertexTileHalos,
|
|
102
132
|
weldTerrainContourTiles: () => weldTerrainContourTiles,
|
|
@@ -417,13 +447,13 @@ function validateBatch(positions, output) {
|
|
|
417
447
|
|
|
418
448
|
// dist/terrain/mesh-skirts.js
|
|
419
449
|
function createTerrainSkirt(mesh, options) {
|
|
420
|
-
const { positions, indices } = mesh, { height, edges } = options;
|
|
450
|
+
const { positions, indices } = mesh, { height, baseZ, edges: edges2 } = options;
|
|
421
451
|
const maxVertices = options.maxVertices ?? 2e6, maxTriangles = options.maxTriangles ?? 4e6;
|
|
422
|
-
if (!Number.isFinite(height)
|
|
452
|
+
if ((baseZ === void 0 ? !(Number.isFinite(height) && height > 0) : height !== void 0 || !Number.isFinite(baseZ)) || !Number.isSafeInteger(maxVertices) || maxVertices < 0 || maxVertices > 4294967295 || !Number.isSafeInteger(maxTriangles) || maxTriangles < 0 || maxTriangles > 4294967295)
|
|
423
453
|
throw new Error("Invalid terrain skirt height or capacity");
|
|
424
454
|
if (!(positions instanceof Float32Array || positions instanceof Float64Array) || positions.length < 3 || positions.length % 3 || !positions.every(Number.isFinite) || !(indices instanceof Uint16Array || indices instanceof Uint32Array) || indices.length % 3 || positions.length / 3 > maxVertices || indices.length / 3 > maxTriangles)
|
|
425
455
|
throw new Error("Invalid terrain skirt mesh or capacity");
|
|
426
|
-
if (
|
|
456
|
+
if (edges2 !== void 0 && (!(edges2 instanceof Uint16Array || edges2 instanceof Uint32Array) || edges2.length % 2))
|
|
427
457
|
throw new Error("Invalid terrain skirt edge pairs");
|
|
428
458
|
const vertexCount = positions.length / 3, triangleCount = indices.length / 3;
|
|
429
459
|
const boundary = /* @__PURE__ */ new Map();
|
|
@@ -447,11 +477,11 @@ function createTerrainSkirt(mesh, options) {
|
|
|
447
477
|
}
|
|
448
478
|
}
|
|
449
479
|
let selected;
|
|
450
|
-
if (
|
|
480
|
+
if (edges2) {
|
|
451
481
|
selected = [];
|
|
452
482
|
const used = /* @__PURE__ */ new Set();
|
|
453
|
-
for (let i = 0; i <
|
|
454
|
-
const key2 = edgeKey(
|
|
483
|
+
for (let i = 0; i < edges2.length; i += 2) {
|
|
484
|
+
const key2 = edgeKey(edges2[i], edges2[i + 1]), edge2 = boundary.get(key2);
|
|
455
485
|
if (!edge2 || edge2.count !== 1 || used.has(key2))
|
|
456
486
|
throw new Error("Terrain skirt selection must contain unique boundary edges");
|
|
457
487
|
used.add(key2);
|
|
@@ -475,7 +505,7 @@ function createTerrainSkirt(mesh, options) {
|
|
|
475
505
|
[b, lowerB]
|
|
476
506
|
]) {
|
|
477
507
|
resultPositions.set(positions.subarray(3 * source, 3 * source + 3), 3 * target);
|
|
478
|
-
resultPositions[3 * target + 2] = positions[3 * source + 2] - height;
|
|
508
|
+
resultPositions[3 * target + 2] = baseZ ?? positions[3 * source + 2] - height;
|
|
479
509
|
if (!Number.isFinite(resultPositions[3 * target + 2]) || resultPositions[3 * target + 2] >= positions[3 * source + 2])
|
|
480
510
|
throw new Error("Terrain skirt height cannot be represented in position precision");
|
|
481
511
|
sourceVertexIndices[target - vertexCount] = source;
|
|
@@ -636,17 +666,17 @@ var GeographicHeightField = class {
|
|
|
636
666
|
});
|
|
637
667
|
}
|
|
638
668
|
/** Longitude must use the bounds' unwrapped interval; no implicit wrapping or clamping. */
|
|
639
|
-
sample(longitude,
|
|
640
|
-
const valid = Number.isFinite(longitude) && Number.isFinite(
|
|
641
|
-
const inside = valid && longitude >= this.bounds[0] && longitude <= this.bounds[2] &&
|
|
642
|
-
const sample = this.field.sample(inside ? this.projectX(longitude) : NaN, inside ? this.projectY(
|
|
669
|
+
sample(longitude, latitude2, options, result) {
|
|
670
|
+
const valid = Number.isFinite(longitude) && Number.isFinite(latitude2);
|
|
671
|
+
const inside = valid && longitude >= this.bounds[0] && longitude <= this.bounds[2] && latitude2 >= this.bounds[1] && latitude2 <= this.bounds[3];
|
|
672
|
+
const sample = this.field.sample(inside ? this.projectX(longitude) : NaN, inside ? this.projectY(latitude2) : NaN, options, result);
|
|
643
673
|
if (!inside) {
|
|
644
674
|
sample.status = sample.gradientStatus = valid ? TerrainSampleStatus.OUTSIDE_DOMAIN : TerrainSampleStatus.INVALID_INPUT;
|
|
645
675
|
return sample;
|
|
646
676
|
}
|
|
647
677
|
if (sample.gradientStatus !== TerrainSampleStatus.VALID)
|
|
648
678
|
return sample;
|
|
649
|
-
const phi =
|
|
679
|
+
const phi = latitude2 * RADIANS;
|
|
650
680
|
const denominator = 1 - ECCENTRICITY_SQUARED * Math.sin(phi) ** 2;
|
|
651
681
|
const n = RADIUS / Math.sqrt(denominator);
|
|
652
682
|
const m = RADIUS * (1 - ECCENTRICITY_SQUARED) / denominator ** 1.5;
|
|
@@ -670,8 +700,8 @@ var GeographicHeightField = class {
|
|
|
670
700
|
projectX(longitude) {
|
|
671
701
|
return this.projection === "web-mercator" ? RADIUS * longitude * RADIANS : longitude;
|
|
672
702
|
}
|
|
673
|
-
projectY(
|
|
674
|
-
return this.projection === "web-mercator" ? RADIUS * Math.asinh(Math.tan(
|
|
703
|
+
projectY(latitude2) {
|
|
704
|
+
return this.projection === "web-mercator" ? RADIUS * Math.asinh(Math.tan(latitude2 * RADIANS)) : latitude2;
|
|
675
705
|
}
|
|
676
706
|
};
|
|
677
707
|
|
|
@@ -1143,7 +1173,7 @@ function createTransform(steps) {
|
|
|
1143
1173
|
}
|
|
1144
1174
|
|
|
1145
1175
|
// dist/terrain/surface.js
|
|
1146
|
-
var
|
|
1176
|
+
var import_spatial_index = require("@math.gl/geometry/spatial-index");
|
|
1147
1177
|
|
|
1148
1178
|
// dist/terrain/mesh-data.js
|
|
1149
1179
|
function assembleTerrainMesh(field, gridCoordinates, indices, options) {
|
|
@@ -1285,8 +1315,8 @@ var TerrainSurface = class {
|
|
|
1285
1315
|
}
|
|
1286
1316
|
this.activeTriangleCount = active;
|
|
1287
1317
|
this.topology = buildTopology(this.indices, this.validity);
|
|
1288
|
-
this.xyIndex = new
|
|
1289
|
-
this.bvh = new
|
|
1318
|
+
this.xyIndex = new import_spatial_index.BoxIndex({ bounds: bounds2, dimension: 2 });
|
|
1319
|
+
this.bvh = new import_spatial_index.TriangleBVH({ positions: this.positions, indices: this.indices });
|
|
1290
1320
|
}
|
|
1291
1321
|
/** Detached source data; changing these buffers never changes this surface. */
|
|
1292
1322
|
copyData() {
|
|
@@ -1530,16 +1560,16 @@ var TerrainSurface = class {
|
|
|
1530
1560
|
};
|
|
1531
1561
|
function buildTopology(indices, validity) {
|
|
1532
1562
|
const halfedges = new Int32Array(indices.length).fill(-1);
|
|
1533
|
-
const
|
|
1563
|
+
const edges2 = /* @__PURE__ */ new Map();
|
|
1534
1564
|
for (let i = 0; i < indices.length; i++) {
|
|
1535
1565
|
const triangle = Math.floor(i / 3);
|
|
1536
1566
|
if (!validity[triangle])
|
|
1537
1567
|
continue;
|
|
1538
1568
|
const a = indices[i], b = indices[triangle * 3 + (i % 3 + 1) % 3];
|
|
1539
1569
|
const key2 = a < b ? `${a}/${b}` : `${b}/${a}`;
|
|
1540
|
-
const opposite =
|
|
1570
|
+
const opposite = edges2.get(key2);
|
|
1541
1571
|
if (opposite === void 0)
|
|
1542
|
-
|
|
1572
|
+
edges2.set(key2, i);
|
|
1543
1573
|
else {
|
|
1544
1574
|
if (halfedges[opposite] !== -1)
|
|
1545
1575
|
throw new Error("Nonmanifold terrain edge");
|
|
@@ -1815,19 +1845,19 @@ function createMartiniTerrainMesh(field, options) {
|
|
|
1815
1845
|
throw new Error("Adaptive terrain sample capacity exceeded");
|
|
1816
1846
|
if (field.validCount !== size * size)
|
|
1817
1847
|
throw new Error("Adaptive terrain requires complete source data; use a regular mesh for holes");
|
|
1818
|
-
const
|
|
1819
|
-
for (const edge2 of
|
|
1848
|
+
const edges2 = options.fullEdges ?? [];
|
|
1849
|
+
for (const edge2 of edges2)
|
|
1820
1850
|
if (!["minColumn", "maxColumn", "minRow", "maxRow"].includes(edge2))
|
|
1821
1851
|
throw new Error("Unknown adaptive terrain edge");
|
|
1822
1852
|
const { heights } = field.copyData();
|
|
1823
1853
|
const tile = new import_martini.default(size).createTile(heights);
|
|
1824
|
-
for (const edge2 of
|
|
1854
|
+
for (const edge2 of edges2)
|
|
1825
1855
|
for (let i = 0; i < size; i++) {
|
|
1826
1856
|
const column = edge2 === "minColumn" ? 0 : edge2 === "maxColumn" ? cells : i;
|
|
1827
1857
|
const row = edge2 === "minRow" ? 0 : edge2 === "maxRow" ? cells : i;
|
|
1828
1858
|
tile.errors[row * size + column] = Infinity;
|
|
1829
1859
|
}
|
|
1830
|
-
if (
|
|
1860
|
+
if (edges2.length)
|
|
1831
1861
|
tile.update();
|
|
1832
1862
|
let threshold = options.maxError;
|
|
1833
1863
|
for (let pass = 0; pass <= 8; pass++) {
|
|
@@ -2448,7 +2478,7 @@ function createTerrainContours(field, levels, options = {}) {
|
|
|
2448
2478
|
const outputLevels = Float64Array.from(levels), positions = [], coordinates = [], segments = [], levelIndices = [];
|
|
2449
2479
|
const shift = field.registration === "cell" ? 0.5 : 0;
|
|
2450
2480
|
for (let levelIndex = 0; levelIndex < outputLevels.length; levelIndex++) {
|
|
2451
|
-
const level = outputLevels[levelIndex], vertices = /* @__PURE__ */ new Map(),
|
|
2481
|
+
const level = outputLevels[levelIndex], vertices = /* @__PURE__ */ new Map(), edges2 = /* @__PURE__ */ new Set();
|
|
2452
2482
|
const height = (i) => field.getHeight(i % field.width, Math.floor(i / field.width));
|
|
2453
2483
|
const intersection = (a, b) => {
|
|
2454
2484
|
if (a > b)
|
|
@@ -2502,13 +2532,13 @@ function createTerrainContours(field, levels, options = {}) {
|
|
|
2502
2532
|
return;
|
|
2503
2533
|
const va = vertex(hits[0]), vb = vertex(hits[1]);
|
|
2504
2534
|
const key2 = va < vb ? `${va}/${vb}` : `${vb}/${va}`;
|
|
2505
|
-
if (
|
|
2535
|
+
if (edges2.has(key2))
|
|
2506
2536
|
return;
|
|
2507
2537
|
if (segments.length / 2 >= maxSegments)
|
|
2508
2538
|
throw new Error("Terrain contour segment capacity exceeded");
|
|
2509
2539
|
if (positions[3 * va] === positions[3 * vb] && positions[3 * va + 1] === positions[3 * vb + 1])
|
|
2510
2540
|
throw new Error("Terrain contour segment collapses; use a local origin");
|
|
2511
|
-
|
|
2541
|
+
edges2.add(key2);
|
|
2512
2542
|
segments.push(va, vb);
|
|
2513
2543
|
levelIndices.push(levelIndex);
|
|
2514
2544
|
};
|
|
@@ -2667,7 +2697,7 @@ function weldTerrainContourTiles(tiles, options) {
|
|
|
2667
2697
|
const levels = first.levels.slice();
|
|
2668
2698
|
const positions = [], grid = [], segments = [], levelIndices = [];
|
|
2669
2699
|
const vertices = /* @__PURE__ */ new Map();
|
|
2670
|
-
const
|
|
2700
|
+
const edges2 = /* @__PURE__ */ new Map();
|
|
2671
2701
|
const addresses = /* @__PURE__ */ new Set();
|
|
2672
2702
|
let inputVertices = 0;
|
|
2673
2703
|
let inputSegments = 0;
|
|
@@ -2744,7 +2774,7 @@ function weldTerrainContourTiles(tiles, options) {
|
|
|
2744
2774
|
if (a === b || positions[3 * a] === positions[3 * b] && positions[3 * a + 1] === positions[3 * b + 1])
|
|
2745
2775
|
throw new Error("Degenerate terrain contour segment after rebasing");
|
|
2746
2776
|
const edge2 = a < b ? `${a}/${b}` : `${b}/${a}`;
|
|
2747
|
-
const previous =
|
|
2777
|
+
const previous = edges2.get(edge2);
|
|
2748
2778
|
if (previous !== void 0) {
|
|
2749
2779
|
if (previous === tileIndex)
|
|
2750
2780
|
throw new Error("Duplicate terrain contour segment");
|
|
@@ -2752,7 +2782,7 @@ function weldTerrainContourTiles(tiles, options) {
|
|
|
2752
2782
|
}
|
|
2753
2783
|
if (levelIndices.length >= limits.maxSegments)
|
|
2754
2784
|
throw new Error("Terrain contour segment capacity exceeded");
|
|
2755
|
-
|
|
2785
|
+
edges2.set(edge2, tileIndex);
|
|
2756
2786
|
segments.push(a, b);
|
|
2757
2787
|
levelIndices.push(level);
|
|
2758
2788
|
}
|
|
@@ -3825,7 +3855,7 @@ function weldTerrainMixedContourTiles(tiles, options = {}) {
|
|
|
3825
3855
|
const positions = [], grid = [], vertexLevels = [];
|
|
3826
3856
|
const roundedBoundary = /* @__PURE__ */ new Map();
|
|
3827
3857
|
const boundary = /* @__PURE__ */ new Set(), shared = /* @__PURE__ */ new Map();
|
|
3828
|
-
const
|
|
3858
|
+
const edges2 = [];
|
|
3829
3859
|
let inputVertices = 0, inputSegments = 0;
|
|
3830
3860
|
for (let ti = 0; ti < sorted.length; ti++) {
|
|
3831
3861
|
const tile = sorted[ti], data = tile.contours;
|
|
@@ -3902,11 +3932,11 @@ function weldTerrainMixedContourTiles(tiles, options = {}) {
|
|
|
3902
3932
|
localEdges.add(key2);
|
|
3903
3933
|
const box = bounds2[ti];
|
|
3904
3934
|
const seam = grid[2 * a] === grid[2 * b] && (grid[2 * a] === box[0] || grid[2 * a] === box[2]) || grid[2 * a + 1] === grid[2 * b + 1] && (grid[2 * a + 1] === box[1] || grid[2 * a + 1] === box[3]);
|
|
3905
|
-
|
|
3935
|
+
edges2.push({ a, b, level, tile: ti, seam });
|
|
3906
3936
|
}
|
|
3907
3937
|
}
|
|
3908
3938
|
const segments = [], levels = [], emitted = /* @__PURE__ */ new Map();
|
|
3909
|
-
for (const edge2 of
|
|
3939
|
+
for (const edge2 of edges2) {
|
|
3910
3940
|
const { a, b, level } = edge2;
|
|
3911
3941
|
const axis = grid[2 * a] === grid[2 * b] ? 1 : 0;
|
|
3912
3942
|
const start = grid[2 * a + axis], end = grid[2 * b + axis];
|
|
@@ -4043,56 +4073,48 @@ function buildMixedVertexTileHalos(tiles, options = {}, targets, preparation) {
|
|
|
4043
4073
|
if (![maxSamples, maxTests].every((v) => Number.isSafeInteger(v) && v >= 0))
|
|
4044
4074
|
throw new Error("Invalid mixed halo capacity");
|
|
4045
4075
|
let count = 0;
|
|
4046
|
-
|
|
4076
|
+
let previousKey;
|
|
4047
4077
|
let frame;
|
|
4048
4078
|
const sources = [...tiles].sort((a, b) => a.spacing - b.spacing || a.column - b.column || a.row - b.row).map((tile) => {
|
|
4049
|
-
if (![tile.column, tile.row, tile.spacing].every(Number.isSafeInteger) || tile.spacing < 1 || 2 ** Math.round(Math.log2(tile.spacing)) !== tile.spacing)
|
|
4050
|
-
throw new Error("Invalid mixed halo lattice");
|
|
4051
|
-
const key2 = `${tile.spacing}/${tile.column}/${tile.row}`;
|
|
4052
|
-
if (addresses.has(key2))
|
|
4053
|
-
throw new Error("Duplicate mixed halo tile");
|
|
4054
|
-
addresses.add(key2);
|
|
4055
4079
|
count += (tile.field.width + 2) * (tile.field.height + 2);
|
|
4056
4080
|
if (!Number.isSafeInteger(count) || count > maxSamples)
|
|
4057
4081
|
throw new Error("Mixed halo sample capacity exceeded");
|
|
4058
|
-
let
|
|
4059
|
-
if (!
|
|
4060
|
-
|
|
4061
|
-
preparation == null ? void 0 : preparation.
|
|
4082
|
+
let prepared = preparation == null ? void 0 : preparation.tiles.get(tile);
|
|
4083
|
+
if (!prepared) {
|
|
4084
|
+
prepared = prepareMixedHaloTile(tile);
|
|
4085
|
+
preparation == null ? void 0 : preparation.tiles.set(tile, prepared);
|
|
4086
|
+
}
|
|
4087
|
+
const { key: key2, source: field, columnStep: column, rowStep: row, frameOrigin: origin, scale } = prepared;
|
|
4088
|
+
if (previousKey === key2)
|
|
4089
|
+
throw new Error("Duplicate mixed halo tile");
|
|
4090
|
+
previousKey = key2;
|
|
4091
|
+
if (frame) {
|
|
4092
|
+
if (frame.reference !== field.heightReference)
|
|
4093
|
+
throw new Error("Mixed halo frames or height references differ");
|
|
4094
|
+
for (let i = 0; i < 2; i++) {
|
|
4095
|
+
if (column[i] !== frame.column[i] || row[i] !== frame.row[i] || origin[i] !== frame.origin[i] && Math.abs(origin[i] - frame.origin[i]) > Math.min(16 * Number.EPSILON * Math.max(scale[i], frame.scale[i]), 1e-9 * Math.max(Math.abs(column[i]), Math.abs(row[i]))))
|
|
4096
|
+
throw new Error("Mixed halo frames or height references differ");
|
|
4097
|
+
}
|
|
4062
4098
|
}
|
|
4063
|
-
if (field.registration !== "vertex")
|
|
4064
|
-
throw new Error("Mixed halos require vertex registration");
|
|
4065
|
-
const column = field.columnStep.map((v) => v / tile.spacing);
|
|
4066
|
-
const row = field.rowStep.map((v) => v / tile.spacing);
|
|
4067
|
-
const origin = field.origin.map((v, axis) => v - tile.column * column[axis] - tile.row * row[axis]);
|
|
4068
|
-
const scale = field.origin.map((v, i) => Math.max(1, Math.abs(v), Math.abs(tile.column * column[i]), Math.abs(tile.row * row[i])));
|
|
4069
|
-
if (!origin.every(Number.isFinite))
|
|
4070
|
-
throw new Error("Mixed halo coordinate overflow");
|
|
4071
|
-
if (frame && (frame.reference !== field.heightReference || column.some((v, i) => v !== frame.column[i]) || row.some((v, i) => v !== frame.row[i]) || origin.some((v, i) => Math.abs(v - frame.origin[i]) > Math.min(16 * Number.EPSILON * Math.max(scale[i], frame.scale[i]), 1e-9 * Math.max(Math.abs(column[i]), Math.abs(row[i]))))))
|
|
4072
|
-
throw new Error("Mixed halo frames or height references differ");
|
|
4073
4099
|
frame ?? (frame = { origin, column, row, reference: field.heightReference, scale });
|
|
4074
|
-
return
|
|
4100
|
+
return prepared;
|
|
4075
4101
|
});
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
if (sources.length && !Number.isSafeInteger(max - min))
|
|
4087
|
-
throw new Error("Mixed halo lattice span overflow");
|
|
4088
|
-
}
|
|
4102
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
4103
|
+
for (let i = 0; i < sources.length; i++) {
|
|
4104
|
+
const { haloBounds } = sources[i];
|
|
4105
|
+
minX = Math.min(minX, haloBounds.minX);
|
|
4106
|
+
minY = Math.min(minY, haloBounds.minY);
|
|
4107
|
+
maxX = Math.max(maxX, haloBounds.maxX);
|
|
4108
|
+
maxY = Math.max(maxY, haloBounds.maxY);
|
|
4109
|
+
}
|
|
4110
|
+
if (sources.length && (!Number.isSafeInteger(maxX - minX) || !Number.isSafeInteger(maxY - minY)))
|
|
4111
|
+
throw new Error("Mixed halo lattice span overflow");
|
|
4089
4112
|
if (targets && targets.size === 0)
|
|
4090
4113
|
return { tiles: [] };
|
|
4091
4114
|
let index;
|
|
4092
4115
|
if (sources.length > 8) {
|
|
4093
|
-
const keys = preparation && sources.map((tile) => `${tile.spacing}/${tile.column}/${tile.row}/${tile.source.width}/${tile.source.height}`);
|
|
4094
4116
|
const cached = preparation == null ? void 0 : preparation.layout;
|
|
4095
|
-
if (
|
|
4117
|
+
if (cached && sources.length === cached.keys.length && sources.every((tile, i) => tile.layoutKey === cached.keys[i])) {
|
|
4096
4118
|
index = cached.query;
|
|
4097
4119
|
} else {
|
|
4098
4120
|
index = createTerrainBoxIndex(sources.map((tile) => ({
|
|
@@ -4101,8 +4123,8 @@ function buildMixedVertexTileHalos(tiles, options = {}, targets, preparation) {
|
|
|
4101
4123
|
maxX: tile.column + (tile.source.width - 1) * tile.spacing,
|
|
4102
4124
|
maxY: tile.row + (tile.source.height - 1) * tile.spacing
|
|
4103
4125
|
})));
|
|
4104
|
-
if (preparation
|
|
4105
|
-
preparation.layout = { keys, query: index };
|
|
4126
|
+
if (preparation)
|
|
4127
|
+
preparation.layout = { keys: sources.map((tile) => tile.layoutKey), query: index };
|
|
4106
4128
|
}
|
|
4107
4129
|
}
|
|
4108
4130
|
let tests = 0;
|
|
@@ -4111,21 +4133,17 @@ function buildMixedVertexTileHalos(tiles, options = {}, targets, preparation) {
|
|
|
4111
4133
|
throw new Error("Mixed halo tile-test budget exceeded");
|
|
4112
4134
|
};
|
|
4113
4135
|
return {
|
|
4114
|
-
tiles: sources.filter((tile) => !targets || targets.has(
|
|
4136
|
+
tiles: sources.filter((tile) => !targets || targets.has(tile.key)).map((tile) => {
|
|
4115
4137
|
const source = tile.source, width = source.width + 2, height = source.height + 2;
|
|
4116
4138
|
const heights = new Float64Array(width * height), validity = new Uint8Array(heights.length), statuses = new Uint8Array(heights.length);
|
|
4117
|
-
const candidates = (index == null ? void 0 : index(
|
|
4118
|
-
minX: tile.column - tile.spacing,
|
|
4119
|
-
minY: tile.row - tile.spacing,
|
|
4120
|
-
maxX: tile.column + source.width * tile.spacing,
|
|
4121
|
-
maxY: tile.row + source.height * tile.spacing
|
|
4122
|
-
}, charge).map((id) => sources[id])) ?? sources;
|
|
4139
|
+
const candidates = (index == null ? void 0 : index(tile.haloBounds, charge).map((id) => sources[id])) ?? sources;
|
|
4123
4140
|
for (let y = 0; y < height; y++)
|
|
4124
4141
|
for (let x = 0; x < width; x++) {
|
|
4125
4142
|
const gx = tile.column + (x - 1) * tile.spacing, gy = tile.row + (y - 1) * tile.spacing;
|
|
4126
|
-
if (!
|
|
4143
|
+
if (!Number.isSafeInteger(gx) || !Number.isSafeInteger(gy))
|
|
4127
4144
|
throw new Error("Mixed halo lattice overflow");
|
|
4128
|
-
for (
|
|
4145
|
+
for (let candidateIndex = 0; candidateIndex < candidates.length; candidateIndex++) {
|
|
4146
|
+
const candidate = candidates[candidateIndex];
|
|
4129
4147
|
charge();
|
|
4130
4148
|
const cx = (gx - candidate.column) / candidate.spacing, cy = (gy - candidate.row) / candidate.spacing;
|
|
4131
4149
|
const f = candidate.source;
|
|
@@ -4168,6 +4186,36 @@ function buildMixedVertexTileHalos(tiles, options = {}, targets, preparation) {
|
|
|
4168
4186
|
})
|
|
4169
4187
|
};
|
|
4170
4188
|
}
|
|
4189
|
+
function prepareMixedHaloTile(tile) {
|
|
4190
|
+
const { column, row, spacing } = tile;
|
|
4191
|
+
if (![column, row, spacing].every(Number.isSafeInteger) || spacing < 1 || 2 ** Math.round(Math.log2(spacing)) !== spacing)
|
|
4192
|
+
throw new Error("Invalid mixed halo lattice");
|
|
4193
|
+
const source = new HeightField(tile.field);
|
|
4194
|
+
if (source.registration !== "vertex")
|
|
4195
|
+
throw new Error("Mixed halos require vertex registration");
|
|
4196
|
+
const columnStep = source.columnStep.map((v) => v / spacing);
|
|
4197
|
+
const rowStep = source.rowStep.map((v) => v / spacing);
|
|
4198
|
+
const frameOrigin = source.origin.map((v, i) => v - column * columnStep[i] - row * rowStep[i]);
|
|
4199
|
+
const scale = source.origin.map((v, i) => Math.max(1, Math.abs(v), Math.abs(column * columnStep[i]), Math.abs(row * rowStep[i])));
|
|
4200
|
+
if (!frameOrigin.every(Number.isFinite))
|
|
4201
|
+
throw new Error("Mixed halo coordinate overflow");
|
|
4202
|
+
const minX = column - spacing, minY = row - spacing;
|
|
4203
|
+
const maxX = column + source.width * spacing, maxY = row + source.height * spacing;
|
|
4204
|
+
if (![minX, minY, maxX, maxY].every(Number.isSafeInteger))
|
|
4205
|
+
throw new Error("Mixed halo lattice overflow");
|
|
4206
|
+
const key2 = `${spacing}/${column}/${row}`;
|
|
4207
|
+
return {
|
|
4208
|
+
...tile,
|
|
4209
|
+
source,
|
|
4210
|
+
columnStep,
|
|
4211
|
+
rowStep,
|
|
4212
|
+
frameOrigin,
|
|
4213
|
+
scale,
|
|
4214
|
+
key: key2,
|
|
4215
|
+
layoutKey: `${key2}/${source.width}/${source.height}`,
|
|
4216
|
+
haloBounds: { minX, minY, maxX, maxY }
|
|
4217
|
+
};
|
|
4218
|
+
}
|
|
4171
4219
|
|
|
4172
4220
|
// dist/terrain/mixed-halo-update.js
|
|
4173
4221
|
var key = (t) => `${t.spacing}/${t.column}/${t.row}`;
|
|
@@ -4213,14 +4261,21 @@ function updateTerrainMixedVertexTileHalos(previous, resident, options = {}) {
|
|
|
4213
4261
|
const budget = options.maxDependencyTests ?? 1e7;
|
|
4214
4262
|
if (!Number.isSafeInteger(budget) || budget < 0)
|
|
4215
4263
|
throw new Error("Invalid mixed halo dependency budget");
|
|
4216
|
-
const old = new Map(previous == null ? void 0 : previous.sources.map((t) => [key(t), t]));
|
|
4217
|
-
const current = new Map(resident.map((t) => [key(t), t]));
|
|
4218
|
-
const cached = new Map(previous == null ? void 0 : previous.tiles.map((t) => [key(t), t]));
|
|
4219
|
-
const targets = /* @__PURE__ */ new Set();
|
|
4220
4264
|
const unchangedLayout = (previous == null ? void 0 : previous.sources.length) === resident.length && resident.every((tile, i) => {
|
|
4221
4265
|
const prior = previous.sources[i];
|
|
4222
|
-
return
|
|
4266
|
+
return prior === tile || prior.column === tile.column && prior.row === tile.row && prior.spacing === tile.spacing && prior.field.width === tile.field.width && prior.field.height === tile.field.height;
|
|
4223
4267
|
});
|
|
4268
|
+
const old = unchangedLayout ? void 0 : new Map(previous == null ? void 0 : previous.sources.map((t) => [key(t), t]));
|
|
4269
|
+
const targets = /* @__PURE__ */ new Set();
|
|
4270
|
+
const initialized = previous !== null && preparations.has(previous);
|
|
4271
|
+
if (!initialized) {
|
|
4272
|
+
const cached = new Set(previous == null ? void 0 : previous.tiles.map(key));
|
|
4273
|
+
for (const tile of resident) {
|
|
4274
|
+
const address = key(tile);
|
|
4275
|
+
if (!cached.has(address))
|
|
4276
|
+
targets.add(address);
|
|
4277
|
+
}
|
|
4278
|
+
}
|
|
4224
4279
|
let index = unchangedLayout && previous ? targetIndexes.get(previous) : void 0;
|
|
4225
4280
|
let tests = 0;
|
|
4226
4281
|
const charge = () => {
|
|
@@ -4232,12 +4287,13 @@ function updateTerrainMixedVertexTileHalos(previous, resident, options = {}) {
|
|
|
4232
4287
|
for (const id of index(box, charge))
|
|
4233
4288
|
targets.add(key(resident[id]));
|
|
4234
4289
|
}
|
|
4235
|
-
for (
|
|
4236
|
-
const
|
|
4237
|
-
const prior = old.get(
|
|
4238
|
-
if (
|
|
4239
|
-
|
|
4240
|
-
|
|
4290
|
+
for (let i = 0; i < resident.length; i++) {
|
|
4291
|
+
const tile = resident[i];
|
|
4292
|
+
const prior = unchangedLayout ? previous.sources[i] : old == null ? void 0 : old.get(key(tile));
|
|
4293
|
+
if (prior === tile)
|
|
4294
|
+
continue;
|
|
4295
|
+
targets.add(key(tile));
|
|
4296
|
+
if (!previous)
|
|
4241
4297
|
continue;
|
|
4242
4298
|
if (!prior) {
|
|
4243
4299
|
invalidate(bounds(tile));
|
|
@@ -4250,24 +4306,44 @@ function updateTerrainMixedVertexTileHalos(previous, resident, options = {}) {
|
|
|
4250
4306
|
invalidate(dirty);
|
|
4251
4307
|
}
|
|
4252
4308
|
}
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4309
|
+
const removed = [];
|
|
4310
|
+
if (old == null ? void 0 : old.size) {
|
|
4311
|
+
const current = new Set(resident.map(key));
|
|
4312
|
+
for (const [address, tile] of old) {
|
|
4313
|
+
if (current.has(address))
|
|
4314
|
+
continue;
|
|
4315
|
+
removed.push(address);
|
|
4316
|
+
if (resident.length)
|
|
4317
|
+
invalidate(bounds(tile));
|
|
4318
|
+
}
|
|
4256
4319
|
}
|
|
4257
4320
|
const priorPreparation = previous && preparations.get(previous);
|
|
4258
4321
|
const preparation = {
|
|
4259
|
-
|
|
4322
|
+
tiles: (priorPreparation == null ? void 0 : priorPreparation.tiles) ?? /* @__PURE__ */ new WeakMap(),
|
|
4260
4323
|
layout: priorPreparation == null ? void 0 : priorPreparation.layout
|
|
4261
4324
|
};
|
|
4262
4325
|
const built = buildMixedVertexTileHalos(resident, options, targets, preparation).tiles;
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4326
|
+
let tiles;
|
|
4327
|
+
if (unchangedLayout && initialized) {
|
|
4328
|
+
let cursor = 0;
|
|
4329
|
+
tiles = previous.tiles.map((tile) => {
|
|
4330
|
+
const replacement = built[cursor];
|
|
4331
|
+
if ((replacement == null ? void 0 : replacement.spacing) !== tile.spacing || replacement.column !== tile.column || replacement.row !== tile.row)
|
|
4332
|
+
return tile;
|
|
4333
|
+
cursor++;
|
|
4334
|
+
return replacement;
|
|
4335
|
+
});
|
|
4336
|
+
} else {
|
|
4337
|
+
const cached = new Map(previous == null ? void 0 : previous.tiles.map((tile) => [key(tile), tile]));
|
|
4338
|
+
for (const tile of built)
|
|
4339
|
+
cached.set(key(tile), tile);
|
|
4340
|
+
tiles = resident.map((tile) => cached.get(key(tile))).sort((a, b) => a.spacing - b.spacing || a.column - b.column || a.row - b.row);
|
|
4341
|
+
}
|
|
4266
4342
|
const snapshot = {
|
|
4267
4343
|
sources: resident.slice(),
|
|
4268
4344
|
tiles,
|
|
4269
4345
|
rebuilt: built.map(key),
|
|
4270
|
-
removed:
|
|
4346
|
+
removed: removed.sort()
|
|
4271
4347
|
};
|
|
4272
4348
|
preparations.set(snapshot, preparation);
|
|
4273
4349
|
if (index)
|
|
@@ -4326,24 +4402,24 @@ function simplifyTerrainContourPathsTopology(paths, options) {
|
|
|
4326
4402
|
const points = new Array(paths.positions.length / 3);
|
|
4327
4403
|
for (const i of new Set(paths.indices))
|
|
4328
4404
|
points[i] = { x: integer(paths.positions[3 * i]), y: integer(paths.positions[3 * i + 1]) };
|
|
4329
|
-
const
|
|
4405
|
+
const edges2 = [];
|
|
4330
4406
|
for (let p = 0; p < paths.closed.length; p++)
|
|
4331
4407
|
for (let i = paths.offsets[p]; i + 1 < paths.offsets[p + 1]; i++)
|
|
4332
|
-
|
|
4408
|
+
edges2.push({ a: paths.indices[i], b: paths.indices[i + 1], p, i });
|
|
4333
4409
|
const box = (a, b) => ({
|
|
4334
4410
|
minX: Math.min(paths.positions[3 * a], paths.positions[3 * b]),
|
|
4335
4411
|
maxX: Math.max(paths.positions[3 * a], paths.positions[3 * b]),
|
|
4336
4412
|
minY: Math.min(paths.positions[3 * a + 1], paths.positions[3 * b + 1]),
|
|
4337
4413
|
maxY: Math.max(paths.positions[3 * a + 1], paths.positions[3 * b + 1])
|
|
4338
4414
|
});
|
|
4339
|
-
const edgeBoxes =
|
|
4415
|
+
const edgeBoxes = edges2.map((e) => box(e.a, e.b)), edgeIndex = createTerrainBoxIndex(edgeBoxes);
|
|
4340
4416
|
const vertexIds = [...new Set(paths.indices)], vertexIndex = createTerrainBoxIndex(vertexIds.map((v) => box(v, v)));
|
|
4341
|
-
for (let i = 0; i <
|
|
4417
|
+
for (let i = 0; i < edges2.length; i++)
|
|
4342
4418
|
for (const j of edgeIndex(edgeBoxes[i], charge)) {
|
|
4343
4419
|
if (j <= i)
|
|
4344
4420
|
continue;
|
|
4345
4421
|
charge();
|
|
4346
|
-
const a =
|
|
4422
|
+
const a = edges2[i], b = edges2[j];
|
|
4347
4423
|
const common = [a.a, a.b].filter((v) => v === b.a || v === b.b);
|
|
4348
4424
|
if (common.length === 1) {
|
|
4349
4425
|
const v = common[0], x = a.a === v ? a.b : a.a, y = b.a === v ? b.b : b.a;
|
|
@@ -4376,7 +4452,7 @@ function simplifyTerrainContourPathsTopology(paths, options) {
|
|
|
4376
4452
|
const interior = new Set(Array.from(paths.indices.subarray(start + 1, end)));
|
|
4377
4453
|
let unsafe = false;
|
|
4378
4454
|
for (const edgeId of edgeIndex(box(a, b), charge)) {
|
|
4379
|
-
const edge2 =
|
|
4455
|
+
const edge2 = edges2[edgeId];
|
|
4380
4456
|
if (edge2.p === p && edge2.i >= start && edge2.i < end) {
|
|
4381
4457
|
if (straight)
|
|
4382
4458
|
continue;
|
|
@@ -4616,7 +4692,7 @@ function createTerrainIsobands(fields, levels, options = {}) {
|
|
|
4616
4692
|
return out.filter((v, i) => v.key !== out[(i + 1) % out.length].key);
|
|
4617
4693
|
};
|
|
4618
4694
|
for (let band = 0; band + 1 < levels.length; band++) {
|
|
4619
|
-
const
|
|
4695
|
+
const edges2 = /* @__PURE__ */ new Map();
|
|
4620
4696
|
for (const fieldId of rangeIndex({ minX: levels[band], maxX: levels[band + 1], minY: 0, maxY: 0 }, charge))
|
|
4621
4697
|
for (let y = 0; y < fields[fieldId].height - 1; y++)
|
|
4622
4698
|
for (let x = 0; x < fields[fieldId].width - 1; x++) {
|
|
@@ -4672,33 +4748,33 @@ function createTerrainIsobands(fields, levels, options = {}) {
|
|
|
4672
4748
|
if (++edgeCount > maxEdges)
|
|
4673
4749
|
throw new Error("Isoband edge capacity exceeded");
|
|
4674
4750
|
const key2 = `${a.key}>${b.key}`, reverse = `${b.key}>${a.key}`;
|
|
4675
|
-
if (
|
|
4676
|
-
|
|
4751
|
+
if (edges2.has(reverse))
|
|
4752
|
+
edges2.delete(reverse);
|
|
4677
4753
|
else {
|
|
4678
|
-
if (
|
|
4754
|
+
if (edges2.has(key2))
|
|
4679
4755
|
throw new Error("Overlapping isoband tiles");
|
|
4680
|
-
|
|
4756
|
+
edges2.set(key2, { a, b });
|
|
4681
4757
|
}
|
|
4682
4758
|
}
|
|
4683
4759
|
}
|
|
4684
4760
|
}
|
|
4685
4761
|
const outgoing = /* @__PURE__ */ new Map();
|
|
4686
|
-
for (const [key2, e] of
|
|
4762
|
+
for (const [key2, e] of edges2) {
|
|
4687
4763
|
if (!outgoing.has(e.a.key))
|
|
4688
4764
|
outgoing.set(e.a.key, /* @__PURE__ */ new Set());
|
|
4689
4765
|
outgoing.get(e.a.key).add(key2);
|
|
4690
4766
|
}
|
|
4691
|
-
while (
|
|
4692
|
-
const first =
|
|
4767
|
+
while (edges2.size) {
|
|
4768
|
+
const first = edges2.values().next().value, ring = [];
|
|
4693
4769
|
let edge2 = first;
|
|
4694
4770
|
for (; ; ) {
|
|
4695
4771
|
charge();
|
|
4696
4772
|
ring.push(edge2.a);
|
|
4697
|
-
|
|
4773
|
+
edges2.delete(`${edge2.a.key}>${edge2.b.key}`);
|
|
4698
4774
|
outgoing.get(edge2.a.key).delete(`${edge2.a.key}>${edge2.b.key}`);
|
|
4699
4775
|
if (edge2.b.key === first.a.key)
|
|
4700
4776
|
break;
|
|
4701
|
-
const choices = [...outgoing.get(edge2.b.key) ?? []].map((k) =>
|
|
4777
|
+
const choices = [...outgoing.get(edge2.b.key) ?? []].map((k) => edges2.get(k));
|
|
4702
4778
|
if (!choices.length)
|
|
4703
4779
|
throw new Error("Open isoband boundary");
|
|
4704
4780
|
const angle = (e) => Math.atan2((edge2.b.x - edge2.a.x) * (e.b.y - e.a.y) - (edge2.b.y - edge2.a.y) * (e.b.x - e.a.x), (edge2.b.x - edge2.a.x) * (e.b.x - e.a.x) + (edge2.b.y - edge2.a.y) * (e.b.y - e.a.y));
|
|
@@ -5579,12 +5655,12 @@ function meshValidDomain(field, options, constraints) {
|
|
|
5579
5655
|
const { width, height, origin, heightReference } = regular;
|
|
5580
5656
|
const active = new Uint8Array(count);
|
|
5581
5657
|
const boundary = /* @__PURE__ */ new Map();
|
|
5582
|
-
const
|
|
5658
|
+
const edgeKey3 = (a, b) => Math.min(a, b) * count + Math.max(a, b);
|
|
5583
5659
|
for (let i = 0; i < regular.indices.length; i += 3) {
|
|
5584
5660
|
for (let j = 0; j < 3; j++) {
|
|
5585
5661
|
const a = regular.indices[i + j], b = regular.indices[i + (j + 1) % 3];
|
|
5586
5662
|
active[a] = 1;
|
|
5587
|
-
const key2 =
|
|
5663
|
+
const key2 = edgeKey3(a, b);
|
|
5588
5664
|
if (!boundary.delete(key2))
|
|
5589
5665
|
boundary.set(key2, [a, b]);
|
|
5590
5666
|
}
|
|
@@ -5600,8 +5676,8 @@ function meshValidDomain(field, options, constraints) {
|
|
|
5600
5676
|
}
|
|
5601
5677
|
return selected[i];
|
|
5602
5678
|
};
|
|
5603
|
-
const
|
|
5604
|
-
const extra = constraints == null ? void 0 : constraints(points, heights,
|
|
5679
|
+
const edges2 = Array.from(boundary.values(), ([a, b]) => [add2(a), add2(b)]);
|
|
5680
|
+
const extra = constraints == null ? void 0 : constraints(points, heights, edges2, selected, origin[2]);
|
|
5605
5681
|
const inDomain = ([a, b, c]) => {
|
|
5606
5682
|
const x = (points[a][0] + points[b][0] + points[c][0]) / 3;
|
|
5607
5683
|
const y = (points[a][1] + points[b][1] + points[c][1]) / 3;
|
|
@@ -5619,7 +5695,7 @@ function meshValidDomain(field, options, constraints) {
|
|
|
5619
5695
|
let certifiedSamples = 0;
|
|
5620
5696
|
let tests = 0;
|
|
5621
5697
|
for (let pass = 0; points.length; pass++) {
|
|
5622
|
-
triangles = (0, import_cdt2d.default)(points, (extra == null ? void 0 : extra.edges) ??
|
|
5698
|
+
triangles = (0, import_cdt2d.default)(points, (extra == null ? void 0 : extra.edges) ?? edges2, {
|
|
5623
5699
|
exterior: Boolean(extra),
|
|
5624
5700
|
delaunay: false
|
|
5625
5701
|
});
|
|
@@ -5763,7 +5839,7 @@ function createBreaklineTerrainMesh(field, options) {
|
|
|
5763
5839
|
throw new Error("Zero-length breakline");
|
|
5764
5840
|
breaklineEdges.push([p, q]);
|
|
5765
5841
|
}
|
|
5766
|
-
const
|
|
5842
|
+
const edges3 = [];
|
|
5767
5843
|
for (const [a, b] of boundary) {
|
|
5768
5844
|
const split = [
|
|
5769
5845
|
a,
|
|
@@ -5773,7 +5849,7 @@ function createBreaklineTerrainMesh(field, options) {
|
|
|
5773
5849
|
const [x, y] = points[a];
|
|
5774
5850
|
split.sort((i, j) => Math.hypot(points[i][0] - x, points[i][1] - y) - Math.hypot(points[j][0] - x, points[j][1] - y));
|
|
5775
5851
|
for (let i = 1; i < split.length; i++)
|
|
5776
|
-
|
|
5852
|
+
edges3.push([split[i - 1], split[i]]);
|
|
5777
5853
|
}
|
|
5778
5854
|
const seen = /* @__PURE__ */ new Set();
|
|
5779
5855
|
for (const [a, b] of breaklineEdges) {
|
|
@@ -5783,19 +5859,19 @@ function createBreaklineTerrainMesh(field, options) {
|
|
|
5783
5859
|
seen.add(key2);
|
|
5784
5860
|
const p = points[a], q = points[b];
|
|
5785
5861
|
let coincident = false;
|
|
5786
|
-
for (const [c, d] of
|
|
5862
|
+
for (const [c, d] of edges3) {
|
|
5787
5863
|
if (a === c && b === d || a === d && b === c) {
|
|
5788
5864
|
coincident = true;
|
|
5789
5865
|
continue;
|
|
5790
5866
|
}
|
|
5791
5867
|
const r = points[c], s = points[d];
|
|
5792
|
-
const
|
|
5793
|
-
if (
|
|
5868
|
+
const intersects3 = Math.sign(cross(p, q, r)) * Math.sign(cross(p, q, s)) < 0 && Math.sign(cross(r, s, p)) * Math.sign(cross(r, s, q)) < 0;
|
|
5869
|
+
if (intersects3 || c !== a && c !== b && onSegment(p, q, r) || d !== a && d !== b && onSegment(p, q, s) || a !== c && a !== d && onSegment(r, s, p) || b !== c && b !== d && onSegment(r, s, q)) {
|
|
5794
5870
|
throw new Error("Breaklines and domain edges must meet only at shared endpoints");
|
|
5795
5871
|
}
|
|
5796
5872
|
}
|
|
5797
5873
|
if (!coincident)
|
|
5798
|
-
|
|
5874
|
+
edges3.push([a, b]);
|
|
5799
5875
|
for (let y = Math.ceil(Math.min(p[1], q[1])); y <= Math.floor(Math.max(p[1], q[1])); y++) {
|
|
5800
5876
|
for (let x = Math.ceil(Math.min(p[0], q[0])); x <= Math.floor(Math.max(p[0], q[0])); x++) {
|
|
5801
5877
|
const source = field.getHeight(x, y);
|
|
@@ -5814,16 +5890,16 @@ function createBreaklineTerrainMesh(field, options) {
|
|
|
5814
5890
|
}
|
|
5815
5891
|
}
|
|
5816
5892
|
overriddenSamples = excluded.size;
|
|
5817
|
-
return { edges:
|
|
5893
|
+
return { edges: edges3, excluded, fixedSamples };
|
|
5818
5894
|
});
|
|
5819
|
-
const
|
|
5895
|
+
const edges2 = /* @__PURE__ */ new Set();
|
|
5820
5896
|
for (let i = 0; i < mesh.indices.length; i += 3) {
|
|
5821
5897
|
for (let j = 0; j < 3; j++) {
|
|
5822
5898
|
const a = mesh.indices[i + j], b = mesh.indices[i + (j + 1) % 3];
|
|
5823
|
-
|
|
5899
|
+
edges2.add(`${Math.min(a, b)},${Math.max(a, b)}`);
|
|
5824
5900
|
}
|
|
5825
5901
|
}
|
|
5826
|
-
if (breaklineEdges.some(([a, b]) => !
|
|
5902
|
+
if (breaklineEdges.some(([a, b]) => !edges2.has(`${Math.min(a, b)},${Math.max(a, b)}`))) {
|
|
5827
5903
|
throw new Error("Breakline was not preserved inside the valid terrain domain");
|
|
5828
5904
|
}
|
|
5829
5905
|
return { ...mesh, breaklineEdges: Uint32Array.from(breaklineEdges.flat()), overriddenSamples };
|
|
@@ -6023,21 +6099,21 @@ function wrapTerrainLongitude(longitude, west, east) {
|
|
|
6023
6099
|
function measureGeographicTerrainSeam(a, b, probes, options = {}) {
|
|
6024
6100
|
if (a && b && a.heightReference !== b.heightReference)
|
|
6025
6101
|
throw new Error("Terrain seam height references differ");
|
|
6026
|
-
const sample = (field, longitude,
|
|
6102
|
+
const sample = (field, longitude, latitude2) => {
|
|
6027
6103
|
if (!field || !Number.isFinite(longitude))
|
|
6028
|
-
return field == null ? void 0 : field.sample(longitude,
|
|
6104
|
+
return field == null ? void 0 : field.sample(longitude, latitude2, options);
|
|
6029
6105
|
const mapped = wrapTerrainLongitude(longitude, field.bounds[0], field.bounds[2]);
|
|
6030
|
-
return field.sample(mapped ?? longitude,
|
|
6106
|
+
return field.sample(mapped ?? longitude, latitude2, options);
|
|
6031
6107
|
};
|
|
6032
|
-
return probes.map(([longitude,
|
|
6033
|
-
const left = sample(a, longitude,
|
|
6034
|
-
const right = sample(b, longitude,
|
|
6108
|
+
return probes.map(([longitude, latitude2]) => {
|
|
6109
|
+
const left = sample(a, longitude, latitude2);
|
|
6110
|
+
const right = sample(b, longitude, latitude2);
|
|
6035
6111
|
const valid = (left == null ? void 0 : left.status) === TerrainSampleStatus.VALID && (right == null ? void 0 : right.status) === TerrainSampleStatus.VALID;
|
|
6036
6112
|
const derivatives = (left == null ? void 0 : left.gradientStatus) === TerrainSampleStatus.VALID && (right == null ? void 0 : right.gradientStatus) === TerrainSampleStatus.VALID;
|
|
6037
6113
|
const normalAngle = derivatives ? Math.atan2(Math.hypot(left.normalY * right.normalZ - left.normalZ * right.normalY, left.normalZ * right.normalX - left.normalX * right.normalZ, left.normalX * right.normalY - left.normalY * right.normalX), left.normalX * right.normalX + left.normalY * right.normalY + left.normalZ * right.normalZ) : null;
|
|
6038
6114
|
return {
|
|
6039
6115
|
longitude,
|
|
6040
|
-
latitude,
|
|
6116
|
+
latitude: latitude2,
|
|
6041
6117
|
statusA: (left == null ? void 0 : left.status) ?? TerrainSampleStatus.NOT_RESIDENT,
|
|
6042
6118
|
statusB: (right == null ? void 0 : right.status) ?? TerrainSampleStatus.NOT_RESIDENT,
|
|
6043
6119
|
gradientStatusA: (left == null ? void 0 : left.gradientStatus) ?? TerrainSampleStatus.NOT_RESIDENT,
|
|
@@ -6048,15 +6124,75 @@ function measureGeographicTerrainSeam(a, b, probes, options = {}) {
|
|
|
6048
6124
|
});
|
|
6049
6125
|
}
|
|
6050
6126
|
|
|
6127
|
+
// dist/terrain/lod-screen-error.js
|
|
6128
|
+
function slack(value) {
|
|
6129
|
+
return Math.abs(value) * (2 * Number.EPSILON) + Number.MIN_VALUE;
|
|
6130
|
+
}
|
|
6131
|
+
function down(value) {
|
|
6132
|
+
return value - slack(value);
|
|
6133
|
+
}
|
|
6134
|
+
function up(value) {
|
|
6135
|
+
return value + slack(value);
|
|
6136
|
+
}
|
|
6137
|
+
function boundTerrainLodScreenError(bounds2, projection) {
|
|
6138
|
+
if (bounds2.min.length !== 3 || bounds2.max.length !== 3 || !bounds2.min.every((value, i) => Number.isFinite(value) && value <= bounds2.max[i]) || !bounds2.max.every(Number.isFinite) || !Number.isFinite(bounds2.geometricError) || bounds2.geometricError < 0)
|
|
6139
|
+
throw new RangeError("Invalid terrain LOD screen-error bounds");
|
|
6140
|
+
return prepareTerrainLodScreenError(projection)(bounds2);
|
|
6141
|
+
}
|
|
6142
|
+
function prepareTerrainLodScreenError(projection) {
|
|
6143
|
+
const { width, height, depthRange = "negative-one-to-one", reversedDepth = false } = projection;
|
|
6144
|
+
if (projection.matrix.length !== 16)
|
|
6145
|
+
throw new RangeError("Invalid terrain LOD clip matrix");
|
|
6146
|
+
const matrix = Array.from(projection.matrix);
|
|
6147
|
+
if (!matrix.every(Number.isFinite) || !Number.isFinite(width) || width <= 0 || !Number.isFinite(height) || height <= 0 || depthRange !== "negative-one-to-one" && depthRange !== "zero-to-one")
|
|
6148
|
+
throw new RangeError("Invalid terrain LOD projection");
|
|
6149
|
+
return ({ min, max, geometricError: error }) => {
|
|
6150
|
+
if (error === 0)
|
|
6151
|
+
return 0;
|
|
6152
|
+
function row(index) {
|
|
6153
|
+
let lower = matrix[12 + index];
|
|
6154
|
+
let upper = lower;
|
|
6155
|
+
let change = 0;
|
|
6156
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
6157
|
+
const coefficient = matrix[4 * axis + index];
|
|
6158
|
+
const a = coefficient * min[axis];
|
|
6159
|
+
const b = coefficient * max[axis];
|
|
6160
|
+
lower = down(lower + down(Math.min(a, b)));
|
|
6161
|
+
upper = up(upper + up(Math.max(a, b)));
|
|
6162
|
+
change = up(change + up(Math.abs(coefficient) * error));
|
|
6163
|
+
}
|
|
6164
|
+
return { lower, upper, change };
|
|
6165
|
+
}
|
|
6166
|
+
const w = row(3);
|
|
6167
|
+
const z = row(2);
|
|
6168
|
+
const nearLow = reversedDepth ? down(w.lower - z.upper) : depthRange === "zero-to-one" ? z.lower : down(z.lower + w.lower);
|
|
6169
|
+
const nearHigh = reversedDepth ? up(w.upper - z.lower) : depthRange === "zero-to-one" ? z.upper : up(z.upper + w.upper);
|
|
6170
|
+
const nearChange = !reversedDepth && depthRange === "zero-to-one" ? z.change : up(z.change + w.change);
|
|
6171
|
+
if (up(nearHigh + nearChange) < 0)
|
|
6172
|
+
return 0;
|
|
6173
|
+
const denominator = down(w.lower - w.change);
|
|
6174
|
+
if (!(down(nearLow - nearChange) > 0 && denominator > 0))
|
|
6175
|
+
return Infinity;
|
|
6176
|
+
function pixelAxis(index, extent) {
|
|
6177
|
+
const coordinate = row(index);
|
|
6178
|
+
const magnitude2 = Math.max(Math.abs(coordinate.lower), Math.abs(coordinate.upper));
|
|
6179
|
+
const ndc = up(magnitude2 / denominator);
|
|
6180
|
+
const coupling = up(ndc * w.change);
|
|
6181
|
+
const numerator = up(coordinate.change + coupling);
|
|
6182
|
+
return up(up(numerator / denominator) * up(extent / 2));
|
|
6183
|
+
}
|
|
6184
|
+
const pixels = pixelAxis(0, width) + pixelAxis(1, height);
|
|
6185
|
+
return Number.isFinite(pixels) ? up(pixels) : Infinity;
|
|
6186
|
+
};
|
|
6187
|
+
}
|
|
6188
|
+
|
|
6051
6189
|
// dist/terrain/lod-select.js
|
|
6052
6190
|
function selectTerrainLod(roots, view) {
|
|
6053
6191
|
var _a;
|
|
6054
|
-
const {
|
|
6055
|
-
if (!
|
|
6192
|
+
const { targetPixels, hysteresis = 0.2, previouslyRefined, maxVisited = 1e5 } = view;
|
|
6193
|
+
if (!Number.isFinite(targetPixels) || targetPixels <= 0 || !(hysteresis >= 0 && hysteresis < 1) || !Number.isSafeInteger(maxVisited) || maxVisited < 1)
|
|
6056
6194
|
throw new Error("Invalid terrain LOD view");
|
|
6057
|
-
const
|
|
6058
|
-
if (!Number.isFinite(scale))
|
|
6059
|
-
throw new Error("Terrain LOD projection scale overflow");
|
|
6195
|
+
const pixelError = "projection" in view ? prepareTerrainLodScreenError(view.projection) : createDistanceEstimator(view.position, view.verticalFov, view.viewportHeight);
|
|
6060
6196
|
const selected = [];
|
|
6061
6197
|
const refined = /* @__PURE__ */ new Set();
|
|
6062
6198
|
const unavailable = [];
|
|
@@ -6069,14 +6205,13 @@ function selectTerrainLod(roots, view) {
|
|
|
6069
6205
|
if (seen.has(tile.id))
|
|
6070
6206
|
throw new Error("Duplicate terrain LOD tile or cycle");
|
|
6071
6207
|
seen.add(tile.id);
|
|
6072
|
-
if (![...tile.min, ...tile.max, tile.geometricError].every(Number.isFinite) || tile.geometricError < 0 || tile.min.some((n, i) => n > tile.max[i]))
|
|
6208
|
+
if (tile.min.length !== 3 || tile.max.length !== 3 || ![...tile.min, ...tile.max, tile.geometricError].every(Number.isFinite) || tile.geometricError < 0 || tile.min.some((n, i) => n > tile.max[i]))
|
|
6073
6209
|
throw new Error("Invalid terrain LOD tile bounds or error");
|
|
6074
6210
|
if (!tile.resident) {
|
|
6075
6211
|
unavailable.push(tile.id);
|
|
6076
6212
|
continue;
|
|
6077
6213
|
}
|
|
6078
|
-
const
|
|
6079
|
-
const pixels = tile.geometricError === 0 ? 0 : tile.geometricError / distance * scale;
|
|
6214
|
+
const pixels = pixelError(tile);
|
|
6080
6215
|
const threshold = targetPixels * ((previouslyRefined == null ? void 0 : previouslyRefined.has(tile.id)) ? 1 - hysteresis : 1);
|
|
6081
6216
|
if (pixels > threshold && ((_a = tile.children) == null ? void 0 : _a.length) && tile.children.every((child) => child.resident)) {
|
|
6082
6217
|
if (pending.length + seen.size + tile.children.length > maxVisited)
|
|
@@ -6090,20 +6225,41 @@ function selectTerrainLod(roots, view) {
|
|
|
6090
6225
|
}
|
|
6091
6226
|
return { selected, refined, unavailable };
|
|
6092
6227
|
}
|
|
6228
|
+
function createDistanceEstimator(position, verticalFov, viewportHeight) {
|
|
6229
|
+
if (!position.every(Number.isFinite) || !Number.isFinite(verticalFov) || verticalFov <= 0 || verticalFov >= Math.PI || !Number.isFinite(viewportHeight) || viewportHeight <= 0)
|
|
6230
|
+
throw new Error("Invalid terrain LOD view");
|
|
6231
|
+
const scale = viewportHeight / (2 * Math.tan(verticalFov / 2));
|
|
6232
|
+
if (!Number.isFinite(scale))
|
|
6233
|
+
throw new Error("Terrain LOD projection scale overflow");
|
|
6234
|
+
return (tile) => {
|
|
6235
|
+
const distance = Math.hypot(...position.map((n, i) => Math.max(tile.min[i] - n, n - tile.max[i], 0)));
|
|
6236
|
+
return tile.geometricError === 0 ? 0 : tile.geometricError / distance * scale;
|
|
6237
|
+
};
|
|
6238
|
+
}
|
|
6093
6239
|
|
|
6094
6240
|
// dist/terrain/lod-stitch.js
|
|
6095
6241
|
function stitchTerrainLodCut(input, seams) {
|
|
6096
6242
|
const meshes = input.slice();
|
|
6097
6243
|
const paired = [];
|
|
6098
|
-
for (const { a, edgeA, b, edgeB, options } of seams) {
|
|
6244
|
+
for (const { a, edgeA, b, edgeB, options, offsetBX = 0 } of seams) {
|
|
6099
6245
|
if (a === b || !Number.isInteger(a) || !Number.isInteger(b) || !meshes[a] || !meshes[b])
|
|
6100
6246
|
throw new Error("Invalid terrain LOD seam tile index");
|
|
6101
|
-
|
|
6247
|
+
if (!Number.isFinite(offsetBX))
|
|
6248
|
+
throw new Error("Invalid terrain LOD seam offset");
|
|
6249
|
+
const meshB = meshes[b];
|
|
6250
|
+
const shiftedB = offsetBX === 0 ? meshB : {
|
|
6251
|
+
...meshB,
|
|
6252
|
+
origin: [meshB.origin[0] + offsetBX, meshB.origin[1], meshB.origin[2]]
|
|
6253
|
+
};
|
|
6254
|
+
const result = stitchTerrainMeshEdges(meshes[a], edgeA, shiftedB, edgeB, options);
|
|
6102
6255
|
meshes[a] = result.a;
|
|
6103
|
-
meshes[b] = result.b
|
|
6104
|
-
|
|
6256
|
+
meshes[b] = offsetBX === 0 ? result.b : {
|
|
6257
|
+
...result.b,
|
|
6258
|
+
origin: [result.b.origin[0] - offsetBX, result.b.origin[1], result.b.origin[2]]
|
|
6259
|
+
};
|
|
6260
|
+
paired.push({ a, b, idsA: result.seamA, idsB: result.seamB, offsetBX });
|
|
6105
6261
|
}
|
|
6106
|
-
for (const { a, b, idsA, idsB } of paired) {
|
|
6262
|
+
for (const { a, b, idsA, idsB, offsetBX } of paired) {
|
|
6107
6263
|
const ma = meshes[a], mb = meshes[b];
|
|
6108
6264
|
const path = (mesh, ids) => {
|
|
6109
6265
|
const links = /* @__PURE__ */ new Set();
|
|
@@ -6122,7 +6278,7 @@ function stitchTerrainLodCut(input, seams) {
|
|
|
6122
6278
|
throw new Error("Overlapping terrain LOD seam ranges require a common subdivision");
|
|
6123
6279
|
for (let i = 0; i < idsA.length; i++) {
|
|
6124
6280
|
for (let axis = 0; axis < 3; axis++) {
|
|
6125
|
-
const offset = mb.origin[axis] - ma.origin[axis];
|
|
6281
|
+
const offset = mb.origin[axis] + (axis === 0 ? offsetBX : 0) - ma.origin[axis];
|
|
6126
6282
|
const av = ma.positions[3 * idsA[i] + axis], bv = mb.positions[3 * idsB[i] + axis];
|
|
6127
6283
|
const residual = av - bv - offset;
|
|
6128
6284
|
const roundoff = 8 * Number.EPSILON * (Math.abs(av) + Math.abs(bv) + Math.abs(offset));
|
|
@@ -6176,14 +6332,14 @@ function splitTerrainBreaklines(input, options = {}) {
|
|
|
6176
6332
|
throw new Error("Breakline output limit exceeded");
|
|
6177
6333
|
knots.push({ t, point });
|
|
6178
6334
|
};
|
|
6179
|
-
const
|
|
6335
|
+
const cross4 = (ax, ay, bx, by) => ax * by - ay * bx;
|
|
6180
6336
|
for (let i = 0; i < lines.length; i++) {
|
|
6181
6337
|
const a = lines[i];
|
|
6182
6338
|
for (let j = i + 1; j < lines.length; j++) {
|
|
6183
6339
|
const b = lines[j];
|
|
6184
6340
|
const x = b.p[0] - a.p[0], y = b.p[1] - a.p[1];
|
|
6185
|
-
const det =
|
|
6186
|
-
const u =
|
|
6341
|
+
const det = cross4(a.dx, a.dy, b.dx, b.dy);
|
|
6342
|
+
const u = cross4(x, y, a.dx, a.dy), t = cross4(x, y, b.dx, b.dy);
|
|
6187
6343
|
if (![det, u, t].every(Number.isFinite))
|
|
6188
6344
|
throw new Error("Breakline intersection overflow");
|
|
6189
6345
|
if (det === 0) {
|
|
@@ -6272,7 +6428,7 @@ function certifyTerrainMeshCoverage(field, mesh, options = {}) {
|
|
|
6272
6428
|
}
|
|
6273
6429
|
const vertices = [];
|
|
6274
6430
|
const vertexIds = /* @__PURE__ */ new Map();
|
|
6275
|
-
const
|
|
6431
|
+
const edges2 = /* @__PURE__ */ new Map();
|
|
6276
6432
|
function vertex(x, y) {
|
|
6277
6433
|
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
6278
6434
|
throw new Error("Nonfinite coverage coordinate");
|
|
@@ -6292,11 +6448,11 @@ function certifyTerrainMeshCoverage(field, mesh, options = {}) {
|
|
|
6292
6448
|
weight = -weight;
|
|
6293
6449
|
}
|
|
6294
6450
|
const key2 = b < 2 ** 26 ? a * 2 ** 26 + b : `${a},${b}`;
|
|
6295
|
-
const sum = (((_a2 =
|
|
6451
|
+
const sum = (((_a2 = edges2.get(key2)) == null ? void 0 : _a2.weight) ?? 0) + weight;
|
|
6296
6452
|
if (sum === 0)
|
|
6297
|
-
|
|
6453
|
+
edges2.delete(key2);
|
|
6298
6454
|
else
|
|
6299
|
-
|
|
6455
|
+
edges2.set(key2, { a, b, weight: sum });
|
|
6300
6456
|
}
|
|
6301
6457
|
function triangle(a, b, c, weight) {
|
|
6302
6458
|
edge2(a, b, weight);
|
|
@@ -6361,7 +6517,7 @@ function certifyTerrainMeshCoverage(field, mesh, options = {}) {
|
|
|
6361
6517
|
}
|
|
6362
6518
|
}
|
|
6363
6519
|
const lines = /* @__PURE__ */ new Map();
|
|
6364
|
-
for (const { a, b, weight } of
|
|
6520
|
+
for (const { a, b, weight } of edges2.values()) {
|
|
6365
6521
|
const p = vertices[a], q = vertices[b];
|
|
6366
6522
|
const [x, y] = p.map(exact2), [u, v] = q.map(exact2);
|
|
6367
6523
|
const divisor = gcd(u - x, v - y);
|
|
@@ -6397,7 +6553,1825 @@ function certifyTerrainMeshCoverage(field, mesh, options = {}) {
|
|
|
6397
6553
|
unmatchedSegments,
|
|
6398
6554
|
witness,
|
|
6399
6555
|
trianglesVisited,
|
|
6400
|
-
residualEdges:
|
|
6556
|
+
residualEdges: edges2.size
|
|
6557
|
+
};
|
|
6558
|
+
}
|
|
6559
|
+
|
|
6560
|
+
// dist/geographic-tiles.js
|
|
6561
|
+
function getGeographicTileBounds(tile) {
|
|
6562
|
+
const size = gridSize(tile.level);
|
|
6563
|
+
if (![tile.x, tile.y].every((v) => Number.isInteger(v) && v >= 0 && v < size))
|
|
6564
|
+
throw new RangeError("Tile coordinates must be integers inside the level grid");
|
|
6565
|
+
return [
|
|
6566
|
+
-180 + 360 * tile.x / size,
|
|
6567
|
+
90 - 180 * (tile.y + 1) / size,
|
|
6568
|
+
-180 + 360 * (tile.x + 1) / size,
|
|
6569
|
+
90 - 180 * tile.y / size
|
|
6570
|
+
];
|
|
6571
|
+
}
|
|
6572
|
+
function gridSize(level) {
|
|
6573
|
+
if (!Number.isInteger(level) || level < 0 || level > 30)
|
|
6574
|
+
throw new RangeError("Level must be an integer from 0 through 30");
|
|
6575
|
+
return 2 ** level;
|
|
6576
|
+
}
|
|
6577
|
+
|
|
6578
|
+
// dist/terrain/geographic-neighbor.js
|
|
6579
|
+
function getGeographicTerrainNeighbor(tile, edge2) {
|
|
6580
|
+
getGeographicTileBounds(tile);
|
|
6581
|
+
const { x, y, level } = tile;
|
|
6582
|
+
const size = 2 ** level;
|
|
6583
|
+
switch (edge2) {
|
|
6584
|
+
case "west":
|
|
6585
|
+
case "east": {
|
|
6586
|
+
const ownerX = edge2 === "west" ? x : (x + 1) % size;
|
|
6587
|
+
return {
|
|
6588
|
+
owner: { x: ownerX, y, level },
|
|
6589
|
+
ownerEdge: "west",
|
|
6590
|
+
other: { x: (ownerX + size - 1) % size, y, level },
|
|
6591
|
+
otherEdge: "east",
|
|
6592
|
+
crossesAntimeridian: ownerX === 0
|
|
6593
|
+
};
|
|
6594
|
+
}
|
|
6595
|
+
case "north":
|
|
6596
|
+
case "south": {
|
|
6597
|
+
const ownerY = edge2 === "north" ? y : y + 1;
|
|
6598
|
+
if (ownerY === 0 || ownerY === size)
|
|
6599
|
+
return null;
|
|
6600
|
+
return {
|
|
6601
|
+
owner: { x, y: ownerY, level },
|
|
6602
|
+
ownerEdge: "north",
|
|
6603
|
+
other: { x, y: ownerY - 1, level },
|
|
6604
|
+
otherEdge: "south",
|
|
6605
|
+
crossesAntimeridian: false
|
|
6606
|
+
};
|
|
6607
|
+
}
|
|
6608
|
+
default:
|
|
6609
|
+
throw new RangeError("Invalid geographic terrain edge");
|
|
6610
|
+
}
|
|
6611
|
+
}
|
|
6612
|
+
|
|
6613
|
+
// dist/terrain/sweep-sphere.js
|
|
6614
|
+
function sweepTerrainSphere(surface, start, end, radius, { fractionTolerance = 1e-6, maxWork = 1e5 } = {}) {
|
|
6615
|
+
if (!(fractionTolerance >= Number.EPSILON && fractionTolerance <= 1) || !Number.isSafeInteger(maxWork) || maxWork < 0)
|
|
6616
|
+
throw new RangeError("Invalid terrain sphere sweep limits");
|
|
6617
|
+
const delta = end.map((value, axis) => value - start[axis]);
|
|
6618
|
+
if (start.length !== 3 || end.length !== 3 || !start.every(Number.isFinite) || !end.every(Number.isFinite) || !delta.every(Number.isFinite) || !Number.isFinite(radius) || radius < 0)
|
|
6619
|
+
throw new RangeError("Invalid terrain sphere sweep motion or radius");
|
|
6620
|
+
let work = 0;
|
|
6621
|
+
let lower = 0;
|
|
6622
|
+
let upper = 1;
|
|
6623
|
+
const prefix = (fraction) => {
|
|
6624
|
+
const endPoint = fraction === 0 ? start : fraction === 1 ? end : [
|
|
6625
|
+
start[0] + delta[0] * fraction,
|
|
6626
|
+
start[1] + delta[1] * fraction,
|
|
6627
|
+
start[2] + delta[2] * fraction
|
|
6628
|
+
];
|
|
6629
|
+
const query = surface.intersectCapsule(start, endPoint, radius, {
|
|
6630
|
+
maxWork: maxWork - work,
|
|
6631
|
+
maxContacts: 1
|
|
6632
|
+
});
|
|
6633
|
+
work += query.work;
|
|
6634
|
+
return query;
|
|
6635
|
+
};
|
|
6636
|
+
const initial = prefix(0);
|
|
6637
|
+
if (initial.result[0])
|
|
6638
|
+
return { status: "hit", fraction: 0, lowerFraction: 0, contact: initial.result[0], work };
|
|
6639
|
+
if (!initial.complete)
|
|
6640
|
+
return { status: "incomplete", work };
|
|
6641
|
+
const full = prefix(1);
|
|
6642
|
+
let contact = full.result[0];
|
|
6643
|
+
if (!contact)
|
|
6644
|
+
return { status: full.complete ? "miss" : "incomplete", work };
|
|
6645
|
+
while (upper - lower > fractionTolerance) {
|
|
6646
|
+
const middle = (lower + upper) / 2;
|
|
6647
|
+
const query = prefix(middle);
|
|
6648
|
+
if (query.result[0]) {
|
|
6649
|
+
upper = middle;
|
|
6650
|
+
contact = query.result[0];
|
|
6651
|
+
} else if (query.complete) {
|
|
6652
|
+
lower = middle;
|
|
6653
|
+
} else {
|
|
6654
|
+
return { status: "incomplete", work };
|
|
6655
|
+
}
|
|
6656
|
+
}
|
|
6657
|
+
return { status: "hit", fraction: upper, lowerFraction: lower, contact, work };
|
|
6658
|
+
}
|
|
6659
|
+
|
|
6660
|
+
// dist/terrain/sweep-capsule.js
|
|
6661
|
+
function sweepTerrainCapsule(surface, start, end, translation, radius, { fractionTolerance = 1e-6, maxWork = 1e5 } = {}) {
|
|
6662
|
+
var _a;
|
|
6663
|
+
const speed = Math.hypot(...translation);
|
|
6664
|
+
if (![start, end, translation].every((point) => point.length === 3 && point.every(Number.isFinite)) || !Number.isFinite(speed) || !Number.isFinite(radius) || radius < 0 || !(fractionTolerance >= Number.EPSILON && fractionTolerance <= 1) || !Number.isSafeInteger(maxWork) || maxWork < 0)
|
|
6665
|
+
throw new RangeError("Invalid terrain capsule sweep");
|
|
6666
|
+
let work = 0;
|
|
6667
|
+
const probe = (fraction) => {
|
|
6668
|
+
if (work >= maxWork)
|
|
6669
|
+
return null;
|
|
6670
|
+
work++;
|
|
6671
|
+
const move = (point) => [
|
|
6672
|
+
point[0] + translation[0] * fraction,
|
|
6673
|
+
point[1] + translation[1] * fraction,
|
|
6674
|
+
point[2] + translation[2] * fraction
|
|
6675
|
+
];
|
|
6676
|
+
const query = surface.nearestSegmentQuery(move(start), move(end), { maxWork: maxWork - work });
|
|
6677
|
+
work += query.work;
|
|
6678
|
+
return query;
|
|
6679
|
+
};
|
|
6680
|
+
const initial = probe(0);
|
|
6681
|
+
if ((initial == null ? void 0 : initial.result) && initial.result.distance <= radius)
|
|
6682
|
+
return { status: "hit", work, fraction: 0, lowerFraction: 0, contact: initial.result };
|
|
6683
|
+
if (!(initial == null ? void 0 : initial.complete))
|
|
6684
|
+
return { status: "incomplete", work };
|
|
6685
|
+
if (!initial.result || speed === 0)
|
|
6686
|
+
return { status: "miss", work };
|
|
6687
|
+
let clearUntil = 0;
|
|
6688
|
+
let witness;
|
|
6689
|
+
const pending = [[0, 1]];
|
|
6690
|
+
while (pending.length) {
|
|
6691
|
+
const [lower, upper] = pending.pop();
|
|
6692
|
+
if (witness && witness.fraction - clearUntil <= fractionTolerance)
|
|
6693
|
+
return { status: "hit", work, lowerFraction: clearUntil, ...witness };
|
|
6694
|
+
const middle = lower + (upper - lower) / 2;
|
|
6695
|
+
const query = probe(middle);
|
|
6696
|
+
if (!query)
|
|
6697
|
+
return { status: "incomplete", work };
|
|
6698
|
+
const hit = query.result;
|
|
6699
|
+
if (hit && hit.distance <= radius) {
|
|
6700
|
+
witness = { fraction: middle, contact: hit };
|
|
6701
|
+
if (middle - clearUntil <= fractionTolerance)
|
|
6702
|
+
return { status: "hit", work, lowerFraction: clearUntil, ...witness };
|
|
6703
|
+
pending.push([lower, middle]);
|
|
6704
|
+
continue;
|
|
6705
|
+
}
|
|
6706
|
+
if (!query.complete)
|
|
6707
|
+
return { status: "incomplete", work };
|
|
6708
|
+
const travel = speed * Math.max(middle - lower, upper - middle);
|
|
6709
|
+
const allowance = 8 * Number.EPSILON * Math.max((hit == null ? void 0 : hit.distance) ?? 0, radius, travel);
|
|
6710
|
+
if (!hit || hit.distance - radius > travel + allowance) {
|
|
6711
|
+
clearUntil = upper;
|
|
6712
|
+
continue;
|
|
6713
|
+
}
|
|
6714
|
+
if (upper - lower <= fractionTolerance) {
|
|
6715
|
+
const final = (_a = probe(upper)) == null ? void 0 : _a.result;
|
|
6716
|
+
if (final && final.distance <= radius && upper - clearUntil <= fractionTolerance)
|
|
6717
|
+
return { status: "hit", work, fraction: upper, lowerFraction: clearUntil, contact: final };
|
|
6718
|
+
return { status: "incomplete", work };
|
|
6719
|
+
}
|
|
6720
|
+
pending.push([middle, upper], [lower, middle]);
|
|
6721
|
+
}
|
|
6722
|
+
return witness ? { status: "hit", work, lowerFraction: clearUntil, ...witness } : { status: "miss", work };
|
|
6723
|
+
}
|
|
6724
|
+
function sweepTerrainTaperedCapsule(surface, start, end, translation, radiusStart, radiusEnd, { maxWork = 1e5, fractionTolerance } = {}) {
|
|
6725
|
+
if (![radiusStart, radiusEnd].every((radius) => Number.isFinite(radius) && radius >= 0))
|
|
6726
|
+
throw new RangeError("Invalid terrain tapered capsule radii");
|
|
6727
|
+
const outer = sweepTerrainCapsule(surface, start, end, translation, Math.max(radiusStart, radiusEnd), {
|
|
6728
|
+
maxWork,
|
|
6729
|
+
fractionTolerance
|
|
6730
|
+
});
|
|
6731
|
+
if (outer.status !== "hit" || radiusStart === radiusEnd)
|
|
6732
|
+
return outer;
|
|
6733
|
+
const inner = sweepTerrainCapsule(surface, start, end, translation, Math.min(radiusStart, radiusEnd), {
|
|
6734
|
+
maxWork: maxWork - outer.work,
|
|
6735
|
+
fractionTolerance
|
|
6736
|
+
});
|
|
6737
|
+
const work = outer.work + inner.work;
|
|
6738
|
+
return inner.status === "hit" && outer.lowerFraction <= inner.fraction ? { ...inner, lowerFraction: outer.lowerFraction, work } : { status: "incomplete", work };
|
|
6739
|
+
}
|
|
6740
|
+
|
|
6741
|
+
// dist/terrain/sweep-polytope.js
|
|
6742
|
+
var sub2 = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
6743
|
+
var cross2 = (a, b) => [
|
|
6744
|
+
a[1] * b[2] - a[2] * b[1],
|
|
6745
|
+
a[2] * b[0] - a[0] * b[2],
|
|
6746
|
+
a[0] * b[1] - a[1] * b[0]
|
|
6747
|
+
];
|
|
6748
|
+
var dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
6749
|
+
var edges = ([a, b, c]) => [sub2(b, a), sub2(c, b), sub2(a, c)];
|
|
6750
|
+
function sweepTerrainPolytope(surface, collider, translation, { maxWork = 1e5 } = {}) {
|
|
6751
|
+
return queryTerrainPolytope(surface.copyData(), surface.origin, collider, translation, maxWork);
|
|
6752
|
+
}
|
|
6753
|
+
function queryTerrainPolytope(data, origin, collider, translation, maxWork, padding = 0) {
|
|
6754
|
+
if (!Number.isSafeInteger(maxWork) || maxWork < 0 || translation.length !== 3 || !translation.every(Number.isFinite) || collider.vertices.length < 4 || collider.faces.length < 4 || collider.vertices.some((point) => point.length !== 3 || !point.every(Number.isFinite)))
|
|
6755
|
+
throw new RangeError("Invalid terrain polytope sweep");
|
|
6756
|
+
const vertices = collider.vertices.map((point) => sub2(point, origin));
|
|
6757
|
+
const normals = [];
|
|
6758
|
+
const directions = [];
|
|
6759
|
+
for (const face of collider.faces) {
|
|
6760
|
+
if (face.length !== 3 || face.some((i) => !Number.isSafeInteger(i) || !vertices[i]))
|
|
6761
|
+
throw new RangeError("Invalid terrain polytope face");
|
|
6762
|
+
const side = edges([vertices[face[0]], vertices[face[1]], vertices[face[2]]]);
|
|
6763
|
+
const normal = cross2(side[0], side[1]);
|
|
6764
|
+
if (!normal.every(Number.isFinite) || !normal.some(Boolean))
|
|
6765
|
+
throw new RangeError("Degenerate terrain polytope face");
|
|
6766
|
+
normals.push(normal);
|
|
6767
|
+
directions.push(...side);
|
|
6768
|
+
}
|
|
6769
|
+
return sweepTriangles(data, vertices, normals, directions, translation, maxWork, void 0, padding);
|
|
6770
|
+
}
|
|
6771
|
+
function sweepTerrainTriangleMesh(surface, collider, translation, { maxWork = 1e5 } = {}) {
|
|
6772
|
+
if (!Number.isSafeInteger(maxWork) || maxWork < 0 || translation.length !== 3 || !translation.every(Number.isFinite))
|
|
6773
|
+
throw new RangeError("Invalid terrain triangle mesh sweep");
|
|
6774
|
+
const data = surface.copyData();
|
|
6775
|
+
let work = 0;
|
|
6776
|
+
let best;
|
|
6777
|
+
for (const face of collider.faces) {
|
|
6778
|
+
if (face.length !== 3)
|
|
6779
|
+
throw new RangeError("Invalid terrain sweep mesh face");
|
|
6780
|
+
const vertices = face.map((index) => {
|
|
6781
|
+
const point = collider.vertices[index];
|
|
6782
|
+
if (!Number.isSafeInteger(index) || !point || point.length !== 3 || !point.every(Number.isFinite))
|
|
6783
|
+
throw new RangeError("Invalid terrain sweep mesh vertex");
|
|
6784
|
+
return sub2(point, surface.origin);
|
|
6785
|
+
});
|
|
6786
|
+
const directions = edges(vertices);
|
|
6787
|
+
const normal = cross2(directions[0], directions[1]);
|
|
6788
|
+
if (!normal.every(Number.isFinite) || !normal.some(Boolean))
|
|
6789
|
+
throw new RangeError("Degenerate terrain sweep mesh face");
|
|
6790
|
+
const result = sweepTriangles(data, vertices, [normal], directions, translation, maxWork - work, normal);
|
|
6791
|
+
work += result.work;
|
|
6792
|
+
if (result.status === "incomplete")
|
|
6793
|
+
return { status: "incomplete", work };
|
|
6794
|
+
if (result.status === "hit" && (!best || result.fraction < best.fraction))
|
|
6795
|
+
best = result;
|
|
6796
|
+
}
|
|
6797
|
+
return best ? { ...best, work } : { status: "miss", work };
|
|
6798
|
+
}
|
|
6799
|
+
function sweepTriangles(data, vertices, normals, directions, translation, maxWork, movingTriangleNormal, padding = 0) {
|
|
6800
|
+
let work = 0;
|
|
6801
|
+
let best;
|
|
6802
|
+
const vertex = (index) => {
|
|
6803
|
+
const i = 3 * data.indices[index];
|
|
6804
|
+
return [data.positions[i], data.positions[i + 1], data.positions[i + 2]];
|
|
6805
|
+
};
|
|
6806
|
+
for (let i = 0; i < data.triangleValidity.length; i++) {
|
|
6807
|
+
if (!data.triangleValidity[i])
|
|
6808
|
+
continue;
|
|
6809
|
+
const triangle = [vertex(3 * i), vertex(3 * i + 1), vertex(3 * i + 2)];
|
|
6810
|
+
const sides = edges(triangle);
|
|
6811
|
+
let enter = 0;
|
|
6812
|
+
let exit = (best == null ? void 0 : best.fraction) ?? 1;
|
|
6813
|
+
let normal = null;
|
|
6814
|
+
function* axes() {
|
|
6815
|
+
const terrainNormal = cross2(sides[0], sides[1]);
|
|
6816
|
+
yield terrainNormal;
|
|
6817
|
+
if (movingTriangleNormal) {
|
|
6818
|
+
for (const side of sides)
|
|
6819
|
+
yield cross2(terrainNormal, side);
|
|
6820
|
+
for (const direction of directions)
|
|
6821
|
+
yield cross2(movingTriangleNormal, direction);
|
|
6822
|
+
}
|
|
6823
|
+
yield* normals;
|
|
6824
|
+
for (const side of sides)
|
|
6825
|
+
for (const direction of directions)
|
|
6826
|
+
yield cross2(side, direction);
|
|
6827
|
+
}
|
|
6828
|
+
for (const axis of axes()) {
|
|
6829
|
+
if (work >= maxWork)
|
|
6830
|
+
return { status: "incomplete", work };
|
|
6831
|
+
work++;
|
|
6832
|
+
const length = Math.hypot(...axis);
|
|
6833
|
+
if (length === 0)
|
|
6834
|
+
continue;
|
|
6835
|
+
const unit = [axis[0] / length, axis[1] / length, axis[2] / length];
|
|
6836
|
+
const low = Math.min(...triangle.map((point) => dot(point, unit)));
|
|
6837
|
+
const high = Math.max(...triangle.map((point) => dot(point, unit)));
|
|
6838
|
+
let min = Infinity;
|
|
6839
|
+
let max = -Infinity;
|
|
6840
|
+
for (const point of vertices) {
|
|
6841
|
+
const projection = dot(point, unit);
|
|
6842
|
+
min = Math.min(min, projection);
|
|
6843
|
+
max = Math.max(max, projection);
|
|
6844
|
+
}
|
|
6845
|
+
min -= padding;
|
|
6846
|
+
max += padding;
|
|
6847
|
+
const speed = dot(translation, unit);
|
|
6848
|
+
if (![low, high, min, max, speed, length].every(Number.isFinite))
|
|
6849
|
+
throw new RangeError("Terrain polytope projection overflow");
|
|
6850
|
+
if (speed === 0) {
|
|
6851
|
+
if (min > high || max < low)
|
|
6852
|
+
exit = -1;
|
|
6853
|
+
} else {
|
|
6854
|
+
const first = (low - max) / speed;
|
|
6855
|
+
const last = (high - min) / speed;
|
|
6856
|
+
const entry = Math.min(first, last);
|
|
6857
|
+
if (entry > enter) {
|
|
6858
|
+
enter = entry;
|
|
6859
|
+
normal = speed < 0 ? unit : [-unit[0], -unit[1], -unit[2]];
|
|
6860
|
+
}
|
|
6861
|
+
exit = Math.min(exit, Math.max(first, last));
|
|
6862
|
+
}
|
|
6863
|
+
if (enter > exit)
|
|
6864
|
+
break;
|
|
6865
|
+
}
|
|
6866
|
+
if (enter <= exit && (!best || enter < best.fraction)) {
|
|
6867
|
+
best = { status: "hit", fraction: enter, triangleIndex: i, normal, work };
|
|
6868
|
+
if (enter === 0)
|
|
6869
|
+
break;
|
|
6870
|
+
}
|
|
6871
|
+
}
|
|
6872
|
+
return best ? { ...best, work } : { status: "miss", work };
|
|
6873
|
+
}
|
|
6874
|
+
function sweepTerrainBox(surface, center, halfExtents, translation, options) {
|
|
6875
|
+
return sweepTerrainPolytope(surface, createSweepBox(center, halfExtents), translation, options);
|
|
6876
|
+
}
|
|
6877
|
+
function createSweepBox(center, halfExtents) {
|
|
6878
|
+
if (halfExtents.length !== 3 || halfExtents.some((value) => !(value > 0)))
|
|
6879
|
+
throw new RangeError("Terrain box half extents must be positive");
|
|
6880
|
+
const vertices = Array.from({ length: 8 }, (_, i) => [
|
|
6881
|
+
center[0] + (i & 1 ? 1 : -1) * halfExtents[0],
|
|
6882
|
+
center[1] + (i & 2 ? 1 : -1) * halfExtents[1],
|
|
6883
|
+
center[2] + (i & 4 ? 1 : -1) * halfExtents[2]
|
|
6884
|
+
]);
|
|
6885
|
+
return {
|
|
6886
|
+
vertices,
|
|
6887
|
+
faces: [
|
|
6888
|
+
[0, 1, 3],
|
|
6889
|
+
[0, 3, 2],
|
|
6890
|
+
[4, 6, 7],
|
|
6891
|
+
[4, 7, 5],
|
|
6892
|
+
[0, 4, 5],
|
|
6893
|
+
[0, 5, 1],
|
|
6894
|
+
[2, 3, 7],
|
|
6895
|
+
[2, 7, 6],
|
|
6896
|
+
[0, 2, 6],
|
|
6897
|
+
[0, 6, 4],
|
|
6898
|
+
[1, 5, 7],
|
|
6899
|
+
[1, 7, 3]
|
|
6900
|
+
]
|
|
6901
|
+
};
|
|
6902
|
+
}
|
|
6903
|
+
|
|
6904
|
+
// dist/terrain/sweep-rotating-capsule.js
|
|
6905
|
+
function sweepTerrainRotatingCapsule(surface, start, end, radius, { pivot, translation, rotation }, { maxWork = 1e5, fractionTolerance = 1e-5 } = {}) {
|
|
6906
|
+
var _a;
|
|
6907
|
+
const norm = Math.hypot(...rotation);
|
|
6908
|
+
if (![start, end, pivot, translation].every((p) => p.length === 3 && p.every(Number.isFinite)) || rotation.length !== 4 || !(norm > 0 && Number.isFinite(norm)) || !Number.isFinite(radius) || radius < 0 || !Number.isSafeInteger(maxWork) || maxWork < 0 || !(fractionTolerance >= Number.EPSILON && fractionTolerance <= 1))
|
|
6909
|
+
throw new RangeError("Invalid terrain capsule rigid motion");
|
|
6910
|
+
const sign2 = rotation[3] < 0 ? -1 : 1;
|
|
6911
|
+
const axisLength = Math.hypot(rotation[0], rotation[1], rotation[2]);
|
|
6912
|
+
const angle = 2 * Math.atan2(axisLength, Math.abs(rotation[3]));
|
|
6913
|
+
if (angle === 0) {
|
|
6914
|
+
return sweepTerrainCapsule(surface, start, end, translation, radius, {
|
|
6915
|
+
maxWork,
|
|
6916
|
+
fractionTolerance
|
|
6917
|
+
});
|
|
6918
|
+
}
|
|
6919
|
+
const x = rotation[0] / axisLength * sign2;
|
|
6920
|
+
const y = rotation[1] / axisLength * sign2;
|
|
6921
|
+
const z = rotation[2] / axisLength * sign2;
|
|
6922
|
+
const offsets = [start, end].map((p) => p.map((v, i) => v - pivot[i]));
|
|
6923
|
+
const reach = Math.max(...offsets.map((p) => Math.hypot(...p)));
|
|
6924
|
+
const speed = Math.hypot(...translation) + angle * reach;
|
|
6925
|
+
const scale = Math.max(Math.hypot(...pivot), reach, speed, radius);
|
|
6926
|
+
if (!Number.isFinite(scale))
|
|
6927
|
+
throw new RangeError("Terrain capsule rigid motion overflow");
|
|
6928
|
+
let work = 0;
|
|
6929
|
+
function probe(t) {
|
|
6930
|
+
if (work >= maxWork)
|
|
6931
|
+
return null;
|
|
6932
|
+
work++;
|
|
6933
|
+
const sin = Math.sin(angle * t);
|
|
6934
|
+
const cos = Math.cos(angle * t);
|
|
6935
|
+
const [a, b] = t === 0 ? [start, end] : offsets.map(([u, v, w]) => {
|
|
6936
|
+
const d = (x * u + y * v + z * w) * (1 - cos);
|
|
6937
|
+
const pos = [
|
|
6938
|
+
pivot[0] + (translation[0] * t + u * cos + (y * w - z * v) * sin + x * d),
|
|
6939
|
+
pivot[1] + (translation[1] * t + v * cos + (z * u - x * w) * sin + y * d),
|
|
6940
|
+
pivot[2] + (translation[2] * t + w * cos + (x * v - y * u) * sin + z * d)
|
|
6941
|
+
];
|
|
6942
|
+
if (!pos.every(Number.isFinite))
|
|
6943
|
+
throw new RangeError("Terrain capsule pose overflow");
|
|
6944
|
+
return pos;
|
|
6945
|
+
});
|
|
6946
|
+
const query = surface.nearestSegmentQuery(a, b, { maxWork: maxWork - work });
|
|
6947
|
+
work += query.work;
|
|
6948
|
+
return query;
|
|
6949
|
+
}
|
|
6950
|
+
const initial = probe(0);
|
|
6951
|
+
if ((initial == null ? void 0 : initial.result) && initial.result.distance <= radius)
|
|
6952
|
+
return { status: "hit", fraction: 0, lowerFraction: 0, work, contact: initial.result };
|
|
6953
|
+
if (!(initial == null ? void 0 : initial.complete))
|
|
6954
|
+
return { status: "incomplete", work };
|
|
6955
|
+
if (!initial.result || speed === 0)
|
|
6956
|
+
return { status: "miss", work };
|
|
6957
|
+
let clearUntil = 0;
|
|
6958
|
+
let witness;
|
|
6959
|
+
const pending = [[0, 1]];
|
|
6960
|
+
while (pending.length) {
|
|
6961
|
+
if (witness && witness.fraction - clearUntil <= fractionTolerance)
|
|
6962
|
+
return { status: "hit", lowerFraction: clearUntil, work, ...witness };
|
|
6963
|
+
const [lo, hi] = pending.pop();
|
|
6964
|
+
const mid = lo + (hi - lo) / 2;
|
|
6965
|
+
const query = probe(mid);
|
|
6966
|
+
const contact = query == null ? void 0 : query.result;
|
|
6967
|
+
if (contact && contact.distance <= radius) {
|
|
6968
|
+
witness = { fraction: mid, contact };
|
|
6969
|
+
if (mid - clearUntil <= fractionTolerance)
|
|
6970
|
+
return { status: "hit", lowerFraction: clearUntil, work, ...witness };
|
|
6971
|
+
if (mid === lo || mid === hi)
|
|
6972
|
+
return { status: "incomplete", work };
|
|
6973
|
+
pending.push([lo, mid]);
|
|
6974
|
+
continue;
|
|
6975
|
+
}
|
|
6976
|
+
if (!(query == null ? void 0 : query.complete))
|
|
6977
|
+
return { status: "incomplete", work };
|
|
6978
|
+
const travel = speed * Math.max(mid - lo, hi - mid);
|
|
6979
|
+
const allowance = 16 * Number.EPSILON * Math.max(scale, (contact == null ? void 0 : contact.distance) ?? 0);
|
|
6980
|
+
if (!contact || contact.distance - radius > travel + allowance) {
|
|
6981
|
+
clearUntil = hi;
|
|
6982
|
+
continue;
|
|
6983
|
+
}
|
|
6984
|
+
if (hi - clearUntil <= fractionTolerance) {
|
|
6985
|
+
const final = (witness == null ? void 0 : witness.fraction) === hi ? witness.contact : (_a = probe(hi)) == null ? void 0 : _a.result;
|
|
6986
|
+
if (final && final.distance <= radius)
|
|
6987
|
+
return { status: "hit", fraction: hi, lowerFraction: clearUntil, work, contact: final };
|
|
6988
|
+
}
|
|
6989
|
+
if (mid === lo || mid === hi || hi - lo <= fractionTolerance / 4)
|
|
6990
|
+
return { status: "incomplete", work };
|
|
6991
|
+
pending.push([mid, hi], [lo, mid]);
|
|
6992
|
+
}
|
|
6993
|
+
return witness ? { status: "hit", lowerFraction: clearUntil, work, ...witness } : { status: "miss", work };
|
|
6994
|
+
}
|
|
6995
|
+
function sweepTerrainRotatingSphere(surface, center, radius, motion, options) {
|
|
6996
|
+
return sweepTerrainRotatingCapsule(surface, center, center, radius, motion, options);
|
|
6997
|
+
}
|
|
6998
|
+
|
|
6999
|
+
// dist/terrain/sweep-cylinder.js
|
|
7000
|
+
function sweepTerrainCylinder(surface, center, height, radiusBottom, radiusTop, translation, { sides = 16, maxWork = 1e5 } = {}) {
|
|
7001
|
+
if (center.length !== 3 || !center.every(Number.isFinite) || ![height, radiusBottom, radiusTop].every((value) => Number.isFinite(value) && value > 0) || !Number.isInteger(sides) || sides < 3 || sides > 128)
|
|
7002
|
+
throw new RangeError("Invalid terrain cylinder sweep");
|
|
7003
|
+
const faces = [];
|
|
7004
|
+
for (let i = 0; i < sides; i++) {
|
|
7005
|
+
const next = (i + 1) % sides;
|
|
7006
|
+
faces.push([i, next, next + sides], [i, next + sides, i + sides]);
|
|
7007
|
+
if (i > 0 && i < sides - 1)
|
|
7008
|
+
faces.push([0, i + 1, i], [sides, sides + i, sides + i + 1]);
|
|
7009
|
+
}
|
|
7010
|
+
const hull = (scale) => ({
|
|
7011
|
+
faces,
|
|
7012
|
+
vertices: Array.from({ length: 2 * sides }, (_, i) => {
|
|
7013
|
+
const top = i >= sides;
|
|
7014
|
+
const angle = 2 * Math.PI * (i % sides) / sides;
|
|
7015
|
+
const radius = (top ? radiusTop : radiusBottom) * scale;
|
|
7016
|
+
return [
|
|
7017
|
+
center[0] + radius * Math.cos(angle),
|
|
7018
|
+
center[1] + radius * Math.sin(angle),
|
|
7019
|
+
center[2] + (top ? height : -height) / 2
|
|
7020
|
+
];
|
|
7021
|
+
})
|
|
7022
|
+
});
|
|
7023
|
+
const outer = sweepTerrainPolytope(surface, hull(1 / Math.cos(Math.PI / sides)), translation, {
|
|
7024
|
+
maxWork
|
|
7025
|
+
});
|
|
7026
|
+
if (outer.status !== "hit")
|
|
7027
|
+
return outer;
|
|
7028
|
+
const inner = sweepTerrainPolytope(surface, hull(1), translation, {
|
|
7029
|
+
maxWork: maxWork - outer.work
|
|
7030
|
+
});
|
|
7031
|
+
const work = outer.work + inner.work;
|
|
7032
|
+
if (inner.status !== "hit" || inner.fraction < outer.fraction)
|
|
7033
|
+
return { status: "incomplete", work };
|
|
7034
|
+
return { ...inner, normal: null, lowerFraction: outer.fraction, work };
|
|
7035
|
+
}
|
|
7036
|
+
|
|
7037
|
+
// dist/terrain/sweep-plane.js
|
|
7038
|
+
function sweepTerrainPlane(surface, point, normal, translation, { maxWork = 1e5 } = {}) {
|
|
7039
|
+
const length = Math.hypot(...normal);
|
|
7040
|
+
if (![point, normal, translation].every((v) => v.length === 3 && v.every(Number.isFinite)) || !(length > 0 && Number.isFinite(length)) || !Number.isSafeInteger(maxWork) || maxWork < 0)
|
|
7041
|
+
throw new RangeError("Invalid terrain plane sweep");
|
|
7042
|
+
const unit = [normal[0] / length, normal[1] / length, normal[2] / length];
|
|
7043
|
+
const velocity = translation[0] * unit[0] + translation[1] * unit[1] + translation[2] * unit[2];
|
|
7044
|
+
if (!Number.isFinite(velocity))
|
|
7045
|
+
throw new RangeError("Terrain plane velocity overflow");
|
|
7046
|
+
const { positions, indices, triangleValidity } = surface.copyData();
|
|
7047
|
+
const local = point.map((value, axis) => value - surface.origin[axis]);
|
|
7048
|
+
let work = 0;
|
|
7049
|
+
let fraction = Infinity;
|
|
7050
|
+
let triangleIndex = -1;
|
|
7051
|
+
for (let i = 0; i < triangleValidity.length; i++) {
|
|
7052
|
+
if (!triangleValidity[i])
|
|
7053
|
+
continue;
|
|
7054
|
+
if (work >= maxWork)
|
|
7055
|
+
return { status: "incomplete", work };
|
|
7056
|
+
work++;
|
|
7057
|
+
let min = Infinity;
|
|
7058
|
+
let max = -Infinity;
|
|
7059
|
+
for (let j = 0; j < 3; j++) {
|
|
7060
|
+
const k = indices[3 * i + j] * 3;
|
|
7061
|
+
const distance = (positions[k] - local[0]) * unit[0] + (positions[k + 1] - local[1]) * unit[1] + (positions[k + 2] - local[2]) * unit[2];
|
|
7062
|
+
if (!Number.isFinite(distance))
|
|
7063
|
+
throw new RangeError("Terrain plane projection overflow");
|
|
7064
|
+
min = Math.min(min, distance);
|
|
7065
|
+
max = Math.max(max, distance);
|
|
7066
|
+
}
|
|
7067
|
+
if (min <= 0 && max >= 0)
|
|
7068
|
+
return { status: "hit", fraction: 0, triangleIndex: i, normal: null, work };
|
|
7069
|
+
const entry = velocity > 0 ? min / velocity : max / velocity;
|
|
7070
|
+
if (velocity !== 0 && entry > 0 && entry <= 1 && entry < fraction) {
|
|
7071
|
+
triangleIndex = i;
|
|
7072
|
+
fraction = entry;
|
|
7073
|
+
}
|
|
7074
|
+
}
|
|
7075
|
+
if (triangleIndex < 0)
|
|
7076
|
+
return { status: "miss", work };
|
|
7077
|
+
const entryNormal = velocity < 0 ? unit : [-unit[0], -unit[1], -unit[2]];
|
|
7078
|
+
return { status: "hit", fraction, triangleIndex, normal: entryNormal, work };
|
|
7079
|
+
}
|
|
7080
|
+
|
|
7081
|
+
// dist/terrain/geographic-lod-seams.js
|
|
7082
|
+
function discoverGeographicTerrainLodSeams(cut) {
|
|
7083
|
+
const vertical = /* @__PURE__ */ new Map();
|
|
7084
|
+
const horizontal = /* @__PURE__ */ new Map();
|
|
7085
|
+
const world = 2 ** 30;
|
|
7086
|
+
const addresses = /* @__PURE__ */ new Set();
|
|
7087
|
+
const key2 = (level, x, y) => `${level}/${x}/${y}`;
|
|
7088
|
+
for (const tile of cut) {
|
|
7089
|
+
getGeographicTileBounds(tile);
|
|
7090
|
+
const address = key2(tile.level, tile.x, tile.y);
|
|
7091
|
+
if (addresses.has(address))
|
|
7092
|
+
throw new Error("Duplicate geographic terrain tile");
|
|
7093
|
+
addresses.add(address);
|
|
7094
|
+
}
|
|
7095
|
+
function add2(lines, line, side, span) {
|
|
7096
|
+
let group = lines.get(line);
|
|
7097
|
+
if (!group) {
|
|
7098
|
+
group = { before: [], after: [] };
|
|
7099
|
+
lines.set(line, group);
|
|
7100
|
+
}
|
|
7101
|
+
group[side].push(span);
|
|
7102
|
+
}
|
|
7103
|
+
cut.forEach(({ level, x, y }, tile) => {
|
|
7104
|
+
for (let parent = level - 1; parent >= 0; parent--) {
|
|
7105
|
+
const scale = 2 ** (level - parent);
|
|
7106
|
+
if (addresses.has(key2(parent, Math.floor(x / scale), Math.floor(y / scale))))
|
|
7107
|
+
throw new Error("Overlapping geographic terrain tiles");
|
|
7108
|
+
}
|
|
7109
|
+
const size = 2 ** (30 - level);
|
|
7110
|
+
const west = x * size;
|
|
7111
|
+
const north = y * size;
|
|
7112
|
+
const east = west + size;
|
|
7113
|
+
const south = north + size;
|
|
7114
|
+
add2(vertical, west, "after", { tile, start: north, end: south });
|
|
7115
|
+
add2(vertical, east % world, "before", { tile, start: north, end: south });
|
|
7116
|
+
if (north !== 0)
|
|
7117
|
+
add2(horizontal, north, "after", { tile, start: west, end: east });
|
|
7118
|
+
if (south !== world)
|
|
7119
|
+
add2(horizontal, south, "before", { tile, start: west, end: east });
|
|
7120
|
+
});
|
|
7121
|
+
const seams = [];
|
|
7122
|
+
function match(lines, column) {
|
|
7123
|
+
const beforeEdge = column ? "maxColumn" : "maxRow";
|
|
7124
|
+
const afterEdge = column ? "minColumn" : "minRow";
|
|
7125
|
+
const byStart = (a, b) => a.start - b.start;
|
|
7126
|
+
for (const [line, { before, after }] of lines) {
|
|
7127
|
+
before.sort(byStart);
|
|
7128
|
+
after.sort(byStart);
|
|
7129
|
+
let i = 0;
|
|
7130
|
+
let j = 0;
|
|
7131
|
+
while (i < before.length && j < after.length) {
|
|
7132
|
+
const left = before[i];
|
|
7133
|
+
const right = after[j];
|
|
7134
|
+
const start = Math.max(left.start, right.start);
|
|
7135
|
+
const end = Math.min(left.end, right.end);
|
|
7136
|
+
const leftLevel = cut[left.tile].level;
|
|
7137
|
+
const rightLevel = cut[right.tile].level;
|
|
7138
|
+
if (end > start && leftLevel !== rightLevel) {
|
|
7139
|
+
const leftOwns = leftLevel < rightLevel;
|
|
7140
|
+
const coarse = leftOwns ? left : right;
|
|
7141
|
+
seams.push({
|
|
7142
|
+
a: coarse.tile,
|
|
7143
|
+
edgeA: leftOwns ? beforeEdge : afterEdge,
|
|
7144
|
+
b: leftOwns ? right.tile : left.tile,
|
|
7145
|
+
edgeB: leftOwns ? afterEdge : beforeEdge,
|
|
7146
|
+
...column && line === 0 ? { offsetBX: leftOwns ? 360 : -360 } : {},
|
|
7147
|
+
options: {
|
|
7148
|
+
rangeA: [
|
|
7149
|
+
(start - coarse.start) / (coarse.end - coarse.start),
|
|
7150
|
+
(end - coarse.start) / (coarse.end - coarse.start)
|
|
7151
|
+
]
|
|
7152
|
+
}
|
|
7153
|
+
});
|
|
7154
|
+
}
|
|
7155
|
+
if (left.end <= right.end)
|
|
7156
|
+
i++;
|
|
7157
|
+
if (right.end <= left.end)
|
|
7158
|
+
j++;
|
|
7159
|
+
}
|
|
7160
|
+
}
|
|
7161
|
+
}
|
|
7162
|
+
match(vertical, true);
|
|
7163
|
+
match(horizontal, false);
|
|
7164
|
+
const edges2 = ["minColumn", "maxColumn", "minRow", "maxRow"];
|
|
7165
|
+
return seams.sort((a, b) => cut[a.a].level - cut[b.a].level || cut[a.a].y - cut[b.a].y || cut[a.a].x - cut[b.a].x || edges2.indexOf(a.edgeA) - edges2.indexOf(b.edgeA) || a.options.rangeA[0] - b.options.rangeA[0]);
|
|
7166
|
+
}
|
|
7167
|
+
|
|
7168
|
+
// dist/terrain/geographic-poles.js
|
|
7169
|
+
function discoverGeographicTerrainPoles(cut) {
|
|
7170
|
+
function collect(latitude2, edge2) {
|
|
7171
|
+
const incident = [];
|
|
7172
|
+
for (let tile = 0; tile < cut.length; tile++) {
|
|
7173
|
+
const [west, south, east, north] = getGeographicTileBounds(cut[tile]);
|
|
7174
|
+
if ((edge2 === "north" ? north : south) === latitude2)
|
|
7175
|
+
incident.push({ tile, edge: edge2, longitude: [west, east] });
|
|
7176
|
+
}
|
|
7177
|
+
incident.sort((a, b) => a.longitude[0] - b.longitude[0]);
|
|
7178
|
+
const gaps = [];
|
|
7179
|
+
let cursor = -180;
|
|
7180
|
+
for (const { longitude: [west, east] } of incident) {
|
|
7181
|
+
if (west < cursor)
|
|
7182
|
+
throw new Error("Overlapping geographic terrain pole sectors");
|
|
7183
|
+
if (west > cursor)
|
|
7184
|
+
gaps.push([cursor, west]);
|
|
7185
|
+
cursor = east;
|
|
7186
|
+
}
|
|
7187
|
+
if (cursor < 180)
|
|
7188
|
+
gaps.push([cursor, 180]);
|
|
7189
|
+
return { latitude: latitude2, incident, gaps };
|
|
7190
|
+
}
|
|
7191
|
+
return { north: collect(90, "north"), south: collect(-90, "south") };
|
|
7192
|
+
}
|
|
7193
|
+
|
|
7194
|
+
// dist/terrain/sweep-rotation.js
|
|
7195
|
+
function sweepTerrainRotatingPolytope(surface, collider, { pivot, translation, rotation }, { maxWork = 1e5, fractionTolerance = 1e-5 } = {}) {
|
|
7196
|
+
const norm = Math.hypot(...rotation);
|
|
7197
|
+
if (pivot.length !== 3 || translation.length !== 3 || rotation.length !== 4 || !pivot.every(Number.isFinite) || !translation.every(Number.isFinite) || !(norm > 0 && Number.isFinite(norm)) || !Number.isSafeInteger(maxWork) || maxWork < 0 || !(fractionTolerance >= Number.EPSILON && fractionTolerance <= 1))
|
|
7198
|
+
throw new RangeError("Invalid terrain rigid motion");
|
|
7199
|
+
const localPivot = pivot.map((v, i) => v - surface.origin[i]);
|
|
7200
|
+
const offsets = collider.vertices.map((v) => v.map((x2, i) => x2 - pivot[i]));
|
|
7201
|
+
const radius = offsets.reduce((r, v) => Math.max(r, Math.hypot(...v)), 0);
|
|
7202
|
+
const sign2 = rotation[3] < 0 ? -1 : 1;
|
|
7203
|
+
const vectorNorm = Math.hypot(rotation[0], rotation[1], rotation[2]);
|
|
7204
|
+
const angle = 2 * Math.atan2(vectorNorm, Math.abs(rotation[3]));
|
|
7205
|
+
const speed = Math.hypot(...translation) + angle * radius;
|
|
7206
|
+
if (!Number.isFinite(speed))
|
|
7207
|
+
throw new RangeError("Terrain rigid motion overflow");
|
|
7208
|
+
const data = surface.copyData();
|
|
7209
|
+
if (angle === 0) {
|
|
7210
|
+
const result = queryTerrainPolytope(data, surface.origin, collider, translation, maxWork);
|
|
7211
|
+
return result.status === "hit" ? { ...result, lowerFraction: result.fraction } : result;
|
|
7212
|
+
}
|
|
7213
|
+
const [x, y, z] = rotation.slice(0, 3).map((v) => v / vectorNorm * sign2);
|
|
7214
|
+
const zero = [0, 0, 0];
|
|
7215
|
+
let work = 0;
|
|
7216
|
+
const pose = (t) => {
|
|
7217
|
+
const sin = Math.sin(angle * t);
|
|
7218
|
+
const cos = Math.cos(angle * t);
|
|
7219
|
+
return {
|
|
7220
|
+
faces: collider.faces,
|
|
7221
|
+
vertices: offsets.map(([a, b, c]) => {
|
|
7222
|
+
const projection = (x * a + y * b + z * c) * (1 - cos);
|
|
7223
|
+
return [
|
|
7224
|
+
localPivot[0] + translation[0] * t + a * cos + (y * c - z * b) * sin + x * projection,
|
|
7225
|
+
localPivot[1] + translation[1] * t + b * cos + (z * a - x * c) * sin + y * projection,
|
|
7226
|
+
localPivot[2] + translation[2] * t + c * cos + (x * b - y * a) * sin + z * projection
|
|
7227
|
+
];
|
|
7228
|
+
})
|
|
7229
|
+
};
|
|
7230
|
+
};
|
|
7231
|
+
const probe = (shape, padding = 0) => {
|
|
7232
|
+
if (work >= maxWork)
|
|
7233
|
+
return { status: "incomplete", work: 0 };
|
|
7234
|
+
work++;
|
|
7235
|
+
const result = queryTerrainPolytope(data, zero, shape, zero, maxWork - work, padding);
|
|
7236
|
+
work += result.work;
|
|
7237
|
+
return result;
|
|
7238
|
+
};
|
|
7239
|
+
const initial = probe(pose(0));
|
|
7240
|
+
if (initial.status === "hit")
|
|
7241
|
+
return { ...initial, lowerFraction: 0, work };
|
|
7242
|
+
if (initial.status === "incomplete")
|
|
7243
|
+
return { status: "incomplete", work };
|
|
7244
|
+
let clearUntil = 0;
|
|
7245
|
+
let witness;
|
|
7246
|
+
const pending = [[0, 1]];
|
|
7247
|
+
while (pending.length) {
|
|
7248
|
+
if (witness && witness.fraction - clearUntil <= fractionTolerance)
|
|
7249
|
+
return { ...witness, lowerFraction: clearUntil, work };
|
|
7250
|
+
const [lo, hi] = pending.pop();
|
|
7251
|
+
const mid = lo + (hi - lo) / 2;
|
|
7252
|
+
const shape = pose(mid);
|
|
7253
|
+
const padding = speed * Math.max(mid - lo, hi - mid);
|
|
7254
|
+
const expanded = probe(shape, padding + 8 * Number.EPSILON * (radius + padding));
|
|
7255
|
+
if (expanded.status === "miss") {
|
|
7256
|
+
clearUntil = hi;
|
|
7257
|
+
continue;
|
|
7258
|
+
}
|
|
7259
|
+
if (expanded.status === "incomplete")
|
|
7260
|
+
return { status: "incomplete", work };
|
|
7261
|
+
const hit = probe(shape);
|
|
7262
|
+
if (hit.status === "incomplete")
|
|
7263
|
+
return { status: "incomplete", work };
|
|
7264
|
+
if (hit.status === "hit") {
|
|
7265
|
+
witness = { ...hit, fraction: mid };
|
|
7266
|
+
if (mid - clearUntil <= fractionTolerance)
|
|
7267
|
+
return { ...witness, lowerFraction: clearUntil, work };
|
|
7268
|
+
pending.push([lo, mid]);
|
|
7269
|
+
} else if (hi - clearUntil <= fractionTolerance) {
|
|
7270
|
+
const end = (witness == null ? void 0 : witness.fraction) === hi ? witness : probe(pose(hi));
|
|
7271
|
+
if ((end == null ? void 0 : end.status) === "hit")
|
|
7272
|
+
return { ...end, fraction: hi, lowerFraction: clearUntil, work };
|
|
7273
|
+
if (hi - lo <= fractionTolerance / 4)
|
|
7274
|
+
return { status: "incomplete", work };
|
|
7275
|
+
pending.push([mid, hi], [lo, mid]);
|
|
7276
|
+
} else {
|
|
7277
|
+
if (mid === lo || mid === hi || hi - lo <= fractionTolerance / 4)
|
|
7278
|
+
return { status: "incomplete", work };
|
|
7279
|
+
pending.push([mid, hi], [lo, mid]);
|
|
7280
|
+
}
|
|
7281
|
+
}
|
|
7282
|
+
return witness ? { ...witness, lowerFraction: clearUntil, work } : { status: "miss", work };
|
|
7283
|
+
}
|
|
7284
|
+
function sweepTerrainRotatingBox(surface, center, halfExtents, motion, options) {
|
|
7285
|
+
return sweepTerrainRotatingPolytope(surface, createSweepBox(center, halfExtents), motion, options);
|
|
7286
|
+
}
|
|
7287
|
+
|
|
7288
|
+
// dist/terrain/regional-viewshed.js
|
|
7289
|
+
var TerrainRegionalViewStatus = {
|
|
7290
|
+
VISIBLE: 0,
|
|
7291
|
+
BLOCKED: 1,
|
|
7292
|
+
UNKNOWN: 2,
|
|
7293
|
+
MISSING_TARGET: 3,
|
|
7294
|
+
OBSERVER: 4
|
|
7295
|
+
};
|
|
7296
|
+
function createTerrainRegionalViewshed(grid, sample, options) {
|
|
7297
|
+
const { width, height, origin, spacing } = grid;
|
|
7298
|
+
const { observer, sampleStep, radius, targetOffset = 0, maxTargets = 1e5, maxSamples = 4e6 } = options;
|
|
7299
|
+
const count = width * height;
|
|
7300
|
+
if (![width, height, count, maxTargets, maxSamples].every(Number.isSafeInteger) || width < 1 || height < 1 || count > maxTargets || maxSamples < 1 || origin.length !== 2 || spacing.length !== 2 || observer.length !== 3 || ![...origin, ...spacing, ...observer, sampleStep, targetOffset].every(Number.isFinite) || spacing.some((value) => value <= 0) || sampleStep <= 0 || targetOffset < 0 || radius !== void 0 && (!Number.isFinite(radius) || radius <= 0 || observer[2] <= -radius))
|
|
7301
|
+
throw new RangeError("Invalid regional viewshed grid or options");
|
|
7302
|
+
const statuses = new Uint8Array(count);
|
|
7303
|
+
const targetStatuses = new Uint8Array(count);
|
|
7304
|
+
const sampledCoverage = new Uint8Array(count);
|
|
7305
|
+
let samples = 0;
|
|
7306
|
+
function read(x, y) {
|
|
7307
|
+
if (samples >= maxSamples)
|
|
7308
|
+
throw new RangeError("Regional viewshed sample budget exceeded");
|
|
7309
|
+
samples++;
|
|
7310
|
+
const result = sample(x, y);
|
|
7311
|
+
if (!Number.isInteger(result.status) || result.status < 0 || result.status > TerrainSampleStatus.NOT_RESIDENT || result.status === TerrainSampleStatus.VALID && (!Number.isFinite(result.height) || radius !== void 0 && result.height <= -radius))
|
|
7312
|
+
throw new RangeError("Invalid regional viewshed sample");
|
|
7313
|
+
return result;
|
|
7314
|
+
}
|
|
7315
|
+
function sight(distance, elevation) {
|
|
7316
|
+
let rise = elevation - observer[2];
|
|
7317
|
+
let run = distance;
|
|
7318
|
+
if (radius !== void 0) {
|
|
7319
|
+
const theta = distance / radius;
|
|
7320
|
+
const radial = radius + elevation;
|
|
7321
|
+
const halfSine = Math.sin(theta / 2);
|
|
7322
|
+
rise -= radial * (2 * halfSine * halfSine);
|
|
7323
|
+
run = radial * Math.sin(theta);
|
|
7324
|
+
}
|
|
7325
|
+
if (!Number.isFinite(rise) || !Number.isFinite(run) || run <= 0)
|
|
7326
|
+
throw new RangeError("Regional viewshed sight calculation overflow");
|
|
7327
|
+
return [rise, run];
|
|
7328
|
+
}
|
|
7329
|
+
const observerSample = { ...read(observer[0], observer[1]) };
|
|
7330
|
+
const observerValid = observerSample.status === TerrainSampleStatus.VALID;
|
|
7331
|
+
for (let i = 0; i < count; i++) {
|
|
7332
|
+
const x = origin[0] + i % width * spacing[0];
|
|
7333
|
+
const y = origin[1] + Math.floor(i / width) * spacing[1];
|
|
7334
|
+
const dx = x - observer[0];
|
|
7335
|
+
const dy = y - observer[1];
|
|
7336
|
+
const distance = Math.hypot(dx, dy);
|
|
7337
|
+
if (!Number.isFinite(distance) || radius !== void 0 && distance / radius >= Math.PI)
|
|
7338
|
+
throw new RangeError("Regional viewshed distance outside supported range");
|
|
7339
|
+
const target = distance === 0 ? observerSample : read(x, y);
|
|
7340
|
+
targetStatuses[i] = target.status;
|
|
7341
|
+
if (target.status !== TerrainSampleStatus.VALID) {
|
|
7342
|
+
statuses[i] = TerrainRegionalViewStatus.MISSING_TARGET;
|
|
7343
|
+
continue;
|
|
7344
|
+
}
|
|
7345
|
+
if (distance === 0) {
|
|
7346
|
+
statuses[i] = TerrainRegionalViewStatus.OBSERVER;
|
|
7347
|
+
sampledCoverage[i] = 1;
|
|
7348
|
+
continue;
|
|
7349
|
+
}
|
|
7350
|
+
const [targetRise, targetRun] = sight(distance, target.height + targetOffset);
|
|
7351
|
+
const segments = Math.max(1, Math.ceil(distance / sampleStep));
|
|
7352
|
+
if (!Number.isSafeInteger(segments) || segments - 1 > maxSamples - samples)
|
|
7353
|
+
throw new RangeError("Regional viewshed sample budget exceeded");
|
|
7354
|
+
let complete = observerValid;
|
|
7355
|
+
let blocked = observerValid && observerSample.height > observer[2];
|
|
7356
|
+
for (let j = 1; j < segments; j++) {
|
|
7357
|
+
const fraction = j / segments;
|
|
7358
|
+
const station = read(observer[0] + dx * fraction, observer[1] + dy * fraction);
|
|
7359
|
+
if (station.status !== TerrainSampleStatus.VALID) {
|
|
7360
|
+
complete = false;
|
|
7361
|
+
} else if (!blocked) {
|
|
7362
|
+
const [rise, run] = sight(distance * fraction, station.height);
|
|
7363
|
+
blocked = compareTerrainSlopes(rise, run, targetRise, targetRun) >= 0;
|
|
7364
|
+
}
|
|
7365
|
+
}
|
|
7366
|
+
sampledCoverage[i] = complete ? 1 : 0;
|
|
7367
|
+
statuses[i] = blocked ? TerrainRegionalViewStatus.BLOCKED : complete ? TerrainRegionalViewStatus.VISIBLE : TerrainRegionalViewStatus.UNKNOWN;
|
|
7368
|
+
}
|
|
7369
|
+
return { statuses, targetStatuses, sampledCoverage, samples };
|
|
7370
|
+
}
|
|
7371
|
+
|
|
7372
|
+
// dist/terrain/hydrology.js
|
|
7373
|
+
function getTerrainCellMetrics(field) {
|
|
7374
|
+
if (field.registration !== "cell")
|
|
7375
|
+
throw new Error("Terrain cell metrics require cell registration");
|
|
7376
|
+
const [cx, cy] = field.columnStep;
|
|
7377
|
+
const [rx, ry] = field.rowStep;
|
|
7378
|
+
const determinant = cx * ry - cy * rx;
|
|
7379
|
+
const columnLength = Math.hypot(cx, cy);
|
|
7380
|
+
const rowLength = Math.hypot(rx, ry);
|
|
7381
|
+
const area = Math.abs(determinant);
|
|
7382
|
+
if (!(area > 0 && Number.isFinite(area) && Number.isFinite(columnLength + rowLength)))
|
|
7383
|
+
throw new RangeError("Invalid terrain cell geometry");
|
|
7384
|
+
const sign2 = Math.sign(determinant);
|
|
7385
|
+
const east = [sign2 * ry / rowLength, -sign2 * rx / rowLength];
|
|
7386
|
+
const south = [-sign2 * cy / columnLength, sign2 * cx / columnLength];
|
|
7387
|
+
return {
|
|
7388
|
+
area,
|
|
7389
|
+
faceLengths: [rowLength, rowLength, columnLength, columnLength],
|
|
7390
|
+
faceNormals: [[-east[0], -east[1]], east, [-south[0], -south[1]], south]
|
|
7391
|
+
};
|
|
7392
|
+
}
|
|
7393
|
+
function createTerrainDrainage(field, { outlets = [], maxCells = 4194304 } = {}) {
|
|
7394
|
+
const { width, height, columnStep, rowStep } = field;
|
|
7395
|
+
const count = width * height;
|
|
7396
|
+
if (!Number.isSafeInteger(maxCells) || maxCells < 0 || count > maxCells || count > 2147483647)
|
|
7397
|
+
throw new RangeError("Terrain drainage exceeds its cell budget");
|
|
7398
|
+
const { area: cellArea } = getTerrainCellMetrics(field);
|
|
7399
|
+
for (const i of outlets) {
|
|
7400
|
+
if (!Number.isInteger(i) || i < 0 || i >= count || field.getHeight(i % width, Math.floor(i / width)) === void 0)
|
|
7401
|
+
throw new RangeError("Terrain outlet must identify a valid cell");
|
|
7402
|
+
}
|
|
7403
|
+
const { heights, validity } = field.copyData();
|
|
7404
|
+
const receiver = new Int32Array(count).fill(-1);
|
|
7405
|
+
const terminal = new Int32Array(count).fill(-1);
|
|
7406
|
+
const contributingCells = new Uint32Array(count);
|
|
7407
|
+
const incoming = new Uint8Array(count);
|
|
7408
|
+
const queue = new Int32Array(count);
|
|
7409
|
+
const outletSet = new Set(outlets);
|
|
7410
|
+
const offsets = [];
|
|
7411
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
7412
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
7413
|
+
if (!dx && !dy)
|
|
7414
|
+
continue;
|
|
7415
|
+
const distance = Math.hypot(dx * columnStep[0] + dy * rowStep[0], dx * columnStep[1] + dy * rowStep[1]);
|
|
7416
|
+
if (!(distance > 0 && Number.isFinite(distance)))
|
|
7417
|
+
throw new RangeError("Invalid terrain neighbor distance");
|
|
7418
|
+
offsets.push({ dx, dy, distance });
|
|
7419
|
+
}
|
|
7420
|
+
}
|
|
7421
|
+
for (let i = 0; i < count; i++) {
|
|
7422
|
+
if (!validity[i])
|
|
7423
|
+
continue;
|
|
7424
|
+
contributingCells[i] = 1;
|
|
7425
|
+
if (outletSet.has(i))
|
|
7426
|
+
continue;
|
|
7427
|
+
const col = i % width;
|
|
7428
|
+
const row = Math.floor(i / width);
|
|
7429
|
+
let steepest = 0;
|
|
7430
|
+
for (const { dx, dy, distance } of offsets) {
|
|
7431
|
+
if (col + dx < 0 || col + dx >= width || row + dy < 0 || row + dy >= height)
|
|
7432
|
+
continue;
|
|
7433
|
+
const j = i + dx + dy * width;
|
|
7434
|
+
if (!validity[j] || heights[j] >= heights[i])
|
|
7435
|
+
continue;
|
|
7436
|
+
if (dx && dy && (!validity[i + dx] || !validity[i + dy * width]))
|
|
7437
|
+
continue;
|
|
7438
|
+
const slope = (heights[i] - heights[j]) / distance;
|
|
7439
|
+
if (!Number.isFinite(slope) || slope === 0)
|
|
7440
|
+
throw new RangeError("Terrain drainage slope is outside the representable range");
|
|
7441
|
+
if (slope > steepest) {
|
|
7442
|
+
steepest = slope;
|
|
7443
|
+
receiver[i] = j;
|
|
7444
|
+
}
|
|
7445
|
+
}
|
|
7446
|
+
if (receiver[i] >= 0)
|
|
7447
|
+
incoming[receiver[i]]++;
|
|
7448
|
+
}
|
|
7449
|
+
let end = 0;
|
|
7450
|
+
for (let i = 0; i < count; i++)
|
|
7451
|
+
if (validity[i] && !incoming[i])
|
|
7452
|
+
queue[end++] = i;
|
|
7453
|
+
for (let cursor = 0; cursor < end; cursor++) {
|
|
7454
|
+
const i = queue[cursor];
|
|
7455
|
+
const next = receiver[i];
|
|
7456
|
+
if (next < 0)
|
|
7457
|
+
continue;
|
|
7458
|
+
contributingCells[next] += contributingCells[i];
|
|
7459
|
+
if (--incoming[next] === 0)
|
|
7460
|
+
queue[end++] = next;
|
|
7461
|
+
}
|
|
7462
|
+
for (let cursor = end - 1; cursor >= 0; cursor--) {
|
|
7463
|
+
const i = queue[cursor];
|
|
7464
|
+
const next = receiver[i];
|
|
7465
|
+
terminal[i] = next < 0 ? i : terminal[next];
|
|
7466
|
+
}
|
|
7467
|
+
return { receiver, terminal, contributingCells, cellArea };
|
|
7468
|
+
}
|
|
7469
|
+
|
|
7470
|
+
// dist/terrain/depression-fill.js
|
|
7471
|
+
function fillTerrainDepressions(field, { outlets, maxCells = 4194304 }) {
|
|
7472
|
+
if (field.registration !== "cell")
|
|
7473
|
+
throw new Error("Terrain depression fill requires cell registration");
|
|
7474
|
+
const { width, height } = field;
|
|
7475
|
+
const count = width * height;
|
|
7476
|
+
if (!Number.isSafeInteger(maxCells) || maxCells < 0 || count > maxCells || count > 2147483647)
|
|
7477
|
+
throw new RangeError("Terrain depression fill exceeds its cell budget");
|
|
7478
|
+
if (!outlets.length)
|
|
7479
|
+
throw new RangeError("Terrain depression fill requires an outlet");
|
|
7480
|
+
for (const i of outlets) {
|
|
7481
|
+
if (!Number.isInteger(i) || i < 0 || i >= count || field.getHeight(i % width, Math.floor(i / width)) === void 0)
|
|
7482
|
+
throw new RangeError("Terrain outlet must identify a valid cell");
|
|
7483
|
+
}
|
|
7484
|
+
const { heights, validity } = field.copyData();
|
|
7485
|
+
const receiver = new Int32Array(count).fill(-2);
|
|
7486
|
+
const heap = new Int32Array(count);
|
|
7487
|
+
let size = 0;
|
|
7488
|
+
let disconnectedCells = field.validCount;
|
|
7489
|
+
const before = (a, b) => heights[a] < heights[b] || heights[a] === heights[b] && a < b;
|
|
7490
|
+
function push(cell) {
|
|
7491
|
+
let slot = size++;
|
|
7492
|
+
while (slot > 0) {
|
|
7493
|
+
const parent = Math.floor((slot - 1) / 2);
|
|
7494
|
+
if (!before(cell, heap[parent]))
|
|
7495
|
+
break;
|
|
7496
|
+
heap[slot] = heap[parent];
|
|
7497
|
+
slot = parent;
|
|
7498
|
+
}
|
|
7499
|
+
heap[slot] = cell;
|
|
7500
|
+
}
|
|
7501
|
+
function pop() {
|
|
7502
|
+
const first = heap[0];
|
|
7503
|
+
const tail = heap[--size];
|
|
7504
|
+
let slot = 0;
|
|
7505
|
+
let child = 1;
|
|
7506
|
+
while (child < size) {
|
|
7507
|
+
if (child + 1 < size && before(heap[child + 1], heap[child]))
|
|
7508
|
+
child++;
|
|
7509
|
+
if (!before(heap[child], tail))
|
|
7510
|
+
break;
|
|
7511
|
+
heap[slot] = heap[child];
|
|
7512
|
+
slot = child;
|
|
7513
|
+
child = slot * 2 + 1;
|
|
7514
|
+
}
|
|
7515
|
+
if (size)
|
|
7516
|
+
heap[slot] = tail;
|
|
7517
|
+
return first;
|
|
7518
|
+
}
|
|
7519
|
+
function visit(cell, parent) {
|
|
7520
|
+
if (!validity[cell] || receiver[cell] !== -2)
|
|
7521
|
+
return;
|
|
7522
|
+
receiver[cell] = parent;
|
|
7523
|
+
disconnectedCells--;
|
|
7524
|
+
if (parent >= 0)
|
|
7525
|
+
heights[cell] = Math.max(heights[cell], heights[parent]);
|
|
7526
|
+
push(cell);
|
|
7527
|
+
}
|
|
7528
|
+
for (const outlet of outlets)
|
|
7529
|
+
visit(outlet, -1);
|
|
7530
|
+
while (size) {
|
|
7531
|
+
const cell = pop();
|
|
7532
|
+
const column = cell % width;
|
|
7533
|
+
if (column > 0)
|
|
7534
|
+
visit(cell - 1, cell);
|
|
7535
|
+
if (column + 1 < width)
|
|
7536
|
+
visit(cell + 1, cell);
|
|
7537
|
+
if (cell >= width)
|
|
7538
|
+
visit(cell - width, cell);
|
|
7539
|
+
if (cell < count - width)
|
|
7540
|
+
visit(cell + width, cell);
|
|
7541
|
+
}
|
|
7542
|
+
return {
|
|
7543
|
+
field: new HeightField({
|
|
7544
|
+
width,
|
|
7545
|
+
height,
|
|
7546
|
+
heights,
|
|
7547
|
+
validity,
|
|
7548
|
+
origin: field.origin,
|
|
7549
|
+
columnStep: field.columnStep,
|
|
7550
|
+
rowStep: field.rowStep,
|
|
7551
|
+
registration: field.registration,
|
|
7552
|
+
diagonal: field.diagonal,
|
|
7553
|
+
heightReference: field.heightReference
|
|
7554
|
+
}),
|
|
7555
|
+
receiver,
|
|
7556
|
+
disconnectedCells
|
|
7557
|
+
};
|
|
7558
|
+
}
|
|
7559
|
+
|
|
7560
|
+
// dist/terrain/cutout-region.js
|
|
7561
|
+
var PLAN = /* @__PURE__ */ Symbol.for("@math.gl/geospatial/terrain-cutout-polygons/v1");
|
|
7562
|
+
function createTerrainCutoutPlan(plan) {
|
|
7563
|
+
return Object.freeze({ [PLAN]: Object.freeze(plan) });
|
|
7564
|
+
}
|
|
7565
|
+
function getTerrainCutoutPlan(region) {
|
|
7566
|
+
if (Array.isArray(region))
|
|
7567
|
+
return void 0;
|
|
7568
|
+
const plan = region == null ? void 0 : region[PLAN];
|
|
7569
|
+
if (!plan)
|
|
7570
|
+
throw new RangeError("Invalid prepared terrain cutout polygons");
|
|
7571
|
+
return plan;
|
|
7572
|
+
}
|
|
7573
|
+
function copyTerrainCutoutRegion(region) {
|
|
7574
|
+
return getTerrainCutoutPlan(region) ? region : region.map((p) => [p[0], p[1]]);
|
|
7575
|
+
}
|
|
7576
|
+
function sameTerrainCutoutRegion(a, b) {
|
|
7577
|
+
if (getTerrainCutoutPlan(a) || getTerrainCutoutPlan(b))
|
|
7578
|
+
return a === b;
|
|
7579
|
+
const aa = a, bb = b;
|
|
7580
|
+
return aa.length === bb.length && aa.every((p, i) => bb[i].length === 2 && p[0] === bb[i][0] && p[1] === bb[i][1]);
|
|
7581
|
+
}
|
|
7582
|
+
|
|
7583
|
+
// dist/terrain/mesh-cutout.js
|
|
7584
|
+
function splitTerrainMesh(mesh, polygon2, { maxWork = 4e6, maxVertices = 5e5, maxTriangles = 5e5 } = {}) {
|
|
7585
|
+
if (![maxWork, maxVertices, maxTriangles].every((n) => Number.isSafeInteger(n) && n >= 0) || maxVertices > 4294967295 || maxTriangles > 4294967295 || !(mesh.positions instanceof Float32Array || mesh.positions instanceof Float64Array) || !(mesh.indices instanceof Uint16Array || mesh.indices instanceof Uint32Array) || mesh.positions.length % 3 || mesh.indices.length % 3 || mesh.positions.length / 3 > maxVertices || mesh.indices.length / 3 > maxTriangles || !mesh.positions.every(Number.isFinite))
|
|
7586
|
+
throw new RangeError("Invalid terrain cutout mesh or capacity");
|
|
7587
|
+
let work = 0;
|
|
7588
|
+
function charge(amount) {
|
|
7589
|
+
work += amount;
|
|
7590
|
+
if (work > maxWork)
|
|
7591
|
+
throw new RangeError("Terrain cutout work budget exceeded");
|
|
7592
|
+
}
|
|
7593
|
+
const prepared = getTerrainCutoutPlan(polygon2);
|
|
7594
|
+
const ring = prepared ? void 0 : validatePolygon(polygon2, charge);
|
|
7595
|
+
const lines = (prepared == null ? void 0 : prepared.lines) ?? ring.map((p, i) => [p, ring[(i + 1) % ring.length]]);
|
|
7596
|
+
const vertices = [];
|
|
7597
|
+
for (let i = 0; i < mesh.positions.length; i += 3)
|
|
7598
|
+
vertices.push([mesh.positions[i], mesh.positions[i + 1], mesh.positions[i + 2]]);
|
|
7599
|
+
const faces = [];
|
|
7600
|
+
for (let i = 0; i < mesh.indices.length; i += 3) {
|
|
7601
|
+
const face = [mesh.indices[i], mesh.indices[i + 1], mesh.indices[i + 2]];
|
|
7602
|
+
if (face.some((id) => id >= vertices.length))
|
|
7603
|
+
throw new RangeError("Invalid terrain cutout index");
|
|
7604
|
+
checkTriangle(vertices[face[0]], vertices[face[1]], vertices[face[2]]);
|
|
7605
|
+
faces.push(face);
|
|
7606
|
+
}
|
|
7607
|
+
validateTopology(vertices, faces, charge);
|
|
7608
|
+
const patch = createPiece();
|
|
7609
|
+
const remainder = createPiece();
|
|
7610
|
+
const intersections = lines.map(() => /* @__PURE__ */ new Map());
|
|
7611
|
+
let fragmentCount = 0;
|
|
7612
|
+
function addVertex(vertex) {
|
|
7613
|
+
if (vertices.length >= maxVertices || !vertex.every(Number.isFinite))
|
|
7614
|
+
throw new RangeError("Terrain cutout vertex budget or coordinate range exceeded");
|
|
7615
|
+
return vertices.push(vertex) - 1;
|
|
7616
|
+
}
|
|
7617
|
+
function intersection(a, b, da, db, line) {
|
|
7618
|
+
const key2 = edgeKey2(a, b);
|
|
7619
|
+
const cache = intersections[line];
|
|
7620
|
+
const saved = cache.get(key2);
|
|
7621
|
+
if (saved !== void 0)
|
|
7622
|
+
return saved;
|
|
7623
|
+
const pa = vertices[a], pb = vertices[b];
|
|
7624
|
+
if (pa[0] > pb[0] || pa[0] === pb[0] && (pa[1] > pb[1] || pa[1] === pb[1] && pa[2] > pb[2])) {
|
|
7625
|
+
[a, b] = [b, a];
|
|
7626
|
+
[da, db] = [db, da];
|
|
7627
|
+
}
|
|
7628
|
+
const t = Math.abs(da) / (Math.abs(da) + Math.abs(db));
|
|
7629
|
+
if (!(t > 0 && t < 1))
|
|
7630
|
+
throw new RangeError("Unrepresentable terrain cut intersection");
|
|
7631
|
+
const u = vertices[a];
|
|
7632
|
+
const v = vertices[b];
|
|
7633
|
+
const id = addVertex([
|
|
7634
|
+
u[0] + t * (v[0] - u[0]),
|
|
7635
|
+
u[1] + t * (v[1] - u[1]),
|
|
7636
|
+
u[2] + t * (v[2] - u[2])
|
|
7637
|
+
]);
|
|
7638
|
+
cache.set(key2, id);
|
|
7639
|
+
return id;
|
|
7640
|
+
}
|
|
7641
|
+
for (let source = 0; source < faces.length; source++) {
|
|
7642
|
+
let fragments = [{ ids: faces[source], inside: true }];
|
|
7643
|
+
for (let line = 0; line < lines.length; line++) {
|
|
7644
|
+
const next = [];
|
|
7645
|
+
const [a, b] = lines[line];
|
|
7646
|
+
for (const fragment of fragments) {
|
|
7647
|
+
const { ids } = fragment;
|
|
7648
|
+
charge(ids.length);
|
|
7649
|
+
const distances = ids.map((id) => cross3(a, b, vertices[id]));
|
|
7650
|
+
if (distances.some((d) => !Number.isFinite(d)))
|
|
7651
|
+
throw new RangeError("Invalid terrain cut coordinates");
|
|
7652
|
+
if (!distances.some((d) => d < 0))
|
|
7653
|
+
next.push(fragment);
|
|
7654
|
+
else if (!distances.some((d) => d > 0))
|
|
7655
|
+
next.push({ ...fragment, inside: false });
|
|
7656
|
+
else {
|
|
7657
|
+
const positive = [];
|
|
7658
|
+
const negative = [];
|
|
7659
|
+
for (let i = 0; i < ids.length; i++) {
|
|
7660
|
+
const j = (i + 1) % ids.length;
|
|
7661
|
+
const d = distances[i];
|
|
7662
|
+
const e = distances[j];
|
|
7663
|
+
if (d >= 0)
|
|
7664
|
+
positive.push(ids[i]);
|
|
7665
|
+
if (d <= 0)
|
|
7666
|
+
negative.push(ids[i]);
|
|
7667
|
+
if (d < 0 && e > 0 || d > 0 && e < 0) {
|
|
7668
|
+
const id = intersection(ids[i], ids[j], d, e, line);
|
|
7669
|
+
positive.push(id);
|
|
7670
|
+
negative.push(id);
|
|
7671
|
+
}
|
|
7672
|
+
}
|
|
7673
|
+
next.push({ ids: positive, inside: fragment.inside }, { ids: negative, inside: false });
|
|
7674
|
+
}
|
|
7675
|
+
if (fragmentCount + next.length > maxTriangles)
|
|
7676
|
+
throw new RangeError("Terrain cutout fragment budget exceeded");
|
|
7677
|
+
}
|
|
7678
|
+
fragments = next;
|
|
7679
|
+
}
|
|
7680
|
+
fragmentCount += fragments.length;
|
|
7681
|
+
for (const { ids, inside } of fragments) {
|
|
7682
|
+
let center;
|
|
7683
|
+
if (prepared || ids.length > 3) {
|
|
7684
|
+
center = [...vertices[ids[0]]];
|
|
7685
|
+
for (const id of ids) {
|
|
7686
|
+
for (let k = 0; k < 3; k++)
|
|
7687
|
+
center[k] += (vertices[id][k] - vertices[ids[0]][k]) / ids.length;
|
|
7688
|
+
}
|
|
7689
|
+
}
|
|
7690
|
+
const polygonIndex = prepared ? prepared.classify([center[0], center[1]], charge) : inside ? 0 : -1;
|
|
7691
|
+
const piece = polygonIndex >= 0 ? patch : remainder;
|
|
7692
|
+
if (ids.length === 3)
|
|
7693
|
+
emit(piece, ids, source, polygonIndex);
|
|
7694
|
+
else {
|
|
7695
|
+
const hub = addVertex(center);
|
|
7696
|
+
for (let i = 0; i < ids.length; i++)
|
|
7697
|
+
emit(piece, [ids[i], ids[(i + 1) % ids.length], hub], source, polygonIndex);
|
|
7698
|
+
}
|
|
7699
|
+
}
|
|
7700
|
+
}
|
|
7701
|
+
function emit(piece, face, source, polygonIndex) {
|
|
7702
|
+
if (patch.sourceFaces.length + remainder.sourceFaces.length >= maxTriangles)
|
|
7703
|
+
throw new RangeError("Terrain cutout triangle budget exceeded");
|
|
7704
|
+
checkTriangle(vertices[face[0]], vertices[face[1]], vertices[face[2]]);
|
|
7705
|
+
const [a, b, c] = faces[source].map((id) => vertices[id]);
|
|
7706
|
+
const area = cross3(a, b, c);
|
|
7707
|
+
for (let i = 0; i < 3; i++) {
|
|
7708
|
+
const id = face[i];
|
|
7709
|
+
if (!piece.ids.has(id)) {
|
|
7710
|
+
if (patch.ids.size + remainder.ids.size >= maxVertices)
|
|
7711
|
+
throw new RangeError("Terrain cutout output vertex budget exceeded");
|
|
7712
|
+
piece.ids.set(id, piece.ids.size);
|
|
7713
|
+
const p = vertices[id];
|
|
7714
|
+
piece.positions.push(...p);
|
|
7715
|
+
piece.sourceTriangles.push(source);
|
|
7716
|
+
piece.sourceWeights.push(cross3(b, c, p) / area, cross3(c, a, p) / area, cross3(a, b, p) / area);
|
|
7717
|
+
}
|
|
7718
|
+
piece.indices.push(piece.ids.get(id));
|
|
7719
|
+
addEdge(piece.boundary, id, face[(i + 1) % 3], polygonIndex);
|
|
7720
|
+
}
|
|
7721
|
+
piece.sourceFaces.push(source);
|
|
7722
|
+
piece.polygonIndices.push(polygonIndex);
|
|
7723
|
+
}
|
|
7724
|
+
for (const [key2, inside] of patch.boundary) {
|
|
7725
|
+
const outside = remainder.boundary.get(key2);
|
|
7726
|
+
if (!outside)
|
|
7727
|
+
continue;
|
|
7728
|
+
const [a, b] = inside.edge;
|
|
7729
|
+
if (inside.count !== 1 || outside.count !== 1 || outside.edge[0] !== b)
|
|
7730
|
+
throw new Error("Nonconforming terrain cut boundary");
|
|
7731
|
+
patch.cutEdges.push(patch.ids.get(a), patch.ids.get(b));
|
|
7732
|
+
remainder.cutEdges.push(remainder.ids.get(b), remainder.ids.get(a));
|
|
7733
|
+
patch.cutPolygonIndices.push(inside.polygon);
|
|
7734
|
+
remainder.cutPolygonIndices.push(inside.polygon);
|
|
7735
|
+
}
|
|
7736
|
+
return { patch: finish(patch), remainder: finish(remainder) };
|
|
7737
|
+
}
|
|
7738
|
+
function validatePolygon(polygon2, charge) {
|
|
7739
|
+
if (polygon2.length < 3 || polygon2.some((p) => p.length !== 2 || !p.every(Number.isFinite)))
|
|
7740
|
+
throw new RangeError("Invalid terrain cut polygon");
|
|
7741
|
+
const ring = [...polygon2];
|
|
7742
|
+
const orientation2 = cross3(ring[0], ring[1], ring[2]);
|
|
7743
|
+
if (orientation2 < 0)
|
|
7744
|
+
ring.reverse();
|
|
7745
|
+
for (let i = 0; i < ring.length; i++) {
|
|
7746
|
+
charge(ring.length);
|
|
7747
|
+
const j = (i + 1) % ring.length;
|
|
7748
|
+
for (let k = 0; k < ring.length; k++) {
|
|
7749
|
+
if (k === i || k === j)
|
|
7750
|
+
continue;
|
|
7751
|
+
const area = cross3(ring[i], ring[j], ring[k]);
|
|
7752
|
+
if (!(area > 0 && Number.isFinite(area)))
|
|
7753
|
+
throw new RangeError("Terrain cut polygon must be strictly convex");
|
|
7754
|
+
}
|
|
7755
|
+
}
|
|
7756
|
+
return ring;
|
|
7757
|
+
}
|
|
7758
|
+
function checkTriangle(a, b, c) {
|
|
7759
|
+
const area = cross3(a, b, c);
|
|
7760
|
+
const scale = Math.hypot(b[0] - a[0], b[1] - a[1]) * Math.hypot(c[0] - a[0], c[1] - a[1]);
|
|
7761
|
+
if (!(area > Number.EPSILON * scale && Number.isFinite(area)))
|
|
7762
|
+
throw new RangeError("Terrain cut requires upward nondegenerate XY triangles");
|
|
7763
|
+
}
|
|
7764
|
+
function validateTopology(vertices, faces, charge) {
|
|
7765
|
+
const edges2 = /* @__PURE__ */ new Map();
|
|
7766
|
+
const boxes = faces.map((face) => {
|
|
7767
|
+
for (let i = 0; i < 3; i++)
|
|
7768
|
+
addEdge(edges2, face[i], face[(i + 1) % 3]);
|
|
7769
|
+
const points = face.map((id) => vertices[id]);
|
|
7770
|
+
return {
|
|
7771
|
+
face,
|
|
7772
|
+
points,
|
|
7773
|
+
low: Math.min(...points.map((p) => p[0])),
|
|
7774
|
+
high: Math.max(...points.map((p) => p[0])),
|
|
7775
|
+
minY: Math.min(...points.map((p) => p[1])),
|
|
7776
|
+
maxY: Math.max(...points.map((p) => p[1]))
|
|
7777
|
+
};
|
|
7778
|
+
}).sort((a, b) => a.low - b.low);
|
|
7779
|
+
for (let i = 0; i < boxes.length; i++) {
|
|
7780
|
+
const a = boxes[i];
|
|
7781
|
+
for (let j = i + 1; j < boxes.length && boxes[j].low <= a.high; j++) {
|
|
7782
|
+
charge(1);
|
|
7783
|
+
const b = boxes[j];
|
|
7784
|
+
if (a.maxY < b.minY || b.maxY < a.minY)
|
|
7785
|
+
continue;
|
|
7786
|
+
if (!separates(a.points, b.points) && !separates(b.points, a.points))
|
|
7787
|
+
throw new RangeError("Terrain cut input has overlapping XY triangles");
|
|
7788
|
+
checkJunctions(a.face, b.face, vertices);
|
|
7789
|
+
checkJunctions(b.face, a.face, vertices);
|
|
7790
|
+
}
|
|
7791
|
+
}
|
|
7792
|
+
}
|
|
7793
|
+
function separates(a, b) {
|
|
7794
|
+
return a.some((p, i) => b.every((q) => cross3(p, a[(i + 1) % 3], q) <= 0));
|
|
7795
|
+
}
|
|
7796
|
+
function checkJunctions(a, b, vertices) {
|
|
7797
|
+
for (let i = 0; i < 3; i++) {
|
|
7798
|
+
const u = vertices[a[i]];
|
|
7799
|
+
const v = vertices[a[(i + 1) % 3]];
|
|
7800
|
+
const overlaps2 = b.filter((id) => {
|
|
7801
|
+
const p = vertices[id];
|
|
7802
|
+
if (cross3(u, v, p) !== 0)
|
|
7803
|
+
return false;
|
|
7804
|
+
const axis = Math.abs(v[0] - u[0]) >= Math.abs(v[1] - u[1]) ? 0 : 1;
|
|
7805
|
+
const low = Math.min(u[axis], v[axis]);
|
|
7806
|
+
const high = Math.max(u[axis], v[axis]);
|
|
7807
|
+
if (p[axis] > low && p[axis] < high)
|
|
7808
|
+
throw new RangeError("Terrain cut input has a T-junction");
|
|
7809
|
+
return p[axis] >= low && p[axis] <= high;
|
|
7810
|
+
});
|
|
7811
|
+
if (overlaps2.length >= 2 && (!overlaps2.includes(a[i]) || !overlaps2.includes(a[(i + 1) % 3])))
|
|
7812
|
+
throw new RangeError("Terrain cut input has an unwelded shared edge");
|
|
7813
|
+
}
|
|
7814
|
+
}
|
|
7815
|
+
function addEdge(edges2, a, b, polygon2 = -1) {
|
|
7816
|
+
const key2 = edgeKey2(a, b);
|
|
7817
|
+
const entry = edges2.get(key2);
|
|
7818
|
+
if (!entry)
|
|
7819
|
+
edges2.set(key2, { edge: [a, b], count: 1, polygon: polygon2 });
|
|
7820
|
+
else {
|
|
7821
|
+
if (entry.count !== 1 || entry.edge[0] !== b)
|
|
7822
|
+
throw new RangeError("Terrain cut mesh has inconsistent or nonmanifold edges");
|
|
7823
|
+
entry.count++;
|
|
7824
|
+
}
|
|
7825
|
+
}
|
|
7826
|
+
function edgeKey2(a, b) {
|
|
7827
|
+
return a < b ? a + "," + b : b + "," + a;
|
|
7828
|
+
}
|
|
7829
|
+
function cross3(a, b, c) {
|
|
7830
|
+
return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
|
|
7831
|
+
}
|
|
7832
|
+
function createPiece() {
|
|
7833
|
+
return {
|
|
7834
|
+
ids: /* @__PURE__ */ new Map(),
|
|
7835
|
+
positions: [],
|
|
7836
|
+
indices: [],
|
|
7837
|
+
sourceTriangles: [],
|
|
7838
|
+
sourceWeights: [],
|
|
7839
|
+
sourceFaces: [],
|
|
7840
|
+
boundary: /* @__PURE__ */ new Map(),
|
|
7841
|
+
cutEdges: [],
|
|
7842
|
+
polygonIndices: [],
|
|
7843
|
+
cutPolygonIndices: []
|
|
7844
|
+
};
|
|
7845
|
+
}
|
|
7846
|
+
function finish(piece) {
|
|
7847
|
+
return {
|
|
7848
|
+
positions: Float64Array.from(piece.positions),
|
|
7849
|
+
indices: Uint32Array.from(piece.indices),
|
|
7850
|
+
sourceTriangles: Uint32Array.from(piece.sourceTriangles),
|
|
7851
|
+
sourceWeights: Float64Array.from(piece.sourceWeights),
|
|
7852
|
+
sourceFaces: Uint32Array.from(piece.sourceFaces),
|
|
7853
|
+
cutEdges: Uint32Array.from(piece.cutEdges),
|
|
7854
|
+
polygonIndices: Uint32Array.from(piece.polygonIndices),
|
|
7855
|
+
cutPolygonIndices: Uint32Array.from(piece.cutPolygonIndices)
|
|
7856
|
+
};
|
|
7857
|
+
}
|
|
7858
|
+
function validateTerrainCutoutTopology(mesh, maxWork) {
|
|
7859
|
+
const vertices = [];
|
|
7860
|
+
const faces = [];
|
|
7861
|
+
for (let i = 0; i < mesh.positions.length; i += 3)
|
|
7862
|
+
vertices.push([mesh.positions[i], mesh.positions[i + 1], mesh.positions[i + 2]]);
|
|
7863
|
+
for (let i = 0; i < mesh.indices.length; i += 3)
|
|
7864
|
+
faces.push([mesh.indices[i], mesh.indices[i + 1], mesh.indices[i + 2]]);
|
|
7865
|
+
let work = 0;
|
|
7866
|
+
validateTopology(vertices, faces, (amount) => {
|
|
7867
|
+
work += amount;
|
|
7868
|
+
if (work > maxWork)
|
|
7869
|
+
throw new RangeError("Terrain cutout topology work budget exceeded");
|
|
7870
|
+
});
|
|
7871
|
+
}
|
|
7872
|
+
|
|
7873
|
+
// dist/terrain/cutout-skirts.js
|
|
7874
|
+
function createTerrainCutoutSkirts(cutout, { lift = 0, patch, remainder }) {
|
|
7875
|
+
if (!Number.isFinite(lift))
|
|
7876
|
+
throw new RangeError("Invalid terrain cutout lift");
|
|
7877
|
+
const positions = cutout.patch.positions.slice();
|
|
7878
|
+
for (let i = 2; i < positions.length; i += 3) {
|
|
7879
|
+
positions[i] += lift;
|
|
7880
|
+
if (!Number.isFinite(positions[i]))
|
|
7881
|
+
throw new RangeError("Terrain cutout lift overflow");
|
|
7882
|
+
}
|
|
7883
|
+
return {
|
|
7884
|
+
patch: skirtPiece({ ...cutout.patch, positions }, patch),
|
|
7885
|
+
remainder: skirtPiece(cutout.remainder, remainder)
|
|
7886
|
+
};
|
|
7887
|
+
}
|
|
7888
|
+
function skirtPiece(surface, options) {
|
|
7889
|
+
if (!surface.cutEdges.length)
|
|
7890
|
+
return { surface };
|
|
7891
|
+
return {
|
|
7892
|
+
surface,
|
|
7893
|
+
skirt: createTerrainSkirt(surface, { ...options, edges: surface.cutEdges })
|
|
7894
|
+
};
|
|
7895
|
+
}
|
|
7896
|
+
|
|
7897
|
+
// dist/terrain/watershed-accumulation.js
|
|
7898
|
+
function accumulateTerrainWatersheds(receiver, { maxCells = 4194304 } = {}) {
|
|
7899
|
+
const count = receiver.length;
|
|
7900
|
+
if (!Number.isSafeInteger(maxCells) || maxCells < 0 || count > maxCells || count > 2147483647)
|
|
7901
|
+
throw new RangeError("Terrain watershed accumulation exceeds its cell budget");
|
|
7902
|
+
const incoming = new Uint32Array(count);
|
|
7903
|
+
const contributingCells = new Uint32Array(count);
|
|
7904
|
+
const terminal = new Int32Array(count).fill(-1);
|
|
7905
|
+
const queue = new Int32Array(count);
|
|
7906
|
+
let active = 0;
|
|
7907
|
+
for (let i = 0; i < count; i++) {
|
|
7908
|
+
const next = receiver[i];
|
|
7909
|
+
if (next === -2)
|
|
7910
|
+
continue;
|
|
7911
|
+
if (next < -1 || next >= count || next >= 0 && receiver[next] === -2)
|
|
7912
|
+
throw new RangeError("Invalid terrain watershed receiver");
|
|
7913
|
+
active++;
|
|
7914
|
+
contributingCells[i] = 1;
|
|
7915
|
+
if (next >= 0)
|
|
7916
|
+
incoming[next]++;
|
|
7917
|
+
}
|
|
7918
|
+
let end = 0;
|
|
7919
|
+
for (let i = 0; i < count; i++) {
|
|
7920
|
+
if (contributingCells[i] && !incoming[i])
|
|
7921
|
+
queue[end++] = i;
|
|
7922
|
+
}
|
|
7923
|
+
for (let cursor = 0; cursor < end; cursor++) {
|
|
7924
|
+
const i = queue[cursor];
|
|
7925
|
+
const next = receiver[i];
|
|
7926
|
+
if (next < 0)
|
|
7927
|
+
continue;
|
|
7928
|
+
contributingCells[next] += contributingCells[i];
|
|
7929
|
+
if (--incoming[next] === 0)
|
|
7930
|
+
queue[end++] = next;
|
|
7931
|
+
}
|
|
7932
|
+
if (end !== active)
|
|
7933
|
+
throw new RangeError("Terrain watershed receiver graph contains a cycle");
|
|
7934
|
+
for (let cursor = end - 1; cursor >= 0; cursor--) {
|
|
7935
|
+
const i = queue[cursor];
|
|
7936
|
+
const next = receiver[i];
|
|
7937
|
+
terminal[i] = next < 0 ? i : terminal[next];
|
|
7938
|
+
}
|
|
7939
|
+
return { terminal, contributingCells };
|
|
7940
|
+
}
|
|
7941
|
+
|
|
7942
|
+
// dist/terrain/tile-cutout.js
|
|
7943
|
+
function splitTerrainMeshTiles(tiles, polygon2, options = {}) {
|
|
7944
|
+
const assembled = assembleTerrainCutoutTiles(tiles, options);
|
|
7945
|
+
return {
|
|
7946
|
+
...splitTerrainMesh(assembled.mesh, polygon2, { ...options, maxWork: assembled.remainingWork }),
|
|
7947
|
+
sourceTiles: assembled.sourceTiles,
|
|
7948
|
+
sourceTileFaces: assembled.sourceTileFaces
|
|
7949
|
+
};
|
|
7950
|
+
}
|
|
7951
|
+
function assembleTerrainCutoutTiles(tiles, options = {}) {
|
|
7952
|
+
const maxVertices = options.maxVertices ?? 5e5;
|
|
7953
|
+
const maxTriangles = options.maxTriangles ?? 5e5;
|
|
7954
|
+
const maxWork = options.maxWork ?? 4e6;
|
|
7955
|
+
if (![maxVertices, maxTriangles, maxWork].every((n) => Number.isSafeInteger(n) && n >= 0) || maxVertices > 4294967295 || maxTriangles > 4294967295)
|
|
7956
|
+
throw new RangeError("Invalid terrain tile cutout limits");
|
|
7957
|
+
let vertexCount = 0;
|
|
7958
|
+
let faceCount = 0;
|
|
7959
|
+
let work = 0;
|
|
7960
|
+
for (const tile of tiles) {
|
|
7961
|
+
if (!(tile.positions instanceof Float32Array || tile.positions instanceof Float64Array) || !(tile.indices instanceof Uint16Array || tile.indices instanceof Uint32Array) || tile.positions.length % 3 || tile.indices.length % 3)
|
|
7962
|
+
throw new RangeError("Invalid terrain tile cutout mesh");
|
|
7963
|
+
vertexCount += tile.positions.length / 3;
|
|
7964
|
+
faceCount += tile.indices.length / 3;
|
|
7965
|
+
work += 1 + tile.positions.length / 3 + tile.indices.length;
|
|
7966
|
+
if (vertexCount > maxVertices || faceCount > maxTriangles || work > maxWork)
|
|
7967
|
+
throw new RangeError("Terrain tile cutout input budget exceeded");
|
|
7968
|
+
}
|
|
7969
|
+
const positions = new Float64Array(vertexCount * 3);
|
|
7970
|
+
const indices = new Uint32Array(faceCount * 3);
|
|
7971
|
+
const sourceTiles = new Uint32Array(faceCount);
|
|
7972
|
+
const sourceTileFaces = new Uint32Array(faceCount);
|
|
7973
|
+
const vertices = /* @__PURE__ */ new Map();
|
|
7974
|
+
let vertexOffset = 0;
|
|
7975
|
+
let faceOffset = 0;
|
|
7976
|
+
for (let tileIndex = 0; tileIndex < tiles.length; tileIndex++) {
|
|
7977
|
+
const tile = tiles[tileIndex];
|
|
7978
|
+
const remap = new Uint32Array(tile.positions.length / 3);
|
|
7979
|
+
for (let i = 0; i < remap.length; i++) {
|
|
7980
|
+
const x = tile.positions[i * 3];
|
|
7981
|
+
const y = tile.positions[i * 3 + 1];
|
|
7982
|
+
const z = tile.positions[i * 3 + 2];
|
|
7983
|
+
if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
|
|
7984
|
+
throw new RangeError("Invalid terrain tile cutout coordinate");
|
|
7985
|
+
const key2 = `${x},${y},${z}`;
|
|
7986
|
+
let id = vertices.get(key2);
|
|
7987
|
+
if (id === void 0) {
|
|
7988
|
+
id = vertexOffset++;
|
|
7989
|
+
vertices.set(key2, id);
|
|
7990
|
+
positions[id * 3] = x;
|
|
7991
|
+
positions[id * 3 + 1] = y;
|
|
7992
|
+
positions[id * 3 + 2] = z;
|
|
7993
|
+
}
|
|
7994
|
+
remap[i] = id;
|
|
7995
|
+
}
|
|
7996
|
+
for (let i = 0; i < tile.indices.length; i++) {
|
|
7997
|
+
const id = tile.indices[i];
|
|
7998
|
+
if (id >= remap.length)
|
|
7999
|
+
throw new RangeError("Invalid terrain tile cutout index");
|
|
8000
|
+
indices[faceOffset * 3 + i] = remap[id];
|
|
8001
|
+
}
|
|
8002
|
+
for (let i = 0; i < tile.indices.length / 3; i++) {
|
|
8003
|
+
sourceTiles[faceOffset + i] = tileIndex;
|
|
8004
|
+
sourceTileFaces[faceOffset + i] = i;
|
|
8005
|
+
}
|
|
8006
|
+
faceOffset += tile.indices.length / 3;
|
|
8007
|
+
}
|
|
8008
|
+
return {
|
|
8009
|
+
mesh: { positions: positions.subarray(0, vertexOffset * 3), indices },
|
|
8010
|
+
sourceTiles,
|
|
8011
|
+
sourceTileFaces,
|
|
8012
|
+
remainingWork: maxWork - work
|
|
8013
|
+
};
|
|
8014
|
+
}
|
|
8015
|
+
|
|
8016
|
+
// dist/terrain/tile-cutout-update.js
|
|
8017
|
+
var CACHE = /* @__PURE__ */ Symbol("terrain-cutout-cache");
|
|
8018
|
+
function updateTerrainTileCutouts(residents, polygon2, previous, options = {}) {
|
|
8019
|
+
const limits = {
|
|
8020
|
+
maxTiles: options.maxTiles ?? 512,
|
|
8021
|
+
maxPairChecks: options.maxPairChecks ?? 131072,
|
|
8022
|
+
maxBoundaryEdges: options.maxBoundaryEdges ?? 1e6,
|
|
8023
|
+
maxWork: options.maxWork ?? 4e6,
|
|
8024
|
+
maxVertices: options.maxVertices ?? 5e5,
|
|
8025
|
+
maxTriangles: options.maxTriangles ?? 5e5
|
|
8026
|
+
};
|
|
8027
|
+
if (Object.values(limits).some((n) => !Number.isSafeInteger(n) || n < 0) || limits.maxVertices > 4294967295 || limits.maxTriangles > 4294967295 || residents.length > limits.maxTiles)
|
|
8028
|
+
throw new RangeError("Invalid terrain cutout update limits");
|
|
8029
|
+
const prior = previous == null ? void 0 : previous[CACHE];
|
|
8030
|
+
const compatible = prior && sameTerrainCutoutRegion(prior.polygon, polygon2) && Object.keys(limits).every((key2) => prior.options[key2] === limits[key2]);
|
|
8031
|
+
if (!compatible)
|
|
8032
|
+
splitTerrainMesh({ positions: new Float64Array(), indices: new Uint32Array() }, polygon2, limits);
|
|
8033
|
+
const entries = /* @__PURE__ */ new Map();
|
|
8034
|
+
const rebuilt = [];
|
|
8035
|
+
let boundaryCount = 0;
|
|
8036
|
+
for (const resident of residents) {
|
|
8037
|
+
if (!resident.id || typeof resident.id !== "string" || entries.has(resident.id) || !Number.isSafeInteger(resident.revision) || resident.revision < 0)
|
|
8038
|
+
throw new RangeError("Invalid or duplicate terrain cutout resident");
|
|
8039
|
+
const old = compatible ? prior.entries.get(resident.id) : void 0;
|
|
8040
|
+
let entry;
|
|
8041
|
+
if (old && old.resident.mesh === resident.mesh && old.resident.revision === resident.revision)
|
|
8042
|
+
entry = old;
|
|
8043
|
+
else {
|
|
8044
|
+
const split = splitTerrainMesh(resident.mesh, polygon2, limits);
|
|
8045
|
+
const edges2 = [...boundaryEdges(split.patch, 0), ...boundaryEdges(split.remainder, 1)];
|
|
8046
|
+
const bounds2 = [Infinity, Infinity, -Infinity, -Infinity];
|
|
8047
|
+
for (const id of resident.mesh.indices) {
|
|
8048
|
+
const x = resident.mesh.positions[id * 3], y = resident.mesh.positions[id * 3 + 1];
|
|
8049
|
+
bounds2[0] = Math.min(bounds2[0], x);
|
|
8050
|
+
bounds2[1] = Math.min(bounds2[1], y);
|
|
8051
|
+
bounds2[2] = Math.max(bounds2[2], x);
|
|
8052
|
+
bounds2[3] = Math.max(bounds2[3], y);
|
|
8053
|
+
}
|
|
8054
|
+
entry = { resident: { ...resident }, split, displayed: split, bounds: bounds2, edges: edges2 };
|
|
8055
|
+
rebuilt.push(resident.id);
|
|
8056
|
+
}
|
|
8057
|
+
boundaryCount += entry.edges.length;
|
|
8058
|
+
if (boundaryCount > limits.maxBoundaryEdges)
|
|
8059
|
+
throw new RangeError("Terrain cutout boundary budget exceeded");
|
|
8060
|
+
entries.set(resident.id, entry);
|
|
8061
|
+
}
|
|
8062
|
+
const values = [...entries.values()];
|
|
8063
|
+
let pairs = 0;
|
|
8064
|
+
for (let i = 0; i < values.length; i++)
|
|
8065
|
+
for (let j = i + 1; j < values.length; j++) {
|
|
8066
|
+
if (++pairs > limits.maxPairChecks)
|
|
8067
|
+
throw new RangeError("Terrain cutout pair budget exceeded");
|
|
8068
|
+
const a = values[i], b = values[j];
|
|
8069
|
+
if (a.bounds[2] < b.bounds[0] || b.bounds[2] < a.bounds[0] || a.bounds[3] < b.bounds[1] || b.bounds[3] < a.bounds[1])
|
|
8070
|
+
continue;
|
|
8071
|
+
if (compatible && prior.entries.get(a.resident.id) === a && prior.entries.get(b.resident.id) === b)
|
|
8072
|
+
continue;
|
|
8073
|
+
const combined = assembleTerrainCutoutTiles([a.resident.mesh, b.resident.mesh], limits);
|
|
8074
|
+
validateTerrainCutoutTopology(combined.mesh, combined.remainingWork);
|
|
8075
|
+
}
|
|
8076
|
+
const boundaries = /* @__PURE__ */ new Map();
|
|
8077
|
+
const cutKeys = /* @__PURE__ */ new Map();
|
|
8078
|
+
for (let tile = 0; tile < values.length; tile++)
|
|
8079
|
+
for (const edge2 of values[tile].edges) {
|
|
8080
|
+
const other = boundaries.get(edge2.key);
|
|
8081
|
+
if (!other) {
|
|
8082
|
+
boundaries.set(edge2.key, { edge: edge2, paired: false });
|
|
8083
|
+
continue;
|
|
8084
|
+
}
|
|
8085
|
+
if (other.paired || other.edge.start !== edge2.end || other.edge.end !== edge2.start)
|
|
8086
|
+
throw new RangeError("Nonconforming terrain cutout tile boundary");
|
|
8087
|
+
other.paired = true;
|
|
8088
|
+
if (other.edge.side !== edge2.side) {
|
|
8089
|
+
cutKeys.set(edge2.key, edge2.side === 0 ? edge2.polygon : other.edge.polygon);
|
|
8090
|
+
}
|
|
8091
|
+
}
|
|
8092
|
+
const tiles = /* @__PURE__ */ new Map();
|
|
8093
|
+
const changed = [];
|
|
8094
|
+
for (let i = 0; i < values.length; i++) {
|
|
8095
|
+
const entry = values[i];
|
|
8096
|
+
const old = prior == null ? void 0 : prior.entries.get(entry.resident.id);
|
|
8097
|
+
const cuts = [[], []];
|
|
8098
|
+
const polygons = [[], []];
|
|
8099
|
+
for (const edge2 of entry.edges) {
|
|
8100
|
+
const polygonIndex = cutKeys.get(edge2.key);
|
|
8101
|
+
if (polygonIndex !== void 0) {
|
|
8102
|
+
cuts[edge2.side].push(edge2.a, edge2.b);
|
|
8103
|
+
polygons[edge2.side].push(polygonIndex);
|
|
8104
|
+
}
|
|
8105
|
+
}
|
|
8106
|
+
const patch = withEdges(entry.split.patch, cuts[0], polygons[0], old == null ? void 0 : old.displayed.patch);
|
|
8107
|
+
const remainder = withEdges(entry.split.remainder, cuts[1], polygons[1], old == null ? void 0 : old.displayed.remainder);
|
|
8108
|
+
const displayed = old && patch === old.displayed.patch && remainder === old.displayed.remainder ? old.displayed : { patch, remainder };
|
|
8109
|
+
if (displayed !== (old == null ? void 0 : old.displayed))
|
|
8110
|
+
changed.push(entry.resident.id);
|
|
8111
|
+
entries.set(entry.resident.id, displayed === entry.displayed ? entry : { ...entry, displayed });
|
|
8112
|
+
tiles.set(entry.resident.id, displayed);
|
|
8113
|
+
}
|
|
8114
|
+
return {
|
|
8115
|
+
cache: { [CACHE]: { polygon: copyTerrainCutoutRegion(polygon2), options: limits, entries } },
|
|
8116
|
+
tiles,
|
|
8117
|
+
changed,
|
|
8118
|
+
rebuilt,
|
|
8119
|
+
removed: prior ? [...prior.entries.keys()].filter((id) => !entries.has(id)) : []
|
|
8120
|
+
};
|
|
8121
|
+
}
|
|
8122
|
+
function withEdges(piece, edges2, polygons, old) {
|
|
8123
|
+
const same = old && old.positions === piece.positions && old.cutEdges.length === edges2.length && old.cutEdges.every((id, i) => id === edges2[i]) && old.cutPolygonIndices.every((id, i) => id === polygons[i]);
|
|
8124
|
+
return same ? old : { ...piece, cutEdges: Uint32Array.from(edges2), cutPolygonIndices: Uint32Array.from(polygons) };
|
|
8125
|
+
}
|
|
8126
|
+
function boundaryEdges(piece, side) {
|
|
8127
|
+
const edges2 = /* @__PURE__ */ new Map();
|
|
8128
|
+
for (let i = 0; i < piece.indices.length; i += 3)
|
|
8129
|
+
for (let j = 0; j < 3; j++) {
|
|
8130
|
+
const a = piece.indices[i + j], b = piece.indices[i + (j + 1) % 3];
|
|
8131
|
+
const key2 = a < b ? `${a},${b}` : `${b},${a}`;
|
|
8132
|
+
const old = edges2.get(key2);
|
|
8133
|
+
if (old)
|
|
8134
|
+
old.count++;
|
|
8135
|
+
else
|
|
8136
|
+
edges2.set(key2, { a, b, count: 1, polygon: piece.polygonIndices[i / 3] });
|
|
8137
|
+
}
|
|
8138
|
+
const result = [];
|
|
8139
|
+
const point = (id) => `${piece.positions[id * 3]},${piece.positions[id * 3 + 1]},${piece.positions[id * 3 + 2]}`;
|
|
8140
|
+
for (const { a, b, count, polygon: polygon2 } of edges2.values())
|
|
8141
|
+
if (count === 1) {
|
|
8142
|
+
const start = point(a), end = point(b);
|
|
8143
|
+
result.push({
|
|
8144
|
+
polygon: polygon2,
|
|
8145
|
+
a,
|
|
8146
|
+
b,
|
|
8147
|
+
side,
|
|
8148
|
+
start,
|
|
8149
|
+
end,
|
|
8150
|
+
key: start < end ? `${start}/${end}` : `${end}/${start}`
|
|
8151
|
+
});
|
|
8152
|
+
}
|
|
8153
|
+
return result;
|
|
8154
|
+
}
|
|
8155
|
+
|
|
8156
|
+
// dist/terrain/geographic-cutout.js
|
|
8157
|
+
var RAD = Math.PI / 180;
|
|
8158
|
+
function createGeographicTerrainCutoutFrame(options) {
|
|
8159
|
+
if (options.center.length !== 2)
|
|
8160
|
+
throw new RangeError("Invalid geographic terrain cutout center");
|
|
8161
|
+
const frame = {
|
|
8162
|
+
center: [wrap(options.center[0]), options.center[1]],
|
|
8163
|
+
radius: options.radius ?? 6378137,
|
|
8164
|
+
maxAngularRadius: options.maxAngularRadius ?? 30
|
|
8165
|
+
};
|
|
8166
|
+
validateFrame(frame);
|
|
8167
|
+
return Object.freeze({ ...frame, center: Object.freeze(frame.center) });
|
|
8168
|
+
}
|
|
8169
|
+
function projectGeographicTerrainCutout(positions, frame) {
|
|
8170
|
+
var _a;
|
|
8171
|
+
validateFrame(frame);
|
|
8172
|
+
validatePositions(positions);
|
|
8173
|
+
const result = new Float64Array(positions.length);
|
|
8174
|
+
const [sin0, cos0] = latitude(frame.center[1]);
|
|
8175
|
+
const maximum = chartLimit(frame);
|
|
8176
|
+
for (let i = 0; i < positions.length; i += 3) {
|
|
8177
|
+
const lon = positions[i], lat = positions[i + 1];
|
|
8178
|
+
if (lat < -90 || lat > 90)
|
|
8179
|
+
throw new RangeError("Invalid geographic terrain latitude");
|
|
8180
|
+
const sin = Math.sin(lat * RAD);
|
|
8181
|
+
const cos = Math.abs(lat) === 90 ? 0 : Math.cos(lat * RAD);
|
|
8182
|
+
const delta = wrap(wrap(lon) - frame.center[0]) * RAD;
|
|
8183
|
+
const dot2 = sin0 * sin + cos0 * cos * Math.cos(delta);
|
|
8184
|
+
const x = cos * Math.sin(delta) / dot2;
|
|
8185
|
+
const y = (cos0 * sin - sin0 * cos * Math.cos(delta)) / dot2;
|
|
8186
|
+
if (!(dot2 > 0) || Math.hypot(x, y) > maximum)
|
|
8187
|
+
throw new RangeError("Terrain coordinate exceeds geographic cutout chart");
|
|
8188
|
+
result[i] = frame.radius * x;
|
|
8189
|
+
result[i + 1] = frame.radius * y;
|
|
8190
|
+
result[i] || (result[i] = 0);
|
|
8191
|
+
result[_a = i + 1] || (result[_a] = 0);
|
|
8192
|
+
result[i + 2] = positions[i + 2];
|
|
8193
|
+
}
|
|
8194
|
+
if (!result.every(Number.isFinite))
|
|
8195
|
+
throw new RangeError("Geographic terrain projection overflow");
|
|
8196
|
+
return result;
|
|
8197
|
+
}
|
|
8198
|
+
function unprojectGeographicTerrainCutout(positions, frame) {
|
|
8199
|
+
validateFrame(frame);
|
|
8200
|
+
validatePositions(positions);
|
|
8201
|
+
const result = new Float64Array(positions.length);
|
|
8202
|
+
const [sin0, cos0] = latitude(frame.center[1]);
|
|
8203
|
+
const maximum = chartLimit(frame);
|
|
8204
|
+
for (let i = 0; i < positions.length; i += 3) {
|
|
8205
|
+
const x = positions[i] / frame.radius, y = positions[i + 1] / frame.radius;
|
|
8206
|
+
const distance = Math.hypot(x, y);
|
|
8207
|
+
if (!Number.isFinite(distance) || distance > maximum)
|
|
8208
|
+
throw new RangeError("Terrain coordinate exceeds geographic cutout chart");
|
|
8209
|
+
const horizontal = cos0 - y * sin0;
|
|
8210
|
+
const vertical = sin0 + y * cos0;
|
|
8211
|
+
const lat = Math.atan2(vertical, Math.hypot(horizontal, x)) / RAD;
|
|
8212
|
+
result[i] = Math.abs(lat) === 90 ? frame.center[0] : wrap(frame.center[0] + Math.atan2(x, horizontal) / RAD);
|
|
8213
|
+
result[i + 1] = lat;
|
|
8214
|
+
result[i + 2] = positions[i + 2];
|
|
8215
|
+
}
|
|
8216
|
+
return result;
|
|
8217
|
+
}
|
|
8218
|
+
function wrap(longitude) {
|
|
8219
|
+
const result = longitude % 360;
|
|
8220
|
+
return result >= 180 ? result - 360 : result < -180 ? result + 360 : result;
|
|
8221
|
+
}
|
|
8222
|
+
function latitude(degrees) {
|
|
8223
|
+
return [Math.sin(degrees * RAD), Math.abs(degrees) === 90 ? 0 : Math.cos(degrees * RAD)];
|
|
8224
|
+
}
|
|
8225
|
+
function validateFrame(frame) {
|
|
8226
|
+
if (frame.center.length !== 2 || !frame.center.every(Number.isFinite) || frame.center[0] < -180 || frame.center[0] >= 180 || Math.abs(frame.center[1]) > 90 || !Number.isFinite(frame.radius) || frame.radius <= 0 || !Number.isFinite(frame.maxAngularRadius) || frame.maxAngularRadius <= 0 || frame.maxAngularRadius > 80)
|
|
8227
|
+
throw new RangeError("Invalid geographic terrain cutout frame");
|
|
8228
|
+
}
|
|
8229
|
+
function validatePositions(positions) {
|
|
8230
|
+
if (!(positions instanceof Float32Array || positions instanceof Float64Array) || positions.length % 3 || !positions.every(Number.isFinite))
|
|
8231
|
+
throw new RangeError("Invalid geographic terrain cutout positions");
|
|
8232
|
+
}
|
|
8233
|
+
function chartLimit(frame) {
|
|
8234
|
+
const distance = Math.tan(frame.maxAngularRadius * RAD);
|
|
8235
|
+
return distance + 16 * Number.EPSILON * (1 + distance);
|
|
8236
|
+
}
|
|
8237
|
+
|
|
8238
|
+
// dist/terrain/cutout-polygons.js
|
|
8239
|
+
function prepareTerrainCutoutPolygons(polygons, { maxEdges = 2048, maxWork = 4e6 } = {}) {
|
|
8240
|
+
if (![maxEdges, maxWork].every((n) => Number.isSafeInteger(n) && n >= 0) || !polygons.length)
|
|
8241
|
+
throw new RangeError("Invalid terrain cutout polygon limits or empty set");
|
|
8242
|
+
let work = 0, edgeCount = 0;
|
|
8243
|
+
const charge = (amount) => {
|
|
8244
|
+
work += amount;
|
|
8245
|
+
if (work > maxWork)
|
|
8246
|
+
throw new RangeError("Terrain cutout polygon work budget exceeded");
|
|
6401
8247
|
};
|
|
8248
|
+
if (polygons.length > Math.floor(maxEdges / 3))
|
|
8249
|
+
throw new RangeError("Terrain cutout polygon edge budget exceeded");
|
|
8250
|
+
const regions = polygons.map((p) => {
|
|
8251
|
+
var _a;
|
|
8252
|
+
if (1 + (((_a = p.holes) == null ? void 0 : _a.length) ?? 0) > Math.floor((maxEdges - edgeCount) / 3))
|
|
8253
|
+
throw new RangeError("Terrain cutout polygon edge budget exceeded");
|
|
8254
|
+
return [p.outer, ...p.holes ?? []].map((ring) => {
|
|
8255
|
+
edgeCount += ring.length;
|
|
8256
|
+
if (edgeCount > maxEdges)
|
|
8257
|
+
throw new RangeError("Terrain cutout polygon edge budget exceeded");
|
|
8258
|
+
charge(ring.length);
|
|
8259
|
+
if (ring.length < 3 || ring.some((p2) => p2.length !== 2 || !p2.every(Number.isFinite)))
|
|
8260
|
+
throw new RangeError("Invalid terrain cutout polygon ring");
|
|
8261
|
+
return ring.map((p2) => Object.freeze([p2[0], p2[1]]));
|
|
8262
|
+
});
|
|
8263
|
+
});
|
|
8264
|
+
const rings = regions.flat();
|
|
8265
|
+
for (const ring of rings) {
|
|
8266
|
+
let area = 0;
|
|
8267
|
+
for (let i = 0; i < ring.length; i++) {
|
|
8268
|
+
charge(1);
|
|
8269
|
+
const a = ring[i], b = ring[(i + 1) % ring.length], c = ring[(i + 2) % ring.length];
|
|
8270
|
+
if (equal(a, b))
|
|
8271
|
+
throw new RangeError("Duplicate terrain cutout ring vertex");
|
|
8272
|
+
area += orient2(ring[0], a, b);
|
|
8273
|
+
if (orient2(a, b, c) === 0 && (a[0] - b[0]) * (c[0] - b[0]) + (a[1] - b[1]) * (c[1] - b[1]) >= 0)
|
|
8274
|
+
throw new RangeError("Backtracking terrain cutout ring edge");
|
|
8275
|
+
for (let j = i + 1; j < ring.length; j++) {
|
|
8276
|
+
if (j === i + 1 || i === 0 && j === ring.length - 1)
|
|
8277
|
+
continue;
|
|
8278
|
+
charge(1);
|
|
8279
|
+
if (intersects2(a, b, ring[j], ring[(j + 1) % ring.length]))
|
|
8280
|
+
throw new RangeError("Self-intersecting terrain cutout ring");
|
|
8281
|
+
}
|
|
8282
|
+
}
|
|
8283
|
+
if (!Number.isFinite(area) || area === 0)
|
|
8284
|
+
throw new RangeError("Degenerate terrain cutout ring");
|
|
8285
|
+
}
|
|
8286
|
+
for (let i = 0; i < rings.length; i++)
|
|
8287
|
+
for (let j = i + 1; j < rings.length; j++) {
|
|
8288
|
+
const a = rings[i], b = rings[j];
|
|
8289
|
+
for (let x = 0; x < a.length; x++)
|
|
8290
|
+
for (let y = 0; y < b.length; y++) {
|
|
8291
|
+
charge(1);
|
|
8292
|
+
if (intersects2(a[x], a[(x + 1) % a.length], b[y], b[(y + 1) % b.length]))
|
|
8293
|
+
throw new RangeError("Terrain cutout rings must not touch or intersect");
|
|
8294
|
+
}
|
|
8295
|
+
}
|
|
8296
|
+
for (const region of regions)
|
|
8297
|
+
for (let i = 1; i < region.length; i++) {
|
|
8298
|
+
if (contains(region[0], region[i][0], charge) !== 1)
|
|
8299
|
+
throw new RangeError("Terrain cutout hole must be strictly inside its outer ring");
|
|
8300
|
+
for (let j = 1; j < i; j++)
|
|
8301
|
+
if (contains(region[j], region[i][0], charge) === 1 || contains(region[i], region[j][0], charge) === 1)
|
|
8302
|
+
throw new RangeError("Nested terrain cutout holes are not supported");
|
|
8303
|
+
}
|
|
8304
|
+
function inRegion(region, point, budget) {
|
|
8305
|
+
const outer = contains(region[0], point, budget);
|
|
8306
|
+
if (outer !== 1)
|
|
8307
|
+
return outer;
|
|
8308
|
+
for (let i = 1; i < region.length; i++) {
|
|
8309
|
+
const hole = contains(region[i], point, budget);
|
|
8310
|
+
if (hole === 0)
|
|
8311
|
+
return 0;
|
|
8312
|
+
if (hole === 1)
|
|
8313
|
+
return -1;
|
|
8314
|
+
}
|
|
8315
|
+
return 1;
|
|
8316
|
+
}
|
|
8317
|
+
for (let i = 0; i < regions.length; i++)
|
|
8318
|
+
for (let j = i + 1; j < regions.length; j++) {
|
|
8319
|
+
if (inRegion(regions[i], regions[j][0][0], charge) === 1 || inRegion(regions[j], regions[i][0][0], charge) === 1)
|
|
8320
|
+
throw new RangeError("Overlapping terrain cutout polygon domains");
|
|
8321
|
+
}
|
|
8322
|
+
const lines = [];
|
|
8323
|
+
for (const ring of rings)
|
|
8324
|
+
for (let i = 0; i < ring.length; i++) {
|
|
8325
|
+
const a = ring[i], b = ring[(i + 1) % ring.length];
|
|
8326
|
+
if (lines.some(([u, v]) => {
|
|
8327
|
+
charge(1);
|
|
8328
|
+
return orient2(u, v, a) === 0 && orient2(u, v, b) === 0;
|
|
8329
|
+
}))
|
|
8330
|
+
continue;
|
|
8331
|
+
lines.push(a[0] < b[0] || a[0] === b[0] && a[1] < b[1] ? [a, b] : [b, a]);
|
|
8332
|
+
}
|
|
8333
|
+
return createTerrainCutoutPlan({
|
|
8334
|
+
lines: Object.freeze(lines.map((line) => Object.freeze(line))),
|
|
8335
|
+
classify(point, budget) {
|
|
8336
|
+
for (let i = 0; i < regions.length; i++) {
|
|
8337
|
+
const result = inRegion(regions[i], point, budget);
|
|
8338
|
+
if (result === 0)
|
|
8339
|
+
throw new RangeError("Unrepresentable terrain cutout fragment interior");
|
|
8340
|
+
if (result === 1)
|
|
8341
|
+
return i;
|
|
8342
|
+
}
|
|
8343
|
+
return -1;
|
|
8344
|
+
}
|
|
8345
|
+
});
|
|
8346
|
+
}
|
|
8347
|
+
function equal(a, b) {
|
|
8348
|
+
return a[0] === b[0] && a[1] === b[1];
|
|
8349
|
+
}
|
|
8350
|
+
function orient2(a, b, c) {
|
|
8351
|
+
const value = (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
|
|
8352
|
+
if (!Number.isFinite(value))
|
|
8353
|
+
throw new RangeError("Terrain cutout polygon coordinate overflow");
|
|
8354
|
+
return value;
|
|
8355
|
+
}
|
|
8356
|
+
function onSegment2(a, b, p) {
|
|
8357
|
+
return p[0] >= Math.min(a[0], b[0]) && p[0] <= Math.max(a[0], b[0]) && p[1] >= Math.min(a[1], b[1]) && p[1] <= Math.max(a[1], b[1]);
|
|
8358
|
+
}
|
|
8359
|
+
function intersects2(a, b, c, d) {
|
|
8360
|
+
const abC = orient2(a, b, c), abD = orient2(a, b, d), cdA = orient2(c, d, a), cdB = orient2(c, d, b);
|
|
8361
|
+
return abC === 0 && onSegment2(a, b, c) || abD === 0 && onSegment2(a, b, d) || cdA === 0 && onSegment2(c, d, a) || cdB === 0 && onSegment2(c, d, b) || (abC > 0 && abD < 0 || abC < 0 && abD > 0) && (cdA > 0 && cdB < 0 || cdA < 0 && cdB > 0);
|
|
8362
|
+
}
|
|
8363
|
+
function contains(ring, p, charge) {
|
|
8364
|
+
let winding = 0;
|
|
8365
|
+
for (let i = 0; i < ring.length; i++) {
|
|
8366
|
+
charge(1);
|
|
8367
|
+
const a = ring[i], b = ring[(i + 1) % ring.length], cross4 = orient2(a, b, p);
|
|
8368
|
+
if (cross4 === 0 && onSegment2(a, b, p))
|
|
8369
|
+
return 0;
|
|
8370
|
+
if (a[1] <= p[1] && b[1] > p[1] && cross4 > 0)
|
|
8371
|
+
winding++;
|
|
8372
|
+
if (a[1] > p[1] && b[1] <= p[1] && cross4 < 0)
|
|
8373
|
+
winding--;
|
|
8374
|
+
}
|
|
8375
|
+
return winding === 0 ? -1 : 1;
|
|
6402
8376
|
}
|
|
6403
8377
|
//# sourceMappingURL=index.cjs.map
|