@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,452 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
intersectRayBounds,
|
|
7
|
+
normalizeQueryDirection,
|
|
8
|
+
validateQueryDistance,
|
|
9
|
+
validateQueryPoint,
|
|
10
|
+
type QueryPoint
|
|
11
|
+
} from '../culling/queries';
|
|
12
|
+
|
|
13
|
+
export type BoxIndexOptions = {
|
|
14
|
+
/** Flat [minX, minY, (minZ), maxX, maxY, (maxZ)] records, copied at construction. */
|
|
15
|
+
bounds: ArrayLike<number>;
|
|
16
|
+
dimension: 2 | 3;
|
|
17
|
+
leafSize?: number;
|
|
18
|
+
};
|
|
19
|
+
export type NearestIndexResult = {index: number; distance: number};
|
|
20
|
+
/** A work unit visits one BVH node or one leaf item, including its optional refinement. */
|
|
21
|
+
export type IndexQueryBudget = {maxWork?: number};
|
|
22
|
+
/** Incomplete results are provisional: null/empty does not establish absence. */
|
|
23
|
+
export type IndexQueryResult<T> = {result: T; complete: boolean; work: number};
|
|
24
|
+
export type SearchIndexOptions = IndexQueryBudget & {
|
|
25
|
+
filter?: (index: number) => boolean;
|
|
26
|
+
/** Maximum accepted rows retained; one further match establishes truncation. */
|
|
27
|
+
maxResults?: number;
|
|
28
|
+
};
|
|
29
|
+
export type NearestIndexOptions = {
|
|
30
|
+
maxDistance?: number;
|
|
31
|
+
filter?: (index: number) => boolean;
|
|
32
|
+
/** Exact geometry distance, at least its box distance apart from roundoff. Values are never clamped; null excludes it. */
|
|
33
|
+
distanceToItem?: (index: number) => number | null;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** Constraints for the nearest accepted ray hit against indexed boxes or caller-owned geometry. */
|
|
37
|
+
export type RayIndexOptions = {
|
|
38
|
+
/** Inclusive Euclidean distance limit; defaults to Infinity. */
|
|
39
|
+
maxDistance?: number;
|
|
40
|
+
/** Exclude an original row before exact refinement. */
|
|
41
|
+
filter?: (index: number) => boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Exact Euclidean hit distance, or null to reject the row.
|
|
44
|
+
* Must be at least its indexed-box entry distance, apart from floating-point roundoff;
|
|
45
|
+
* geometry must stay inside that box. Refined distances are never rounded or clamped.
|
|
46
|
+
* The second argument is the current accepted distance limit, initially maxDistance.
|
|
47
|
+
* Traversal order is unspecified; this is not an all-intersections callback.
|
|
48
|
+
*/
|
|
49
|
+
intersectItem?: (index: number, maxDistance: number) => number | null;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/** Static median-split BVH. Results refer to original input rows, not tree order. */
|
|
53
|
+
export class BoxIndex {
|
|
54
|
+
readonly dimension: 2 | 3;
|
|
55
|
+
readonly size: number;
|
|
56
|
+
private readonly bounds: Float64Array;
|
|
57
|
+
private readonly nodeBounds: Float64Array;
|
|
58
|
+
private readonly children: Int32Array;
|
|
59
|
+
private readonly starts: Uint32Array;
|
|
60
|
+
private readonly counts: Uint32Array;
|
|
61
|
+
private readonly order: Uint32Array;
|
|
62
|
+
|
|
63
|
+
constructor(options: BoxIndexOptions) {
|
|
64
|
+
const {dimension, bounds, leafSize = 8} = options;
|
|
65
|
+
if (dimension !== 2 && dimension !== 3) throw new RangeError('Index dimension must be 2 or 3');
|
|
66
|
+
if (!Number.isSafeInteger(leafSize) || leafSize < 1)
|
|
67
|
+
throw new RangeError('leafSize must be positive');
|
|
68
|
+
if (bounds.length % (dimension * 2)) throw new RangeError('Incomplete bounds record');
|
|
69
|
+
this.dimension = dimension;
|
|
70
|
+
this.bounds = Float64Array.from(bounds);
|
|
71
|
+
this.size = bounds.length / (dimension * 2);
|
|
72
|
+
if (this.size > 0x7fffffff) throw new RangeError('Index exceeds 32-bit capacity');
|
|
73
|
+
const stride = dimension * 2;
|
|
74
|
+
for (let i = 0; i < this.size; i++)
|
|
75
|
+
this.validateBounds(
|
|
76
|
+
this.bounds.subarray(i * stride, i * stride + dimension),
|
|
77
|
+
this.bounds.subarray(i * stride + dimension, (i + 1) * stride)
|
|
78
|
+
);
|
|
79
|
+
const records: {bounds: number[]; left: number; right: number; start: number; count: number}[] =
|
|
80
|
+
[];
|
|
81
|
+
const ids = Array.from({length: this.size}, (_, i) => i);
|
|
82
|
+
const build = (start: number, end: number): number => {
|
|
83
|
+
const node = records.length;
|
|
84
|
+
const bound = [
|
|
85
|
+
...new Array(dimension).fill(Infinity),
|
|
86
|
+
...new Array(dimension).fill(-Infinity)
|
|
87
|
+
];
|
|
88
|
+
for (let i = start; i < end; i++)
|
|
89
|
+
for (let axis = 0; axis < dimension; axis++) {
|
|
90
|
+
bound[axis] = Math.min(bound[axis], this.bounds[ids[i] * stride + axis]);
|
|
91
|
+
bound[axis + dimension] = Math.max(
|
|
92
|
+
bound[axis + dimension],
|
|
93
|
+
this.bounds[ids[i] * stride + axis + dimension]
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
const record = {bounds: bound, left: -1, right: -1, start, count: end - start};
|
|
97
|
+
records.push(record);
|
|
98
|
+
if (end - start > leafSize) {
|
|
99
|
+
let axis = 0;
|
|
100
|
+
for (let i = 1; i < dimension; i++) {
|
|
101
|
+
if (bound[i + dimension] - bound[i] > bound[axis + dimension] - bound[axis]) axis = i;
|
|
102
|
+
}
|
|
103
|
+
const center = (i: number): number =>
|
|
104
|
+
this.bounds[i * stride + axis] / 2 + this.bounds[i * stride + axis + dimension] / 2;
|
|
105
|
+
const sorted = ids.slice(start, end).sort((a, b) => center(a) - center(b) || a - b);
|
|
106
|
+
for (let i = 0; i < sorted.length; i++) ids[start + i] = sorted[i];
|
|
107
|
+
const middle = Math.floor((start + end) / 2);
|
|
108
|
+
record.left = build(start, middle);
|
|
109
|
+
record.right = build(middle, end);
|
|
110
|
+
record.count = 0;
|
|
111
|
+
}
|
|
112
|
+
return node;
|
|
113
|
+
};
|
|
114
|
+
if (this.size) build(0, this.size);
|
|
115
|
+
this.nodeBounds = new Float64Array(records.length * stride);
|
|
116
|
+
this.children = new Int32Array(records.length * 2);
|
|
117
|
+
this.starts = new Uint32Array(records.length);
|
|
118
|
+
this.counts = new Uint32Array(records.length);
|
|
119
|
+
records.forEach((record, i) => {
|
|
120
|
+
this.nodeBounds.set(record.bounds, i * stride);
|
|
121
|
+
this.children.set([record.left, record.right], i * 2);
|
|
122
|
+
this.starts[i] = record.start;
|
|
123
|
+
this.counts[i] = record.count;
|
|
124
|
+
});
|
|
125
|
+
this.order = Uint32Array.from(ids);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Closed-box overlap, including boundary contact. Sorted by original row index. */
|
|
129
|
+
search(minimum: QueryPoint, maximum: QueryPoint): number[] {
|
|
130
|
+
return this.searchQuery(minimum, maximum).result;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Bounded closed-box overlap. Results are sorted even when incomplete. */
|
|
134
|
+
searchQuery(
|
|
135
|
+
minimum: QueryPoint,
|
|
136
|
+
maximum: QueryPoint,
|
|
137
|
+
options: SearchIndexOptions = {}
|
|
138
|
+
): IndexQueryResult<number[]> {
|
|
139
|
+
this.validateBounds(minimum, maximum);
|
|
140
|
+
const budget = new QueryBudget(options.maxWork);
|
|
141
|
+
const maxResults = validateLimit(options.maxResults);
|
|
142
|
+
const result: number[] = [];
|
|
143
|
+
const overlaps = (bounds: Float64Array, index: number): boolean => {
|
|
144
|
+
const start = index * this.dimension * 2;
|
|
145
|
+
for (let i = 0; i < this.dimension; i++) {
|
|
146
|
+
if (bounds[start + i] > maximum[i] || bounds[start + i + this.dimension] < minimum[i])
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
};
|
|
151
|
+
const stack = this.size ? [0] : [];
|
|
152
|
+
let complete = true;
|
|
153
|
+
search: while (stack.length) {
|
|
154
|
+
if (!budget.consume()) {
|
|
155
|
+
complete = false;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
const node = stack.pop();
|
|
159
|
+
if (!overlaps(this.nodeBounds, node)) continue;
|
|
160
|
+
if (this.counts[node]) {
|
|
161
|
+
for (let i = this.starts[node]; i < this.starts[node] + this.counts[node]; i++) {
|
|
162
|
+
if (!budget.consume()) {
|
|
163
|
+
complete = false;
|
|
164
|
+
break search;
|
|
165
|
+
}
|
|
166
|
+
const index = this.order[i];
|
|
167
|
+
if (overlaps(this.bounds, index) && (!options.filter || options.filter(index))) {
|
|
168
|
+
if (result.length === maxResults) {
|
|
169
|
+
complete = false;
|
|
170
|
+
break search;
|
|
171
|
+
}
|
|
172
|
+
result.push(index);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
} else stack.push(this.children[node * 2], this.children[node * 2 + 1]);
|
|
176
|
+
}
|
|
177
|
+
return {result: result.sort((a, b) => a - b), complete, work: budget.work};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Branch-and-bound nearest box, optionally refined against actual geometry. */
|
|
181
|
+
nearest(point: QueryPoint, options: NearestIndexOptions = {}): NearestIndexResult | null {
|
|
182
|
+
return this.nearestQuery(point, {...options, maxWork: Infinity}).result;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
nearestQuery(
|
|
186
|
+
point: QueryPoint,
|
|
187
|
+
options: NearestIndexOptions & IndexQueryBudget = {}
|
|
188
|
+
): IndexQueryResult<NearestIndexResult | null> {
|
|
189
|
+
return this.nearestBoxQuery(point, point, options);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Nearest indexed box to a filled query box, optionally refined to enclosed geometry. */
|
|
193
|
+
nearestBoxQuery(
|
|
194
|
+
minimum: QueryPoint,
|
|
195
|
+
maximum: QueryPoint,
|
|
196
|
+
options: NearestIndexOptions & IndexQueryBudget = {}
|
|
197
|
+
): IndexQueryResult<NearestIndexResult | null> {
|
|
198
|
+
this.validateBounds(minimum, maximum);
|
|
199
|
+
const budget = new QueryBudget(options.maxWork);
|
|
200
|
+
let best = options.maxDistance ?? Infinity;
|
|
201
|
+
validateQueryDistance(best);
|
|
202
|
+
let result: NearestIndexResult | null = null;
|
|
203
|
+
const distance = (bounds: Float64Array, index: number): number => {
|
|
204
|
+
const start = index * this.dimension * 2;
|
|
205
|
+
let x = 0,
|
|
206
|
+
y = 0,
|
|
207
|
+
z = 0;
|
|
208
|
+
x = Math.max(bounds[start] - maximum[0], 0, minimum[0] - bounds[start + this.dimension]);
|
|
209
|
+
y = Math.max(
|
|
210
|
+
bounds[start + 1] - maximum[1],
|
|
211
|
+
0,
|
|
212
|
+
minimum[1] - bounds[start + this.dimension + 1]
|
|
213
|
+
);
|
|
214
|
+
if (this.dimension === 3)
|
|
215
|
+
z = Math.max(bounds[start + 2] - maximum[2], 0, minimum[2] - bounds[start + 5]);
|
|
216
|
+
return Math.hypot(x, y, z);
|
|
217
|
+
};
|
|
218
|
+
const stack = this.size ? [0] : [];
|
|
219
|
+
let complete = true;
|
|
220
|
+
search: while (stack.length) {
|
|
221
|
+
if (!budget.consume()) {
|
|
222
|
+
complete = false;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
const node = stack.pop();
|
|
226
|
+
const nodeDistance = distance(this.nodeBounds, node);
|
|
227
|
+
if (nodeDistance > best + getDistanceTolerance(nodeDistance, best)) continue;
|
|
228
|
+
if (this.counts[node]) {
|
|
229
|
+
for (let i = this.starts[node]; i < this.starts[node] + this.counts[node]; i++) {
|
|
230
|
+
if (!budget.consume()) {
|
|
231
|
+
complete = false;
|
|
232
|
+
break search;
|
|
233
|
+
}
|
|
234
|
+
const index = this.order[i];
|
|
235
|
+
const lower = distance(this.bounds, index);
|
|
236
|
+
if (
|
|
237
|
+
lower > best + getDistanceTolerance(lower, best) ||
|
|
238
|
+
(options.filter && !options.filter(index))
|
|
239
|
+
)
|
|
240
|
+
continue;
|
|
241
|
+
const exact = options.distanceToItem ? options.distanceToItem(index) : lower;
|
|
242
|
+
if (exact === null) continue;
|
|
243
|
+
validateQueryDistance(exact);
|
|
244
|
+
if (
|
|
245
|
+
exact < lower &&
|
|
246
|
+
(!Number.isFinite(lower) || lower - exact > getDistanceTolerance(lower, exact))
|
|
247
|
+
)
|
|
248
|
+
throw new RangeError('Refinement distance cannot be below box distance');
|
|
249
|
+
if (
|
|
250
|
+
Number.isFinite(exact) &&
|
|
251
|
+
exact <= best &&
|
|
252
|
+
(!result || exact < best || index < result.index)
|
|
253
|
+
) {
|
|
254
|
+
best = exact;
|
|
255
|
+
result = {index, distance: exact};
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
const a = this.children[node * 2],
|
|
260
|
+
b = this.children[node * 2 + 1];
|
|
261
|
+
if (distance(this.nodeBounds, a) < distance(this.nodeBounds, b)) stack.push(b, a);
|
|
262
|
+
else stack.push(a, b);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return {result, complete, work: budget.work};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Nearest accepted box/geometry hit without materializing and sorting all ray candidates.
|
|
270
|
+
* Rejected refinements do not clip the ray. Equal distances select the lowest original row.
|
|
271
|
+
*/
|
|
272
|
+
intersectRay(
|
|
273
|
+
origin: QueryPoint,
|
|
274
|
+
direction: QueryPoint,
|
|
275
|
+
options: RayIndexOptions = {}
|
|
276
|
+
): NearestIndexResult | null {
|
|
277
|
+
return this.intersectRayQuery(origin, direction, {...options, maxWork: Infinity}).result;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
intersectRayQuery(
|
|
281
|
+
origin: QueryPoint,
|
|
282
|
+
direction: QueryPoint,
|
|
283
|
+
options: RayIndexOptions & IndexQueryBudget = {}
|
|
284
|
+
): IndexQueryResult<NearestIndexResult | null> {
|
|
285
|
+
validateQueryPoint(origin, this.dimension);
|
|
286
|
+
const budget = new QueryBudget(options.maxWork);
|
|
287
|
+
const unit = normalizeQueryDirection(direction, this.dimension);
|
|
288
|
+
let best = options.maxDistance ?? Infinity;
|
|
289
|
+
validateQueryDistance(best);
|
|
290
|
+
let result: NearestIndexResult | null = null;
|
|
291
|
+
const getEntry = (bounds: Float64Array, index: number): number | null => {
|
|
292
|
+
const offset = index * this.dimension * 2;
|
|
293
|
+
return intersectRayBounds(
|
|
294
|
+
origin,
|
|
295
|
+
unit,
|
|
296
|
+
bounds.subarray(offset, offset + this.dimension),
|
|
297
|
+
bounds.subarray(offset + this.dimension, offset + this.dimension * 2),
|
|
298
|
+
best + getDistanceTolerance(best, best)
|
|
299
|
+
);
|
|
300
|
+
};
|
|
301
|
+
// Defer the root bounds test until its visit, including for a zero work budget.
|
|
302
|
+
const stack = this.size ? [{index: 0, distance: 0}] : [];
|
|
303
|
+
let complete = true;
|
|
304
|
+
search: while (stack.length) {
|
|
305
|
+
if (!budget.consume()) {
|
|
306
|
+
complete = false;
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
const candidate = stack.pop();
|
|
310
|
+
if (!candidate || candidate.distance > best + getDistanceTolerance(candidate.distance, best))
|
|
311
|
+
continue;
|
|
312
|
+
const node = candidate.index;
|
|
313
|
+
if (node === 0 && getEntry(this.nodeBounds, node) === null) continue;
|
|
314
|
+
if (this.counts[node]) {
|
|
315
|
+
for (
|
|
316
|
+
let offset = this.starts[node];
|
|
317
|
+
offset < this.starts[node] + this.counts[node];
|
|
318
|
+
offset++
|
|
319
|
+
) {
|
|
320
|
+
if (!budget.consume()) {
|
|
321
|
+
complete = false;
|
|
322
|
+
break search;
|
|
323
|
+
}
|
|
324
|
+
const index = this.order[offset];
|
|
325
|
+
const lower = getEntry(this.bounds, index);
|
|
326
|
+
if (lower === null || (options.filter && !options.filter(index))) continue;
|
|
327
|
+
const exact = options.intersectItem ? options.intersectItem(index, best) : lower;
|
|
328
|
+
if (exact === null) continue;
|
|
329
|
+
validateQueryDistance(exact);
|
|
330
|
+
if (
|
|
331
|
+
exact < lower &&
|
|
332
|
+
(!Number.isFinite(lower) || lower - exact > getDistanceTolerance(lower, exact))
|
|
333
|
+
)
|
|
334
|
+
throw new RangeError('Refinement distance cannot be below box entry');
|
|
335
|
+
if (
|
|
336
|
+
Number.isFinite(exact) &&
|
|
337
|
+
exact <= best &&
|
|
338
|
+
(!result || exact < best || index < result.index)
|
|
339
|
+
) {
|
|
340
|
+
best = exact;
|
|
341
|
+
result = {index, distance: exact};
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
} else {
|
|
345
|
+
const first = this.children[node * 2],
|
|
346
|
+
second = this.children[node * 2 + 1];
|
|
347
|
+
const firstDistance = getEntry(this.nodeBounds, first),
|
|
348
|
+
secondDistance = getEntry(this.nodeBounds, second);
|
|
349
|
+
if (firstDistance !== null && secondDistance !== null) {
|
|
350
|
+
if (firstDistance <= secondDistance)
|
|
351
|
+
stack.push(
|
|
352
|
+
{index: second, distance: secondDistance},
|
|
353
|
+
{index: first, distance: firstDistance}
|
|
354
|
+
);
|
|
355
|
+
else
|
|
356
|
+
stack.push(
|
|
357
|
+
{index: first, distance: firstDistance},
|
|
358
|
+
{index: second, distance: secondDistance}
|
|
359
|
+
);
|
|
360
|
+
} else if (firstDistance !== null) stack.push({index: first, distance: firstDistance});
|
|
361
|
+
else if (secondDistance !== null) stack.push({index: second, distance: secondDistance});
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return {result, complete, work: budget.work};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** Broad-phase ray candidates, sorted by entry distance then original row index. */
|
|
368
|
+
searchRay(
|
|
369
|
+
origin: QueryPoint,
|
|
370
|
+
direction: QueryPoint,
|
|
371
|
+
maxDistance = Infinity
|
|
372
|
+
): NearestIndexResult[] {
|
|
373
|
+
validateQueryPoint(origin, this.dimension);
|
|
374
|
+
const unit = normalizeQueryDirection(direction, this.dimension);
|
|
375
|
+
validateQueryDistance(maxDistance);
|
|
376
|
+
const entry = (bounds: Float64Array, index: number): number | null => {
|
|
377
|
+
const start = index * this.dimension * 2;
|
|
378
|
+
return intersectRayBounds(
|
|
379
|
+
origin,
|
|
380
|
+
unit,
|
|
381
|
+
bounds.subarray(start, start + this.dimension),
|
|
382
|
+
bounds.subarray(start + this.dimension, start + this.dimension * 2),
|
|
383
|
+
maxDistance
|
|
384
|
+
);
|
|
385
|
+
};
|
|
386
|
+
const result: NearestIndexResult[] = [];
|
|
387
|
+
const stack = this.size ? [0] : [];
|
|
388
|
+
while (stack.length) {
|
|
389
|
+
const node = stack.pop();
|
|
390
|
+
if (entry(this.nodeBounds, node) === null) continue;
|
|
391
|
+
if (this.counts[node]) {
|
|
392
|
+
for (let i = this.starts[node]; i < this.starts[node] + this.counts[node]; i++) {
|
|
393
|
+
const index = this.order[i],
|
|
394
|
+
distance = entry(this.bounds, index);
|
|
395
|
+
if (distance !== null) result.push({index, distance});
|
|
396
|
+
}
|
|
397
|
+
} else stack.push(this.children[node * 2], this.children[node * 2 + 1]);
|
|
398
|
+
}
|
|
399
|
+
return result.sort((a, b) => a.distance - b.distance || a.index - b.index);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
private validateBounds(minimum: QueryPoint, maximum: QueryPoint): void {
|
|
403
|
+
validateQueryPoint(minimum, this.dimension);
|
|
404
|
+
validateQueryPoint(maximum, this.dimension);
|
|
405
|
+
for (let i = 0; i < this.dimension; i++) {
|
|
406
|
+
if (minimum[i] > maximum[i]) throw new RangeError('Bounds must be ordered');
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** Relative, unit-independent allowance for independently rounded slab and geometry kernels. */
|
|
412
|
+
function getDistanceTolerance(first: number, second: number): number {
|
|
413
|
+
return (
|
|
414
|
+
8 * Math.max(Number.MIN_VALUE, Number.EPSILON * Math.max(Math.abs(first), Math.abs(second)))
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function validateLimit(value = Infinity): number {
|
|
419
|
+
if (value !== Infinity && (!Number.isSafeInteger(value) || value < 0))
|
|
420
|
+
throw new RangeError('Query limits must be nonnegative safe integers or Infinity');
|
|
421
|
+
return value;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
class QueryBudget {
|
|
425
|
+
work = 0;
|
|
426
|
+
private readonly maximum: number;
|
|
427
|
+
constructor(maximum?: number) {
|
|
428
|
+
this.maximum = validateLimit(maximum);
|
|
429
|
+
}
|
|
430
|
+
consume(): boolean {
|
|
431
|
+
if (this.work === this.maximum) return false;
|
|
432
|
+
this.work++;
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** Points are zero-volume boxes: nearest gives exact Euclidean point distance. */
|
|
438
|
+
export class PointIndex extends BoxIndex {
|
|
439
|
+
constructor(options: {positions: ArrayLike<number>; dimension: 2 | 3; leafSize?: number}) {
|
|
440
|
+
const {positions, dimension, leafSize} = options;
|
|
441
|
+
if ((dimension !== 2 && dimension !== 3) || positions.length % dimension) {
|
|
442
|
+
throw new RangeError('Invalid point layout');
|
|
443
|
+
}
|
|
444
|
+
const bounds = new Float64Array(positions.length * 2);
|
|
445
|
+
for (let i = 0; i < positions.length / dimension; i++)
|
|
446
|
+
for (let axis = 0; axis < dimension; axis++) {
|
|
447
|
+
bounds[i * dimension * 2 + axis] = bounds[i * dimension * 2 + axis + dimension] =
|
|
448
|
+
positions[i * dimension + axis];
|
|
449
|
+
}
|
|
450
|
+
super({bounds, dimension, leafSize});
|
|
451
|
+
}
|
|
452
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
export {BoxIndex, PointIndex} from './box-index';
|
|
6
|
+
export type {
|
|
7
|
+
BoxIndexOptions,
|
|
8
|
+
NearestIndexOptions,
|
|
9
|
+
NearestIndexResult,
|
|
10
|
+
RayIndexOptions
|
|
11
|
+
} from './box-index';
|
|
12
|
+
export type {IndexQueryBudget, IndexQueryResult, SearchIndexOptions} from './box-index';
|
|
13
|
+
export {TriangleBVH} from './triangle-bvh';
|
|
14
|
+
export type {
|
|
15
|
+
TriangleBVHOptions,
|
|
16
|
+
TriangleQueryResult,
|
|
17
|
+
TriangleRayResult,
|
|
18
|
+
TriangleRayOptions
|
|
19
|
+
} from './triangle-bvh';
|
|
20
|
+
export type {TriangleNearestOptions, TriangleSegmentResult} from './triangle-bvh';
|