@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,273 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND ISC
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/* eslint-disable max-statements, max-depth, complexity, no-unused-expressions */
|
|
6
|
+
|
|
7
|
+
import {equals} from '@math.gl/core';
|
|
8
|
+
import type {NumericArray} from '@math.gl/core';
|
|
9
|
+
|
|
10
|
+
/** Direction in which a polygon's vertices are ordered. */
|
|
11
|
+
export type WindingDirection = 'clockwise' | 'counter-clockwise' | 'none';
|
|
12
|
+
|
|
13
|
+
/** A non-degenerate polygon winding direction. */
|
|
14
|
+
export type PolygonWinding = Exclude<WindingDirection, 'none'>;
|
|
15
|
+
|
|
16
|
+
/** Polygon representation where each point is represented as a separate array of positions. */
|
|
17
|
+
type PointsArray = NumericArray[];
|
|
18
|
+
|
|
19
|
+
/** Segment visitor callback type for polygons defined with flat arrays, */
|
|
20
|
+
type SegmentVisitorFlat = (
|
|
21
|
+
p1x: number,
|
|
22
|
+
p1y: number,
|
|
23
|
+
p2x: number,
|
|
24
|
+
p2y: number,
|
|
25
|
+
i1: number,
|
|
26
|
+
i2: number
|
|
27
|
+
) => void;
|
|
28
|
+
|
|
29
|
+
/** Segment visitor callback type for polygons defined with array of points. */
|
|
30
|
+
export type SegmentVisitorPoints = (
|
|
31
|
+
p1: NumericArray,
|
|
32
|
+
p2: NumericArray,
|
|
33
|
+
i1: number,
|
|
34
|
+
i2: number
|
|
35
|
+
) => void;
|
|
36
|
+
|
|
37
|
+
export type Plane2D = 'xy' | 'yz' | 'xz';
|
|
38
|
+
|
|
39
|
+
/** Parameters of a polygon. */
|
|
40
|
+
type PolygonParams = {
|
|
41
|
+
/**
|
|
42
|
+
* Start index of the polygon in the array of positions.
|
|
43
|
+
* @default `0`
|
|
44
|
+
*/
|
|
45
|
+
start?: number;
|
|
46
|
+
/**
|
|
47
|
+
* End index of the polygon in the array of positions.
|
|
48
|
+
* @default number of positions
|
|
49
|
+
*/
|
|
50
|
+
end?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Size of a point, 2 (XZ) or 3 (XYZ). Affects only polygons stored in flat arrays.
|
|
53
|
+
* @default `2`
|
|
54
|
+
*/
|
|
55
|
+
size?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Indicates that the first point of the polygon is equal to the last point, and additional checks should be ommited.
|
|
58
|
+
*/
|
|
59
|
+
isClosed?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* The 2D projection plane on which to calculate the area of a 3D polygon.
|
|
62
|
+
* @default `'xy'`
|
|
63
|
+
*/
|
|
64
|
+
plane?: Plane2D;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.
|
|
69
|
+
* Note: points are modified in-place.
|
|
70
|
+
* @param points An array that represents points of the polygon.
|
|
71
|
+
* @param direction Requested winding direction.
|
|
72
|
+
* @param options Parameters of the polygon.
|
|
73
|
+
* @return Returns true if the winding direction was changed.
|
|
74
|
+
*/
|
|
75
|
+
export function modifyPolygonWindingDirection(
|
|
76
|
+
points: NumericArray,
|
|
77
|
+
direction: PolygonWinding,
|
|
78
|
+
options: PolygonParams = {}
|
|
79
|
+
): boolean {
|
|
80
|
+
const windingDirection = getPolygonWindingDirection(points, options);
|
|
81
|
+
if (windingDirection !== direction) {
|
|
82
|
+
reversePolygon(points, options);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Returns winding direction of the polygon.
|
|
90
|
+
* @param points An array that represents points of the polygon.
|
|
91
|
+
* @param options Parameters of the polygon.
|
|
92
|
+
* @returns Winding direction of the polygon.
|
|
93
|
+
*/
|
|
94
|
+
export function getPolygonWindingDirection(
|
|
95
|
+
points: NumericArray,
|
|
96
|
+
options: PolygonParams = {}
|
|
97
|
+
): WindingDirection {
|
|
98
|
+
return getWindingDirection(getPolygonSignedArea(points, options));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const DimIndex: Record<string, number> = {
|
|
102
|
+
x: 0,
|
|
103
|
+
y: 1,
|
|
104
|
+
z: 2
|
|
105
|
+
} as const;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Returns signed area of the polygon.
|
|
109
|
+
* @param points An array that represents points of the polygon.
|
|
110
|
+
* @param options Parameters of the polygon.
|
|
111
|
+
* @returns Signed area of the polygon.
|
|
112
|
+
* https://en.wikipedia.org/wiki/Shoelace_formula
|
|
113
|
+
*/
|
|
114
|
+
export function getPolygonSignedArea(points: NumericArray, options: PolygonParams = {}): number {
|
|
115
|
+
const {start = 0, end = points.length, plane = 'xy'} = options;
|
|
116
|
+
const dim = options.size || 2;
|
|
117
|
+
let area = 0;
|
|
118
|
+
const i0 = DimIndex[plane[0]];
|
|
119
|
+
const i1 = DimIndex[plane[1]];
|
|
120
|
+
|
|
121
|
+
for (let i = start, j = end - dim; i < end; i += dim) {
|
|
122
|
+
area += (points[i + i0] - points[j + i0]) * (points[i + i1] + points[j + i1]);
|
|
123
|
+
j = i;
|
|
124
|
+
}
|
|
125
|
+
return area / 2;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Calls the visitor callback for each segment in the polygon.
|
|
130
|
+
* @param points An array that represents points of the polygon
|
|
131
|
+
* @param visitor A callback to call for each segment.
|
|
132
|
+
* @param options Parameters of the polygon.
|
|
133
|
+
*/
|
|
134
|
+
export function forEachSegmentInPolygon(
|
|
135
|
+
points: NumericArray,
|
|
136
|
+
visitor: SegmentVisitorFlat,
|
|
137
|
+
options: PolygonParams = {}
|
|
138
|
+
): void {
|
|
139
|
+
const {start = 0, end = points.length, size = 2, isClosed} = options;
|
|
140
|
+
|
|
141
|
+
const numPoints = (end - start) / size;
|
|
142
|
+
for (let i = 0; i < numPoints - 1; ++i) {
|
|
143
|
+
visitor(
|
|
144
|
+
points[start + i * size],
|
|
145
|
+
points[start + i * size + 1],
|
|
146
|
+
points[start + (i + 1) * size],
|
|
147
|
+
points[start + (i + 1) * size + 1],
|
|
148
|
+
i,
|
|
149
|
+
i + 1
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const endPointIndex = start + (numPoints - 1) * size;
|
|
154
|
+
const isClosedEx =
|
|
155
|
+
isClosed ||
|
|
156
|
+
(equals(points[start], points[endPointIndex]) &&
|
|
157
|
+
equals(points[start + 1], points[endPointIndex + 1]));
|
|
158
|
+
|
|
159
|
+
if (!isClosedEx) {
|
|
160
|
+
visitor(
|
|
161
|
+
points[endPointIndex],
|
|
162
|
+
points[endPointIndex + 1],
|
|
163
|
+
points[start],
|
|
164
|
+
points[start + 1],
|
|
165
|
+
numPoints - 1,
|
|
166
|
+
0
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function reversePolygon(
|
|
172
|
+
points: NumericArray,
|
|
173
|
+
options: {start?: number; end?: number; size?: number}
|
|
174
|
+
): void {
|
|
175
|
+
const {start = 0, end = points.length, size = 2} = options;
|
|
176
|
+
|
|
177
|
+
const numPoints = (end - start) / size;
|
|
178
|
+
const numSwaps = Math.floor(numPoints / 2);
|
|
179
|
+
for (let i = 0; i < numSwaps; ++i) {
|
|
180
|
+
const b1 = start + i * size;
|
|
181
|
+
const b2 = start + (numPoints - 1 - i) * size;
|
|
182
|
+
for (let j = 0; j < size; ++j) {
|
|
183
|
+
const tmp = points[b1 + j];
|
|
184
|
+
points[b1 + j] = points[b2 + j];
|
|
185
|
+
points[b2 + j] = tmp;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.
|
|
192
|
+
* Note: points are modified in-place.
|
|
193
|
+
* @param points Array of points that represent the polygon.
|
|
194
|
+
* @param direction Requested winding direction.
|
|
195
|
+
* @param options Parameters of the polygon.
|
|
196
|
+
* @return Returns true if the winding direction was changed.
|
|
197
|
+
*/
|
|
198
|
+
export function modifyPolygonWindingDirectionPoints(
|
|
199
|
+
points: PointsArray,
|
|
200
|
+
direction: PolygonWinding,
|
|
201
|
+
options: PolygonParams = {}
|
|
202
|
+
): boolean {
|
|
203
|
+
const currentDirection = getPolygonWindingDirectionPoints(points, options);
|
|
204
|
+
if (currentDirection !== direction) {
|
|
205
|
+
points.reverse();
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Returns winding direction of the polygon.
|
|
213
|
+
* @param points Array of points that represent the polygon.
|
|
214
|
+
* @param options Parameters of the polygon.
|
|
215
|
+
* @returns Winding direction of the polygon.
|
|
216
|
+
*/
|
|
217
|
+
export function getPolygonWindingDirectionPoints(
|
|
218
|
+
points: PointsArray,
|
|
219
|
+
options: PolygonParams = {}
|
|
220
|
+
): WindingDirection {
|
|
221
|
+
return getWindingDirection(getPolygonSignedAreaPoints(points, options));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function getWindingDirection(signedArea: number): WindingDirection {
|
|
225
|
+
if (signedArea > 0) return 'clockwise';
|
|
226
|
+
if (signedArea < 0) return 'counter-clockwise';
|
|
227
|
+
return 'none';
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Returns signed area of the polygon.
|
|
232
|
+
* @param points Array of points that represent the polygon.
|
|
233
|
+
* @param options Parameters of the polygon.
|
|
234
|
+
* @returns Signed area of the polygon.
|
|
235
|
+
*/
|
|
236
|
+
export function getPolygonSignedAreaPoints(
|
|
237
|
+
points: PointsArray,
|
|
238
|
+
options: PolygonParams = {}
|
|
239
|
+
): number {
|
|
240
|
+
// https://en.wikipedia.org/wiki/Shoelace_formula
|
|
241
|
+
const {start = 0, end = points.length, plane = 'xy'} = options;
|
|
242
|
+
let area = 0;
|
|
243
|
+
const i0 = DimIndex[plane[0]];
|
|
244
|
+
const i1 = DimIndex[plane[1]];
|
|
245
|
+
|
|
246
|
+
for (let i = start, j = end - 1; i < end; ++i) {
|
|
247
|
+
area += (points[i][i0] - points[j][i0]) * (points[i][i1] + points[j][i1]);
|
|
248
|
+
j = i;
|
|
249
|
+
}
|
|
250
|
+
return area / 2;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Calls visitor callback for each segment in the polygon.
|
|
255
|
+
* @param points Array of points that represent the polygon.
|
|
256
|
+
* @param visitor A callback to call for each segment.
|
|
257
|
+
* @param options Parameters of the polygon.
|
|
258
|
+
*/
|
|
259
|
+
export function forEachSegmentInPolygonPoints(
|
|
260
|
+
points: PointsArray,
|
|
261
|
+
visitor: SegmentVisitorPoints,
|
|
262
|
+
options: PolygonParams = {}
|
|
263
|
+
): void {
|
|
264
|
+
const {start = 0, end = points.length, isClosed} = options;
|
|
265
|
+
for (let i = start; i < end - 1; ++i) {
|
|
266
|
+
visitor(points[i], points[i + 1], i, i + 1);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const isClosedEx = isClosed || equals(points[end - 1], points[0]);
|
|
270
|
+
if (!isClosedEx) {
|
|
271
|
+
visitor(points[end - 1], points[0], end - 1, 0);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/* eslint-disable no-undef, no-console */
|
|
6
|
+
import {isArray} from '@math.gl/core';
|
|
7
|
+
import type {PolygonWinding, SegmentVisitorPoints, WindingDirection} from './polygon-utils';
|
|
8
|
+
import type {NumericArray} from '@math.gl/core';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
getPolygonSignedArea,
|
|
12
|
+
forEachSegmentInPolygon,
|
|
13
|
+
modifyPolygonWindingDirection,
|
|
14
|
+
getPolygonSignedAreaPoints,
|
|
15
|
+
forEachSegmentInPolygonPoints,
|
|
16
|
+
modifyPolygonWindingDirectionPoints
|
|
17
|
+
} from './polygon-utils';
|
|
18
|
+
|
|
19
|
+
export type PolygonOptions = {
|
|
20
|
+
start?: number;
|
|
21
|
+
end?: number;
|
|
22
|
+
size?: number;
|
|
23
|
+
isClosed?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export class Polygon {
|
|
27
|
+
points: NumericArray | number[][];
|
|
28
|
+
isFlatArray: boolean;
|
|
29
|
+
options: PolygonOptions;
|
|
30
|
+
|
|
31
|
+
constructor(points: NumericArray | number[][], options: PolygonOptions = {}) {
|
|
32
|
+
this.points = points;
|
|
33
|
+
this.isFlatArray = !isArray(points[0]);
|
|
34
|
+
|
|
35
|
+
this.options = {
|
|
36
|
+
start: options.start || 0,
|
|
37
|
+
end: options.end || points.length,
|
|
38
|
+
size: options.size || 2,
|
|
39
|
+
isClosed: options.isClosed
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
Object.freeze(this);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns signed area of the polygon.
|
|
47
|
+
* @returns Signed area of the polygon.
|
|
48
|
+
*/
|
|
49
|
+
getSignedArea(): number {
|
|
50
|
+
if (this.isFlatArray) return getPolygonSignedArea(this.points as NumericArray, this.options);
|
|
51
|
+
|
|
52
|
+
return getPolygonSignedAreaPoints(this.points as number[][], this.options);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Returns absolute area of the polygon.
|
|
57
|
+
* @returns Absolute area of the polygon.
|
|
58
|
+
*/
|
|
59
|
+
getArea(): number {
|
|
60
|
+
return Math.abs(this.getSignedArea());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Returns winding direction of the polygon.
|
|
65
|
+
* @returns `'clockwise'`, `'counter-clockwise'`, or `'none'` for a degenerate polygon.
|
|
66
|
+
*/
|
|
67
|
+
getWindingDirection(): WindingDirection {
|
|
68
|
+
const signedArea = this.getSignedArea();
|
|
69
|
+
if (signedArea > 0) return 'clockwise';
|
|
70
|
+
if (signedArea < 0) return 'counter-clockwise';
|
|
71
|
+
return 'none';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Calls the visitor callback for each segment in the polygon.
|
|
76
|
+
* @param visitor A callback to call for each segment.
|
|
77
|
+
*/
|
|
78
|
+
forEachSegment(visitor: SegmentVisitorPoints): void {
|
|
79
|
+
if (this.isFlatArray) {
|
|
80
|
+
forEachSegmentInPolygon(
|
|
81
|
+
this.points as NumericArray,
|
|
82
|
+
// eslint-disable-next-line max-params
|
|
83
|
+
(x1, y1, x2, y2, i1, i2) => {
|
|
84
|
+
// TODO @igorDykhta original visitor uses arrays for each point, but with flat arrays performance degrades if we allocate points for each segment
|
|
85
|
+
visitor([x1, y1], [x2, y2], i1, i2);
|
|
86
|
+
},
|
|
87
|
+
this.options
|
|
88
|
+
);
|
|
89
|
+
} else {
|
|
90
|
+
forEachSegmentInPolygonPoints(this.points as number[][], visitor, this.options);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.
|
|
96
|
+
* @param direction Requested winding direction.
|
|
97
|
+
* @return Returns true if the winding direction was changed.
|
|
98
|
+
*/
|
|
99
|
+
modifyWindingDirection(direction: PolygonWinding): boolean {
|
|
100
|
+
if (this.isFlatArray) {
|
|
101
|
+
return modifyPolygonWindingDirection(this.points as NumericArray, direction, this.options);
|
|
102
|
+
}
|
|
103
|
+
return modifyPolygonWindingDirectionPoints(this.points as number[][], direction, this.options);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** A constant-speed source edge, sampled at fractions of its declared length.
|
|
6
|
+
* Endpoints must match the factory inputs exactly. Samples are copied before use.
|
|
7
|
+
*/
|
|
8
|
+
export type PolylineEdgeSampler = {
|
|
9
|
+
readonly length: number;
|
|
10
|
+
sample: (fraction: number) => ArrayLike<number>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** Configuration for sampling source edges through a nonlinear transform. */
|
|
14
|
+
export type SubdividePolylineOptions = {
|
|
15
|
+
/** Maps a source position to target coordinates; null or nonfinite output rejects the geometry.
|
|
16
|
+
* Must be deterministic. A fresh array is passed on every invocation.
|
|
17
|
+
*/
|
|
18
|
+
transform: (position: readonly number[]) => ArrayLike<number> | null;
|
|
19
|
+
/** Positive error tolerance in target-coordinate units, measured across all output components. */
|
|
20
|
+
tolerance: number;
|
|
21
|
+
/** Optional factory, called once per original edge with independent endpoint copies.
|
|
22
|
+
* Without it, source coordinates interpolate linearly. Must be deterministic.
|
|
23
|
+
*/
|
|
24
|
+
createEdgeSampler?: (
|
|
25
|
+
start: readonly number[],
|
|
26
|
+
end: readonly number[],
|
|
27
|
+
segmentIndex: number
|
|
28
|
+
) => PolylineEdgeSampler;
|
|
29
|
+
/** Number of source components per vertex. Default 2. */
|
|
30
|
+
size?: 2 | 3;
|
|
31
|
+
/** Number of target components per vertex. Defaults to size. */
|
|
32
|
+
targetSize?: 2 | 3;
|
|
33
|
+
/** Positive maximum leaf length: Euclidean source distance by default, or the
|
|
34
|
+
* custom sampler's declared length multiplied by its fraction interval.
|
|
35
|
+
*/
|
|
36
|
+
maxSegmentLength?: number;
|
|
37
|
+
/** Maximum bisection depth per input edge. Default 16; maximum 30. */
|
|
38
|
+
maxDepth?: number;
|
|
39
|
+
/** Maximum output vertex count for the entire polyline. Default 65536. */
|
|
40
|
+
maxVertices?: number;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** Subdivided source and target coordinates with attribution for interpolating other data. */
|
|
44
|
+
export type SubdividedPolyline = {
|
|
45
|
+
/** Flat source positions, including inserted vertices. Input storage is never modified. */
|
|
46
|
+
sourcePositions: Float64Array;
|
|
47
|
+
/** Flat transformed positions, in the transform's target units. */
|
|
48
|
+
positions: Float64Array;
|
|
49
|
+
/** Input edge index for each output vertex. Edge i connects input vertices i and i + 1.
|
|
50
|
+
* Shared endpoints belong to the preceding edge; a lone input vertex uses index 0.
|
|
51
|
+
*/
|
|
52
|
+
segmentIndices: Uint32Array;
|
|
53
|
+
/** Fraction along the attributed input edge. The first vertex uses 0; endpoints use 1. */
|
|
54
|
+
segmentFractions: Float64Array;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type Sample = {source: number[]; target: number[]; fraction: number};
|
|
58
|
+
|
|
59
|
+
/** Adaptively subdivides a flat polyline by sampling a supplied coordinate transform.
|
|
60
|
+
* Each leaf edge checks its quarter, midpoint and three-quarter positions against linear
|
|
61
|
+
* interpolation of its target endpoints. This is a sampled criterion, not a guaranteed
|
|
62
|
+
* bound for arbitrary transforms. Source components interpolate linearly unless a custom
|
|
63
|
+
* constant-speed source-edge sampler is supplied.
|
|
64
|
+
* Explicitly closed rings stay closed. Split seams and clip invalid domains before calling.
|
|
65
|
+
* @throws RangeError For invalid options/coordinates, rejected transform samples, or exhausted limits.
|
|
66
|
+
* Exceptions thrown by the transform itself propagate unchanged.
|
|
67
|
+
*/
|
|
68
|
+
export function subdividePolyline(
|
|
69
|
+
input: ArrayLike<number>,
|
|
70
|
+
options: SubdividePolylineOptions
|
|
71
|
+
): SubdividedPolyline {
|
|
72
|
+
const {
|
|
73
|
+
transform,
|
|
74
|
+
tolerance,
|
|
75
|
+
createEdgeSampler,
|
|
76
|
+
size = 2,
|
|
77
|
+
targetSize = size,
|
|
78
|
+
maxSegmentLength = Infinity,
|
|
79
|
+
maxDepth = 16,
|
|
80
|
+
maxVertices = 65536
|
|
81
|
+
} = options;
|
|
82
|
+
if (
|
|
83
|
+
typeof transform !== 'function' ||
|
|
84
|
+
(createEdgeSampler !== undefined && typeof createEdgeSampler !== 'function') ||
|
|
85
|
+
!Number.isFinite(tolerance) ||
|
|
86
|
+
tolerance <= 0 ||
|
|
87
|
+
(size !== 2 && size !== 3) ||
|
|
88
|
+
(targetSize !== 2 && targetSize !== 3) ||
|
|
89
|
+
!(maxSegmentLength > 0) ||
|
|
90
|
+
(!Number.isFinite(maxSegmentLength) && maxSegmentLength !== Infinity) ||
|
|
91
|
+
!Number.isInteger(maxDepth) ||
|
|
92
|
+
maxDepth < 0 ||
|
|
93
|
+
maxDepth > 30 ||
|
|
94
|
+
!Number.isSafeInteger(maxVertices) ||
|
|
95
|
+
maxVertices < 1 ||
|
|
96
|
+
maxVertices > 0xffffffff ||
|
|
97
|
+
!Number.isSafeInteger(input.length) ||
|
|
98
|
+
input.length < 0 ||
|
|
99
|
+
input.length % size !== 0
|
|
100
|
+
) {
|
|
101
|
+
throw new RangeError('Invalid polyline subdivision options or input length');
|
|
102
|
+
}
|
|
103
|
+
const vertexCount = input.length / size;
|
|
104
|
+
if (vertexCount > maxVertices) throw new RangeError('Polyline exceeds maxVertices');
|
|
105
|
+
const sources: number[] = [];
|
|
106
|
+
for (let i = 0; i < input.length; i++) {
|
|
107
|
+
const value = input[i];
|
|
108
|
+
if (!Number.isFinite(value)) throw new RangeError('Source positions must be finite');
|
|
109
|
+
sources.push(value);
|
|
110
|
+
}
|
|
111
|
+
const sourcePositions: number[] = [];
|
|
112
|
+
const positions: number[] = [];
|
|
113
|
+
const segmentIndices: number[] = [];
|
|
114
|
+
const segmentFractions: number[] = [];
|
|
115
|
+
|
|
116
|
+
function sample(source: number[], fraction: number): Sample {
|
|
117
|
+
const projected = transform(source.slice());
|
|
118
|
+
if (!projected || projected.length !== targetSize) {
|
|
119
|
+
throw new RangeError('Transform must return a position with targetSize components');
|
|
120
|
+
}
|
|
121
|
+
const target = Array.from(projected);
|
|
122
|
+
if (!target.every(Number.isFinite))
|
|
123
|
+
throw new RangeError('Transform returned nonfinite coordinates');
|
|
124
|
+
return {source, target, fraction};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function append(point: Sample, segment: number): void {
|
|
128
|
+
if (segmentIndices.length >= maxVertices) {
|
|
129
|
+
throw new RangeError('Polyline subdivision exceeded maxVertices');
|
|
130
|
+
}
|
|
131
|
+
for (const value of point.source) sourcePositions.push(value);
|
|
132
|
+
for (const value of point.target) positions.push(value);
|
|
133
|
+
segmentIndices.push(segment);
|
|
134
|
+
segmentFractions.push(point.fraction);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function sampledSource(sampler: PolylineEdgeSampler, fraction: number): number[] {
|
|
138
|
+
const value = sampler.sample(fraction);
|
|
139
|
+
if (!value || value.length !== size) throw new RangeError('Invalid source-edge sample size');
|
|
140
|
+
const source = Array.from(value);
|
|
141
|
+
if (!source.every(Number.isFinite)) throw new RangeError('Nonfinite source-edge sample');
|
|
142
|
+
return source;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function interpolate(
|
|
146
|
+
a: Sample,
|
|
147
|
+
b: Sample,
|
|
148
|
+
fraction: number,
|
|
149
|
+
sampler?: PolylineEdgeSampler
|
|
150
|
+
): Sample {
|
|
151
|
+
const originalFraction = a.fraction * (1 - fraction) + b.fraction * fraction;
|
|
152
|
+
// Always sample the original edge, never a new curve fitted to recursive endpoints.
|
|
153
|
+
const source = sampler
|
|
154
|
+
? sampledSource(sampler, originalFraction)
|
|
155
|
+
: a.source.map((value, i) => value * (1 - fraction) + b.source[i] * fraction);
|
|
156
|
+
return sample(source, originalFraction);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function subdivide(
|
|
160
|
+
a: Sample,
|
|
161
|
+
b: Sample,
|
|
162
|
+
segment: number,
|
|
163
|
+
depth: number,
|
|
164
|
+
sampler?: PolylineEdgeSampler
|
|
165
|
+
): void {
|
|
166
|
+
let error = 0;
|
|
167
|
+
let midpoint: Sample;
|
|
168
|
+
for (const fraction of [0.25, 0.5, 0.75]) {
|
|
169
|
+
const point = interpolate(a, b, fraction, sampler);
|
|
170
|
+
if (fraction === 0.5) midpoint = point;
|
|
171
|
+
const delta = point.target.map(
|
|
172
|
+
(value, i) => value - (a.target[i] * (1 - fraction) + b.target[i] * fraction)
|
|
173
|
+
);
|
|
174
|
+
error = Math.max(error, Math.hypot(...delta));
|
|
175
|
+
}
|
|
176
|
+
const sourceLength = sampler
|
|
177
|
+
? sampler.length * (b.fraction - a.fraction)
|
|
178
|
+
: Math.hypot(...a.source.map((value, i) => value - b.source[i]));
|
|
179
|
+
if (error <= tolerance && sourceLength <= maxSegmentLength) {
|
|
180
|
+
append(b, segment);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (depth >= maxDepth) {
|
|
184
|
+
throw new RangeError(`Polyline subdivision exceeded maxDepth on input edge ${segment}`);
|
|
185
|
+
}
|
|
186
|
+
subdivide(a, midpoint!, segment, depth + 1, sampler);
|
|
187
|
+
subdivide(midpoint!, b, segment, depth + 1, sampler);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (vertexCount) {
|
|
191
|
+
let previous = sample(sources.slice(0, size), 0);
|
|
192
|
+
append(previous, 0);
|
|
193
|
+
for (let i = 1; i < vertexCount; i++) {
|
|
194
|
+
const next = sample(sources.slice(i * size, (i + 1) * size), 1);
|
|
195
|
+
const start = {...previous, fraction: 0};
|
|
196
|
+
const sampler = createEdgeSampler?.(start.source.slice(), next.source.slice(), i - 1);
|
|
197
|
+
if (createEdgeSampler) {
|
|
198
|
+
if (
|
|
199
|
+
!sampler ||
|
|
200
|
+
typeof sampler.sample !== 'function' ||
|
|
201
|
+
!Number.isFinite(sampler.length) ||
|
|
202
|
+
sampler.length < 0
|
|
203
|
+
) {
|
|
204
|
+
throw new RangeError('Invalid source-edge sampler');
|
|
205
|
+
}
|
|
206
|
+
for (const endpoint of [start, next]) {
|
|
207
|
+
const sampled = sampledSource(sampler, endpoint.fraction);
|
|
208
|
+
if (sampled.some((value, component) => value !== endpoint.source[component])) {
|
|
209
|
+
throw new RangeError('Source-edge sampler endpoints must match input');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
subdivide(start, next, i - 1, 0, sampler);
|
|
214
|
+
previous = next;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
sourcePositions: new Float64Array(sourcePositions),
|
|
219
|
+
positions: new Float64Array(positions),
|
|
220
|
+
segmentIndices: new Uint32Array(segmentIndices),
|
|
221
|
+
segmentFractions: new Float64Array(segmentFractions)
|
|
222
|
+
};
|
|
223
|
+
}
|