@math.gl/geometry 5.0.0-alpha.9 → 5.0.0-beta.1
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 +5867 -16
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -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 +627 -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 +68 -0
- package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -0
- package/dist/polygon/subdivide-triangle-mesh.js +228 -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/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/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 +175 -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 +798 -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 +322 -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/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/rgb565.ts +26 -0
- package/src/utils/typed-array-utils.ts +16 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {NumericArray} from '@math.gl/core';
|
|
6
|
+
import {Curve, copyPoints, type CurvePoint} from './curve';
|
|
7
|
+
import {HermiteCurve} from './hermite-curve';
|
|
8
|
+
|
|
9
|
+
export type CatmullRomCurveOptions = {
|
|
10
|
+
closed?: boolean;
|
|
11
|
+
parameterization?: 'centripetal' | 'chordal' | 'uniform';
|
|
12
|
+
/** Uniform splines only. Default 0.5; zero gives stationary knot tangents. */
|
|
13
|
+
tension?: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export class CatmullRomCurve extends Curve {
|
|
17
|
+
readonly closed: boolean;
|
|
18
|
+
private readonly segments: HermiteCurve[];
|
|
19
|
+
|
|
20
|
+
constructor(points: readonly CurvePoint[], options: CatmullRomCurveOptions = {}) {
|
|
21
|
+
const data = copyPoints(points);
|
|
22
|
+
super(data[0].length);
|
|
23
|
+
this.closed = options.closed ?? false;
|
|
24
|
+
if (data.length < (this.closed ? 3 : 2)) throw new RangeError('Not enough spline points');
|
|
25
|
+
const mode = options.parameterization ?? 'centripetal';
|
|
26
|
+
if (!['centripetal', 'chordal', 'uniform'].includes(mode)) {
|
|
27
|
+
throw new RangeError('Unknown Catmull-Rom parameterization');
|
|
28
|
+
}
|
|
29
|
+
const tension = options.tension ?? 0.5;
|
|
30
|
+
if (!Number.isFinite(tension) || tension < 0 || tension > 1) {
|
|
31
|
+
throw new RangeError('tension must be in [0, 1]');
|
|
32
|
+
}
|
|
33
|
+
if (options.tension !== undefined && mode !== 'uniform') {
|
|
34
|
+
throw new RangeError('tension is only supported for uniform splines');
|
|
35
|
+
}
|
|
36
|
+
const point = (index: number): number[] => {
|
|
37
|
+
if (this.closed) return data[(index + data.length) % data.length];
|
|
38
|
+
if (index < 0) return data[0].map((x, i) => 2 * x - data[1][i]);
|
|
39
|
+
if (index >= data.length) {
|
|
40
|
+
return data[data.length - 1].map((x, i) => 2 * x - data[data.length - 2][i]);
|
|
41
|
+
}
|
|
42
|
+
return data[index];
|
|
43
|
+
};
|
|
44
|
+
this.segments = [];
|
|
45
|
+
for (let s = 0; s < data.length - (this.closed ? 0 : 1); s++) {
|
|
46
|
+
const p0 = point(s - 1);
|
|
47
|
+
const p1 = point(s);
|
|
48
|
+
const p2 = point(s + 1);
|
|
49
|
+
const p3 = point(s + 2);
|
|
50
|
+
const interval = (a: number[], b: number[]): number => {
|
|
51
|
+
const distance = Math.hypot(...a.map((x, i) => b[i] - x));
|
|
52
|
+
return distance ** (mode === 'chordal' ? 1 : 0.5);
|
|
53
|
+
};
|
|
54
|
+
const d1 = interval(p1, p2);
|
|
55
|
+
if (mode !== 'uniform' && d1 === 0) {
|
|
56
|
+
// A repeated knot is a stationary segment, rather than a spurious loop.
|
|
57
|
+
const zero = new Array<number>(this.dimension).fill(0);
|
|
58
|
+
this.segments.push(new HermiteCurve(p1, p2, zero, zero));
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
// Reuse the current interval for coincident neighbors. This is scale invariant.
|
|
62
|
+
const d0 = interval(p0, p1) || d1;
|
|
63
|
+
const d2 = interval(p2, p3) || d1;
|
|
64
|
+
const m1 = p1.map((x, i) =>
|
|
65
|
+
mode === 'uniform'
|
|
66
|
+
? tension * (p2[i] - p0[i])
|
|
67
|
+
: d1 * ((x - p0[i]) / d0 - (p2[i] - p0[i]) / (d0 + d1) + (p2[i] - x) / d1)
|
|
68
|
+
);
|
|
69
|
+
const m2 = p2.map((x, i) =>
|
|
70
|
+
mode === 'uniform'
|
|
71
|
+
? tension * (p3[i] - p1[i])
|
|
72
|
+
: d1 * ((x - p1[i]) / d1 - (p3[i] - p1[i]) / (d1 + d2) + (p3[i] - x) / d2)
|
|
73
|
+
);
|
|
74
|
+
this.segments.push(new HermiteCurve(p1, p2, m1, m2));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
protected evaluate(t: number, result: NumericArray, derivative: boolean): void {
|
|
79
|
+
const scaled = t * this.segments.length;
|
|
80
|
+
const index = Math.min(Math.floor(scaled), this.segments.length - 1);
|
|
81
|
+
const local = scaled - index;
|
|
82
|
+
if (derivative) {
|
|
83
|
+
this.segments[index].getDerivative(local, result);
|
|
84
|
+
for (let i = 0; i < this.dimension; i++) result[i] *= this.segments.length;
|
|
85
|
+
} else {
|
|
86
|
+
this.segments[index].getPoint(local, result);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {NumericArray} from '@math.gl/core';
|
|
6
|
+
import {Curve, validateDivisions, validateParameter} from './curve';
|
|
7
|
+
|
|
8
|
+
/** Reusable polyline approximation to a curve's cumulative arc length. */
|
|
9
|
+
export class CurveArcLength {
|
|
10
|
+
readonly curve: Curve;
|
|
11
|
+
readonly divisions: number;
|
|
12
|
+
readonly length: number;
|
|
13
|
+
private readonly cumulativeLengths: Float64Array;
|
|
14
|
+
|
|
15
|
+
constructor(curve: Curve, divisions = 1024) {
|
|
16
|
+
validateDivisions(divisions);
|
|
17
|
+
this.curve = curve;
|
|
18
|
+
this.divisions = divisions;
|
|
19
|
+
this.cumulativeLengths = new Float64Array(divisions + 1);
|
|
20
|
+
let previous = curve.getPoint(0);
|
|
21
|
+
let current = new Array<number>(curve.dimension);
|
|
22
|
+
let length = 0;
|
|
23
|
+
for (let i = 1; i <= divisions; i++) {
|
|
24
|
+
curve.getPoint(i / divisions, current);
|
|
25
|
+
length += Math.hypot(
|
|
26
|
+
current[0] - previous[0],
|
|
27
|
+
current[1] - previous[1],
|
|
28
|
+
curve.dimension === 3 ? current[2] - previous[2] : 0
|
|
29
|
+
);
|
|
30
|
+
if (!Number.isFinite(length)) throw new RangeError('Curve arc length must be finite');
|
|
31
|
+
this.cumulativeLengths[i] = length;
|
|
32
|
+
[previous, current] = [current, previous];
|
|
33
|
+
}
|
|
34
|
+
this.length = length;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Map a fraction of total length to t, preserving endpoints and zero-length curves. */
|
|
38
|
+
getParameterAt(u: number): number {
|
|
39
|
+
validateParameter(u);
|
|
40
|
+
if (u === 0 || u === 1 || this.length === 0) return u;
|
|
41
|
+
const target = u * this.length;
|
|
42
|
+
let low = 0;
|
|
43
|
+
let high = this.divisions;
|
|
44
|
+
while (low + 1 < high) {
|
|
45
|
+
const middle = Math.floor((low + high) / 2);
|
|
46
|
+
if (this.cumulativeLengths[middle] <= target) low = middle;
|
|
47
|
+
else high = middle;
|
|
48
|
+
}
|
|
49
|
+
const span = this.cumulativeLengths[high] - this.cumulativeLengths[low];
|
|
50
|
+
return (low + (span > 0 ? (target - this.cumulativeLengths[low]) / span : 0)) / this.divisions;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getPointAt(u: number): number[];
|
|
54
|
+
getPointAt<T extends NumericArray>(u: number, result: T): T;
|
|
55
|
+
getPointAt(u: number, result: NumericArray = new Array(this.curve.dimension)): NumericArray {
|
|
56
|
+
return this.curve.getPoint(this.getParameterAt(u), result);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Flat samples at approximately equal distances along the curve. */
|
|
60
|
+
getSpacedPoints(divisions = 64): Float64Array {
|
|
61
|
+
validateDivisions(divisions);
|
|
62
|
+
const points = new Float64Array((divisions + 1) * this.curve.dimension);
|
|
63
|
+
const point = new Array<number>(this.curve.dimension);
|
|
64
|
+
for (let i = 0; i <= divisions; i++) {
|
|
65
|
+
this.getPointAt(i / divisions, point);
|
|
66
|
+
points.set(point, i * this.curve.dimension);
|
|
67
|
+
}
|
|
68
|
+
return points;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {NumericArray} from '@math.gl/core';
|
|
6
|
+
|
|
7
|
+
export type CurvePoint = Readonly<ArrayLike<number>>;
|
|
8
|
+
|
|
9
|
+
/** Parameterized Euclidean curve, with t in [0, 1]. */
|
|
10
|
+
export abstract class Curve {
|
|
11
|
+
readonly dimension: number;
|
|
12
|
+
|
|
13
|
+
protected constructor(dimension: number) {
|
|
14
|
+
if (dimension !== 2 && dimension !== 3) {
|
|
15
|
+
throw new RangeError('Curve points must have two or three coordinates');
|
|
16
|
+
}
|
|
17
|
+
this.dimension = dimension;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getPoint(t: number): number[];
|
|
21
|
+
getPoint<T extends NumericArray>(t: number, result: T): T;
|
|
22
|
+
getPoint(t: number, result: NumericArray = new Array(this.dimension)): NumericArray {
|
|
23
|
+
validateParameter(t);
|
|
24
|
+
validateResult(result, this.dimension);
|
|
25
|
+
this.evaluate(t, result, false);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Derivative with respect to the normalized curve parameter t. */
|
|
30
|
+
getDerivative(t: number): number[];
|
|
31
|
+
getDerivative<T extends NumericArray>(t: number, result: T): T;
|
|
32
|
+
getDerivative(t: number, result: NumericArray = new Array(this.dimension)): NumericArray {
|
|
33
|
+
validateParameter(t);
|
|
34
|
+
validateResult(result, this.dimension);
|
|
35
|
+
this.evaluate(t, result, true);
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Unit tangent; returns a zero vector at stationary points. */
|
|
40
|
+
getTangent(t: number): number[];
|
|
41
|
+
getTangent<T extends NumericArray>(t: number, result: T): T;
|
|
42
|
+
getTangent(t: number, result: NumericArray = new Array(this.dimension)): NumericArray {
|
|
43
|
+
this.getDerivative(t, result);
|
|
44
|
+
const length = Math.hypot(result[0], result[1], this.dimension === 3 ? result[2] : 0);
|
|
45
|
+
if (length > 0) {
|
|
46
|
+
for (let i = 0; i < this.dimension; i++) result[i] /= length;
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Flat coordinates for divisions + 1 evenly spaced parameter samples. */
|
|
52
|
+
getPoints(divisions = 64): Float64Array {
|
|
53
|
+
validateDivisions(divisions);
|
|
54
|
+
const points = new Float64Array((divisions + 1) * this.dimension);
|
|
55
|
+
const point = new Array<number>(this.dimension);
|
|
56
|
+
for (let i = 0; i <= divisions; i++) {
|
|
57
|
+
this.getPoint(i / divisions, point);
|
|
58
|
+
points.set(point, i * this.dimension);
|
|
59
|
+
}
|
|
60
|
+
return points;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected abstract evaluate(t: number, result: NumericArray, derivative: boolean): void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Copy caller-owned control data so curves and their length tables stay stable. */
|
|
67
|
+
export function copyPoints(points: readonly CurvePoint[]): number[][] {
|
|
68
|
+
if (!points.length) throw new RangeError('Invalid number of curve control points');
|
|
69
|
+
const dimension = points[0].length;
|
|
70
|
+
if (dimension !== 2 && dimension !== 3) {
|
|
71
|
+
throw new RangeError('Curve points must have two or three coordinates');
|
|
72
|
+
}
|
|
73
|
+
return points.map(point => {
|
|
74
|
+
if (point.length !== dimension) throw new RangeError('Control point dimensions must match');
|
|
75
|
+
return Array.from(point, value => {
|
|
76
|
+
if (!Number.isFinite(value)) throw new RangeError('Control coordinates must be finite');
|
|
77
|
+
return value;
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function validateParameter(t: number): void {
|
|
83
|
+
if (!Number.isFinite(t) || t < 0 || t > 1) {
|
|
84
|
+
throw new RangeError('Curve parameter must be finite and in [0, 1]');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function validateDivisions(divisions: number): void {
|
|
89
|
+
if (!Number.isSafeInteger(divisions) || divisions < 1) {
|
|
90
|
+
throw new RangeError('divisions must be a positive safe integer');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function validateResult(result: NumericArray, dimension: number): void {
|
|
95
|
+
if (result.length < dimension) throw new RangeError('Result buffer is too short');
|
|
96
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {NumericArray} from '@math.gl/core';
|
|
6
|
+
import {Curve, copyPoints, type CurvePoint} from './curve';
|
|
7
|
+
|
|
8
|
+
/** Cubic curve with endpoint derivatives (not unit tangent directions). */
|
|
9
|
+
export class HermiteCurve extends Curve {
|
|
10
|
+
private readonly data: number[][];
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
start: CurvePoint,
|
|
14
|
+
end: CurvePoint,
|
|
15
|
+
startTangent: CurvePoint,
|
|
16
|
+
endTangent: CurvePoint
|
|
17
|
+
) {
|
|
18
|
+
const data = copyPoints([start, end, startTangent, endTangent]);
|
|
19
|
+
super(data[0].length);
|
|
20
|
+
this.data = data;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
protected evaluate(t: number, result: NumericArray, derivative: boolean): void {
|
|
24
|
+
const t2 = t * t;
|
|
25
|
+
const h0 = derivative ? 6 * t2 - 6 * t : (1 + 2 * t) * (1 - t) ** 2;
|
|
26
|
+
const h1 = derivative ? -6 * t2 + 6 * t : t2 * (3 - 2 * t);
|
|
27
|
+
const h2 = derivative ? 3 * t2 - 4 * t + 1 : t * (1 - t) ** 2;
|
|
28
|
+
const h3 = derivative ? 3 * t2 - 2 * t : t2 * (t - 1);
|
|
29
|
+
for (let i = 0; i < this.dimension; i++) {
|
|
30
|
+
result[i] =
|
|
31
|
+
h0 * this.data[0][i] + h1 * this.data[1][i] + h2 * this.data[2][i] + h3 * this.data[3][i];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
export {Curve} from './curve';
|
|
6
|
+
export type {CurvePoint} from './curve';
|
|
7
|
+
export {
|
|
8
|
+
LineCurve,
|
|
9
|
+
QuadraticBezierCurve,
|
|
10
|
+
CubicBezierCurve
|
|
11
|
+
} from './bezier-curves';
|
|
12
|
+
export {HermiteCurve} from './hermite-curve';
|
|
13
|
+
export {CatmullRomCurve} from './catmull-rom-curve';
|
|
14
|
+
export type {CatmullRomCurveOptions} from './catmull-rom-curve';
|
|
15
|
+
export {CurveArcLength} from './curve-arc-length';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// math.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {Geometry, type GeometryAttributeInput} from '../lib/geometry';
|
|
6
6
|
import {assertPositive, makeIndices, type PrimitiveGeometryProps} from './geometry-helpers';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// math.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {Geometry} from '../lib/geometry';
|
|
6
6
|
import {assertPositive, assertSegments, type PrimitiveGeometryProps} from './geometry-helpers';
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {GeometryProps} from '../lib/geometry';
|
|
6
|
+
import {assertSegments, makeIndices, type PrimitiveGeometryProps} from './geometry-helpers';
|
|
7
|
+
export const FULL_CIRCLE = Math.PI * 2;
|
|
8
|
+
export type Vector = [number, number, number];
|
|
9
|
+
export type Vertex = {position: Vector; normal: Vector; textureCoordinates: [number, number]};
|
|
10
|
+
export function radial(angle: number, direction = 1): Vector {
|
|
11
|
+
return [Math.cos(angle) * direction, 0, -Math.sin(angle) * direction];
|
|
12
|
+
}
|
|
13
|
+
export function vertex(
|
|
14
|
+
radius: number,
|
|
15
|
+
height: number,
|
|
16
|
+
angle: number,
|
|
17
|
+
normal: Vector,
|
|
18
|
+
textureCoordinates?: [number, number]
|
|
19
|
+
): Vertex {
|
|
20
|
+
return {
|
|
21
|
+
position: [radius * Math.cos(angle), height, -radius * Math.sin(angle)],
|
|
22
|
+
normal,
|
|
23
|
+
textureCoordinates: textureCoordinates ?? [(Math.cos(angle) + 1) / 2, (Math.sin(angle) + 1) / 2]
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function validateArc(segments: number, startAngle: number, sweepAngle: number): void {
|
|
27
|
+
assertSegments(segments, 'segments', 3);
|
|
28
|
+
if (!Number.isFinite(startAngle)) throw new Error('startAngle must be finite');
|
|
29
|
+
if (!Number.isFinite(sweepAngle) || sweepAngle <= 0 || sweepAngle > FULL_CIRCLE)
|
|
30
|
+
throw new Error('sweepAngle must be positive and at most 2π');
|
|
31
|
+
}
|
|
32
|
+
export class PrimitiveMeshBuilder {
|
|
33
|
+
private positions: number[] = [];
|
|
34
|
+
private normals: number[] = [];
|
|
35
|
+
private textureCoordinates: number[] = [];
|
|
36
|
+
private indices: number[] = [];
|
|
37
|
+
private addVertex(current: Vertex): number {
|
|
38
|
+
const index = this.positions.length / 3;
|
|
39
|
+
this.positions.push(...current.position);
|
|
40
|
+
this.normals.push(...current.normal);
|
|
41
|
+
this.textureCoordinates.push(...current.textureCoordinates);
|
|
42
|
+
return index;
|
|
43
|
+
}
|
|
44
|
+
private addTriangle(first: Vertex, second: Vertex, third: Vertex, indices: number[]): void {
|
|
45
|
+
const firstEdge = second.position.map((value, index) => value - first.position[index]);
|
|
46
|
+
const secondEdge = third.position.map((value, index) => value - first.position[index]);
|
|
47
|
+
const cross = [
|
|
48
|
+
firstEdge[1] * secondEdge[2] - firstEdge[2] * secondEdge[1],
|
|
49
|
+
firstEdge[2] * secondEdge[0] - firstEdge[0] * secondEdge[2],
|
|
50
|
+
firstEdge[0] * secondEdge[1] - firstEdge[1] * secondEdge[0]
|
|
51
|
+
];
|
|
52
|
+
const orientation = cross.reduce(
|
|
53
|
+
(sum, value, index) =>
|
|
54
|
+
sum + value * (first.normal[index] + second.normal[index] + third.normal[index]),
|
|
55
|
+
0
|
|
56
|
+
);
|
|
57
|
+
this.indices.push(...(orientation < 0 ? [indices[0], indices[2], indices[1]] : indices));
|
|
58
|
+
}
|
|
59
|
+
triangle(first: Vertex, second: Vertex, third: Vertex): void {
|
|
60
|
+
this.addTriangle(first, second, third, [
|
|
61
|
+
this.addVertex(first),
|
|
62
|
+
this.addVertex(second),
|
|
63
|
+
this.addVertex(third)
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
quad(first: Vertex, second: Vertex, third: Vertex, fourth: Vertex): void {
|
|
67
|
+
const indices = [first, second, third, fourth].map(current => this.addVertex(current));
|
|
68
|
+
this.addTriangle(first, second, third, indices.slice(0, 3));
|
|
69
|
+
this.addTriangle(first, third, fourth, [indices[0], indices[2], indices[3]]);
|
|
70
|
+
}
|
|
71
|
+
getProps(props: PrimitiveGeometryProps): GeometryProps {
|
|
72
|
+
return {
|
|
73
|
+
id: props.id,
|
|
74
|
+
topology: 'triangle-list',
|
|
75
|
+
indices: makeIndices(this.positions.length / 3, this.indices),
|
|
76
|
+
attributes: {
|
|
77
|
+
POSITION: {size: 3, value: new Float32Array(this.positions)},
|
|
78
|
+
NORMAL: {size: 3, value: new Float32Array(this.normals)},
|
|
79
|
+
TEXCOORD_0: {size: 2, value: new Float32Array(this.textureCoordinates)},
|
|
80
|
+
...props.attributes
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Geometry} from '../lib/geometry';
|
|
6
|
+
import {assertPositive, type PrimitiveGeometryProps} from './geometry-helpers';
|
|
7
|
+
import {
|
|
8
|
+
PrimitiveMeshBuilder,
|
|
9
|
+
FULL_CIRCLE,
|
|
10
|
+
radial,
|
|
11
|
+
validateArc,
|
|
12
|
+
vertex,
|
|
13
|
+
type Vector,
|
|
14
|
+
type Vertex
|
|
15
|
+
} from './primitive-mesh-builder';
|
|
16
|
+
export type PrismGeometryProps = PrimitiveGeometryProps & {
|
|
17
|
+
radius?: number;
|
|
18
|
+
height?: number;
|
|
19
|
+
sides?: number;
|
|
20
|
+
startAngle?: number;
|
|
21
|
+
};
|
|
22
|
+
/** Closed regular prism, centered at the origin with Y vertical and flat side normals. */
|
|
23
|
+
export class PrismGeometry extends Geometry {
|
|
24
|
+
constructor(props: PrismGeometryProps = {}) {
|
|
25
|
+
const {radius = 1, height = 1, sides = 6, startAngle = 0} = props;
|
|
26
|
+
assertPositive(radius, 'radius');
|
|
27
|
+
assertPositive(height, 'height');
|
|
28
|
+
validateArc(sides, startAngle, FULL_CIRCLE);
|
|
29
|
+
const mesh = new PrimitiveMeshBuilder();
|
|
30
|
+
for (let segment = 0; segment < sides; segment++) {
|
|
31
|
+
const firstAngle = startAngle + (segment * FULL_CIRCLE) / sides;
|
|
32
|
+
const secondAngle = startAngle + ((segment + 1) * FULL_CIRCLE) / sides;
|
|
33
|
+
const normal = radial((firstAngle + secondAngle) / 2);
|
|
34
|
+
const secondCornerAngle = segment === sides - 1 ? startAngle : secondAngle;
|
|
35
|
+
mesh.quad(
|
|
36
|
+
vertex(radius, -height / 2, firstAngle, normal, [segment / sides, 0]),
|
|
37
|
+
vertex(radius, height / 2, firstAngle, normal, [segment / sides, 1]),
|
|
38
|
+
vertex(radius, height / 2, secondCornerAngle, normal, [(segment + 1) / sides, 1]),
|
|
39
|
+
vertex(radius, -height / 2, secondCornerAngle, normal, [(segment + 1) / sides, 0])
|
|
40
|
+
);
|
|
41
|
+
for (const direction of [-1, 1]) {
|
|
42
|
+
const capNormal: Vector = [0, direction, 0];
|
|
43
|
+
const center: Vertex = {
|
|
44
|
+
position: [0, (direction * height) / 2, 0],
|
|
45
|
+
normal: capNormal,
|
|
46
|
+
textureCoordinates: [0.5, 0.5]
|
|
47
|
+
};
|
|
48
|
+
mesh.triangle(
|
|
49
|
+
center,
|
|
50
|
+
vertex(radius, (direction * height) / 2, firstAngle, capNormal),
|
|
51
|
+
vertex(radius, (direction * height) / 2, secondCornerAngle, capNormal)
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
super(mesh.getProps(props));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Geometry} from '../lib/geometry';
|
|
6
|
+
import {assertPositive, type PrimitiveGeometryProps} from './geometry-helpers';
|
|
7
|
+
import {
|
|
8
|
+
PrimitiveMeshBuilder,
|
|
9
|
+
FULL_CIRCLE,
|
|
10
|
+
radial,
|
|
11
|
+
validateArc,
|
|
12
|
+
vertex,
|
|
13
|
+
type Vector
|
|
14
|
+
} from './primitive-mesh-builder';
|
|
15
|
+
export type RingGeometryProps = PrimitiveGeometryProps & {
|
|
16
|
+
innerRadius?: number;
|
|
17
|
+
outerRadius?: number;
|
|
18
|
+
height?: number;
|
|
19
|
+
segments?: number;
|
|
20
|
+
startAngle?: number;
|
|
21
|
+
sweepAngle?: number;
|
|
22
|
+
};
|
|
23
|
+
/** Closed annular sector in XZ, centered vertically with hard top, bottom and end caps. */
|
|
24
|
+
export class RingGeometry extends Geometry {
|
|
25
|
+
constructor(props: RingGeometryProps = {}) {
|
|
26
|
+
const {
|
|
27
|
+
innerRadius = 0.5,
|
|
28
|
+
outerRadius = 1,
|
|
29
|
+
height = 0.1,
|
|
30
|
+
segments = 48,
|
|
31
|
+
startAngle = 0,
|
|
32
|
+
sweepAngle = FULL_CIRCLE
|
|
33
|
+
} = props;
|
|
34
|
+
assertPositive(innerRadius, 'innerRadius');
|
|
35
|
+
assertPositive(outerRadius, 'outerRadius');
|
|
36
|
+
assertPositive(height, 'height');
|
|
37
|
+
if (innerRadius >= outerRadius) throw new Error('innerRadius must be smaller than outerRadius');
|
|
38
|
+
validateArc(segments, startAngle, sweepAngle);
|
|
39
|
+
const mesh = new PrimitiveMeshBuilder();
|
|
40
|
+
for (let segment = 0; segment < segments; segment++) {
|
|
41
|
+
const firstAngle = startAngle + (segment * sweepAngle) / segments;
|
|
42
|
+
const secondAngle =
|
|
43
|
+
segment === segments - 1
|
|
44
|
+
? sweepAngle === FULL_CIRCLE
|
|
45
|
+
? startAngle
|
|
46
|
+
: startAngle + sweepAngle
|
|
47
|
+
: startAngle + ((segment + 1) * sweepAngle) / segments;
|
|
48
|
+
const makeCapVertex = (radius: number, height: number, angle: number, normal: Vector) =>
|
|
49
|
+
vertex(radius, height, angle, normal, [
|
|
50
|
+
((radius * Math.cos(angle)) / outerRadius + 1) / 2,
|
|
51
|
+
((radius * Math.sin(angle)) / outerRadius + 1) / 2
|
|
52
|
+
]);
|
|
53
|
+
for (const direction of [-1, 1]) {
|
|
54
|
+
const normal: Vector = [0, direction, 0];
|
|
55
|
+
mesh.quad(
|
|
56
|
+
makeCapVertex(innerRadius, (direction * height) / 2, firstAngle, normal),
|
|
57
|
+
makeCapVertex(outerRadius, (direction * height) / 2, firstAngle, normal),
|
|
58
|
+
makeCapVertex(outerRadius, (direction * height) / 2, secondAngle, normal),
|
|
59
|
+
makeCapVertex(innerRadius, (direction * height) / 2, secondAngle, normal)
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
for (const [radius, direction] of [
|
|
63
|
+
[innerRadius, -1],
|
|
64
|
+
[outerRadius, 1]
|
|
65
|
+
]) {
|
|
66
|
+
mesh.quad(
|
|
67
|
+
vertex(radius, -height / 2, firstAngle, radial(firstAngle, direction), [
|
|
68
|
+
segment / segments,
|
|
69
|
+
0
|
|
70
|
+
]),
|
|
71
|
+
vertex(radius, height / 2, firstAngle, radial(firstAngle, direction), [
|
|
72
|
+
segment / segments,
|
|
73
|
+
1
|
|
74
|
+
]),
|
|
75
|
+
vertex(radius, height / 2, secondAngle, radial(secondAngle, direction), [
|
|
76
|
+
(segment + 1) / segments,
|
|
77
|
+
1
|
|
78
|
+
]),
|
|
79
|
+
vertex(radius, -height / 2, secondAngle, radial(secondAngle, direction), [
|
|
80
|
+
(segment + 1) / segments,
|
|
81
|
+
0
|
|
82
|
+
])
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (sweepAngle < FULL_CIRCLE) {
|
|
87
|
+
for (const [angle, direction] of [
|
|
88
|
+
[startAngle, -1],
|
|
89
|
+
[startAngle + sweepAngle, 1]
|
|
90
|
+
]) {
|
|
91
|
+
const normal: Vector = [-Math.sin(angle) * direction, 0, -Math.cos(angle) * direction];
|
|
92
|
+
mesh.quad(
|
|
93
|
+
vertex(innerRadius, -height / 2, angle, normal, [0, 0]),
|
|
94
|
+
vertex(outerRadius, -height / 2, angle, normal, [1, 0]),
|
|
95
|
+
vertex(outerRadius, height / 2, angle, normal, [1, 1]),
|
|
96
|
+
vertex(innerRadius, height / 2, angle, normal, [0, 1])
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
super(mesh.getProps(props));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// math.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {Geometry} from '../lib/geometry';
|
|
6
6
|
import {assertPositive, assertSegments, type PrimitiveGeometryProps} from './geometry-helpers';
|