@math.gl/geometry 5.0.0-alpha.9 → 5.0.0-beta.10
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/LICENSE +97 -49
- package/README.md +77 -1
- package/THIRD-PARTY-NOTICES.md +18 -0
- package/dist/color/color-lut-types.d.ts +16 -0
- package/dist/color/color-lut-types.d.ts.map +1 -0
- package/dist/color/color-lut-types.js +5 -0
- package/dist/color/color-lut-types.js.map +1 -0
- package/dist/color/index.cjs +132 -0
- package/dist/color/index.cjs.map +6 -0
- package/dist/color/index.d.ts +4 -0
- package/dist/color/index.d.ts.map +1 -0
- package/dist/color/index.js +5 -0
- package/dist/color/index.js.map +1 -0
- package/dist/color/sample-lut.d.ts +13 -0
- package/dist/color/sample-lut.d.ts.map +1 -0
- package/dist/color/sample-lut.js +132 -0
- package/dist/color/sample-lut.js.map +1 -0
- package/dist/culling/bounds.d.ts +20 -0
- package/dist/culling/bounds.d.ts.map +1 -0
- package/dist/culling/bounds.js +121 -0
- package/dist/culling/bounds.js.map +1 -0
- package/dist/culling/constants.d.ts +3 -0
- package/dist/culling/constants.d.ts.map +1 -0
- package/dist/culling/constants.js +5 -0
- package/dist/culling/constants.js.map +1 -0
- package/dist/culling/frustum-planes.d.ts +5 -0
- package/dist/culling/frustum-planes.d.ts.map +1 -0
- package/dist/culling/frustum-planes.js +37 -0
- package/dist/culling/frustum-planes.js.map +1 -0
- package/dist/culling/geometric-queries.d.ts +34 -0
- package/dist/culling/geometric-queries.d.ts.map +1 -0
- package/dist/culling/geometric-queries.js +208 -0
- package/dist/culling/geometric-queries.js.map +1 -0
- package/dist/culling/index.cjs +2560 -0
- package/dist/culling/index.cjs.map +6 -0
- package/dist/culling/index.d.ts +37 -0
- package/dist/culling/index.d.ts.map +1 -0
- package/dist/culling/index.js +29 -0
- package/dist/culling/index.js.map +1 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts +15 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.js +137 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.js.map +1 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts +14 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.js +146 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.js.map +1 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts +37 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.js +137 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.js.map +1 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts +7 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js +26 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +56 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +133 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts +40 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.js +123 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts +30 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.js +7 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts +62 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js +230 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js.map +1 -0
- package/dist/culling/lib/culling-volume.d.ts +49 -0
- package/dist/culling/lib/culling-volume.d.ts.map +1 -0
- package/dist/culling/lib/culling-volume.js +133 -0
- package/dist/culling/lib/culling-volume.js.map +1 -0
- package/dist/culling/lib/perspective-frustum.d.ts +153 -0
- package/dist/culling/lib/perspective-frustum.d.ts.map +1 -0
- package/dist/culling/lib/perspective-frustum.js +191 -0
- package/dist/culling/lib/perspective-frustum.js.map +1 -0
- package/dist/culling/lib/perspective-off-center-frustum.d.ts +158 -0
- package/dist/culling/lib/perspective-off-center-frustum.d.ts.map +1 -0
- package/dist/culling/lib/perspective-off-center-frustum.js +276 -0
- package/dist/culling/lib/perspective-off-center-frustum.js.map +1 -0
- package/dist/culling/lib/plane.d.ts +35 -0
- package/dist/culling/lib/plane.d.ts.map +1 -0
- package/dist/culling/lib/plane.js +90 -0
- package/dist/culling/lib/plane.js.map +1 -0
- package/dist/culling/lib/ray.d.ts +18 -0
- package/dist/culling/lib/ray.d.ts.map +1 -0
- package/dist/culling/lib/ray.js +51 -0
- package/dist/culling/lib/ray.js.map +1 -0
- package/dist/culling/lib/shapes/box-shape.d.ts +19 -0
- package/dist/culling/lib/shapes/box-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/box-shape.js +69 -0
- package/dist/culling/lib/shapes/box-shape.js.map +1 -0
- package/dist/culling/lib/shapes/capsule-shape.d.ts +23 -0
- package/dist/culling/lib/shapes/capsule-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/capsule-shape.js +151 -0
- package/dist/culling/lib/shapes/capsule-shape.js.map +1 -0
- package/dist/culling/lib/shapes/cylinder-shape.d.ts +22 -0
- package/dist/culling/lib/shapes/cylinder-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/cylinder-shape.js +99 -0
- package/dist/culling/lib/shapes/cylinder-shape.js.map +1 -0
- package/dist/culling/lib/shapes/implicit-shape.d.ts +56 -0
- package/dist/culling/lib/shapes/implicit-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/implicit-shape.js +142 -0
- package/dist/culling/lib/shapes/implicit-shape.js.map +1 -0
- package/dist/culling/lib/shapes/plane-shape.d.ts +27 -0
- package/dist/culling/lib/shapes/plane-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/plane-shape.js +71 -0
- package/dist/culling/lib/shapes/plane-shape.js.map +1 -0
- package/dist/culling/lib/shapes/sphere-shape.d.ts +18 -0
- package/dist/culling/lib/shapes/sphere-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/sphere-shape.js +43 -0
- package/dist/culling/lib/shapes/sphere-shape.js.map +1 -0
- package/dist/culling/oriented-box-2d.d.ts +22 -0
- package/dist/culling/oriented-box-2d.d.ts.map +1 -0
- package/dist/culling/oriented-box-2d.js +86 -0
- package/dist/culling/oriented-box-2d.js.map +1 -0
- package/dist/culling/queries.d.ts +44 -0
- package/dist/culling/queries.d.ts.map +1 -0
- package/dist/culling/queries.js +259 -0
- package/dist/culling/queries.js.map +1 -0
- package/dist/culling/screen-ray.d.ts +22 -0
- package/dist/culling/screen-ray.d.ts.map +1 -0
- package/dist/culling/screen-ray.js +55 -0
- package/dist/culling/screen-ray.js.map +1 -0
- package/dist/curves/adaptive-sampling.d.ts +16 -0
- package/dist/curves/adaptive-sampling.d.ts.map +1 -0
- package/dist/curves/adaptive-sampling.js +59 -0
- package/dist/curves/adaptive-sampling.js.map +1 -0
- package/dist/curves/bezier-curves.d.ts +18 -0
- package/dist/curves/bezier-curves.d.ts.map +1 -0
- package/dist/curves/bezier-curves.js +54 -0
- package/dist/curves/bezier-curves.js.map +1 -0
- package/dist/curves/catmull-rom-curve.d.ts +15 -0
- package/dist/curves/catmull-rom-curve.d.ts.map +1 -0
- package/dist/curves/catmull-rom-curve.js +77 -0
- package/dist/curves/catmull-rom-curve.js.map +1 -0
- package/dist/curves/curve-arc-length.d.ts +17 -0
- package/dist/curves/curve-arc-length.d.ts.map +1 -0
- package/dist/curves/curve-arc-length.js +58 -0
- package/dist/curves/curve-arc-length.js.map +1 -0
- package/dist/curves/curve.d.ts +23 -0
- package/dist/curves/curve.d.ts.map +1 -0
- package/dist/curves/curve.js +77 -0
- package/dist/curves/curve.js.map +1 -0
- package/dist/curves/hermite-curve.d.ts +9 -0
- package/dist/curves/hermite-curve.d.ts.map +1 -0
- package/dist/curves/hermite-curve.js +24 -0
- package/dist/curves/hermite-curve.js.map +1 -0
- package/dist/curves/index.d.ts +12 -0
- package/dist/curves/index.d.ts.map +1 -0
- package/dist/curves/index.js +11 -0
- package/dist/curves/index.js.map +1 -0
- package/dist/curves/parallel-transport.d.ts +12 -0
- package/dist/curves/parallel-transport.d.ts.map +1 -0
- package/dist/curves/parallel-transport.js +83 -0
- package/dist/curves/parallel-transport.js.map +1 -0
- package/dist/geometries/box-geometry.js +1 -1
- package/dist/geometries/box-geometry.js.map +1 -1
- package/dist/geometries/capsule-geometry.js +1 -1
- package/dist/geometries/capsule-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.js +1 -1
- package/dist/geometries/cylinder-geometry.js.map +1 -1
- package/dist/geometries/geometry-helpers.js +1 -1
- package/dist/geometries/geometry-helpers.js.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +1 -1
- package/dist/geometries/ico-sphere-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.js +1 -1
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometries/primitive-mesh-builder.d.ts +24 -0
- package/dist/geometries/primitive-mesh-builder.d.ts.map +1 -0
- package/dist/geometries/primitive-mesh-builder.js +74 -0
- package/dist/geometries/primitive-mesh-builder.js.map +1 -0
- package/dist/geometries/prism-geometry.d.ts +13 -0
- package/dist/geometries/prism-geometry.d.ts.map +1 -0
- package/dist/geometries/prism-geometry.js +34 -0
- package/dist/geometries/prism-geometry.js.map +1 -0
- package/dist/geometries/ring-geometry.d.ts +15 -0
- package/dist/geometries/ring-geometry.d.ts.map +1 -0
- package/dist/geometries/ring-geometry.js +64 -0
- package/dist/geometries/ring-geometry.js.map +1 -0
- package/dist/geometries/sphere-geometry.js +1 -1
- package/dist/geometries/sphere-geometry.js.map +1 -1
- package/dist/geometries/surface-of-revolution.js +1 -1
- package/dist/geometries/surface-of-revolution.js.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +1 -1
- package/dist/geometries/truncated-cone-geometry.js.map +1 -1
- package/dist/index.cjs +6993 -37
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/geometry-utils.js +1 -1
- package/dist/lib/geometry-utils.js.map +1 -1
- package/dist/lib/geometry.d.ts +1 -1
- package/dist/lib/geometry.d.ts.map +1 -1
- package/dist/lib/geometry.js +1 -1
- package/dist/lib/geometry.js.map +1 -1
- package/dist/lib/hinge-tree.d.ts +33 -0
- package/dist/lib/hinge-tree.d.ts.map +1 -0
- package/dist/lib/hinge-tree.js +144 -0
- package/dist/lib/hinge-tree.js.map +1 -0
- package/dist/lighting/index.cjs +175 -0
- package/dist/lighting/index.cjs.map +6 -0
- package/dist/lighting/index.d.ts +4 -0
- package/dist/lighting/index.d.ts.map +1 -0
- package/dist/lighting/index.js +5 -0
- package/dist/lighting/index.js.map +1 -0
- package/dist/lighting/lighting-types.d.ts +16 -0
- package/dist/lighting/lighting-types.d.ts.map +1 -0
- package/dist/lighting/lighting-types.js +5 -0
- package/dist/lighting/lighting-types.js.map +1 -0
- package/dist/lighting/photometry.d.ts +36 -0
- package/dist/lighting/photometry.d.ts.map +1 -0
- package/dist/lighting/photometry.js +181 -0
- package/dist/lighting/photometry.js.map +1 -0
- package/dist/parametric/lathe-geometry.d.ts +14 -0
- package/dist/parametric/lathe-geometry.d.ts.map +1 -0
- package/dist/parametric/lathe-geometry.js +48 -0
- package/dist/parametric/lathe-geometry.js.map +1 -0
- package/dist/parametric/parametric-geometry.d.ts +20 -0
- package/dist/parametric/parametric-geometry.d.ts.map +1 -0
- package/dist/parametric/parametric-geometry.js +88 -0
- package/dist/parametric/parametric-geometry.js.map +1 -0
- package/dist/parametric/torus-geometry.d.ts +19 -0
- package/dist/parametric/torus-geometry.d.ts.map +1 -0
- package/dist/parametric/torus-geometry.js +89 -0
- package/dist/parametric/torus-geometry.js.map +1 -0
- package/dist/parametric.d.ts +7 -0
- package/dist/parametric.d.ts.map +1 -0
- package/dist/parametric.js +7 -0
- package/dist/parametric.js.map +1 -0
- package/dist/polygon/clip-triangle-mesh.d.ts +41 -0
- package/dist/polygon/clip-triangle-mesh.d.ts.map +1 -0
- package/dist/polygon/clip-triangle-mesh.js +155 -0
- package/dist/polygon/clip-triangle-mesh.js.map +1 -0
- package/dist/polygon/cut-by-grid.d.ts +24 -0
- package/dist/polygon/cut-by-grid.d.ts.map +1 -0
- package/dist/polygon/cut-by-grid.js +221 -0
- package/dist/polygon/cut-by-grid.js.map +1 -0
- package/dist/polygon/cut-by-mercator-bounds.d.ts +17 -0
- package/dist/polygon/cut-by-mercator-bounds.d.ts.map +1 -0
- package/dist/polygon/cut-by-mercator-bounds.js +149 -0
- package/dist/polygon/cut-by-mercator-bounds.js.map +1 -0
- package/dist/polygon/earcut.d.ts +13 -0
- package/dist/polygon/earcut.d.ts.map +1 -0
- package/dist/polygon/earcut.js +693 -0
- package/dist/polygon/earcut.js.map +1 -0
- package/dist/polygon/index.d.ts +16 -0
- package/dist/polygon/index.d.ts.map +1 -0
- package/dist/polygon/index.js +14 -0
- package/dist/polygon/index.js.map +1 -0
- package/dist/polygon/lineclip.d.ts +31 -0
- package/dist/polygon/lineclip.d.ts.map +1 -0
- package/dist/polygon/lineclip.js +184 -0
- package/dist/polygon/lineclip.js.map +1 -0
- package/dist/polygon/pole-of-inaccessibility.d.ts +21 -0
- package/dist/polygon/pole-of-inaccessibility.d.ts.map +1 -0
- package/dist/polygon/pole-of-inaccessibility.js +285 -0
- package/dist/polygon/pole-of-inaccessibility.js.map +1 -0
- package/dist/polygon/polygon-utils.d.ts +103 -0
- package/dist/polygon/polygon-utils.d.ts.map +1 -0
- package/dist/polygon/polygon-utils.js +155 -0
- package/dist/polygon/polygon-utils.js.map +1 -0
- package/dist/polygon/polygon.d.ts +41 -0
- package/dist/polygon/polygon.d.ts.map +1 -0
- package/dist/polygon/polygon.js +76 -0
- package/dist/polygon/polygon.js.map +1 -0
- package/dist/polygon/subdivide-polyline.d.ts +56 -0
- package/dist/polygon/subdivide-polyline.d.ts.map +1 -0
- package/dist/polygon/subdivide-polyline.js +141 -0
- package/dist/polygon/subdivide-polyline.js.map +1 -0
- package/dist/polygon/subdivide-triangle-mesh.d.ts +78 -0
- package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -0
- package/dist/polygon/subdivide-triangle-mesh.js +238 -0
- package/dist/polygon/subdivide-triangle-mesh.js.map +1 -0
- package/dist/polygon/utils.d.ts +5 -0
- package/dist/polygon/utils.d.ts.map +1 -0
- package/dist/polygon/utils.js +38 -0
- package/dist/polygon/utils.js.map +1 -0
- package/dist/spatial-index/box-index.d.ts +86 -0
- package/dist/spatial-index/box-index.d.ts.map +1 -0
- package/dist/spatial-index/box-index.js +335 -0
- package/dist/spatial-index/box-index.js.map +1 -0
- package/dist/spatial-index/index.d.ts +7 -0
- package/dist/spatial-index/index.d.ts.map +1 -0
- package/dist/spatial-index/index.js +6 -0
- package/dist/spatial-index/index.js.map +1 -0
- package/dist/spatial-index/triangle-bvh.d.ts +74 -0
- package/dist/spatial-index/triangle-bvh.d.ts.map +1 -0
- package/dist/spatial-index/triangle-bvh.js +221 -0
- package/dist/spatial-index/triangle-bvh.js.map +1 -0
- package/dist/utils/attribute-compression.d.ts +50 -0
- package/dist/utils/attribute-compression.d.ts.map +1 -0
- package/dist/utils/attribute-compression.js +186 -0
- package/dist/utils/attribute-compression.js.map +1 -0
- package/dist/utils/attribute-iterator.d.ts +8 -0
- package/dist/utils/attribute-iterator.d.ts.map +1 -0
- package/dist/utils/attribute-iterator.js +25 -0
- package/dist/utils/attribute-iterator.js.map +1 -0
- package/dist/utils/compose-attribute-provenance.d.ts +13 -0
- package/dist/utils/compose-attribute-provenance.d.ts.map +1 -0
- package/dist/utils/compose-attribute-provenance.js +63 -0
- package/dist/utils/compose-attribute-provenance.js.map +1 -0
- package/dist/utils/compute-vertex-normals.d.ts +4 -0
- package/dist/utils/compute-vertex-normals.d.ts.map +1 -0
- package/dist/utils/compute-vertex-normals.js +54 -0
- package/dist/utils/compute-vertex-normals.js.map +1 -0
- package/dist/utils/constants.d.ts +52 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +39 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/coordinates.d.ts +3 -0
- package/dist/utils/coordinates.d.ts.map +1 -0
- package/dist/utils/coordinates.js +8 -0
- package/dist/utils/coordinates.js.map +1 -0
- package/dist/utils/geometry.d.ts +20 -0
- package/dist/utils/geometry.d.ts.map +1 -0
- package/dist/utils/geometry.js +31 -0
- package/dist/utils/geometry.js.map +1 -0
- package/dist/utils/gl-type.d.ts +17 -0
- package/dist/utils/gl-type.d.ts.map +1 -0
- package/dist/utils/gl-type.js +69 -0
- package/dist/utils/gl-type.js.map +1 -0
- package/dist/utils/index.d.ts +18 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +16 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/interpolate-packed-attributes.d.ts +43 -0
- package/dist/utils/interpolate-packed-attributes.d.ts.map +1 -0
- package/dist/utils/interpolate-packed-attributes.js +192 -0
- package/dist/utils/interpolate-packed-attributes.js.map +1 -0
- package/dist/utils/mesh-processing.d.ts +18 -0
- package/dist/utils/mesh-processing.d.ts.map +1 -0
- package/dist/utils/mesh-processing.js +300 -0
- package/dist/utils/mesh-processing.js.map +1 -0
- package/dist/utils/primitive-iterator.d.ts +21 -0
- package/dist/utils/primitive-iterator.d.ts.map +1 -0
- package/dist/utils/primitive-iterator.js +117 -0
- package/dist/utils/primitive-iterator.js.map +1 -0
- package/dist/utils/project-bounds.d.ts +44 -0
- package/dist/utils/project-bounds.d.ts.map +1 -0
- package/dist/utils/project-bounds.js +93 -0
- package/dist/utils/project-bounds.js.map +1 -0
- package/dist/utils/project-texture-coordinates.d.ts +19 -0
- package/dist/utils/project-texture-coordinates.d.ts.map +1 -0
- package/dist/utils/project-texture-coordinates.js +49 -0
- package/dist/utils/project-texture-coordinates.js.map +1 -0
- package/dist/utils/qualify-surface-transition.d.ts +21 -0
- package/dist/utils/qualify-surface-transition.d.ts.map +1 -0
- package/dist/utils/qualify-surface-transition.js +140 -0
- package/dist/utils/qualify-surface-transition.js.map +1 -0
- package/dist/utils/rgb565.d.ts +5 -0
- package/dist/utils/rgb565.d.ts.map +1 -0
- package/dist/utils/rgb565.js +24 -0
- package/dist/utils/rgb565.js.map +1 -0
- package/dist/utils/typed-array-utils.d.ts +3 -0
- package/dist/utils/typed-array-utils.d.ts.map +1 -0
- package/dist/utils/typed-array-utils.js +16 -0
- package/dist/utils/typed-array-utils.js.map +1 -0
- package/package.json +24 -4
- package/src/color/color-lut-types.ts +19 -0
- package/src/color/index.ts +6 -0
- package/src/color/sample-lut.ts +175 -0
- package/src/culling/bounds.ts +152 -0
- package/src/culling/constants.ts +6 -0
- package/src/culling/frustum-planes.ts +41 -0
- package/src/culling/geometric-queries.ts +299 -0
- package/src/culling/index.ts +93 -0
- package/src/culling/lib/algorithms/bounding-box-from-points.ts +174 -0
- package/src/culling/lib/algorithms/bounding-sphere-from-points.ts +175 -0
- package/src/culling/lib/algorithms/compute-eigen-decomposition.ts +171 -0
- package/src/culling/lib/algorithms/oriented-bounding-box-quaternion.ts +32 -0
- package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +171 -0
- package/src/culling/lib/bounding-volumes/bounding-sphere.ts +154 -0
- package/src/culling/lib/bounding-volumes/bounding-volume.ts +38 -0
- package/src/culling/lib/bounding-volumes/oriented-bounding-box.ts +320 -0
- package/src/culling/lib/culling-volume.ts +171 -0
- package/src/culling/lib/perspective-frustum.ts +288 -0
- package/src/culling/lib/perspective-off-center-frustum.ts +381 -0
- package/src/culling/lib/plane.ts +118 -0
- package/src/culling/lib/ray.ts +54 -0
- package/src/culling/lib/shapes/box-shape.ts +78 -0
- package/src/culling/lib/shapes/capsule-shape.ts +232 -0
- package/src/culling/lib/shapes/cylinder-shape.ts +133 -0
- package/src/culling/lib/shapes/implicit-shape.ts +209 -0
- package/src/culling/lib/shapes/plane-shape.ts +78 -0
- package/src/culling/lib/shapes/sphere-shape.ts +60 -0
- package/src/culling/oriented-box-2d.ts +165 -0
- package/src/culling/queries.ts +332 -0
- package/src/culling/screen-ray.ts +75 -0
- package/src/curves/adaptive-sampling.ts +85 -0
- package/src/curves/bezier-curves.ts +62 -0
- package/src/curves/catmull-rom-curve.ts +89 -0
- package/src/curves/curve-arc-length.ts +70 -0
- package/src/curves/curve.ts +96 -0
- package/src/curves/hermite-curve.ts +34 -0
- package/src/curves/index.ts +19 -0
- package/src/curves/parallel-transport.ts +104 -0
- package/src/geometries/box-geometry.ts +1 -1
- package/src/geometries/capsule-geometry.ts +1 -1
- package/src/geometries/cylinder-geometry.ts +1 -1
- package/src/geometries/geometry-helpers.ts +1 -1
- package/src/geometries/ico-sphere-geometry.ts +1 -1
- package/src/geometries/plane-geometry.ts +1 -1
- package/src/geometries/primitive-mesh-builder.ts +84 -0
- package/src/geometries/prism-geometry.ts +57 -0
- package/src/geometries/ring-geometry.ts +102 -0
- package/src/geometries/sphere-geometry.ts +1 -1
- package/src/geometries/surface-of-revolution.ts +1 -1
- package/src/geometries/truncated-cone-geometry.ts +1 -1
- package/src/index.ts +226 -1
- package/src/lib/geometry-utils.ts +2 -2
- package/src/lib/geometry.ts +2 -2
- package/src/lib/hinge-tree.ts +170 -0
- package/src/lighting/index.ts +10 -0
- package/src/lighting/lighting-types.ts +20 -0
- package/src/lighting/photometry.ts +264 -0
- package/src/parametric/lathe-geometry.ts +70 -0
- package/src/parametric/parametric-geometry.ts +118 -0
- package/src/parametric/torus-geometry.ts +118 -0
- package/src/parametric.ts +9 -0
- package/src/polygon/clip-triangle-mesh.ts +218 -0
- package/src/polygon/cut-by-grid.ts +313 -0
- package/src/polygon/cut-by-mercator-bounds.ts +204 -0
- package/src/polygon/earcut.ts +859 -0
- package/src/polygon/index.ts +48 -0
- package/src/polygon/lineclip.ts +218 -0
- package/src/polygon/pole-of-inaccessibility.ts +330 -0
- package/src/polygon/polygon-utils.ts +273 -0
- package/src/polygon/polygon.ts +105 -0
- package/src/polygon/subdivide-polyline.ts +223 -0
- package/src/polygon/subdivide-triangle-mesh.ts +342 -0
- package/src/polygon/utils.ts +50 -0
- package/src/spatial-index/box-index.ts +452 -0
- package/src/spatial-index/index.ts +20 -0
- package/src/spatial-index/triangle-bvh.ts +345 -0
- package/src/utils/attribute-compression.ts +234 -0
- package/src/utils/attribute-iterator.ts +28 -0
- package/src/utils/compose-attribute-provenance.ts +74 -0
- package/src/utils/compute-vertex-normals.ts +63 -0
- package/src/utils/constants.ts +42 -0
- package/src/utils/coordinates.ts +8 -0
- package/src/utils/geometry.ts +49 -0
- package/src/utils/gl-type.ts +87 -0
- package/src/utils/index.ts +55 -0
- package/src/utils/interpolate-packed-attributes.ts +284 -0
- package/src/utils/mesh-processing.ts +377 -0
- package/src/utils/primitive-iterator.ts +145 -0
- package/src/utils/project-bounds.ts +154 -0
- package/src/utils/project-texture-coordinates.ts +67 -0
- package/src/utils/qualify-surface-transition.ts +169 -0
- package/src/utils/rgb565.ts +26 -0
- package/src/utils/typed-array-utils.ts +16 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/** Creates a snapshot sampler with per-channel 1D linear or red-fastest 3D trilinear interpolation. */
|
|
2
|
+
export function createColorLUTSampler(lut) {
|
|
3
|
+
const writeSample = createColorLUTWriter(lut);
|
|
4
|
+
return (red, green, blue) => {
|
|
5
|
+
const result = [0, 0, 0];
|
|
6
|
+
writeSample(red, green, blue, result, 0);
|
|
7
|
+
return result;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/** Creates a validated snapshot writer with reusable per-sampler scratch storage. */
|
|
11
|
+
function createColorLUTWriter(lut) {
|
|
12
|
+
const { dimension, size } = lut;
|
|
13
|
+
if (![1, 3].includes(dimension) ||
|
|
14
|
+
!Number.isSafeInteger(size) ||
|
|
15
|
+
size < 2 ||
|
|
16
|
+
!Number.isSafeInteger(size ** dimension * 3) ||
|
|
17
|
+
lut.data.length !== size ** dimension * 3 ||
|
|
18
|
+
lut.domainMinimum.length !== 3 ||
|
|
19
|
+
lut.domainMaximum.length !== 3) {
|
|
20
|
+
throw new Error('LUT: invalid calculation table');
|
|
21
|
+
}
|
|
22
|
+
const minimum = Array.from(lut.domainMinimum);
|
|
23
|
+
const maximum = Array.from(lut.domainMaximum);
|
|
24
|
+
for (let channel = 0; channel < 3; channel++) {
|
|
25
|
+
if (!Number.isFinite(minimum[channel]) ||
|
|
26
|
+
!Number.isFinite(maximum[channel]) ||
|
|
27
|
+
!Number.isFinite(maximum[channel] - minimum[channel]) ||
|
|
28
|
+
maximum[channel] <= minimum[channel])
|
|
29
|
+
throw new Error('LUT: invalid calculation domain');
|
|
30
|
+
}
|
|
31
|
+
if (!lut.data.every(Number.isFinite))
|
|
32
|
+
throw new Error('LUT: invalid calculation samples');
|
|
33
|
+
const data = lut.data.slice();
|
|
34
|
+
const grid = lut.inputGrid?.slice();
|
|
35
|
+
if (grid &&
|
|
36
|
+
(grid.length !== size ||
|
|
37
|
+
grid[0] !== 0 ||
|
|
38
|
+
grid[size - 1] !== 1 ||
|
|
39
|
+
grid.some((value, index) => !Number.isFinite(value) || (index > 0 && value <= grid[index - 1])))) {
|
|
40
|
+
throw new Error('LUT: invalid nonuniform input grid');
|
|
41
|
+
}
|
|
42
|
+
const coordinates = [0, 0, 0];
|
|
43
|
+
const indices = [0, 0, 0];
|
|
44
|
+
const weights = [0, 0, 0];
|
|
45
|
+
const accumulated = [0, 0, 0];
|
|
46
|
+
return (red, green, blue, result, resultOffset) => {
|
|
47
|
+
coordinates[0] = red;
|
|
48
|
+
coordinates[1] = green;
|
|
49
|
+
coordinates[2] = blue;
|
|
50
|
+
for (let channel = 0; channel < 3; channel++) {
|
|
51
|
+
const value = coordinates[channel];
|
|
52
|
+
if (!Number.isFinite(value))
|
|
53
|
+
throw new Error('LUT: input colors must be finite');
|
|
54
|
+
const normalized = value <= minimum[channel]
|
|
55
|
+
? 0
|
|
56
|
+
: value >= maximum[channel]
|
|
57
|
+
? 1
|
|
58
|
+
: (value - minimum[channel]) / (maximum[channel] - minimum[channel]);
|
|
59
|
+
writeLUTInterval(normalized, size, grid, indices, weights, channel);
|
|
60
|
+
}
|
|
61
|
+
accumulated[0] = 0;
|
|
62
|
+
accumulated[1] = 0;
|
|
63
|
+
accumulated[2] = 0;
|
|
64
|
+
if (dimension === 1) {
|
|
65
|
+
for (let channel = 0; channel < 3; channel++) {
|
|
66
|
+
const offset = indices[channel] * 3 + channel;
|
|
67
|
+
accumulated[channel] =
|
|
68
|
+
data[offset] * (1 - weights[channel]) + data[offset + 3] * weights[channel];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
for (let blueCorner = 0; blueCorner < 2; blueCorner++) {
|
|
73
|
+
for (let greenCorner = 0; greenCorner < 2; greenCorner++) {
|
|
74
|
+
for (let redCorner = 0; redCorner < 2; redCorner++) {
|
|
75
|
+
const weight = (redCorner ? weights[0] : 1 - weights[0]) *
|
|
76
|
+
(greenCorner ? weights[1] : 1 - weights[1]) *
|
|
77
|
+
(blueCorner ? weights[2] : 1 - weights[2]);
|
|
78
|
+
const offset = (((indices[2] + blueCorner) * size + indices[1] + greenCorner) * size +
|
|
79
|
+
indices[0] +
|
|
80
|
+
redCorner) *
|
|
81
|
+
3;
|
|
82
|
+
for (let channel = 0; channel < 3; channel++)
|
|
83
|
+
accumulated[channel] += data[offset + channel] * weight;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (let channel = 0; channel < 3; channel++)
|
|
89
|
+
result[resultOffset + channel] = accumulated[channel];
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** Applies a LUT to floating-point pixels without changing the source or applying transfer functions. */
|
|
93
|
+
export function applyColorLUT(lut, colors, options = {}) {
|
|
94
|
+
const { components = 3 } = options;
|
|
95
|
+
if (![3, 4].includes(components) || colors.length % components !== 0)
|
|
96
|
+
throw new Error('LUT: invalid pixel component count');
|
|
97
|
+
const writeSample = createColorLUTWriter(lut);
|
|
98
|
+
const result = new Float32Array(colors.length);
|
|
99
|
+
for (let offset = 0; offset < colors.length; offset += components) {
|
|
100
|
+
writeSample(colors[offset], colors[offset + 1], colors[offset + 2], result, offset);
|
|
101
|
+
if (components === 4) {
|
|
102
|
+
const alpha = colors[offset + 3];
|
|
103
|
+
result[offset + 3] = alpha;
|
|
104
|
+
if (!Number.isFinite(alpha) || !Number.isFinite(result[offset + 3]))
|
|
105
|
+
throw new Error('LUT: alpha cannot be represented as float32');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
/** Finds normalized uniform/nonuniform knots, retaining the final endpoint in the last interval. */
|
|
111
|
+
function writeLUTInterval(value, size, grid, indices, weights, channel) {
|
|
112
|
+
if (!grid) {
|
|
113
|
+
const coordinate = value * (size - 1);
|
|
114
|
+
const lower = Math.min(Math.floor(coordinate), size - 2);
|
|
115
|
+
indices[channel] = lower;
|
|
116
|
+
weights[channel] = coordinate - lower;
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
let lower = 0;
|
|
120
|
+
let upper = size - 1;
|
|
121
|
+
while (upper - lower > 1) {
|
|
122
|
+
const midpoint = Math.floor((lower + upper) / 2);
|
|
123
|
+
if (value < grid[midpoint])
|
|
124
|
+
upper = midpoint;
|
|
125
|
+
else
|
|
126
|
+
lower = midpoint;
|
|
127
|
+
}
|
|
128
|
+
lower = Math.min(lower, size - 2);
|
|
129
|
+
indices[channel] = lower;
|
|
130
|
+
weights[channel] = (value - grid[lower]) / (grid[lower + 1] - grid[lower]);
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=sample-lut.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-lut.js","sourceRoot":"","sources":["../../src/color/sample-lut.ts"],"names":[],"mappings":"AAkBA,uGAAuG;AACvG,MAAM,UAAU,qBAAqB,CAAC,GAAa;IACjD,MAAM,WAAW,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QAC1B,MAAM,MAAM,GAA6B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACnD,WAAW,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QACzC,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED,qFAAqF;AACrF,SAAS,oBAAoB,CAAC,GAAa;IACzC,MAAM,EAAC,SAAS,EAAE,IAAI,EAAC,GAAG,GAAG,CAAC;IAC9B,IACE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;QAC3B,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC;QAC3B,IAAI,GAAG,CAAC;QACR,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,IAAI,SAAS,GAAG,CAAC,CAAC;QAC5C,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,SAAS,GAAG,CAAC;QACzC,GAAG,CAAC,aAAa,CAAC,MAAM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CAAC;IACd,IAAI,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC;IACrB,OAAO,KAAK,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QACjD,IAAI,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC;YAAE,KAAK,GAAG,QAAQ,CAAC;;YACxC,KAAK,GAAG,QAAQ,CAAC;IACxB,CAAC;IACD,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC;IAClC,OAAO,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;IACzB,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Bounds, Bounds2D, Bounds3D, NumericArray } from '@math.gl/core';
|
|
2
|
+
type ReadonlyBounds = readonly [ArrayLike<number>, ArrayLike<number>];
|
|
3
|
+
export declare function createEmptyBounds(dimension: 2): Bounds2D;
|
|
4
|
+
export declare function createEmptyBounds(dimension: 3): Bounds3D;
|
|
5
|
+
export declare function createEmptyBounds(dimension: 2 | 3): Bounds;
|
|
6
|
+
/** Any inverted axis denotes empty bounds. Equal endpoints describe a nonempty point. */
|
|
7
|
+
export declare function isEmptyBounds(bounds: ReadonlyBounds): boolean;
|
|
8
|
+
export declare function boundsContainsPoint(bounds: ReadonlyBounds, p: ArrayLike<number>): boolean;
|
|
9
|
+
export declare function boundsContainsBounds(a: ReadonlyBounds, b: ReadonlyBounds): boolean;
|
|
10
|
+
export declare function boundsIntersect(a: ReadonlyBounds, b: ReadonlyBounds): boolean;
|
|
11
|
+
export declare function unionBounds(a: ReadonlyBounds, b: ReadonlyBounds, out?: Bounds): Bounds;
|
|
12
|
+
export declare function intersectBounds(a: ReadonlyBounds, b: ReadonlyBounds, out?: Bounds): Bounds;
|
|
13
|
+
export declare function expandBoundsByPoint(bounds: ReadonlyBounds, p: ArrayLike<number>, out?: Bounds): Bounds;
|
|
14
|
+
/** Negative padding shrinks bounds; an inverted result becomes canonical empty bounds. */
|
|
15
|
+
export declare function expandBounds(bounds: ReadonlyBounds, padding: number, out?: Bounds): Bounds;
|
|
16
|
+
export declare function clampPointToBounds(bounds: ReadonlyBounds, p: ArrayLike<number>, out?: NumericArray): NumericArray | null;
|
|
17
|
+
export declare function spheresIntersect(a: ArrayLike<number>, ar: number, b: ArrayLike<number>, br: number): boolean;
|
|
18
|
+
export declare function boundsIntersectSphere(bounds: ReadonlyBounds, center: ArrayLike<number>, r: number): boolean;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=bounds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bounds.d.ts","sourceRoot":"","sources":["../../src/culling/bounds.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAE5E,KAAK,cAAc,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;AA4BtE,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,CAAC,GAAG,QAAQ,CAAC;AAC1D,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,CAAC,GAAG,QAAQ,CAAC;AAC1D,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;AAK5D,yFAAyF;AACzF,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAI7D;AACD,wBAAgB,mBAA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 @@
|
|
|
1
|
+
function dimension(bounds) {
|
|
2
|
+
const n = bounds[0].length;
|
|
3
|
+
if ((n !== 2 && n !== 3) ||
|
|
4
|
+
bounds[1].length !== n ||
|
|
5
|
+
[...Array.from(bounds[0]), ...Array.from(bounds[1])].some(Number.isNaN)) {
|
|
6
|
+
throw new RangeError('Expected 2D or 3D bounds without NaN');
|
|
7
|
+
}
|
|
8
|
+
const empty = Array.from({ length: n }, (_, i) => bounds[0][i] > bounds[1][i]).some(Boolean);
|
|
9
|
+
if (!empty &&
|
|
10
|
+
[...Array.from(bounds[0]), ...Array.from(bounds[1])].some(x => !Number.isFinite(x))) {
|
|
11
|
+
throw new RangeError('Nonempty bounds must be finite');
|
|
12
|
+
}
|
|
13
|
+
return n;
|
|
14
|
+
}
|
|
15
|
+
function pair(a, b) {
|
|
16
|
+
const n = dimension(a);
|
|
17
|
+
if (dimension(b) !== n)
|
|
18
|
+
throw new RangeError('Bounds dimensions must match');
|
|
19
|
+
return n;
|
|
20
|
+
}
|
|
21
|
+
function point(p, n) {
|
|
22
|
+
if (p.length !== n || Array.from(p).some(x => !Number.isFinite(x)))
|
|
23
|
+
throw new RangeError('Expected a finite point of matching dimension');
|
|
24
|
+
}
|
|
25
|
+
export function createEmptyBounds(dimension) {
|
|
26
|
+
if (dimension !== 2 && dimension !== 3)
|
|
27
|
+
throw new RangeError('Expected dimension 2 or 3');
|
|
28
|
+
return [new Array(dimension).fill(Infinity), new Array(dimension).fill(-Infinity)];
|
|
29
|
+
}
|
|
30
|
+
/** Any inverted axis denotes empty bounds. Equal endpoints describe a nonempty point. */
|
|
31
|
+
export function isEmptyBounds(bounds) {
|
|
32
|
+
return Array.from({ length: dimension(bounds) }, (_, i) => bounds[0][i] > bounds[1][i]).some(Boolean);
|
|
33
|
+
}
|
|
34
|
+
export function boundsContainsPoint(bounds, p) {
|
|
35
|
+
point(p, dimension(bounds));
|
|
36
|
+
return (!isEmptyBounds(bounds) && Array.from(p).every((x, i) => x >= bounds[0][i] && x <= bounds[1][i]));
|
|
37
|
+
}
|
|
38
|
+
export function boundsContainsBounds(a, b) {
|
|
39
|
+
const n = pair(a, b);
|
|
40
|
+
return (isEmptyBounds(b) ||
|
|
41
|
+
(!isEmptyBounds(a) &&
|
|
42
|
+
Array.from({ length: n }, (_, i) => a[0][i] <= b[0][i] && a[1][i] >= b[1][i]).every(Boolean)));
|
|
43
|
+
}
|
|
44
|
+
export function boundsIntersect(a, b) {
|
|
45
|
+
const n = pair(a, b);
|
|
46
|
+
return (!isEmptyBounds(a) &&
|
|
47
|
+
!isEmptyBounds(b) &&
|
|
48
|
+
Array.from({ length: n }, (_, i) => a[0][i] <= b[1][i] && b[0][i] <= a[1][i]).every(Boolean));
|
|
49
|
+
}
|
|
50
|
+
function store(values, out = createEmptyBounds(values[0].length)) {
|
|
51
|
+
if (out[0].length !== values[0].length || out[1].length !== values[0].length) {
|
|
52
|
+
throw new RangeError('Output bounds dimensions must match');
|
|
53
|
+
}
|
|
54
|
+
for (let j = 0; j < 2; j++)
|
|
55
|
+
for (let i = 0; i < values[j].length; i++)
|
|
56
|
+
out[j][i] = values[j][i];
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
export function unionBounds(a, b, out) {
|
|
60
|
+
const n = pair(a, b);
|
|
61
|
+
const values = createEmptyBounds(n);
|
|
62
|
+
const ea = isEmptyBounds(a), eb = isEmptyBounds(b);
|
|
63
|
+
for (let i = 0; i < n; i++) {
|
|
64
|
+
values[0][i] = Math.min(ea ? Infinity : a[0][i], eb ? Infinity : b[0][i]);
|
|
65
|
+
values[1][i] = Math.max(ea ? -Infinity : a[1][i], eb ? -Infinity : b[1][i]);
|
|
66
|
+
}
|
|
67
|
+
return store(values, out);
|
|
68
|
+
}
|
|
69
|
+
export function intersectBounds(a, b, out) {
|
|
70
|
+
const n = pair(a, b), values = createEmptyBounds(n);
|
|
71
|
+
if (boundsIntersect(a, b))
|
|
72
|
+
for (let i = 0; i < n; i++) {
|
|
73
|
+
values[0][i] = Math.max(a[0][i], b[0][i]);
|
|
74
|
+
values[1][i] = Math.min(a[1][i], b[1][i]);
|
|
75
|
+
}
|
|
76
|
+
return store(values, out);
|
|
77
|
+
}
|
|
78
|
+
export function expandBoundsByPoint(bounds, p, out) {
|
|
79
|
+
point(p, dimension(bounds));
|
|
80
|
+
return unionBounds(bounds, [p, p], out);
|
|
81
|
+
}
|
|
82
|
+
/** Negative padding shrinks bounds; an inverted result becomes canonical empty bounds. */
|
|
83
|
+
export function expandBounds(bounds, padding, out) {
|
|
84
|
+
if (!Number.isFinite(padding))
|
|
85
|
+
throw new RangeError('Padding must be finite');
|
|
86
|
+
const n = dimension(bounds), values = createEmptyBounds(n);
|
|
87
|
+
if (!isEmptyBounds(bounds))
|
|
88
|
+
for (let i = 0; i < n; i++) {
|
|
89
|
+
values[0][i] = bounds[0][i] - padding;
|
|
90
|
+
values[1][i] = bounds[1][i] + padding;
|
|
91
|
+
}
|
|
92
|
+
return store(isEmptyBounds(values) ? createEmptyBounds(n) : values, out);
|
|
93
|
+
}
|
|
94
|
+
export function clampPointToBounds(bounds, p, out = new Array(p.length)) {
|
|
95
|
+
point(p, dimension(bounds));
|
|
96
|
+
if (out.length < p.length)
|
|
97
|
+
throw new RangeError('Result buffer is too short');
|
|
98
|
+
if (isEmptyBounds(bounds))
|
|
99
|
+
return null;
|
|
100
|
+
const result = Array.from(p, (x, i) => Math.max(bounds[0][i], Math.min(bounds[1][i], x)));
|
|
101
|
+
for (let i = 0; i < result.length; i++)
|
|
102
|
+
out[i] = result[i];
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
function radius(r) {
|
|
106
|
+
if (!Number.isFinite(r) || r < 0)
|
|
107
|
+
throw new RangeError('Radius must be finite and nonnegative');
|
|
108
|
+
}
|
|
109
|
+
export function spheresIntersect(a, ar, b, br) {
|
|
110
|
+
point(a, 3);
|
|
111
|
+
point(b, 3);
|
|
112
|
+
radius(ar);
|
|
113
|
+
radius(br);
|
|
114
|
+
return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]) <= ar + br;
|
|
115
|
+
}
|
|
116
|
+
export function boundsIntersectSphere(bounds, center, r) {
|
|
117
|
+
radius(r);
|
|
118
|
+
const closest = clampPointToBounds(bounds, center);
|
|
119
|
+
return closest !== null && Math.hypot(...Array.from(center, (x, i) => x - closest[i])) <= r;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=bounds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bounds.js","sourceRoot":"","sources":["../../src/culling/bounds.ts"],"names":[],"mappings":"AAMA,SAAS,SAAS,CAAC,MAAsB;IACvC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC3B,IACE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpB,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC;QACtB,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EACvE,CAAC;QACD,MAAM,IAAI,UAAU,CAAC,sCAAsC,CAAC,CAAC;IAC/D,CAAC;IACD,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,EAAC,MAAM,EAAE,CAAC,EAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3F,IACE,CAAC,KAAK;QACN,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC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C,CAAC,CAAC;AAClG,CAAC;AACD,MAAM,UAAU,gBAAgB,CAC9B,CAAoB,EACpB,EAAU,EACV,CAAoB,EACpB,EAAU;IAEV,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACZ,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACZ,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC;AACtE,CAAC;AACD,MAAM,UAAU,qBAAqB,CACnC,MAAsB,EACtB,MAAyB,EACzB,CAAS;IAET,MAAM,CAAC,CAAC,CAAC,CAAC;IACV,MAAM,OAAO,GAAG,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnD,OAAO,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAC9F,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/culling/constants.ts"],"names":[],"mappings":"AAIA,6DAA6D;AAC7D,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,cAAc,GAAG,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/culling/constants.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ProjectionDepthOptions } from '@math.gl/core';
|
|
2
|
+
import { Plane } from "./lib/plane.js";
|
|
3
|
+
/** Inward planes: left, right, bottom, top, near, far. An infinite far plane is omitted. */
|
|
4
|
+
export declare function extractFrustumPlanes(matrix: ArrayLike<number>, options?: ProjectionDepthOptions): Plane[];
|
|
5
|
+
//# sourceMappingURL=frustum-planes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frustum-planes.d.ts","sourceRoot":"","sources":["../../src/culling/frustum-planes.ts"],"names":[],"mappings":"AAGA,OAAO,EAA0B,KAAK,sBAAsB,EAAC,MAAM,eAAe,CAAC;AACnF,OAAO,EAAC,KAAK,EAAC,uBAAoB;AAElC,4FAA4F;AAC5F,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EACzB,OAAO,GAAE,sBAA2B,GACnC,KAAK,EAAE,CA8BT"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import { getProjectionDepthRange } from '@math.gl/core';
|
|
5
|
+
import { Plane } from "./lib/plane.js";
|
|
6
|
+
/** Inward planes: left, right, bottom, top, near, far. An infinite far plane is omitted. */
|
|
7
|
+
export function extractFrustumPlanes(matrix, options = {}) {
|
|
8
|
+
if (matrix.length !== 16 || Array.from(matrix).some(x => !Number.isFinite(x)))
|
|
9
|
+
throw new RangeError('Expected a finite view-projection matrix');
|
|
10
|
+
const [near, far] = getProjectionDepthRange(options);
|
|
11
|
+
const low = Math.min(near, far), high = Math.max(near, far);
|
|
12
|
+
const row = (i) => [matrix[i], matrix[i + 4], matrix[i + 8], matrix[i + 12]];
|
|
13
|
+
const x = row(0), y = row(1), z = row(2), w = row(3);
|
|
14
|
+
const combine = (a, b, factor) => a.map((v, i) => v + factor * b[i]);
|
|
15
|
+
const lo = combine(z, w, -low), hi = w.map((v, i) => high * v - z[i]);
|
|
16
|
+
const coefficients = [
|
|
17
|
+
combine(w, x, 1),
|
|
18
|
+
combine(w, x, -1),
|
|
19
|
+
combine(w, y, 1),
|
|
20
|
+
combine(w, y, -1),
|
|
21
|
+
...(options.reversedDepth ? [hi, lo] : [lo, hi])
|
|
22
|
+
];
|
|
23
|
+
const planes = [];
|
|
24
|
+
for (const [a, b, c, d] of coefficients) {
|
|
25
|
+
const length = Math.hypot(a, b, c);
|
|
26
|
+
if (length === 0) {
|
|
27
|
+
if (d < 0)
|
|
28
|
+
throw new RangeError('Empty clipping volume');
|
|
29
|
+
}
|
|
30
|
+
else
|
|
31
|
+
planes.push(new Plane([a / length, b / length, c / length], d / length));
|
|
32
|
+
}
|
|
33
|
+
if (planes.length < 4)
|
|
34
|
+
throw new RangeError('Degenerate clipping volume');
|
|
35
|
+
return planes;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=frustum-planes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frustum-planes.js","sourceRoot":"","sources":["../../src/culling/frustum-planes.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAC5D,OAAO,EAAC,uBAAuB,EAA8B,MAAM,eAAe,CAAC;AACnF,OAAO,EAAC,KAAK,EAAC,uBAAoB;AAElC,4FAA4F;AAC5F,MAAM,UAAU,oBAAoB,CAClC,MAAyB,EACzB,UAAkC,EAAE;IAEpC,IAAI,MAAM,CAAC,MAAM,KAAK,EAAE,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC3E,MAAM,IAAI,UAAU,CAAC,0CAA0C,CAAC,CAAC;IACnE,MAAM,CAAC,IAAI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AO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACjB,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;KACjD,CAAC;IACF,MAAM,MAAM,GAAY,EAAE,CAAC;IAC3B,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,YAAY,EAAE,CAAC;QACxC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACnC,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;YACjB,IAAI,CAAC,GAAG,CAAC;gBAAE,MAAM,IAAI,UAAU,CAAC,uBAAuB,CAAC,CAAC;QAC3D,CAAC;;YAAM,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;IAClF,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,4BAA4B,CAAC,CAAC;IAC1E,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { NumericArray } from '@math.gl/core';
|
|
2
|
+
import { type QueryPoint } from "./queries.js";
|
|
3
|
+
type V = [number, number, number];
|
|
4
|
+
export declare function getRayPoint(origin: QueryPoint, dir: QueryPoint, t: number, out?: NumericArray): NumericArray;
|
|
5
|
+
export declare function getClosestPointOnRay(point: QueryPoint, origin: QueryPoint, dir: QueryPoint, out?: NumericArray): NumericArray;
|
|
6
|
+
export declare function distanceToRay(point: QueryPoint, origin: QueryPoint, dir: QueryPoint): number;
|
|
7
|
+
export type RaySegmentClosestPoints = {
|
|
8
|
+
rayPoint: V;
|
|
9
|
+
segmentPoint: V;
|
|
10
|
+
rayParameter: number;
|
|
11
|
+
segmentFraction: number;
|
|
12
|
+
distance: number;
|
|
13
|
+
};
|
|
14
|
+
export declare function getClosestPointsRaySegment(origin: QueryPoint, dir: QueryPoint, a: QueryPoint, b: QueryPoint): RaySegmentClosestPoints;
|
|
15
|
+
/** Finite affine transforms only. The unnormalized output direction preserves the ray parameter. */
|
|
16
|
+
export declare function transformRay(origin: QueryPoint, dir: QueryPoint, matrix: QueryPoint): {
|
|
17
|
+
origin: V;
|
|
18
|
+
direction: V;
|
|
19
|
+
};
|
|
20
|
+
/** Barycentrics of the point's orthogonal projection; null for a degenerate triangle. */
|
|
21
|
+
export declare function getTriangleBarycentric(point: QueryPoint, a: QueryPoint, b: QueryPoint, c: QueryPoint, out?: NumericArray): NumericArray | null;
|
|
22
|
+
export declare function getTriangleArea(a: QueryPoint, b: QueryPoint, c: QueryPoint): number;
|
|
23
|
+
export declare function getTriangleNormal(a: QueryPoint, b: QueryPoint, c: QueryPoint, out?: NumericArray): NumericArray;
|
|
24
|
+
/** Front-facing means the oriented normal points against the viewing/ray direction. */
|
|
25
|
+
export declare function isTriangleFrontFacing(a: QueryPoint, b: QueryPoint, c: QueryPoint, dir: QueryPoint): boolean;
|
|
26
|
+
/** Relative tolerance: plane distance is scaled by the longest edge from a. */
|
|
27
|
+
export declare function triangleContainsPoint(point: QueryPoint, a: QueryPoint, b: QueryPoint, c: QueryPoint, tolerance?: number): boolean;
|
|
28
|
+
export declare function interpolateTriangleAttribute(weights: QueryPoint, a: QueryPoint, b: QueryPoint, c: QueryPoint, out?: NumericArray): NumericArray;
|
|
29
|
+
/** Closed segment; a coplanar segment returns its start, a disjoint segment returns null. */
|
|
30
|
+
export declare function intersectPlaneSegment(normal: QueryPoint, constant: number, start: QueryPoint, end: QueryPoint, out?: NumericArray): NumericArray | null;
|
|
31
|
+
/** Separating-axis test for a closed AABB. Degenerate triangles reduce to segments/points. */
|
|
32
|
+
export declare function triangleIntersectsBounds(a: QueryPoint, b: QueryPoint, c: QueryPoint, minimum: QueryPoint, maximum: QueryPoint): boolean;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=geometric-queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometric-queries.d.ts","sourceRoot":"","sources":["../../src/culling/geometric-queries.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAChD,OAAO,EAA8C,KAAK,UAAU,EAAC,qBAAkB;AAEvF,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAqBlC,wBAAgB,WAAW,CACzB,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,UAAU,EACf,CAAC,EAAE,MAAM,EACT,GAAG,GAAE,YAAwB,GAC5B,YAAY,CAMd;AACD,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,UAAU,EACf,GAAG,GAAE,YAAwB,GAC5B,YAAY,CASd;AACD,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,MAAM,CAG5F;AACD,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,EAAE,CAAC,CAAC;IACZ,YAAY,EAAE,CAAC,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AACF,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,UAAU,EACf,CAAC,EAAE,UAAU,EACb,CAAC,EAAE,UAAU,GACZ,uBAAuB,CAkDzB;AACD,oGAAoG;AACpG,wBAAgB,YAAY,CAC1B,MAAM,EA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AACD,8FAA8F;AAC9F,wBAAgB,wBAAwB,CACtC,CAAC,EAAE,UAAU,EACb,CAAC,EAAE,UAAU,EACb,CAAC,EAAE,UAAU,EACb,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,UAAU,GAClB,OAAO,CA0BT"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { validateQueryPoint, normalizeQueryDirection } from "./queries.js";
|
|
2
|
+
const sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
3
|
+
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
4
|
+
const cross = (a, b) => [
|
|
5
|
+
a[1] * b[2] - a[2] * b[1],
|
|
6
|
+
a[2] * b[0] - a[0] * b[2],
|
|
7
|
+
a[0] * b[1] - a[1] * b[0]
|
|
8
|
+
];
|
|
9
|
+
const check = (...points) => {
|
|
10
|
+
for (const p of points)
|
|
11
|
+
validateQueryPoint(p, 3);
|
|
12
|
+
};
|
|
13
|
+
function output(out, values) {
|
|
14
|
+
if (out.length < values.length)
|
|
15
|
+
throw new RangeError('Result buffer is too short');
|
|
16
|
+
const copy = Array.from(values);
|
|
17
|
+
for (let i = 0; i < copy.length; i++)
|
|
18
|
+
out[i] = copy[i];
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
function direction(d) {
|
|
22
|
+
check(d);
|
|
23
|
+
if (Math.hypot(d[0], d[1], d[2]) === 0)
|
|
24
|
+
throw new RangeError('Ray direction must be nonzero');
|
|
25
|
+
}
|
|
26
|
+
export function getRayPoint(origin, dir, t, out = [0, 0, 0]) {
|
|
27
|
+
check(origin);
|
|
28
|
+
direction(dir);
|
|
29
|
+
if (!Number.isFinite(t) || t < 0)
|
|
30
|
+
throw new RangeError('Ray parameter must be finite and nonnegative');
|
|
31
|
+
return output(out, [origin[0] + t * dir[0], origin[1] + t * dir[1], origin[2] + t * dir[2]]);
|
|
32
|
+
}
|
|
33
|
+
export function getClosestPointOnRay(point, origin, dir, out = [0, 0, 0]) {
|
|
34
|
+
check(point, origin);
|
|
35
|
+
direction(dir);
|
|
36
|
+
const unit = normalizeQueryDirection(dir, 3);
|
|
37
|
+
const distance = Math.max(0, dot(sub(point, origin), unit));
|
|
38
|
+
return output(out, [0, 1, 2].map(i => origin[i] + distance * unit[i]));
|
|
39
|
+
}
|
|
40
|
+
export function distanceToRay(point, origin, dir) {
|
|
41
|
+
const p = getClosestPointOnRay(point, origin, dir);
|
|
42
|
+
return Math.hypot(...sub(point, p));
|
|
43
|
+
}
|
|
44
|
+
export function getClosestPointsRaySegment(origin, dir, a, b) {
|
|
45
|
+
check(origin, a, b);
|
|
46
|
+
direction(dir);
|
|
47
|
+
const unit = normalizeQueryDirection(dir, 3);
|
|
48
|
+
const directionLength = Math.hypot(dir[0], dir[1], dir[2]);
|
|
49
|
+
const edge = sub(b, a), offset = sub(origin, a);
|
|
50
|
+
const segmentLength = Math.hypot(...edge);
|
|
51
|
+
const segmentUnit = edge.map(x => (segmentLength ? x / segmentLength : 0));
|
|
52
|
+
const bb = dot(unit, segmentUnit), dd = dot(unit, offset), ee = dot(segmentUnit, offset);
|
|
53
|
+
const candidates = [
|
|
54
|
+
[0, Math.max(0, Math.min(segmentLength, ee))],
|
|
55
|
+
[Math.max(0, -dd), 0],
|
|
56
|
+
[Math.max(0, bb * segmentLength - dd), segmentLength]
|
|
57
|
+
];
|
|
58
|
+
// Cross products retain the angle when nearly parallel dot products round to one.
|
|
59
|
+
const normal = cross(unit, segmentUnit);
|
|
60
|
+
const sine = Math.hypot(...normal);
|
|
61
|
+
if (segmentLength > 0 && sine > 0) {
|
|
62
|
+
const normalUnit = normal.map(value => value / sine);
|
|
63
|
+
const separation = sub(a, origin);
|
|
64
|
+
const t = dot(cross(separation, segmentUnit), normalUnit) / sine;
|
|
65
|
+
const u = dot(cross(separation, unit), normalUnit) / sine;
|
|
66
|
+
if (t >= 0 && u >= 0 && u <= segmentLength)
|
|
67
|
+
candidates.push([t, u]);
|
|
68
|
+
}
|
|
69
|
+
let best;
|
|
70
|
+
for (const [t, u] of candidates) {
|
|
71
|
+
const rayPoint = [
|
|
72
|
+
origin[0] + t * unit[0],
|
|
73
|
+
origin[1] + t * unit[1],
|
|
74
|
+
origin[2] + t * unit[2]
|
|
75
|
+
];
|
|
76
|
+
const segmentPoint = [
|
|
77
|
+
a[0] + u * segmentUnit[0],
|
|
78
|
+
a[1] + u * segmentUnit[1],
|
|
79
|
+
a[2] + u * segmentUnit[2]
|
|
80
|
+
];
|
|
81
|
+
const distance = Math.hypot(...sub(rayPoint, segmentPoint));
|
|
82
|
+
if (!best || distance < best.distance)
|
|
83
|
+
best = {
|
|
84
|
+
rayPoint,
|
|
85
|
+
segmentPoint,
|
|
86
|
+
rayParameter: t / directionLength,
|
|
87
|
+
segmentFraction: segmentLength ? u / segmentLength : 0,
|
|
88
|
+
distance
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return best;
|
|
92
|
+
}
|
|
93
|
+
/** Finite affine transforms only. The unnormalized output direction preserves the ray parameter. */
|
|
94
|
+
export function transformRay(origin, dir, matrix) {
|
|
95
|
+
check(origin);
|
|
96
|
+
direction(dir);
|
|
97
|
+
if (matrix.length !== 16 ||
|
|
98
|
+
Array.from(matrix).some(x => !Number.isFinite(x)) ||
|
|
99
|
+
matrix[3] !== 0 ||
|
|
100
|
+
matrix[7] !== 0 ||
|
|
101
|
+
matrix[11] !== 0 ||
|
|
102
|
+
matrix[15] !== 1)
|
|
103
|
+
throw new RangeError('Expected a finite affine matrix');
|
|
104
|
+
const apply = (p, w) => [0, 1, 2].map(i => matrix[i] * p[0] + matrix[i + 4] * p[1] + matrix[i + 8] * p[2] + w * matrix[i + 12]);
|
|
105
|
+
const transformed = { origin: apply(origin, 1), direction: apply(dir, 0) };
|
|
106
|
+
check(transformed.origin);
|
|
107
|
+
direction(transformed.direction);
|
|
108
|
+
return transformed;
|
|
109
|
+
}
|
|
110
|
+
function triangle(a, b, c) {
|
|
111
|
+
check(a, b, c);
|
|
112
|
+
const ab = sub(b, a), ac = sub(c, a);
|
|
113
|
+
const scale = Math.max(Math.hypot(...ab), Math.hypot(...ac));
|
|
114
|
+
const u = ab.map(x => (scale ? x / scale : 0)), v = ac.map(x => (scale ? x / scale : 0));
|
|
115
|
+
return { u, v, scale, normal: cross(u, v) };
|
|
116
|
+
}
|
|
117
|
+
/** Barycentrics of the point's orthogonal projection; null for a degenerate triangle. */
|
|
118
|
+
export function getTriangleBarycentric(point, a, b, c, out = [0, 0, 0]) {
|
|
119
|
+
check(point);
|
|
120
|
+
const { u, v, scale, normal } = triangle(a, b, c), denominator = dot(normal, normal);
|
|
121
|
+
if (denominator === 0)
|
|
122
|
+
return null;
|
|
123
|
+
const p = sub(point, a).map(x => x / scale);
|
|
124
|
+
const second = dot(cross(p, v), normal) / denominator;
|
|
125
|
+
const third = dot(cross(u, p), normal) / denominator;
|
|
126
|
+
return output(out, [1 - second - third, second, third]);
|
|
127
|
+
}
|
|
128
|
+
export function getTriangleArea(a, b, c) {
|
|
129
|
+
const { normal, scale } = triangle(a, b, c);
|
|
130
|
+
return (Math.hypot(...normal) * scale * scale) / 2;
|
|
131
|
+
}
|
|
132
|
+
export function getTriangleNormal(a, b, c, out = [0, 0, 0]) {
|
|
133
|
+
const { normal } = triangle(a, b, c), length = Math.hypot(...normal);
|
|
134
|
+
return output(out, normal.map(x => (length ? x / length : 0)));
|
|
135
|
+
}
|
|
136
|
+
/** Front-facing means the oriented normal points against the viewing/ray direction. */
|
|
137
|
+
export function isTriangleFrontFacing(a, b, c, dir) {
|
|
138
|
+
direction(dir);
|
|
139
|
+
return dot(triangle(a, b, c).normal, dir) < 0;
|
|
140
|
+
}
|
|
141
|
+
/** Relative tolerance: plane distance is scaled by the longest edge from a. */
|
|
142
|
+
export function triangleContainsPoint(point, a, b, c, tolerance = 1e-10) {
|
|
143
|
+
if (!Number.isFinite(tolerance) || tolerance < 0)
|
|
144
|
+
throw new RangeError('Invalid tolerance');
|
|
145
|
+
const weights = getTriangleBarycentric(point, a, b, c);
|
|
146
|
+
if (!weights)
|
|
147
|
+
return false;
|
|
148
|
+
const { normal, scale } = triangle(a, b, c);
|
|
149
|
+
const distance = Math.abs(dot(sub(point, a).map(x => x / scale), normal)) / Math.hypot(...normal);
|
|
150
|
+
return (distance <= tolerance && Array.from(weights).every(x => x >= -tolerance && x <= 1 + tolerance));
|
|
151
|
+
}
|
|
152
|
+
export function interpolateTriangleAttribute(weights, a, b, c, out = new Array(a.length)) {
|
|
153
|
+
check(weights);
|
|
154
|
+
if (!a.length ||
|
|
155
|
+
a.length !== b.length ||
|
|
156
|
+
a.length !== c.length ||
|
|
157
|
+
[a, b, c].some(p => Array.from(p).some(x => !Number.isFinite(x))))
|
|
158
|
+
throw new RangeError('Expected matching finite attributes');
|
|
159
|
+
return output(out, Array.from(a, (x, i) => weights[0] * x + weights[1] * b[i] + weights[2] * c[i]));
|
|
160
|
+
}
|
|
161
|
+
/** Closed segment; a coplanar segment returns its start, a disjoint segment returns null. */
|
|
162
|
+
export function intersectPlaneSegment(normal, constant, start, end, out = [0, 0, 0]) {
|
|
163
|
+
check(start, end);
|
|
164
|
+
direction(normal);
|
|
165
|
+
if (!Number.isFinite(constant))
|
|
166
|
+
throw new RangeError('Plane constant must be finite');
|
|
167
|
+
const a = dot(normal, start) + constant, b = dot(normal, end) + constant;
|
|
168
|
+
if (a === 0)
|
|
169
|
+
return output(out, start);
|
|
170
|
+
if (b === 0)
|
|
171
|
+
return output(out, end);
|
|
172
|
+
if (a > 0 === b > 0)
|
|
173
|
+
return null;
|
|
174
|
+
const t = a / (a - b);
|
|
175
|
+
return output(out, [0, 1, 2].map(i => start[i] + t * (end[i] - start[i])));
|
|
176
|
+
}
|
|
177
|
+
/** Separating-axis test for a closed AABB. Degenerate triangles reduce to segments/points. */
|
|
178
|
+
export function triangleIntersectsBounds(a, b, c, minimum, maximum) {
|
|
179
|
+
check(a, b, c, minimum, maximum);
|
|
180
|
+
if ([0, 1, 2].some(i => minimum[i] > maximum[i]))
|
|
181
|
+
return false;
|
|
182
|
+
const center = [0, 1, 2].map(i => minimum[i] / 2 + maximum[i] / 2);
|
|
183
|
+
const extent = [0, 1, 2].map(i => maximum[i] / 2 - minimum[i] / 2);
|
|
184
|
+
const vertices = [a, b, c].map(p => sub(p, center));
|
|
185
|
+
const edges = [sub(b, a), sub(c, b), sub(a, c)];
|
|
186
|
+
const basis = [
|
|
187
|
+
[1, 0, 0],
|
|
188
|
+
[0, 1, 0],
|
|
189
|
+
[0, 0, 1]
|
|
190
|
+
];
|
|
191
|
+
const axes = [
|
|
192
|
+
...basis,
|
|
193
|
+
cross(edges[0], edges[1]),
|
|
194
|
+
...edges.flatMap(e => basis.map(axis => cross(e, axis)))
|
|
195
|
+
];
|
|
196
|
+
for (const axis of axes) {
|
|
197
|
+
const length = Math.hypot(...axis);
|
|
198
|
+
if (!length)
|
|
199
|
+
continue;
|
|
200
|
+
const unit = axis.map(x => x / length);
|
|
201
|
+
const projections = vertices.map(v => dot(v, unit));
|
|
202
|
+
const radius = extent.reduce((sum, x, i) => sum + x * Math.abs(unit[i]), 0);
|
|
203
|
+
if (Math.min(...projections) > radius || Math.max(...projections) < -radius)
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=geometric-queries.js.map
|