@math.gl/geometry 5.0.0-alpha.9 → 5.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +97 -49
- package/README.md +16 -1
- package/THIRD-PARTY-NOTICES.md +18 -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/index.cjs +2124 -0
- package/dist/culling/index.cjs.map +6 -0
- package/dist/culling/index.d.ts +31 -0
- package/dist/culling/index.d.ts.map +1 -0
- package/dist/culling/index.js +25 -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 +116 -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 +46 -0
- package/dist/culling/lib/culling-volume.d.ts.map +1 -0
- package/dist/culling/lib/culling-volume.js +126 -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 +13 -0
- package/dist/culling/lib/ray.d.ts.map +1 -0
- package/dist/culling/lib/ray.js +30 -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/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 +8 -0
- package/dist/curves/index.d.ts.map +1 -0
- package/dist/curves/index.js +9 -0
- package/dist/curves/index.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 +6105 -16
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -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/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 +14 -0
- package/dist/polygon/index.d.ts.map +1 -0
- package/dist/polygon/index.js +13 -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/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/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 +12 -4
- package/src/culling/constants.ts +6 -0
- package/src/culling/index.ts +55 -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 +153 -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 +163 -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 +33 -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/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 +15 -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 +179 -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/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 +42 -0
- package/src/polygon/lineclip.ts +218 -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/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,118 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright 2011-2018 CesiumJS Contributors
|
|
4
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
5
|
+
// SPDX-FileComment: Derived from Cesium. See the repository LICENSE for upstream attribution and Apache-2.0 terms.
|
|
6
|
+
|
|
7
|
+
// This file is derived from the Cesium math library under Apache 2 license
|
|
8
|
+
// See ../../../LICENSE for the retained Cesium notice and Apache-2.0 terms.
|
|
9
|
+
|
|
10
|
+
/* eslint-disable */
|
|
11
|
+
import {Vector3, equals, assert, NumericArray, _MathUtils} from '@math.gl/core';
|
|
12
|
+
import {Ray} from './ray';
|
|
13
|
+
|
|
14
|
+
const scratchPosition = new Vector3();
|
|
15
|
+
const scratchNormal = new Vector3();
|
|
16
|
+
|
|
17
|
+
// A plane in Hessian Normal Form
|
|
18
|
+
export class Plane {
|
|
19
|
+
readonly normal: Vector3;
|
|
20
|
+
distance: number;
|
|
21
|
+
|
|
22
|
+
constructor(normal: Readonly<NumericArray> = [0, 0, 1], distance: number = 0) {
|
|
23
|
+
this.normal = new Vector3();
|
|
24
|
+
this.distance = -0;
|
|
25
|
+
this.fromNormalDistance(normal, distance);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Creates a plane from a normal and a distance from the origin. */
|
|
29
|
+
fromNormalDistance(normal: Readonly<NumericArray>, distance: number): this {
|
|
30
|
+
assert(Number.isFinite(distance));
|
|
31
|
+
this.normal.from(normal).normalize();
|
|
32
|
+
this.distance = distance;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Creates a plane from a normal and a point on the plane. */
|
|
37
|
+
fromPointNormal(point: Readonly<NumericArray>, normal: Readonly<NumericArray>): this {
|
|
38
|
+
point = scratchPosition.from(point);
|
|
39
|
+
this.normal.from(normal).normalize();
|
|
40
|
+
const distance = -this.normal.dot(point);
|
|
41
|
+
this.distance = distance;
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Creates a plane from the general equation */
|
|
46
|
+
fromCoefficients(a: number, b: number, c: number, d: number): this {
|
|
47
|
+
this.normal.set(a, b, c);
|
|
48
|
+
assert(equals(this.normal.len(), 1));
|
|
49
|
+
this.distance = d;
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Duplicates a Plane instance. */
|
|
54
|
+
clone(): Plane {
|
|
55
|
+
return new Plane(this.normal, this.distance);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Compares the provided Planes by normal and distance */
|
|
59
|
+
equals(right: Plane): boolean {
|
|
60
|
+
return equals(this.distance, right.distance) && equals(this.normal, right.normal);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Computes the signed shortest distance of a point to a plane.
|
|
64
|
+
* The sign of the distance determines which side of the plane the point is on.
|
|
65
|
+
*/
|
|
66
|
+
getPointDistance(point: Readonly<NumericArray>): number {
|
|
67
|
+
return this.normal.dot(point) + this.distance;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Transforms the plane by the given transformation matrix. */
|
|
71
|
+
transform(matrix4: Readonly<NumericArray>): this {
|
|
72
|
+
const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();
|
|
73
|
+
const point = this.normal.scale(-this.distance).transform(matrix4);
|
|
74
|
+
return this.fromPointNormal(point, normal);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Projects a point onto the plane. */
|
|
78
|
+
projectPointOntoPlane(point: Readonly<NumericArray>, result: Vector3): Vector3;
|
|
79
|
+
projectPointOntoPlane(
|
|
80
|
+
point: Readonly<NumericArray>,
|
|
81
|
+
result?: readonly number[]
|
|
82
|
+
): readonly number[];
|
|
83
|
+
|
|
84
|
+
projectPointOntoPlane(point: Readonly<NumericArray>, result = [0, 0, 0]) {
|
|
85
|
+
const scratchPoint = scratchPosition.from(point);
|
|
86
|
+
// projectedPoint = point - (normal.point + scale) * normal
|
|
87
|
+
const pointDistance = this.getPointDistance(scratchPoint);
|
|
88
|
+
const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);
|
|
89
|
+
|
|
90
|
+
return scratchPoint.subtract(scaledNormal).to(result);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Computes the intersection of a ray and this plane.
|
|
95
|
+
*
|
|
96
|
+
* @param {Ray} ray The ray.
|
|
97
|
+
* @param {Vector3} [result] The object onto which to store the result.
|
|
98
|
+
* @returns {Vector3} The intersection point or undefined if there is no intersection.
|
|
99
|
+
*/
|
|
100
|
+
intersectWithRay(ray: Ray, result: Vector3 = new Vector3()): Vector3 | undefined {
|
|
101
|
+
const origin = ray.origin;
|
|
102
|
+
const direction = ray.direction;
|
|
103
|
+
const normal = this.normal;
|
|
104
|
+
const denominator = normal.dot(direction);
|
|
105
|
+
|
|
106
|
+
if (Math.abs(denominator) < _MathUtils.EPSILON15) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const t = (-this.distance - normal.dot(origin)) / denominator;
|
|
111
|
+
|
|
112
|
+
if (t < 0) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return result.copy(direction).multiplyByScalar(t).add(origin);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright 2011-2018 CesiumJS Contributors
|
|
4
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
5
|
+
// SPDX-FileComment: Derived from Cesium. See the repository LICENSE for upstream attribution and Apache-2.0 terms.
|
|
6
|
+
|
|
7
|
+
// This file is derived from the Cesium library under Apache 2 license
|
|
8
|
+
// See ../../../LICENSE for the retained Cesium notice and Apache-2.0 terms.
|
|
9
|
+
|
|
10
|
+
import {Vector3} from '@math.gl/core';
|
|
11
|
+
|
|
12
|
+
/* Represents a ray that extends infinitely from the provided origin in the provided direction. */
|
|
13
|
+
export class Ray {
|
|
14
|
+
origin: Vector3;
|
|
15
|
+
direction: Vector3;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new ray that extends infinitely from the provided origin in the provided direction.
|
|
19
|
+
*
|
|
20
|
+
* @param [origin=Vector3] The origin of the ray.
|
|
21
|
+
* @param [direction=Vector3] The direction of the ray.
|
|
22
|
+
*/
|
|
23
|
+
constructor(origin?: Vector3, direction?: Vector3) {
|
|
24
|
+
if (origin) origin = origin.clone();
|
|
25
|
+
else origin = new Vector3();
|
|
26
|
+
|
|
27
|
+
if (direction) direction = direction.clone().normalize();
|
|
28
|
+
else direction = new Vector3();
|
|
29
|
+
|
|
30
|
+
this.origin = origin;
|
|
31
|
+
this.direction = direction;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {ImplicitShapeBase, type ImplicitShape, type LocalRayIntersection} from './implicit-shape';
|
|
6
|
+
|
|
7
|
+
const EPSILON = 1e-6;
|
|
8
|
+
|
|
9
|
+
export type BoxShapeProps = {size?: readonly [number, number, number]; matrix?: readonly number[]};
|
|
10
|
+
|
|
11
|
+
/** Analytic glTF box shape. */
|
|
12
|
+
export class BoxShape extends ImplicitShapeBase {
|
|
13
|
+
readonly type = 'box' as const;
|
|
14
|
+
readonly size: readonly [number, number, number];
|
|
15
|
+
private readonly halfSize: readonly [number, number, number];
|
|
16
|
+
|
|
17
|
+
constructor(props: BoxShapeProps = {}) {
|
|
18
|
+
super(props.matrix);
|
|
19
|
+
this.size = props.size ? [...props.size] : [1, 1, 1];
|
|
20
|
+
if (this.size.some(value => !Number.isFinite(value) || value <= 0))
|
|
21
|
+
throw new Error('Box size values must be greater than zero');
|
|
22
|
+
this.halfSize = [this.size[0] / 2, this.size[1] / 2, this.size[2] / 2];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
clone(): BoxShape {
|
|
26
|
+
return new BoxShape({size: this.size, matrix: this.matrix});
|
|
27
|
+
}
|
|
28
|
+
override equals(shape: ImplicitShape): boolean {
|
|
29
|
+
return (
|
|
30
|
+
shape instanceof BoxShape &&
|
|
31
|
+
super.equals(shape) &&
|
|
32
|
+
this.size.every((value, i) => value === shape.size[i])
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
containsLocalPoint(point: readonly number[]): boolean {
|
|
36
|
+
return point.every((value, i) => Math.abs(value) <= this.halfSize[i] + EPSILON);
|
|
37
|
+
}
|
|
38
|
+
distanceToLocalPoint(point: readonly number[]): number {
|
|
39
|
+
return Math.hypot(...point.map((value, i) => Math.max(0, Math.abs(value) - this.halfSize[i])));
|
|
40
|
+
}
|
|
41
|
+
supportLocal(direction: readonly number[]): readonly number[] {
|
|
42
|
+
return direction.map((value, i) => (value < 0 ? -this.halfSize[i] : this.halfSize[i]));
|
|
43
|
+
}
|
|
44
|
+
intersectLocalRay(
|
|
45
|
+
origin: readonly number[],
|
|
46
|
+
direction: readonly number[]
|
|
47
|
+
): LocalRayIntersection | undefined {
|
|
48
|
+
let near = -Infinity;
|
|
49
|
+
let far = Infinity;
|
|
50
|
+
let nearAxis = 0;
|
|
51
|
+
let farAxis = 0;
|
|
52
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
53
|
+
if (Math.abs(direction[axis]) < 1e-15) {
|
|
54
|
+
if (Math.abs(origin[axis]) > this.halfSize[axis]) return undefined;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
let t1 = (-this.halfSize[axis] - origin[axis]) / direction[axis];
|
|
58
|
+
let t2 = (this.halfSize[axis] - origin[axis]) / direction[axis];
|
|
59
|
+
if (t1 > t2) [t1, t2] = [t2, t1];
|
|
60
|
+
if (t1 > near) {
|
|
61
|
+
near = t1;
|
|
62
|
+
nearAxis = axis;
|
|
63
|
+
}
|
|
64
|
+
if (t2 < far) {
|
|
65
|
+
far = t2;
|
|
66
|
+
farAxis = axis;
|
|
67
|
+
}
|
|
68
|
+
if (near > far) return undefined;
|
|
69
|
+
}
|
|
70
|
+
const distance = near >= 0 ? near : far;
|
|
71
|
+
if (distance < 0 || !Number.isFinite(distance)) return undefined;
|
|
72
|
+
const axis = near >= 0 ? nearAxis : farAxis;
|
|
73
|
+
const pointCoordinate = origin[axis] + distance * direction[axis];
|
|
74
|
+
const normal = [0, 0, 0];
|
|
75
|
+
normal[axis] = pointCoordinate < 0 ? -1 : 1;
|
|
76
|
+
return {distance, normal};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
closestDistanceToCircleArc2D,
|
|
7
|
+
closestDistanceToSegment2D,
|
|
8
|
+
ImplicitShapeBase,
|
|
9
|
+
solveQuadratic,
|
|
10
|
+
type ImplicitShape,
|
|
11
|
+
type LocalRayIntersection
|
|
12
|
+
} from './implicit-shape';
|
|
13
|
+
|
|
14
|
+
const EPSILON = 1e-6;
|
|
15
|
+
|
|
16
|
+
export type CapsuleShapeProps = {
|
|
17
|
+
height?: number;
|
|
18
|
+
radiusBottom?: number;
|
|
19
|
+
radiusTop?: number;
|
|
20
|
+
matrix?: readonly number[];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Analytic glTF capsule: the convex hull of two spheres on the Y axis. */
|
|
24
|
+
export class CapsuleShape extends ImplicitShapeBase {
|
|
25
|
+
readonly type = 'capsule' as const;
|
|
26
|
+
readonly height: number;
|
|
27
|
+
readonly radiusBottom: number;
|
|
28
|
+
readonly radiusTop: number;
|
|
29
|
+
|
|
30
|
+
constructor(props: CapsuleShapeProps = {}) {
|
|
31
|
+
super(props.matrix);
|
|
32
|
+
this.height = props.height ?? 1;
|
|
33
|
+
this.radiusBottom = props.radiusBottom ?? 0.5;
|
|
34
|
+
this.radiusTop = props.radiusTop ?? 0.5;
|
|
35
|
+
if (!Number.isFinite(this.height) || this.height <= 0)
|
|
36
|
+
throw new Error('Capsule height must be greater than zero');
|
|
37
|
+
if (![this.radiusBottom, this.radiusTop].every(value => Number.isFinite(value) && value >= 0))
|
|
38
|
+
throw new Error('Capsule radii must be non-negative');
|
|
39
|
+
if (this.radiusBottom === 0 && this.radiusTop === 0)
|
|
40
|
+
throw new Error('At least one capsule radius must be greater than zero');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
clone(): CapsuleShape {
|
|
44
|
+
return new CapsuleShape({
|
|
45
|
+
height: this.height,
|
|
46
|
+
radiusBottom: this.radiusBottom,
|
|
47
|
+
radiusTop: this.radiusTop,
|
|
48
|
+
matrix: this.matrix
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
override equals(shape: ImplicitShape): boolean {
|
|
52
|
+
return (
|
|
53
|
+
shape instanceof CapsuleShape &&
|
|
54
|
+
super.equals(shape) &&
|
|
55
|
+
this.height === shape.height &&
|
|
56
|
+
this.radiusBottom === shape.radiusBottom &&
|
|
57
|
+
this.radiusTop === shape.radiusTop
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
containsLocalPoint(point: readonly number[]): boolean {
|
|
61
|
+
const profile = this.getProfile();
|
|
62
|
+
const radial = Math.hypot(point[0], point[2]);
|
|
63
|
+
if (profile.sphere)
|
|
64
|
+
return (
|
|
65
|
+
Math.hypot(radial, point[1] - profile.sphere.center) <= profile.sphere.radius + EPSILON
|
|
66
|
+
);
|
|
67
|
+
if (point[1] < profile.bottom.y)
|
|
68
|
+
return Math.hypot(radial, point[1] + this.height / 2) <= this.radiusBottom + EPSILON;
|
|
69
|
+
if (point[1] > profile.top.y)
|
|
70
|
+
return Math.hypot(radial, point[1] - this.height / 2) <= this.radiusTop + EPSILON;
|
|
71
|
+
const t = (point[1] - profile.bottom.y) / (profile.top.y - profile.bottom.y);
|
|
72
|
+
return (
|
|
73
|
+
radial <= profile.bottom.radius + (profile.top.radius - profile.bottom.radius) * t + EPSILON
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
distanceToLocalPoint(point: readonly number[]): number {
|
|
77
|
+
if (this.containsLocalPoint(point)) return 0;
|
|
78
|
+
const profile = this.getProfile();
|
|
79
|
+
const radial = Math.hypot(point[0], point[2]);
|
|
80
|
+
if (profile.sphere)
|
|
81
|
+
return Math.max(
|
|
82
|
+
0,
|
|
83
|
+
Math.hypot(radial, point[1] - profile.sphere.center) - profile.sphere.radius
|
|
84
|
+
);
|
|
85
|
+
const delta = this.radiusTop - this.radiusBottom;
|
|
86
|
+
const sideNormalY = -delta / this.height;
|
|
87
|
+
const bottomArc = closestDistanceToCircleArc2D(
|
|
88
|
+
radial,
|
|
89
|
+
point[1],
|
|
90
|
+
-this.height / 2,
|
|
91
|
+
this.radiusBottom,
|
|
92
|
+
-1,
|
|
93
|
+
sideNormalY
|
|
94
|
+
);
|
|
95
|
+
const topArc = closestDistanceToCircleArc2D(
|
|
96
|
+
radial,
|
|
97
|
+
point[1],
|
|
98
|
+
this.height / 2,
|
|
99
|
+
this.radiusTop,
|
|
100
|
+
sideNormalY,
|
|
101
|
+
1
|
|
102
|
+
);
|
|
103
|
+
const side = closestDistanceToSegment2D(
|
|
104
|
+
radial,
|
|
105
|
+
point[1],
|
|
106
|
+
profile.bottom.radius,
|
|
107
|
+
profile.bottom.y,
|
|
108
|
+
profile.top.radius,
|
|
109
|
+
profile.top.y
|
|
110
|
+
);
|
|
111
|
+
return Math.min(bottomArc, topArc, side);
|
|
112
|
+
}
|
|
113
|
+
supportLocal(direction: readonly number[]): readonly number[] {
|
|
114
|
+
const length = Math.hypot(...direction);
|
|
115
|
+
const unit = length ? direction.map(value => value / length) : [1, 0, 0];
|
|
116
|
+
const bottom = [
|
|
117
|
+
unit[0] * this.radiusBottom,
|
|
118
|
+
-this.height / 2 + unit[1] * this.radiusBottom,
|
|
119
|
+
unit[2] * this.radiusBottom
|
|
120
|
+
];
|
|
121
|
+
const top = [
|
|
122
|
+
unit[0] * this.radiusTop,
|
|
123
|
+
this.height / 2 + unit[1] * this.radiusTop,
|
|
124
|
+
unit[2] * this.radiusTop
|
|
125
|
+
];
|
|
126
|
+
return dot(top, direction) >= dot(bottom, direction) ? top : bottom;
|
|
127
|
+
}
|
|
128
|
+
intersectLocalRay(
|
|
129
|
+
origin: readonly number[],
|
|
130
|
+
direction: readonly number[]
|
|
131
|
+
): LocalRayIntersection | undefined {
|
|
132
|
+
const profile = this.getProfile();
|
|
133
|
+
if (profile.sphere)
|
|
134
|
+
return intersectSphere(origin, direction, profile.sphere.center, profile.sphere.radius);
|
|
135
|
+
const candidates: LocalRayIntersection[] = [];
|
|
136
|
+
const slope = (profile.top.radius - profile.bottom.radius) / (profile.top.y - profile.bottom.y);
|
|
137
|
+
const intercept = profile.bottom.radius - slope * profile.bottom.y;
|
|
138
|
+
const radialAtOrigin = intercept + slope * origin[1];
|
|
139
|
+
const radialAlongRay = slope * direction[1];
|
|
140
|
+
for (const distance of solveQuadratic(
|
|
141
|
+
direction[0] ** 2 + direction[2] ** 2 - radialAlongRay ** 2,
|
|
142
|
+
2 * (origin[0] * direction[0] + origin[2] * direction[2] - radialAtOrigin * radialAlongRay),
|
|
143
|
+
origin[0] ** 2 + origin[2] ** 2 - radialAtOrigin ** 2
|
|
144
|
+
)) {
|
|
145
|
+
const y = origin[1] + distance * direction[1];
|
|
146
|
+
if (distance >= 0 && y >= profile.bottom.y - EPSILON && y <= profile.top.y + EPSILON) {
|
|
147
|
+
const x = origin[0] + distance * direction[0];
|
|
148
|
+
const z = origin[2] + distance * direction[2];
|
|
149
|
+
const radial = Math.hypot(x, z) || 1;
|
|
150
|
+
const normal = [x / radial, -slope, z / radial];
|
|
151
|
+
const length = Math.hypot(...normal);
|
|
152
|
+
candidates.push({distance, normal: normal.map(value => value / length)});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
for (const bottomHit of intersectSphereRoots(
|
|
156
|
+
origin,
|
|
157
|
+
direction,
|
|
158
|
+
-this.height / 2,
|
|
159
|
+
this.radiusBottom
|
|
160
|
+
)) {
|
|
161
|
+
const y = origin[1] + bottomHit.distance * direction[1];
|
|
162
|
+
if (y <= profile.bottom.y + EPSILON) candidates.push(bottomHit);
|
|
163
|
+
}
|
|
164
|
+
for (const topHit of intersectSphereRoots(origin, direction, this.height / 2, this.radiusTop)) {
|
|
165
|
+
const y = origin[1] + topHit.distance * direction[1];
|
|
166
|
+
if (y >= profile.top.y - EPSILON) candidates.push(topHit);
|
|
167
|
+
}
|
|
168
|
+
return candidates.sort((a, b) => a.distance - b.distance)[0];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private getProfile(): {
|
|
172
|
+
sphere?: {center: number; radius: number};
|
|
173
|
+
bottom: {radius: number; y: number};
|
|
174
|
+
top: {radius: number; y: number};
|
|
175
|
+
} {
|
|
176
|
+
const delta = this.radiusTop - this.radiusBottom;
|
|
177
|
+
if (Math.abs(delta) >= this.height) {
|
|
178
|
+
const topWins = this.radiusTop >= this.radiusBottom;
|
|
179
|
+
return {
|
|
180
|
+
sphere: {
|
|
181
|
+
center: topWins ? this.height / 2 : -this.height / 2,
|
|
182
|
+
radius: topWins ? this.radiusTop : this.radiusBottom
|
|
183
|
+
},
|
|
184
|
+
bottom: {radius: 0, y: 0},
|
|
185
|
+
top: {radius: 0, y: 0}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const sinSlope = delta / this.height;
|
|
189
|
+
const radialNormal = Math.sqrt(1 - sinSlope * sinSlope);
|
|
190
|
+
const normalY = -sinSlope;
|
|
191
|
+
return {
|
|
192
|
+
bottom: {
|
|
193
|
+
radius: this.radiusBottom * radialNormal,
|
|
194
|
+
y: -this.height / 2 + this.radiusBottom * normalY
|
|
195
|
+
},
|
|
196
|
+
top: {radius: this.radiusTop * radialNormal, y: this.height / 2 + this.radiusTop * normalY}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function intersectSphere(
|
|
202
|
+
origin: readonly number[],
|
|
203
|
+
direction: readonly number[],
|
|
204
|
+
centerY: number,
|
|
205
|
+
radius: number
|
|
206
|
+
): LocalRayIntersection | undefined {
|
|
207
|
+
return intersectSphereRoots(origin, direction, centerY, radius)[0];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function intersectSphereRoots(
|
|
211
|
+
origin: readonly number[],
|
|
212
|
+
direction: readonly number[],
|
|
213
|
+
centerY: number,
|
|
214
|
+
radius: number
|
|
215
|
+
): LocalRayIntersection[] {
|
|
216
|
+
if (radius === 0) return [];
|
|
217
|
+
const relative = [origin[0], origin[1] - centerY, origin[2]];
|
|
218
|
+
return solveQuadratic(
|
|
219
|
+
dot(direction, direction),
|
|
220
|
+
2 * dot(relative, direction),
|
|
221
|
+
dot(relative, relative) - radius * radius
|
|
222
|
+
)
|
|
223
|
+
.filter(distance => distance >= 0)
|
|
224
|
+
.map(distance => ({
|
|
225
|
+
distance,
|
|
226
|
+
normal: relative.map((value, i) => (value + distance * direction[i]) / radius)
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function dot(a: readonly number[], b: readonly number[]): number {
|
|
231
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
232
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
closestDistanceToSegment2D,
|
|
7
|
+
ImplicitShapeBase,
|
|
8
|
+
solveQuadratic,
|
|
9
|
+
type ImplicitShape,
|
|
10
|
+
type LocalRayIntersection
|
|
11
|
+
} from './implicit-shape';
|
|
12
|
+
|
|
13
|
+
const EPSILON = 1e-6;
|
|
14
|
+
|
|
15
|
+
export type CylinderShapeProps = {
|
|
16
|
+
height?: number;
|
|
17
|
+
radiusBottom?: number;
|
|
18
|
+
radiusTop?: number;
|
|
19
|
+
matrix?: readonly number[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Analytic closed, Y-aligned glTF cylinder shape, including tapered cylinders. */
|
|
23
|
+
export class CylinderShape extends ImplicitShapeBase {
|
|
24
|
+
readonly type = 'cylinder' as const;
|
|
25
|
+
readonly height: number;
|
|
26
|
+
readonly radiusBottom: number;
|
|
27
|
+
readonly radiusTop: number;
|
|
28
|
+
|
|
29
|
+
constructor(props: CylinderShapeProps = {}) {
|
|
30
|
+
super(props.matrix);
|
|
31
|
+
this.height = props.height ?? 2;
|
|
32
|
+
this.radiusBottom = props.radiusBottom ?? 0.5;
|
|
33
|
+
this.radiusTop = props.radiusTop ?? 0.5;
|
|
34
|
+
if (!Number.isFinite(this.height) || this.height <= 0)
|
|
35
|
+
throw new Error('Cylinder height must be greater than zero');
|
|
36
|
+
if (![this.radiusBottom, this.radiusTop].every(value => Number.isFinite(value) && value >= 0))
|
|
37
|
+
throw new Error('Cylinder radii must be non-negative');
|
|
38
|
+
if (this.radiusBottom === 0 && this.radiusTop === 0)
|
|
39
|
+
throw new Error('At least one cylinder radius must be greater than zero');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
clone(): CylinderShape {
|
|
43
|
+
return new CylinderShape({
|
|
44
|
+
height: this.height,
|
|
45
|
+
radiusBottom: this.radiusBottom,
|
|
46
|
+
radiusTop: this.radiusTop,
|
|
47
|
+
matrix: this.matrix
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
override equals(shape: ImplicitShape): boolean {
|
|
51
|
+
return (
|
|
52
|
+
shape instanceof CylinderShape &&
|
|
53
|
+
super.equals(shape) &&
|
|
54
|
+
this.height === shape.height &&
|
|
55
|
+
this.radiusBottom === shape.radiusBottom &&
|
|
56
|
+
this.radiusTop === shape.radiusTop
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
containsLocalPoint(point: readonly number[]): boolean {
|
|
60
|
+
const half = this.height / 2;
|
|
61
|
+
if (point[1] < -half - EPSILON || point[1] > half + EPSILON) return false;
|
|
62
|
+
const t = (point[1] + half) / this.height;
|
|
63
|
+
const radius = this.radiusBottom + (this.radiusTop - this.radiusBottom) * t;
|
|
64
|
+
return Math.hypot(point[0], point[2]) <= radius + EPSILON;
|
|
65
|
+
}
|
|
66
|
+
distanceToLocalPoint(point: readonly number[]): number {
|
|
67
|
+
if (this.containsLocalPoint(point)) return 0;
|
|
68
|
+
const radial = Math.hypot(point[0], point[2]);
|
|
69
|
+
const half = this.height / 2;
|
|
70
|
+
const side = closestDistanceToSegment2D(
|
|
71
|
+
radial,
|
|
72
|
+
point[1],
|
|
73
|
+
this.radiusBottom,
|
|
74
|
+
-half,
|
|
75
|
+
this.radiusTop,
|
|
76
|
+
half
|
|
77
|
+
);
|
|
78
|
+
const bottom = closestDistanceToSegment2D(radial, point[1], 0, -half, this.radiusBottom, -half);
|
|
79
|
+
const top = closestDistanceToSegment2D(radial, point[1], 0, half, this.radiusTop, half);
|
|
80
|
+
return Math.min(side, bottom, top);
|
|
81
|
+
}
|
|
82
|
+
supportLocal(direction: readonly number[]): readonly number[] {
|
|
83
|
+
const radialLength = Math.hypot(direction[0], direction[2]);
|
|
84
|
+
const x = radialLength ? direction[0] / radialLength : 1;
|
|
85
|
+
const z = radialLength ? direction[2] / radialLength : 0;
|
|
86
|
+
const half = this.height / 2;
|
|
87
|
+
const bottomValue = radialLength * this.radiusBottom - direction[1] * half;
|
|
88
|
+
const topValue = radialLength * this.radiusTop + direction[1] * half;
|
|
89
|
+
return topValue >= bottomValue
|
|
90
|
+
? [x * this.radiusTop, half, z * this.radiusTop]
|
|
91
|
+
: [x * this.radiusBottom, -half, z * this.radiusBottom];
|
|
92
|
+
}
|
|
93
|
+
intersectLocalRay(
|
|
94
|
+
origin: readonly number[],
|
|
95
|
+
direction: readonly number[]
|
|
96
|
+
): LocalRayIntersection | undefined {
|
|
97
|
+
const half = this.height / 2;
|
|
98
|
+
const slope = (this.radiusTop - this.radiusBottom) / this.height;
|
|
99
|
+
const intercept = (this.radiusTop + this.radiusBottom) / 2;
|
|
100
|
+
const radialAtOrigin = intercept + slope * origin[1];
|
|
101
|
+
const radialAlongRay = slope * direction[1];
|
|
102
|
+
const candidates: LocalRayIntersection[] = [];
|
|
103
|
+
const roots = solveQuadratic(
|
|
104
|
+
direction[0] ** 2 + direction[2] ** 2 - radialAlongRay ** 2,
|
|
105
|
+
2 * (origin[0] * direction[0] + origin[2] * direction[2] - radialAtOrigin * radialAlongRay),
|
|
106
|
+
origin[0] ** 2 + origin[2] ** 2 - radialAtOrigin ** 2
|
|
107
|
+
);
|
|
108
|
+
for (const distance of roots) {
|
|
109
|
+
const y = origin[1] + distance * direction[1];
|
|
110
|
+
if (distance >= 0 && y >= -half - EPSILON && y <= half + EPSILON) {
|
|
111
|
+
const x = origin[0] + distance * direction[0];
|
|
112
|
+
const z = origin[2] + distance * direction[2];
|
|
113
|
+
const radial = Math.hypot(x, z) || 1;
|
|
114
|
+
const normal = [x / radial, -slope, z / radial];
|
|
115
|
+
const length = Math.hypot(...normal);
|
|
116
|
+
candidates.push({distance, normal: normal.map(value => value / length)});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (Math.abs(direction[1]) > 1e-15) {
|
|
120
|
+
for (const [y, radius, normalY] of [
|
|
121
|
+
[-half, this.radiusBottom, -1],
|
|
122
|
+
[half, this.radiusTop, 1]
|
|
123
|
+
]) {
|
|
124
|
+
const distance = (y - origin[1]) / direction[1];
|
|
125
|
+
const x = origin[0] + distance * direction[0];
|
|
126
|
+
const z = origin[2] + distance * direction[2];
|
|
127
|
+
if (distance >= 0 && Math.hypot(x, z) <= radius + EPSILON)
|
|
128
|
+
candidates.push({distance, normal: [0, normalY, 0]});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return candidates.sort((a, b) => a.distance - b.distance)[0];
|
|
132
|
+
}
|
|
133
|
+
}
|