@jbroll/jscad-modeling 2.12.7
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/.claude/settings.local.json +30 -0
- package/CHANGELOG.md +888 -0
- package/CLAUDE.md +135 -0
- package/README.md +99 -0
- package/benchmarks/booleans.bench.js +100 -0
- package/benchmarks/extrusions.bench.js +124 -0
- package/benchmarks/measurements.bench.js +123 -0
- package/benchmarks/run.js +145 -0
- package/benchmarks/transforms.bench.js +106 -0
- package/benchmarks/utils.bench.js +89 -0
- package/dist/jscad-modeling.min.js +1214 -0
- package/package.json +66 -0
- package/src/colors/colorNameToRgb.d.ts +5 -0
- package/src/colors/colorNameToRgb.js +14 -0
- package/src/colors/colorNameToRgb.test.js +14 -0
- package/src/colors/colorize.d.ts +14 -0
- package/src/colors/colorize.js +65 -0
- package/src/colors/colorize.test.js +72 -0
- package/src/colors/cssColors.d.ts +149 -0
- package/src/colors/cssColors.js +176 -0
- package/src/colors/hexToRgb.d.ts +5 -0
- package/src/colors/hexToRgb.js +26 -0
- package/src/colors/hexToRgb.test.js +37 -0
- package/src/colors/hslToRgb.d.ts +8 -0
- package/src/colors/hslToRgb.js +44 -0
- package/src/colors/hslToRgb.test.js +37 -0
- package/src/colors/hsvToRgb.d.ts +8 -0
- package/src/colors/hsvToRgb.js +73 -0
- package/src/colors/hsvToRgb.test.js +27 -0
- package/src/colors/hueToColorComponent.d.ts +3 -0
- package/src/colors/hueToColorComponent.js +18 -0
- package/src/colors/index.d.ts +13 -0
- package/src/colors/index.js +19 -0
- package/src/colors/rgbToHex.d.ts +6 -0
- package/src/colors/rgbToHex.js +27 -0
- package/src/colors/rgbToHex.test.js +15 -0
- package/src/colors/rgbToHsl.d.ts +8 -0
- package/src/colors/rgbToHsl.js +53 -0
- package/src/colors/rgbToHsl.test.js +35 -0
- package/src/colors/rgbToHsv.d.ts +8 -0
- package/src/colors/rgbToHsv.js +52 -0
- package/src/colors/rgbToHsv.test.js +40 -0
- package/src/colors/types.d.ts +6 -0
- package/src/connectors/create.js +23 -0
- package/src/connectors/create.test.js +17 -0
- package/src/connectors/extends.js +15 -0
- package/src/connectors/fromPointAxisNormal.js +21 -0
- package/src/connectors/fromPointAxisNormal.test.js +22 -0
- package/src/connectors/index.js +12 -0
- package/src/connectors/normalize.js +20 -0
- package/src/connectors/toString.js +15 -0
- package/src/connectors/transform.js +28 -0
- package/src/connectors/transform.test.js +106 -0
- package/src/connectors/transformationBetween.js +68 -0
- package/src/connectors/transformationBetween.test.js +40 -0
- package/src/curves/bezier/arcLengthToT.d.ts +10 -0
- package/src/curves/bezier/arcLengthToT.js +63 -0
- package/src/curves/bezier/arcLengthToT.test.js +79 -0
- package/src/curves/bezier/create.d.ts +5 -0
- package/src/curves/bezier/create.js +81 -0
- package/src/curves/bezier/create.test.js +60 -0
- package/src/curves/bezier/index.d.ts +9 -0
- package/src/curves/bezier/index.js +13 -0
- package/src/curves/bezier/length.d.ts +5 -0
- package/src/curves/bezier/length.js +18 -0
- package/src/curves/bezier/length.test.js +54 -0
- package/src/curves/bezier/lengths.d.ts +5 -0
- package/src/curves/bezier/lengths.js +56 -0
- package/src/curves/bezier/lengths.test.js +78 -0
- package/src/curves/bezier/tangentAt.d.ts +5 -0
- package/src/curves/bezier/tangentAt.js +45 -0
- package/src/curves/bezier/tangentAt.test.js +63 -0
- package/src/curves/bezier/type.d.ts +9 -0
- package/src/curves/bezier/valueAt.d.ts +5 -0
- package/src/curves/bezier/valueAt.js +44 -0
- package/src/curves/bezier/valueAt.test.js +63 -0
- package/src/curves/index.d.ts +3 -0
- package/src/curves/index.js +9 -0
- package/src/geometries/geom2/applyTransforms.js +26 -0
- package/src/geometries/geom2/applyTransforms.test.js +21 -0
- package/src/geometries/geom2/clone.d.ts +5 -0
- package/src/geometries/geom2/clone.js +9 -0
- package/src/geometries/geom2/clone.test.js +26 -0
- package/src/geometries/geom2/create.d.ts +6 -0
- package/src/geometries/geom2/create.js +26 -0
- package/src/geometries/geom2/create.test.js +20 -0
- package/src/geometries/geom2/fromCompactBinary.d.ts +5 -0
- package/src/geometries/geom2/fromCompactBinary.js +32 -0
- package/src/geometries/geom2/fromPoints.d.ts +6 -0
- package/src/geometries/geom2/fromPoints.js +35 -0
- package/src/geometries/geom2/fromPoints.test.js +22 -0
- package/src/geometries/geom2/fromToCompactBinary.test.js +122 -0
- package/src/geometries/geom2/index.d.ts +16 -0
- package/src/geometries/geom2/index.js +30 -0
- package/src/geometries/geom2/isA.d.ts +5 -0
- package/src/geometries/geom2/isA.js +18 -0
- package/src/geometries/geom2/isA.test.js +19 -0
- package/src/geometries/geom2/reverse.d.ts +5 -0
- package/src/geometries/geom2/reverse.js +22 -0
- package/src/geometries/geom2/reverse.test.js +20 -0
- package/src/geometries/geom2/toCompactBinary.d.ts +5 -0
- package/src/geometries/geom2/toCompactBinary.js +53 -0
- package/src/geometries/geom2/toOutlines.d.ts +6 -0
- package/src/geometries/geom2/toOutlines.js +119 -0
- package/src/geometries/geom2/toOutlines.test.js +122 -0
- package/src/geometries/geom2/toPoints.d.ts +6 -0
- package/src/geometries/geom2/toPoints.js +25 -0
- package/src/geometries/geom2/toPoints.test.js +24 -0
- package/src/geometries/geom2/toSides.d.ts +6 -0
- package/src/geometries/geom2/toSides.js +16 -0
- package/src/geometries/geom2/toString.d.ts +5 -0
- package/src/geometries/geom2/toString.js +24 -0
- package/src/geometries/geom2/transform.d.ts +6 -0
- package/src/geometries/geom2/transform.js +28 -0
- package/src/geometries/geom2/transform.test.js +110 -0
- package/src/geometries/geom2/type.d.ts +11 -0
- package/src/geometries/geom2/validate.d.ts +3 -0
- package/src/geometries/geom2/validate.js +36 -0
- package/src/geometries/geom3/applyTransforms.js +23 -0
- package/src/geometries/geom3/applyTransforms.test.js +28 -0
- package/src/geometries/geom3/clone.d.ts +5 -0
- package/src/geometries/geom3/clone.js +9 -0
- package/src/geometries/geom3/clone.test.js +31 -0
- package/src/geometries/geom3/create.d.ts +6 -0
- package/src/geometries/geom3/create.js +26 -0
- package/src/geometries/geom3/create.test.js +25 -0
- package/src/geometries/geom3/fromCompactBinary.d.ts +5 -0
- package/src/geometries/geom3/fromCompactBinary.js +44 -0
- package/src/geometries/geom3/fromPoints.d.ts +6 -0
- package/src/geometries/geom3/fromPoints.js +28 -0
- package/src/geometries/geom3/fromPoints.test.js +24 -0
- package/src/geometries/geom3/fromPointsConvex.d.ts +6 -0
- package/src/geometries/geom3/fromPointsConvex.js +26 -0
- package/src/geometries/geom3/fromPointsConvex.test.js +31 -0
- package/src/geometries/geom3/fromToCompactBinary.test.js +139 -0
- package/src/geometries/geom3/index.d.ts +16 -0
- package/src/geometries/geom3/index.js +37 -0
- package/src/geometries/geom3/invert.d.ts +5 -0
- package/src/geometries/geom3/invert.js +18 -0
- package/src/geometries/geom3/invert.test.js +31 -0
- package/src/geometries/geom3/isA.d.ts +5 -0
- package/src/geometries/geom3/isA.js +18 -0
- package/src/geometries/geom3/isA.test.js +19 -0
- package/src/geometries/geom3/toCompactBinary.d.ts +5 -0
- package/src/geometries/geom3/toCompactBinary.js +68 -0
- package/src/geometries/geom3/toPoints.d.ts +6 -0
- package/src/geometries/geom3/toPoints.js +18 -0
- package/src/geometries/geom3/toPoints.test.js +19 -0
- package/src/geometries/geom3/toPolygons.d.ts +6 -0
- package/src/geometries/geom3/toPolygons.js +15 -0
- package/src/geometries/geom3/toString.d.ts +5 -0
- package/src/geometries/geom3/toString.js +23 -0
- package/src/geometries/geom3/transform.d.ts +6 -0
- package/src/geometries/geom3/transform.js +20 -0
- package/src/geometries/geom3/transform.test.js +49 -0
- package/src/geometries/geom3/type.d.ts +11 -0
- package/src/geometries/geom3/validate.d.ts +3 -0
- package/src/geometries/geom3/validate.js +62 -0
- package/src/geometries/index.d.ts +7 -0
- package/src/geometries/index.js +21 -0
- package/src/geometries/path2/appendArc.d.ts +15 -0
- package/src/geometries/path2/appendArc.js +142 -0
- package/src/geometries/path2/appendArc.test.js +88 -0
- package/src/geometries/path2/appendBezier.d.ts +11 -0
- package/src/geometries/path2/appendBezier.js +156 -0
- package/src/geometries/path2/appendBezier.test.js +36 -0
- package/src/geometries/path2/appendPoints.d.ts +6 -0
- package/src/geometries/path2/appendPoints.js +15 -0
- package/src/geometries/path2/appendPoints.test.js +35 -0
- package/src/geometries/path2/applyTransforms.js +20 -0
- package/src/geometries/path2/applyTransforms.test.js +28 -0
- package/src/geometries/path2/clone.d.ts +5 -0
- package/src/geometries/path2/clone.js +9 -0
- package/src/geometries/path2/close.d.ts +5 -0
- package/src/geometries/path2/close.js +33 -0
- package/src/geometries/path2/close.test.js +43 -0
- package/src/geometries/path2/concat.d.ts +5 -0
- package/src/geometries/path2/concat.js +36 -0
- package/src/geometries/path2/concat.test.js +35 -0
- package/src/geometries/path2/create.d.ts +6 -0
- package/src/geometries/path2/create.js +30 -0
- package/src/geometries/path2/create.test.js +7 -0
- package/src/geometries/path2/equals.d.ts +5 -0
- package/src/geometries/path2/equals.js +47 -0
- package/src/geometries/path2/equals.test.js +38 -0
- package/src/geometries/path2/fromCompactBinary.d.ts +5 -0
- package/src/geometries/path2/fromCompactBinary.js +33 -0
- package/src/geometries/path2/fromPoints.d.ts +10 -0
- package/src/geometries/path2/fromPoints.js +42 -0
- package/src/geometries/path2/fromPoints.test.js +33 -0
- package/src/geometries/path2/fromToCompactBinary.test.js +114 -0
- package/src/geometries/path2/index.d.ts +20 -0
- package/src/geometries/path2/index.js +35 -0
- package/src/geometries/path2/isA.d.ts +5 -0
- package/src/geometries/path2/isA.js +20 -0
- package/src/geometries/path2/isA.test.js +19 -0
- package/src/geometries/path2/reverse.d.ts +5 -0
- package/src/geometries/path2/reverse.js +20 -0
- package/src/geometries/path2/reverse.test.js +9 -0
- package/src/geometries/path2/toCompactBinary.d.ts +5 -0
- package/src/geometries/path2/toCompactBinary.js +52 -0
- package/src/geometries/path2/toPoints.d.ts +6 -0
- package/src/geometries/path2/toPoints.js +15 -0
- package/src/geometries/path2/toPoints.test.js +13 -0
- package/src/geometries/path2/toString.d.ts +5 -0
- package/src/geometries/path2/toString.js +24 -0
- package/src/geometries/path2/transform.d.ts +6 -0
- package/src/geometries/path2/transform.js +20 -0
- package/src/geometries/path2/transform.test.js +50 -0
- package/src/geometries/path2/type.d.ts +12 -0
- package/src/geometries/path2/validate.d.ts +3 -0
- package/src/geometries/path2/validate.js +41 -0
- package/src/geometries/poly2/arePointsInside.d.ts +6 -0
- package/src/geometries/poly2/arePointsInside.js +83 -0
- package/src/geometries/poly2/arePointsInside.test.js +77 -0
- package/src/geometries/poly2/create.d.ts +6 -0
- package/src/geometries/poly2/create.js +24 -0
- package/src/geometries/poly2/create.test.js +13 -0
- package/src/geometries/poly2/flip.d.ts +5 -0
- package/src/geometries/poly2/flip.js +15 -0
- package/src/geometries/poly2/index.d.ts +7 -0
- package/src/geometries/poly2/index.js +17 -0
- package/src/geometries/poly2/measureArea.d.ts +5 -0
- package/src/geometries/poly2/measureArea.js +12 -0
- package/src/geometries/poly2/measureArea.test.js +44 -0
- package/src/geometries/poly2/type.d.ts +7 -0
- package/src/geometries/poly3/clone.d.ts +6 -0
- package/src/geometries/poly3/clone.js +28 -0
- package/src/geometries/poly3/clone.test.js +35 -0
- package/src/geometries/poly3/create.d.ts +6 -0
- package/src/geometries/poly3/create.js +24 -0
- package/src/geometries/poly3/create.test.js +9 -0
- package/src/geometries/poly3/fromPoints.d.ts +6 -0
- package/src/geometries/poly3/fromPoints.js +25 -0
- package/src/geometries/poly3/fromPoints.test.js +15 -0
- package/src/geometries/poly3/fromPointsAndPlane.d.ts +7 -0
- package/src/geometries/poly3/fromPointsAndPlane.js +17 -0
- package/src/geometries/poly3/index.d.ts +19 -0
- package/src/geometries/poly3/index.js +29 -0
- package/src/geometries/poly3/invert.d.ts +5 -0
- package/src/geometries/poly3/invert.js +21 -0
- package/src/geometries/poly3/invert.test.js +18 -0
- package/src/geometries/poly3/isA.d.ts +5 -0
- package/src/geometries/poly3/isA.js +18 -0
- package/src/geometries/poly3/isA.test.js +19 -0
- package/src/geometries/poly3/isConvex.d.ts +5 -0
- package/src/geometries/poly3/isConvex.js +44 -0
- package/src/geometries/poly3/isConvex.test.js +24 -0
- package/src/geometries/poly3/measureArea.d.ts +5 -0
- package/src/geometries/poly3/measureArea.js +83 -0
- package/src/geometries/poly3/measureArea.test.js +111 -0
- package/src/geometries/poly3/measureBoundingBox.d.ts +6 -0
- package/src/geometries/poly3/measureBoundingBox.js +20 -0
- package/src/geometries/poly3/measureBoundingBox.test.js +70 -0
- package/src/geometries/poly3/measureBoundingSphere.d.ts +6 -0
- package/src/geometries/poly3/measureBoundingSphere.js +56 -0
- package/src/geometries/poly3/measureBoundingSphere.test.js +60 -0
- package/src/geometries/poly3/measureSignedVolume.d.ts +5 -0
- package/src/geometries/poly3/measureSignedVolume.js +25 -0
- package/src/geometries/poly3/measureSignedVolume.test.js +68 -0
- package/src/geometries/poly3/plane.d.ts +6 -0
- package/src/geometries/poly3/plane.js +10 -0
- package/src/geometries/poly3/toPoints.d.ts +6 -0
- package/src/geometries/poly3/toPoints.js +10 -0
- package/src/geometries/poly3/toString.d.ts +5 -0
- package/src/geometries/poly3/toString.js +17 -0
- package/src/geometries/poly3/transform.d.ts +6 -0
- package/src/geometries/poly3/transform.js +22 -0
- package/src/geometries/poly3/transform.test.js +62 -0
- package/src/geometries/poly3/type.d.ts +11 -0
- package/src/geometries/poly3/validate.d.ts +4 -0
- package/src/geometries/poly3/validate.js +64 -0
- package/src/geometries/types.d.ts +21 -0
- package/src/index.d.ts +17 -0
- package/src/index.js +17 -0
- package/src/index.test-d.ts +26 -0
- package/src/maths/OrthoNormalBasis.js +59 -0
- package/src/maths/constants.d.ts +3 -0
- package/src/maths/constants.js +41 -0
- package/src/maths/index.d.ts +11 -0
- package/src/maths/index.js +19 -0
- package/src/maths/line2/clone.d.ts +5 -0
- package/src/maths/line2/clone.js +18 -0
- package/src/maths/line2/clone.test.js +21 -0
- package/src/maths/line2/closestPoint.d.ts +6 -0
- package/src/maths/line2/closestPoint.js +25 -0
- package/src/maths/line2/closestPoint.test.js +48 -0
- package/src/maths/line2/copy.d.ts +5 -0
- package/src/maths/line2/copy.js +16 -0
- package/src/maths/line2/copy.test.js +27 -0
- package/src/maths/line2/create.d.ts +5 -0
- package/src/maths/line2/create.js +20 -0
- package/src/maths/line2/create.test.js +10 -0
- package/src/maths/line2/direction.d.ts +6 -0
- package/src/maths/line2/direction.js +16 -0
- package/src/maths/line2/direction.test.js +31 -0
- package/src/maths/line2/distanceToPoint.d.ts +6 -0
- package/src/maths/line2/distanceToPoint.js +17 -0
- package/src/maths/line2/distanceToPoint.test.js +31 -0
- package/src/maths/line2/equals.d.ts +5 -0
- package/src/maths/line2/equals.js +11 -0
- package/src/maths/line2/equals.test.js +26 -0
- package/src/maths/line2/fromPoints.d.ts +6 -0
- package/src/maths/line2/fromPoints.js +26 -0
- package/src/maths/line2/fromPoints.test.js +24 -0
- package/src/maths/line2/fromValues.d.ts +5 -0
- package/src/maths/line2/fromValues.js +20 -0
- package/src/maths/line2/fromValues.test.js +12 -0
- package/src/maths/line2/index.d.ts +18 -0
- package/src/maths/line2/index.js +22 -0
- package/src/maths/line2/intersectPointOfLines.d.ts +6 -0
- package/src/maths/line2/intersectPointOfLines.js +21 -0
- package/src/maths/line2/intersectPointOfLines.test.js +31 -0
- package/src/maths/line2/origin.d.ts +6 -0
- package/src/maths/line2/origin.js +13 -0
- package/src/maths/line2/origin.test.js +30 -0
- package/src/maths/line2/reverse.d.ts +5 -0
- package/src/maths/line2/reverse.js +20 -0
- package/src/maths/line2/reverse.test.js +36 -0
- package/src/maths/line2/toString.d.ts +5 -0
- package/src/maths/line2/toString.js +10 -0
- package/src/maths/line2/transform.d.ts +6 -0
- package/src/maths/line2/transform.js +26 -0
- package/src/maths/line2/transform.test.js +89 -0
- package/src/maths/line2/type.d.ts +3 -0
- package/src/maths/line2/xAtY.d.ts +5 -0
- package/src/maths/line2/xAtY.js +22 -0
- package/src/maths/line2/xAtY.test.js +39 -0
- package/src/maths/line3/clone.d.ts +5 -0
- package/src/maths/line3/clone.js +19 -0
- package/src/maths/line3/clone.test.js +24 -0
- package/src/maths/line3/closestPoint.d.ts +6 -0
- package/src/maths/line3/closestPoint.js +24 -0
- package/src/maths/line3/closestPoint.test.js +37 -0
- package/src/maths/line3/copy.d.ts +5 -0
- package/src/maths/line3/copy.js +17 -0
- package/src/maths/line3/copy.test.js +33 -0
- package/src/maths/line3/create.d.ts +5 -0
- package/src/maths/line3/create.js +23 -0
- package/src/maths/line3/create.test.js +11 -0
- package/src/maths/line3/direction.d.ts +6 -0
- package/src/maths/line3/direction.js +10 -0
- package/src/maths/line3/direction.test.js +26 -0
- package/src/maths/line3/distanceToPoint.d.ts +6 -0
- package/src/maths/line3/distanceToPoint.js +19 -0
- package/src/maths/line3/distanceToPoint.test.js +31 -0
- package/src/maths/line3/equals.d.ts +5 -0
- package/src/maths/line3/equals.js +25 -0
- package/src/maths/line3/equals.test.js +17 -0
- package/src/maths/line3/fromPlanes.d.ts +6 -0
- package/src/maths/line3/fromPlanes.js +47 -0
- package/src/maths/line3/fromPlanes.test.js +38 -0
- package/src/maths/line3/fromPointAndDirection.d.ts +6 -0
- package/src/maths/line3/fromPointAndDirection.js +25 -0
- package/src/maths/line3/fromPointAndDirection.test.js +37 -0
- package/src/maths/line3/fromPoints.d.ts +6 -0
- package/src/maths/line3/fromPoints.js +19 -0
- package/src/maths/line3/fromPoints.test.js +37 -0
- package/src/maths/line3/index.d.ts +18 -0
- package/src/maths/line3/index.js +22 -0
- package/src/maths/line3/intersectPointOfLineAndPlane.d.ts +7 -0
- package/src/maths/line3/intersectPointOfLineAndPlane.js +29 -0
- package/src/maths/line3/intersectPointOfLineAndPlane.test.js +29 -0
- package/src/maths/line3/origin.d.ts +6 -0
- package/src/maths/line3/origin.js +10 -0
- package/src/maths/line3/origin.test.js +26 -0
- package/src/maths/line3/reverse.d.ts +5 -0
- package/src/maths/line3/reverse.js +19 -0
- package/src/maths/line3/reverse.test.js +33 -0
- package/src/maths/line3/toString.d.ts +5 -0
- package/src/maths/line3/toString.js +14 -0
- package/src/maths/line3/transform.d.ts +6 -0
- package/src/maths/line3/transform.js +26 -0
- package/src/maths/line3/transform.test.js +66 -0
- package/src/maths/line3/type.d.ts +5 -0
- package/src/maths/mat4/add.d.ts +5 -0
- package/src/maths/mat4/add.js +30 -0
- package/src/maths/mat4/add.test.js +27 -0
- package/src/maths/mat4/clone.d.ts +5 -0
- package/src/maths/mat4/clone.js +31 -0
- package/src/maths/mat4/clone.test.js +21 -0
- package/src/maths/mat4/copy.d.ts +5 -0
- package/src/maths/mat4/copy.js +29 -0
- package/src/maths/mat4/copy.test.js +30 -0
- package/src/maths/mat4/create.d.ts +5 -0
- package/src/maths/mat4/create.js +20 -0
- package/src/maths/mat4/create.test.js +10 -0
- package/src/maths/mat4/equals.d.ts +5 -0
- package/src/maths/mat4/equals.js +16 -0
- package/src/maths/mat4/equals.test.js +56 -0
- package/src/maths/mat4/fromRotation.d.ts +6 -0
- package/src/maths/mat4/fromRotation.js +60 -0
- package/src/maths/mat4/fromRotation.test.js +18 -0
- package/src/maths/mat4/fromScaling.d.ts +6 -0
- package/src/maths/mat4/fromScaling.js +35 -0
- package/src/maths/mat4/fromScaling.test.js +12 -0
- package/src/maths/mat4/fromTaitBryanRotation.d.ts +5 -0
- package/src/maths/mat4/fromTaitBryanRotation.js +55 -0
- package/src/maths/mat4/fromTaitBryanRotation.test.js +24 -0
- package/src/maths/mat4/fromTranslation.d.ts +6 -0
- package/src/maths/mat4/fromTranslation.js +35 -0
- package/src/maths/mat4/fromTranslation.test.js +12 -0
- package/src/maths/mat4/fromValues.d.ts +5 -0
- package/src/maths/mat4/fromValues.js +53 -0
- package/src/maths/mat4/fromValues.test.js +12 -0
- package/src/maths/mat4/fromVectorRotation.d.ts +6 -0
- package/src/maths/mat4/fromVectorRotation.js +49 -0
- package/src/maths/mat4/fromVectorRotation.test.js +127 -0
- package/src/maths/mat4/fromXRotation.d.ts +5 -0
- package/src/maths/mat4/fromXRotation.js +41 -0
- package/src/maths/mat4/fromXRotation.test.js +14 -0
- package/src/maths/mat4/fromYRotation.d.ts +5 -0
- package/src/maths/mat4/fromYRotation.js +41 -0
- package/src/maths/mat4/fromYRotation.test.js +14 -0
- package/src/maths/mat4/fromZRotation.d.ts +5 -0
- package/src/maths/mat4/fromZRotation.js +41 -0
- package/src/maths/mat4/fromZRotation.test.js +14 -0
- package/src/maths/mat4/identity.d.ts +5 -0
- package/src/maths/mat4/identity.js +28 -0
- package/src/maths/mat4/identity.test.js +12 -0
- package/src/maths/mat4/index.d.ts +29 -0
- package/src/maths/mat4/index.js +36 -0
- package/src/maths/mat4/invert.js +71 -0
- package/src/maths/mat4/invert.test.js +32 -0
- package/src/maths/mat4/isIdentity.d.ts +5 -0
- package/src/maths/mat4/isIdentity.js +20 -0
- package/src/maths/mat4/isIdentity.test.js +11 -0
- package/src/maths/mat4/isMirroring.d.ts +5 -0
- package/src/maths/mat4/isMirroring.js +24 -0
- package/src/maths/mat4/isMirroring.test.js +37 -0
- package/src/maths/mat4/isOnlyTransformScale.js +22 -0
- package/src/maths/mat4/isOnlyTransformScale.test.js +29 -0
- package/src/maths/mat4/leftMultiplyVec2.d.ts +6 -0
- package/src/maths/mat4/leftMultiplyVec2.js +28 -0
- package/src/maths/mat4/leftMultiplyVec3.d.ts +6 -0
- package/src/maths/mat4/leftMultiplyVec3.js +29 -0
- package/src/maths/mat4/mirror.d.ts +6 -0
- package/src/maths/mat4/mirror.js +34 -0
- package/src/maths/mat4/mirrorByPlane.d.ts +6 -0
- package/src/maths/mat4/mirrorByPlane.js +32 -0
- package/src/maths/mat4/mirrorByPlane.test.js +28 -0
- package/src/maths/mat4/multiply.d.ts +5 -0
- package/src/maths/mat4/multiply.js +67 -0
- package/src/maths/mat4/multiply.test.js +28 -0
- package/src/maths/mat4/rightMultiplyVec2.d.ts +6 -0
- package/src/maths/mat4/rightMultiplyVec2.js +29 -0
- package/src/maths/mat4/rightMultiplyVec3.d.ts +6 -0
- package/src/maths/mat4/rightMultiplyVec3.js +30 -0
- package/src/maths/mat4/rotate.d.ts +6 -0
- package/src/maths/mat4/rotate.js +82 -0
- package/src/maths/mat4/rotate.test.js +27 -0
- package/src/maths/mat4/rotateX.d.ts +5 -0
- package/src/maths/mat4/rotateX.js +47 -0
- package/src/maths/mat4/rotateX.test.js +21 -0
- package/src/maths/mat4/rotateY.d.ts +5 -0
- package/src/maths/mat4/rotateY.js +47 -0
- package/src/maths/mat4/rotateY.test.js +21 -0
- package/src/maths/mat4/rotateZ.d.ts +5 -0
- package/src/maths/mat4/rotateZ.js +47 -0
- package/src/maths/mat4/rotateZ.test.js +21 -0
- package/src/maths/mat4/scale.d.ts +6 -0
- package/src/maths/mat4/scale.js +34 -0
- package/src/maths/mat4/scale.test.js +21 -0
- package/src/maths/mat4/subtract.d.ts +5 -0
- package/src/maths/mat4/subtract.js +30 -0
- package/src/maths/mat4/subtract.test.js +27 -0
- package/src/maths/mat4/toString.d.ts +5 -0
- package/src/maths/mat4/toString.js +10 -0
- package/src/maths/mat4/translate.d.ts +6 -0
- package/src/maths/mat4/translate.js +51 -0
- package/src/maths/mat4/translate.test.js +72 -0
- package/src/maths/mat4/type.d.ts +8 -0
- package/src/maths/plane/clone.d.ts +5 -0
- package/src/maths/plane/clone.test.js +24 -0
- package/src/maths/plane/copy.d.ts +5 -0
- package/src/maths/plane/copy.test.js +30 -0
- package/src/maths/plane/create.d.ts +5 -0
- package/src/maths/plane/create.test.js +10 -0
- package/src/maths/plane/equals.d.ts +5 -0
- package/src/maths/plane/equals.test.js +17 -0
- package/src/maths/plane/flip.d.ts +5 -0
- package/src/maths/plane/flip.js +17 -0
- package/src/maths/plane/flip.test.js +26 -0
- package/src/maths/plane/fromNoisyPoints.d.ts +6 -0
- package/src/maths/plane/fromNoisyPoints.js +106 -0
- package/src/maths/plane/fromNoisyPoints.test.js +24 -0
- package/src/maths/plane/fromNormalAndPoint.d.ts +6 -0
- package/src/maths/plane/fromNormalAndPoint.js +32 -0
- package/src/maths/plane/fromNormalAndPoint.test.js +12 -0
- package/src/maths/plane/fromPoints.d.ts +6 -0
- package/src/maths/plane/fromPoints.js +47 -0
- package/src/maths/plane/fromPoints.test.js +20 -0
- package/src/maths/plane/fromPointsRandom.d.ts +6 -0
- package/src/maths/plane/fromPointsRandom.js +42 -0
- package/src/maths/plane/fromValues.d.ts +5 -0
- package/src/maths/plane/index.d.ts +17 -0
- package/src/maths/plane/index.js +46 -0
- package/src/maths/plane/projectionOfPoint.d.ts +6 -0
- package/src/maths/plane/projectionOfPoint.js +19 -0
- package/src/maths/plane/projectionOfPoint.test.js +43 -0
- package/src/maths/plane/signedDistanceToPoint.d.ts +6 -0
- package/src/maths/plane/signedDistanceToPoint.js +13 -0
- package/src/maths/plane/signedDistanceToPoint.test.js +20 -0
- package/src/maths/plane/toString.d.ts +5 -0
- package/src/maths/plane/transform.d.ts +6 -0
- package/src/maths/plane/transform.js +40 -0
- package/src/maths/plane/transform.test.js +72 -0
- package/src/maths/plane/type.d.ts +3 -0
- package/src/maths/rotation.test.js +131 -0
- package/src/maths/types.d.ts +8 -0
- package/src/maths/utils/aboutEqualNormals.d.ts +5 -0
- package/src/maths/utils/aboutEqualNormals.js +12 -0
- package/src/maths/utils/area.d.ts +5 -0
- package/src/maths/utils/area.js +17 -0
- package/src/maths/utils/index.d.ts +8 -0
- package/src/maths/utils/index.js +15 -0
- package/src/maths/utils/interpolateBetween2DPointsForY.d.ts +5 -0
- package/src/maths/utils/interpolateBetween2DPointsForY.js +31 -0
- package/src/maths/utils/intersect.d.ts +5 -0
- package/src/maths/utils/intersect.js +40 -0
- package/src/maths/utils/solve2Linear.d.ts +5 -0
- package/src/maths/utils/solve2Linear.js +11 -0
- package/src/maths/utils/trigonometry.d.ts +2 -0
- package/src/maths/utils/trigonometry.js +34 -0
- package/src/maths/utils/trigonometry.test.js +27 -0
- package/src/maths/vec1/type.d.ts +3 -0
- package/src/maths/vec2/abs.d.ts +5 -0
- package/src/maths/vec2/abs.js +15 -0
- package/src/maths/vec2/abs.test.js +24 -0
- package/src/maths/vec2/add.d.ts +5 -0
- package/src/maths/vec2/add.js +16 -0
- package/src/maths/vec2/add.test.js +26 -0
- package/src/maths/vec2/angle.d.ts +3 -0
- package/src/maths/vec2/angle.js +1 -0
- package/src/maths/vec2/angleDegrees.d.ts +5 -0
- package/src/maths/vec2/angleDegrees.js +12 -0
- package/src/maths/vec2/angleDegrees.test.js +24 -0
- package/src/maths/vec2/angleRadians.d.ts +5 -0
- package/src/maths/vec2/angleRadians.js +10 -0
- package/src/maths/vec2/angleRadians.test.js +24 -0
- package/src/maths/vec2/clone.d.ts +5 -0
- package/src/maths/vec2/clone.js +17 -0
- package/src/maths/vec2/clone.test.js +21 -0
- package/src/maths/vec2/copy.d.ts +5 -0
- package/src/maths/vec2/copy.js +15 -0
- package/src/maths/vec2/copy.test.js +30 -0
- package/src/maths/vec2/create.d.ts +5 -0
- package/src/maths/vec2/create.js +15 -0
- package/src/maths/vec2/create.test.js +10 -0
- package/src/maths/vec2/cross.d.ts +6 -0
- package/src/maths/vec2/cross.js +17 -0
- package/src/maths/vec2/cross.test.js +51 -0
- package/src/maths/vec2/distance.d.ts +5 -0
- package/src/maths/vec2/distance.js +15 -0
- package/src/maths/vec2/distance.test.js +30 -0
- package/src/maths/vec2/divide.d.ts +5 -0
- package/src/maths/vec2/divide.js +16 -0
- package/src/maths/vec2/divide.test.js +36 -0
- package/src/maths/vec2/dot.d.ts +5 -0
- package/src/maths/vec2/dot.js +11 -0
- package/src/maths/vec2/dot.test.js +24 -0
- package/src/maths/vec2/equals.d.ts +5 -0
- package/src/maths/vec2/equals.js +11 -0
- package/src/maths/vec2/equals.test.js +17 -0
- package/src/maths/vec2/fromAngleDegrees.d.ts +5 -0
- package/src/maths/vec2/fromAngleDegrees.js +13 -0
- package/src/maths/vec2/fromAngleDegrees.test.js +12 -0
- package/src/maths/vec2/fromAngleRadians.d.ts +5 -0
- package/src/maths/vec2/fromAngleRadians.js +17 -0
- package/src/maths/vec2/fromAngleRadians.test.js +15 -0
- package/src/maths/vec2/fromScalar.d.ts +5 -0
- package/src/maths/vec2/fromScalar.js +15 -0
- package/src/maths/vec2/fromScalar.test.js +12 -0
- package/src/maths/vec2/fromValues.d.ts +5 -0
- package/src/maths/vec2/fromValues.js +18 -0
- package/src/maths/vec2/index.d.ts +36 -0
- package/src/maths/vec2/index.js +39 -0
- package/src/maths/vec2/length.d.ts +5 -0
- package/src/maths/vec2/length.js +10 -0
- package/src/maths/vec2/length.test.js +29 -0
- package/src/maths/vec2/lerp.d.ts +5 -0
- package/src/maths/vec2/lerp.js +19 -0
- package/src/maths/vec2/lerp.test.js +26 -0
- package/src/maths/vec2/max.d.ts +5 -0
- package/src/maths/vec2/max.js +16 -0
- package/src/maths/vec2/max.test.js +31 -0
- package/src/maths/vec2/min.d.ts +5 -0
- package/src/maths/vec2/min.js +16 -0
- package/src/maths/vec2/min.test.js +31 -0
- package/src/maths/vec2/multiply.d.ts +5 -0
- package/src/maths/vec2/multiply.js +16 -0
- package/src/maths/vec2/multiply.test.js +36 -0
- package/src/maths/vec2/negate.d.ts +5 -0
- package/src/maths/vec2/negate.js +15 -0
- package/src/maths/vec2/negate.test.js +26 -0
- package/src/maths/vec2/normal.d.ts +5 -0
- package/src/maths/vec2/normal.js +17 -0
- package/src/maths/vec2/normal.test.js +30 -0
- package/src/maths/vec2/normalize.d.ts +5 -0
- package/src/maths/vec2/normalize.js +23 -0
- package/src/maths/vec2/normalize.test.js +36 -0
- package/src/maths/vec2/rotate.d.ts +5 -0
- package/src/maths/vec2/rotate.js +23 -0
- package/src/maths/vec2/rotate.test.js +31 -0
- package/src/maths/vec2/scale.d.ts +5 -0
- package/src/maths/vec2/scale.js +16 -0
- package/src/maths/vec2/scale.test.js +24 -0
- package/src/maths/vec2/snap.d.ts +5 -0
- package/src/maths/vec2/snap.js +16 -0
- package/src/maths/vec2/snap.test.js +32 -0
- package/src/maths/vec2/squaredDistance.d.ts +5 -0
- package/src/maths/vec2/squaredDistance.js +15 -0
- package/src/maths/vec2/squaredDistance.test.js +30 -0
- package/src/maths/vec2/squaredLength.d.ts +5 -0
- package/src/maths/vec2/squaredLength.js +14 -0
- package/src/maths/vec2/squaredLength.test.js +29 -0
- package/src/maths/vec2/subtract.d.ts +5 -0
- package/src/maths/vec2/subtract.js +16 -0
- package/src/maths/vec2/subtract.test.js +26 -0
- package/src/maths/vec2/toString.d.ts +5 -0
- package/src/maths/vec2/toString.js +10 -0
- package/src/maths/vec2/transform.d.ts +6 -0
- package/src/maths/vec2/transform.js +18 -0
- package/src/maths/vec2/transform.test.js +66 -0
- package/src/maths/vec2/type.d.ts +3 -0
- package/src/maths/vec3/abs.d.ts +5 -0
- package/src/maths/vec3/abs.js +16 -0
- package/src/maths/vec3/abs.test.js +24 -0
- package/src/maths/vec3/add.d.ts +5 -0
- package/src/maths/vec3/add.js +17 -0
- package/src/maths/vec3/add.test.js +26 -0
- package/src/maths/vec3/angle.d.ts +5 -0
- package/src/maths/vec3/angle.js +25 -0
- package/src/maths/vec3/angle.test.js +34 -0
- package/src/maths/vec3/clone.d.ts +5 -0
- package/src/maths/vec3/clone.js +18 -0
- package/src/maths/vec3/clone.test.js +21 -0
- package/src/maths/vec3/copy.d.ts +5 -0
- package/src/maths/vec3/copy.js +16 -0
- package/src/maths/vec3/copy.test.js +27 -0
- package/src/maths/vec3/create.d.ts +5 -0
- package/src/maths/vec3/create.js +15 -0
- package/src/maths/vec3/create.test.js +10 -0
- package/src/maths/vec3/cross.d.ts +5 -0
- package/src/maths/vec3/cross.js +24 -0
- package/src/maths/vec3/cross.test.js +51 -0
- package/src/maths/vec3/distance.d.ts +5 -0
- package/src/maths/vec3/distance.js +16 -0
- package/src/maths/vec3/distance.test.js +46 -0
- package/src/maths/vec3/divide.d.ts +5 -0
- package/src/maths/vec3/divide.js +17 -0
- package/src/maths/vec3/divide.test.js +36 -0
- package/src/maths/vec3/dot.d.ts +5 -0
- package/src/maths/vec3/dot.js +11 -0
- package/src/maths/vec3/dot.test.js +24 -0
- package/src/maths/vec3/equals.d.ts +5 -0
- package/src/maths/vec3/equals.js +11 -0
- package/src/maths/vec3/equals.test.js +17 -0
- package/src/maths/vec3/fromScalar.d.ts +5 -0
- package/src/maths/vec3/fromScalar.js +17 -0
- package/src/maths/vec3/fromScalar.test.js +12 -0
- package/src/maths/vec3/fromValues.d.ts +5 -0
- package/src/maths/vec3/fromValues.js +20 -0
- package/src/maths/vec3/fromValues.test.js +12 -0
- package/src/maths/vec3/fromVec2.d.ts +6 -0
- package/src/maths/vec3/fromVec2.js +17 -0
- package/src/maths/vec3/fromVec2.test.js +13 -0
- package/src/maths/vec3/index.d.ts +35 -0
- package/src/maths/vec3/index.js +39 -0
- package/src/maths/vec3/length.d.ts +5 -0
- package/src/maths/vec3/length.js +15 -0
- package/src/maths/vec3/length.test.js +45 -0
- package/src/maths/vec3/lerp.d.ts +5 -0
- package/src/maths/vec3/lerp.js +18 -0
- package/src/maths/vec3/lerp.test.js +26 -0
- package/src/maths/vec3/max.d.ts +5 -0
- package/src/maths/vec3/max.js +17 -0
- package/src/maths/vec3/max.test.js +31 -0
- package/src/maths/vec3/min.d.ts +5 -0
- package/src/maths/vec3/min.js +17 -0
- package/src/maths/vec3/min.test.js +31 -0
- package/src/maths/vec3/multiply.d.ts +5 -0
- package/src/maths/vec3/multiply.js +17 -0
- package/src/maths/vec3/multiply.test.js +36 -0
- package/src/maths/vec3/negate.d.ts +5 -0
- package/src/maths/vec3/negate.js +16 -0
- package/src/maths/vec3/negate.test.js +26 -0
- package/src/maths/vec3/normalize.d.ts +5 -0
- package/src/maths/vec3/normalize.js +23 -0
- package/src/maths/vec3/normalize.test.js +36 -0
- package/src/maths/vec3/orthogonal.d.ts +5 -0
- package/src/maths/vec3/orthogonal.js +22 -0
- package/src/maths/vec3/orthogonal.test.js +24 -0
- package/src/maths/vec3/rotateX.d.ts +5 -0
- package/src/maths/vec3/rotateX.js +33 -0
- package/src/maths/vec3/rotateX.test.js +31 -0
- package/src/maths/vec3/rotateY.d.ts +5 -0
- package/src/maths/vec3/rotateY.js +33 -0
- package/src/maths/vec3/rotateY.test.js +31 -0
- package/src/maths/vec3/rotateZ.d.ts +5 -0
- package/src/maths/vec3/rotateZ.js +30 -0
- package/src/maths/vec3/rotateZ.test.js +31 -0
- package/src/maths/vec3/scale.d.ts +5 -0
- package/src/maths/vec3/scale.js +17 -0
- package/src/maths/vec3/scale.test.js +36 -0
- package/src/maths/vec3/snap.d.ts +5 -0
- package/src/maths/vec3/snap.js +17 -0
- package/src/maths/vec3/snap.test.js +32 -0
- package/src/maths/vec3/squaredDistance.d.ts +5 -0
- package/src/maths/vec3/squaredDistance.js +16 -0
- package/src/maths/vec3/squaredDistance.test.js +46 -0
- package/src/maths/vec3/squaredLength.d.ts +5 -0
- package/src/maths/vec3/squaredLength.js +15 -0
- package/src/maths/vec3/squaredLength.test.js +45 -0
- package/src/maths/vec3/subtract.d.ts +5 -0
- package/src/maths/vec3/subtract.js +17 -0
- package/src/maths/vec3/subtract.test.js +26 -0
- package/src/maths/vec3/toString.d.ts +5 -0
- package/src/maths/vec3/toString.js +9 -0
- package/src/maths/vec3/transform.d.ts +6 -0
- package/src/maths/vec3/transform.js +22 -0
- package/src/maths/vec3/transform.test.js +66 -0
- package/src/maths/vec3/type.d.ts +3 -0
- package/src/maths/vec4/clone.d.ts +5 -0
- package/src/maths/vec4/clone.js +19 -0
- package/src/maths/vec4/clone.test.js +24 -0
- package/src/maths/vec4/copy.d.ts +5 -0
- package/src/maths/vec4/copy.js +17 -0
- package/src/maths/vec4/copy.test.js +30 -0
- package/src/maths/vec4/create.d.ts +5 -0
- package/src/maths/vec4/create.js +15 -0
- package/src/maths/vec4/create.test.js +10 -0
- package/src/maths/vec4/dot.d.ts +5 -0
- package/src/maths/vec4/dot.js +11 -0
- package/src/maths/vec4/dot.test.js +11 -0
- package/src/maths/vec4/equals.d.ts +5 -0
- package/src/maths/vec4/equals.js +11 -0
- package/src/maths/vec4/equals.test.js +17 -0
- package/src/maths/vec4/fromScalar.d.ts +5 -0
- package/src/maths/vec4/fromScalar.js +17 -0
- package/src/maths/vec4/fromScalar.test.js +12 -0
- package/src/maths/vec4/fromValues.d.ts +5 -0
- package/src/maths/vec4/fromValues.js +22 -0
- package/src/maths/vec4/fromValues.test.js +15 -0
- package/src/maths/vec4/index.d.ts +12 -0
- package/src/maths/vec4/index.js +16 -0
- package/src/maths/vec4/toString.d.ts +5 -0
- package/src/maths/vec4/toString.js +10 -0
- package/src/maths/vec4/transform.d.ts +6 -0
- package/src/maths/vec4/transform.js +20 -0
- package/src/maths/vec4/transform.test.js +66 -0
- package/src/maths/vec4/type.d.ts +3 -0
- package/src/measurements/calculateEpsilonFromBounds.js +11 -0
- package/src/measurements/calculateEpsilonFromBounds.test.js +18 -0
- package/src/measurements/index.d.ts +15 -0
- package/src/measurements/index.js +20 -0
- package/src/measurements/measureAggregateArea.d.ts +6 -0
- package/src/measurements/measureAggregateArea.js +26 -0
- package/src/measurements/measureAggregateArea.test.js +22 -0
- package/src/measurements/measureAggregateBoundingBox.d.ts +8 -0
- package/src/measurements/measureAggregateBoundingBox.js +30 -0
- package/src/measurements/measureAggregateBoundingBox.test.js +35 -0
- package/src/measurements/measureAggregateEpsilon.d.ts +6 -0
- package/src/measurements/measureAggregateEpsilon.js +29 -0
- package/src/measurements/measureAggregateEpsilon.test.js +28 -0
- package/src/measurements/measureAggregateVolume.d.ts +6 -0
- package/src/measurements/measureAggregateVolume.js +26 -0
- package/src/measurements/measureAggregateVolume.test.js +21 -0
- package/src/measurements/measureArea.d.ts +8 -0
- package/src/measurements/measureArea.js +80 -0
- package/src/measurements/measureArea.test.js +58 -0
- package/src/measurements/measureBoundingBox.d.ts +10 -0
- package/src/measurements/measureBoundingBox.js +134 -0
- package/src/measurements/measureBoundingBox.test.js +66 -0
- package/src/measurements/measureBoundingSphere.d.ts +9 -0
- package/src/measurements/measureBoundingSphere.js +146 -0
- package/src/measurements/measureBoundingSphere.test.js +59 -0
- package/src/measurements/measureCenter.d.ts +7 -0
- package/src/measurements/measureCenter.js +28 -0
- package/src/measurements/measureCenter.test.js +58 -0
- package/src/measurements/measureCenterOfMass.d.ts +7 -0
- package/src/measurements/measureCenterOfMass.js +106 -0
- package/src/measurements/measureCenterOfMass.test.js +58 -0
- package/src/measurements/measureDimensions.d.ts +7 -0
- package/src/measurements/measureDimensions.js +28 -0
- package/src/measurements/measureDimensions.test.js +58 -0
- package/src/measurements/measureEpsilon.d.ts +8 -0
- package/src/measurements/measureEpsilon.js +48 -0
- package/src/measurements/measureEpsilon.test.js +58 -0
- package/src/measurements/measureVolume.d.ts +8 -0
- package/src/measurements/measureVolume.js +68 -0
- package/src/measurements/measureVolume.test.js +58 -0
- package/src/measurements/types.d.ts +3 -0
- package/src/operations/booleans/fromFakePolygons.js +52 -0
- package/src/operations/booleans/index.d.ts +6 -0
- package/src/operations/booleans/index.js +14 -0
- package/src/operations/booleans/intersect.d.ts +7 -0
- package/src/operations/booleans/intersect.js +47 -0
- package/src/operations/booleans/intersectGeom2.js +27 -0
- package/src/operations/booleans/intersectGeom2.test.js +69 -0
- package/src/operations/booleans/intersectGeom3.js +25 -0
- package/src/operations/booleans/intersectGeom3.test.js +116 -0
- package/src/operations/booleans/intersectGeom3Sub.js +33 -0
- package/src/operations/booleans/mayOverlap.js +35 -0
- package/src/operations/booleans/mayOverlap.test.js +73 -0
- package/src/operations/booleans/scission.d.ts +6 -0
- package/src/operations/booleans/scission.js +45 -0
- package/src/operations/booleans/scission.test.js +51 -0
- package/src/operations/booleans/scissionGeom3.js +93 -0
- package/src/operations/booleans/subtract.d.ts +7 -0
- package/src/operations/booleans/subtract.js +47 -0
- package/src/operations/booleans/subtractGeom2.js +27 -0
- package/src/operations/booleans/subtractGeom2.test.js +72 -0
- package/src/operations/booleans/subtractGeom3.js +25 -0
- package/src/operations/booleans/subtractGeom3.test.js +109 -0
- package/src/operations/booleans/subtractGeom3Sub.js +31 -0
- package/src/operations/booleans/to3DWalls.js +36 -0
- package/src/operations/booleans/trees/Node.js +144 -0
- package/src/operations/booleans/trees/PolygonTreeNode.js +261 -0
- package/src/operations/booleans/trees/Tree.js +50 -0
- package/src/operations/booleans/trees/index.js +3 -0
- package/src/operations/booleans/trees/splitLineSegmentByPlane.js +15 -0
- package/src/operations/booleans/trees/splitPolygonByPlane.d.ts +33 -0
- package/src/operations/booleans/trees/splitPolygonByPlane.js +119 -0
- package/src/operations/booleans/trees/splitPolygonByPlane.test.js +132 -0
- package/src/operations/booleans/union.d.ts +7 -0
- package/src/operations/booleans/union.js +46 -0
- package/src/operations/booleans/unionGeom2.js +26 -0
- package/src/operations/booleans/unionGeom2.test.js +166 -0
- package/src/operations/booleans/unionGeom3.js +25 -0
- package/src/operations/booleans/unionGeom3.test.js +133 -0
- package/src/operations/booleans/unionGeom3Sub.js +40 -0
- package/src/operations/expansions/expand.d.ts +18 -0
- package/src/operations/expansions/expand.js +42 -0
- package/src/operations/expansions/expand.test.js +188 -0
- package/src/operations/expansions/expandGeom2.js +43 -0
- package/src/operations/expansions/expandGeom3.js +36 -0
- package/src/operations/expansions/expandGeom3.test.js +32 -0
- package/src/operations/expansions/expandPath2.js +99 -0
- package/src/operations/expansions/expandShell.js +224 -0
- package/src/operations/expansions/extrudePolygon.js +34 -0
- package/src/operations/expansions/index.d.ts +4 -0
- package/src/operations/expansions/index.js +11 -0
- package/src/operations/expansions/offset.d.ts +15 -0
- package/src/operations/expansions/offset.js +36 -0
- package/src/operations/expansions/offset.test.js +503 -0
- package/src/operations/expansions/offsetFromPoints.js +170 -0
- package/src/operations/expansions/offsetGeom2.js +47 -0
- package/src/operations/expansions/offsetPath2.js +32 -0
- package/src/operations/extrusions/earcut/assignHoles.js +91 -0
- package/src/operations/extrusions/earcut/assignHoles.test.js +74 -0
- package/src/operations/extrusions/earcut/eliminateHoles.js +131 -0
- package/src/operations/extrusions/earcut/index.js +252 -0
- package/src/operations/extrusions/earcut/linkedList.js +58 -0
- package/src/operations/extrusions/earcut/linkedListSort.js +54 -0
- package/src/operations/extrusions/earcut/linkedPolygon.js +197 -0
- package/src/operations/extrusions/earcut/polygonHierarchy.js +64 -0
- package/src/operations/extrusions/earcut/triangle.js +16 -0
- package/src/operations/extrusions/extrudeFromSlices.d.ts +15 -0
- package/src/operations/extrusions/extrudeFromSlices.js +124 -0
- package/src/operations/extrusions/extrudeFromSlices.test.js +167 -0
- package/src/operations/extrusions/extrudeHelical.d.ts +14 -0
- package/src/operations/extrusions/extrudeHelical.js +109 -0
- package/src/operations/extrusions/extrudeHelical.test.js +70 -0
- package/src/operations/extrusions/extrudeLinear.d.ts +15 -0
- package/src/operations/extrusions/extrudeLinear.js +47 -0
- package/src/operations/extrusions/extrudeLinear.test.js +226 -0
- package/src/operations/extrusions/extrudeLinearGeom2.js +64 -0
- package/src/operations/extrusions/extrudeLinearPath2.js +24 -0
- package/src/operations/extrusions/extrudeRectangular.d.ts +17 -0
- package/src/operations/extrusions/extrudeRectangular.js +45 -0
- package/src/operations/extrusions/extrudeRectangular.test.js +72 -0
- package/src/operations/extrusions/extrudeRectangularGeom2.js +46 -0
- package/src/operations/extrusions/extrudeRectangularPath2.js +33 -0
- package/src/operations/extrusions/extrudeRotate.d.ts +12 -0
- package/src/operations/extrusions/extrudeRotate.js +138 -0
- package/src/operations/extrusions/extrudeRotate.test.js +161 -0
- package/src/operations/extrusions/extrudeWalls.js +78 -0
- package/src/operations/extrusions/extrudeWalls.test.js +82 -0
- package/src/operations/extrusions/index.d.ts +9 -0
- package/src/operations/extrusions/index.js +16 -0
- package/src/operations/extrusions/project.d.ts +14 -0
- package/src/operations/extrusions/project.js +88 -0
- package/src/operations/extrusions/project.test.js +123 -0
- package/src/operations/extrusions/slice/calculatePlane.d.ts +7 -0
- package/src/operations/extrusions/slice/calculatePlane.js +41 -0
- package/src/operations/extrusions/slice/calculatePlane.test.js +35 -0
- package/src/operations/extrusions/slice/clone.d.ts +6 -0
- package/src/operations/extrusions/slice/clone.js +28 -0
- package/src/operations/extrusions/slice/clone.test.js +34 -0
- package/src/operations/extrusions/slice/create.d.ts +5 -0
- package/src/operations/extrusions/slice/create.js +20 -0
- package/src/operations/extrusions/slice/create.test.js +9 -0
- package/src/operations/extrusions/slice/equals.d.ts +5 -0
- package/src/operations/extrusions/slice/equals.js +27 -0
- package/src/operations/extrusions/slice/equals.test.js +17 -0
- package/src/operations/extrusions/slice/fromPoints.d.ts +9 -0
- package/src/operations/extrusions/slice/fromPoints.js +35 -0
- package/src/operations/extrusions/slice/fromPoints.test.js +15 -0
- package/src/operations/extrusions/slice/fromSides.d.ts +7 -0
- package/src/operations/extrusions/slice/fromSides.js +27 -0
- package/src/operations/extrusions/slice/fromSides.test.js +15 -0
- package/src/operations/extrusions/slice/index.d.ts +16 -0
- package/src/operations/extrusions/slice/index.js +19 -0
- package/src/operations/extrusions/slice/isA.d.ts +5 -0
- package/src/operations/extrusions/slice/isA.js +18 -0
- package/src/operations/extrusions/slice/isA.test.js +19 -0
- package/src/operations/extrusions/slice/repair.js +62 -0
- package/src/operations/extrusions/slice/reverse.d.ts +6 -0
- package/src/operations/extrusions/slice/reverse.js +26 -0
- package/src/operations/extrusions/slice/toEdges.d.ts +5 -0
- package/src/operations/extrusions/slice/toEdges.js +13 -0
- package/src/operations/extrusions/slice/toPolygons.d.ts +7 -0
- package/src/operations/extrusions/slice/toPolygons.js +40 -0
- package/src/operations/extrusions/slice/toString.d.ts +5 -0
- package/src/operations/extrusions/slice/toString.js +15 -0
- package/src/operations/extrusions/slice/transform.d.ts +7 -0
- package/src/operations/extrusions/slice/transform.js +21 -0
- package/src/operations/extrusions/slice/transform.test.js +66 -0
- package/src/operations/extrusions/slice/type.d.ts +7 -0
- package/src/operations/hulls/hull.d.ts +8 -0
- package/src/operations/hulls/hull.js +52 -0
- package/src/operations/hulls/hull.test.js +284 -0
- package/src/operations/hulls/hullChain.d.ts +8 -0
- package/src/operations/hulls/hullChain.js +43 -0
- package/src/operations/hulls/hullChain.test.js +87 -0
- package/src/operations/hulls/hullGeom2.js +31 -0
- package/src/operations/hulls/hullGeom3.js +27 -0
- package/src/operations/hulls/hullPath2.js +28 -0
- package/src/operations/hulls/hullPath2.test.js +16 -0
- package/src/operations/hulls/hullPoints2.d.ts +5 -0
- package/src/operations/hulls/hullPoints2.js +62 -0
- package/src/operations/hulls/hullPoints2.test.js +48 -0
- package/src/operations/hulls/hullPoints3.d.ts +6 -0
- package/src/operations/hulls/hullPoints3.js +23 -0
- package/src/operations/hulls/index.d.ts +6 -0
- package/src/operations/hulls/index.js +14 -0
- package/src/operations/hulls/quickhull/Face.js +334 -0
- package/src/operations/hulls/quickhull/HalfEdge.js +56 -0
- package/src/operations/hulls/quickhull/QuickHull.js +754 -0
- package/src/operations/hulls/quickhull/Vertex.js +21 -0
- package/src/operations/hulls/quickhull/VertexList.js +146 -0
- package/src/operations/hulls/quickhull/get-plane-normal.js +20 -0
- package/src/operations/hulls/quickhull/index.js +16 -0
- package/src/operations/hulls/quickhull/point-line-distance.js +42 -0
- package/src/operations/hulls/toUniquePoints.js +34 -0
- package/src/operations/modifiers/generalize.d.ts +12 -0
- package/src/operations/modifiers/generalize.js +82 -0
- package/src/operations/modifiers/generalize.test.js +170 -0
- package/src/operations/modifiers/index.d.ts +3 -0
- package/src/operations/modifiers/index.js +12 -0
- package/src/operations/modifiers/insertTjunctions.js +294 -0
- package/src/operations/modifiers/insertTjunctions.test.js +89 -0
- package/src/operations/modifiers/mergePolygons.js +208 -0
- package/src/operations/modifiers/reTesselateCoplanarPolygons.js +345 -0
- package/src/operations/modifiers/reTesselateCoplanarPolygons.test.js +70 -0
- package/src/operations/modifiers/retessellate.d.ts +3 -0
- package/src/operations/modifiers/retessellate.js +93 -0
- package/src/operations/modifiers/retessellate.test.js +173 -0
- package/src/operations/modifiers/snap.d.ts +6 -0
- package/src/operations/modifiers/snap.js +57 -0
- package/src/operations/modifiers/snap.test.js +146 -0
- package/src/operations/modifiers/snapPolygons.js +32 -0
- package/src/operations/modifiers/snapPolygons.test.js +70 -0
- package/src/operations/modifiers/triangulatePolygons.js +45 -0
- package/src/operations/transforms/align.d.ts +16 -0
- package/src/operations/transforms/align.js +89 -0
- package/src/operations/transforms/align.test.js +96 -0
- package/src/operations/transforms/center.d.ts +24 -0
- package/src/operations/transforms/center.js +90 -0
- package/src/operations/transforms/center.test.js +128 -0
- package/src/operations/transforms/index.d.ts +9 -0
- package/src/operations/transforms/index.js +37 -0
- package/src/operations/transforms/mirror.d.ts +24 -0
- package/src/operations/transforms/mirror.js +78 -0
- package/src/operations/transforms/mirror.test.js +158 -0
- package/src/operations/transforms/rotate.d.ts +19 -0
- package/src/operations/transforms/rotate.js +76 -0
- package/src/operations/transforms/rotate.test.js +154 -0
- package/src/operations/transforms/scale.d.ts +19 -0
- package/src/operations/transforms/scale.js +74 -0
- package/src/operations/transforms/scale.test.js +151 -0
- package/src/operations/transforms/transform.d.ts +7 -0
- package/src/operations/transforms/transform.js +32 -0
- package/src/operations/transforms/transform.test.js +76 -0
- package/src/operations/transforms/translate.d.ts +21 -0
- package/src/operations/transforms/translate.js +72 -0
- package/src/operations/transforms/translate.test.js +151 -0
- package/src/primitives/arc.d.ts +15 -0
- package/src/primitives/arc.js +86 -0
- package/src/primitives/arc.test.js +223 -0
- package/src/primitives/circle.d.ts +14 -0
- package/src/primitives/circle.js +38 -0
- package/src/primitives/circle.test.js +155 -0
- package/src/primitives/commonChecks.js +19 -0
- package/src/primitives/cube.d.ts +11 -0
- package/src/primitives/cube.js +30 -0
- package/src/primitives/cube.test.js +55 -0
- package/src/primitives/cuboid.d.ts +11 -0
- package/src/primitives/cuboid.js +55 -0
- package/src/primitives/cuboid.test.js +64 -0
- package/src/primitives/cylinder.d.ts +13 -0
- package/src/primitives/cylinder.js +46 -0
- package/src/primitives/cylinder.test.js +90 -0
- package/src/primitives/cylinderElliptic.d.ts +16 -0
- package/src/primitives/cylinderElliptic.js +132 -0
- package/src/primitives/cylinderElliptic.test.js +213 -0
- package/src/primitives/ellipse.d.ts +14 -0
- package/src/primitives/ellipse.js +78 -0
- package/src/primitives/ellipse.test.js +146 -0
- package/src/primitives/ellipsoid.d.ts +13 -0
- package/src/primitives/ellipsoid.js +99 -0
- package/src/primitives/ellipsoid.test.js +216 -0
- package/src/primitives/geodesicSphere.d.ts +10 -0
- package/src/primitives/geodesicSphere.js +140 -0
- package/src/primitives/geodesicSphere.test.js +60 -0
- package/src/primitives/index.d.ts +23 -0
- package/src/primitives/index.js +31 -0
- package/src/primitives/line.d.ts +6 -0
- package/src/primitives/line.js +19 -0
- package/src/primitives/line.test.js +17 -0
- package/src/primitives/polygon.d.ts +12 -0
- package/src/primitives/polygon.js +81 -0
- package/src/primitives/polygon.test.js +63 -0
- package/src/primitives/polyhedron.d.ts +14 -0
- package/src/primitives/polyhedron.js +72 -0
- package/src/primitives/polyhedron.test.js +44 -0
- package/src/primitives/rectangle.d.ts +11 -0
- package/src/primitives/rectangle.js +44 -0
- package/src/primitives/rectangle.test.js +59 -0
- package/src/primitives/roundedCuboid.d.ts +13 -0
- package/src/primitives/roundedCuboid.js +193 -0
- package/src/primitives/roundedCuboid.test.js +248 -0
- package/src/primitives/roundedCylinder.d.ts +14 -0
- package/src/primitives/roundedCylinder.js +147 -0
- package/src/primitives/roundedCylinder.test.js +165 -0
- package/src/primitives/roundedRectangle.d.ts +13 -0
- package/src/primitives/roundedRectangle.js +76 -0
- package/src/primitives/roundedRectangle.test.js +124 -0
- package/src/primitives/sphere.d.ts +13 -0
- package/src/primitives/sphere.js +35 -0
- package/src/primitives/sphere.test.js +172 -0
- package/src/primitives/square.d.ts +11 -0
- package/src/primitives/square.js +31 -0
- package/src/primitives/square.test.js +51 -0
- package/src/primitives/star.d.ts +15 -0
- package/src/primitives/star.js +88 -0
- package/src/primitives/star.test.js +148 -0
- package/src/primitives/torus.d.ts +15 -0
- package/src/primitives/torus.js +64 -0
- package/src/primitives/torus.test.js +59 -0
- package/src/primitives/triangle.d.ts +10 -0
- package/src/primitives/triangle.js +163 -0
- package/src/primitives/triangle.test.js +103 -0
- package/src/text/fonts/single-line/hershey/simplex.js +101 -0
- package/src/text/index.d.ts +4 -0
- package/src/text/index.js +12 -0
- package/src/text/text.test.js +187 -0
- package/src/text/vectorChar.d.ts +22 -0
- package/src/text/vectorChar.js +60 -0
- package/src/text/vectorParams.js +26 -0
- package/src/text/vectorText.d.ts +21 -0
- package/src/text/vectorText.js +92 -0
- package/src/utils/areAllShapesTheSameType.d.ts +5 -0
- package/src/utils/areAllShapesTheSameType.js +25 -0
- package/src/utils/areAllShapesTheSameType.test.js +17 -0
- package/src/utils/corners.d.ts +1 -0
- package/src/utils/degToRad.d.ts +3 -0
- package/src/utils/degToRad.js +9 -0
- package/src/utils/degToRad.test.js +19 -0
- package/src/utils/flatten.d.ts +5 -0
- package/src/utils/flatten.js +25 -0
- package/src/utils/flatten.test.js +94 -0
- package/src/utils/fnNumberSort.d.ts +3 -0
- package/src/utils/fnNumberSort.js +6 -0
- package/src/utils/index.d.ts +9 -0
- package/src/utils/index.js +15 -0
- package/src/utils/insertSorted.d.ts +3 -0
- package/src/utils/insertSorted.js +21 -0
- package/src/utils/padArrayToLength.d.ts +3 -0
- package/src/utils/padArrayToLength.js +17 -0
- package/src/utils/padArrayToLength.test.js +27 -0
- package/src/utils/radToDeg.d.ts +3 -0
- package/src/utils/radToDeg.js +9 -0
- package/src/utils/radToDeg.test.js +19 -0
- package/src/utils/radiusToSegments.d.ts +3 -0
- package/src/utils/radiusToSegments.js +18 -0
- package/src/utils/radiusToSegments.test.js +28 -0
- package/src/utils/recursiveArray.d.ts +3 -0
- package/test/helpers/asserts.js +126 -0
- package/test/helpers/comparePoints.js +16 -0
- package/test/helpers/comparePolygonLists.js +10 -0
- package/test/helpers/comparePolygons.js +16 -0
- package/test/helpers/comparePolygonsAsPoints.js +23 -0
- package/test/helpers/compareVectors.js +36 -0
- package/test/helpers/index.js +8 -0
- package/test/helpers/nearlyEqual.js +34 -0
|
@@ -0,0 +1,754 @@
|
|
|
1
|
+
const dot = require('../../../maths/vec3/dot')
|
|
2
|
+
|
|
3
|
+
const pointLineDistance = require('./point-line-distance')
|
|
4
|
+
const getPlaneNormal = require('./get-plane-normal')
|
|
5
|
+
|
|
6
|
+
const VertexList = require('./VertexList')
|
|
7
|
+
const Vertex = require('./Vertex')
|
|
8
|
+
const { Face, VISIBLE, NON_CONVEX, DELETED } = require('./Face')
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Original source from quickhull3d (https://github.com/mauriciopoppe/quickhull3d)
|
|
12
|
+
* Copyright (c) 2015 Mauricio Poppe
|
|
13
|
+
*
|
|
14
|
+
* Adapted to JSCAD by Jeff Gay
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// merge types
|
|
18
|
+
// non convex with respect to the large face
|
|
19
|
+
const MERGE_NON_CONVEX_WRT_LARGER_FACE = 1
|
|
20
|
+
const MERGE_NON_CONVEX = 2
|
|
21
|
+
|
|
22
|
+
class QuickHull {
|
|
23
|
+
constructor (points) {
|
|
24
|
+
if (!Array.isArray(points)) {
|
|
25
|
+
throw TypeError('input is not a valid array')
|
|
26
|
+
}
|
|
27
|
+
if (points.length < 4) {
|
|
28
|
+
throw Error('cannot build a simplex out of <4 points')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
this.tolerance = -1
|
|
32
|
+
|
|
33
|
+
// buffers
|
|
34
|
+
this.nFaces = 0
|
|
35
|
+
this.nPoints = points.length
|
|
36
|
+
|
|
37
|
+
this.faces = []
|
|
38
|
+
this.newFaces = []
|
|
39
|
+
// helpers
|
|
40
|
+
//
|
|
41
|
+
// let `a`, `b` be `Face` instances
|
|
42
|
+
// let `v` be points wrapped as instance of `Vertex`
|
|
43
|
+
//
|
|
44
|
+
// [v, v, ..., v, v, v, ...]
|
|
45
|
+
// ^ ^
|
|
46
|
+
// | |
|
|
47
|
+
// a.outside b.outside
|
|
48
|
+
//
|
|
49
|
+
this.claimed = new VertexList()
|
|
50
|
+
this.unclaimed = new VertexList()
|
|
51
|
+
|
|
52
|
+
// vertices of the hull(internal representation of points)
|
|
53
|
+
this.vertices = []
|
|
54
|
+
for (let i = 0; i < points.length; i += 1) {
|
|
55
|
+
this.vertices.push(new Vertex(points[i], i))
|
|
56
|
+
}
|
|
57
|
+
this.discardedFaces = []
|
|
58
|
+
this.vertexPointIndices = []
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
addVertexToFace (vertex, face) {
|
|
62
|
+
vertex.face = face
|
|
63
|
+
if (!face.outside) {
|
|
64
|
+
this.claimed.add(vertex)
|
|
65
|
+
} else {
|
|
66
|
+
this.claimed.insertBefore(face.outside, vertex)
|
|
67
|
+
}
|
|
68
|
+
face.outside = vertex
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Removes `vertex` for the `claimed` list of vertices, it also makes sure
|
|
73
|
+
* that the link from `face` to the first vertex it sees in `claimed` is
|
|
74
|
+
* linked correctly after the removal
|
|
75
|
+
*
|
|
76
|
+
* @param {Vertex} vertex
|
|
77
|
+
* @param {Face} face
|
|
78
|
+
*/
|
|
79
|
+
removeVertexFromFace (vertex, face) {
|
|
80
|
+
if (vertex === face.outside) {
|
|
81
|
+
// fix face.outside link
|
|
82
|
+
if (vertex.next && vertex.next.face === face) {
|
|
83
|
+
// face has at least 2 outside vertices, move the `outside` reference
|
|
84
|
+
face.outside = vertex.next
|
|
85
|
+
} else {
|
|
86
|
+
// vertex was the only outside vertex that face had
|
|
87
|
+
face.outside = null
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
this.claimed.remove(vertex)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Removes all the visible vertices that `face` is able to see which are
|
|
95
|
+
* stored in the `claimed` vertext list
|
|
96
|
+
*
|
|
97
|
+
* @param {Face} face
|
|
98
|
+
* @return {Vertex|undefined} If face had visible vertices returns
|
|
99
|
+
* `face.outside`, otherwise undefined
|
|
100
|
+
*/
|
|
101
|
+
removeAllVerticesFromFace (face) {
|
|
102
|
+
if (face.outside) {
|
|
103
|
+
// pointer to the last vertex of this face
|
|
104
|
+
// [..., outside, ..., end, outside, ...]
|
|
105
|
+
// | | |
|
|
106
|
+
// a a b
|
|
107
|
+
let end = face.outside
|
|
108
|
+
while (end.next && end.next.face === face) {
|
|
109
|
+
end = end.next
|
|
110
|
+
}
|
|
111
|
+
this.claimed.removeChain(face.outside, end)
|
|
112
|
+
// b
|
|
113
|
+
// [ outside, ...]
|
|
114
|
+
// | removes this link
|
|
115
|
+
// [ outside, ..., end ] -┘
|
|
116
|
+
// | |
|
|
117
|
+
// a a
|
|
118
|
+
end.next = null
|
|
119
|
+
return face.outside
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Removes all the visible vertices that `face` is able to see, additionally
|
|
125
|
+
* checking the following:
|
|
126
|
+
*
|
|
127
|
+
* If `absorbingFace` doesn't exist then all the removed vertices will be
|
|
128
|
+
* added to the `unclaimed` vertex list
|
|
129
|
+
*
|
|
130
|
+
* If `absorbingFace` exists then this method will assign all the vertices of
|
|
131
|
+
* `face` that can see `absorbingFace`, if a vertex cannot see `absorbingFace`
|
|
132
|
+
* it's added to the `unclaimed` vertex list
|
|
133
|
+
*
|
|
134
|
+
* @param {Face} face
|
|
135
|
+
* @param {Face} [absorbingFace]
|
|
136
|
+
*/
|
|
137
|
+
deleteFaceVertices (face, absorbingFace) {
|
|
138
|
+
const faceVertices = this.removeAllVerticesFromFace(face)
|
|
139
|
+
if (faceVertices) {
|
|
140
|
+
if (!absorbingFace) {
|
|
141
|
+
// mark the vertices to be reassigned to some other face
|
|
142
|
+
this.unclaimed.addAll(faceVertices)
|
|
143
|
+
} else {
|
|
144
|
+
// if there's an absorbing face try to assign as many vertices
|
|
145
|
+
// as possible to it
|
|
146
|
+
|
|
147
|
+
// the reference `vertex.next` might be destroyed on
|
|
148
|
+
// `this.addVertexToFace` (see VertexList#add), nextVertex is a
|
|
149
|
+
// reference to it
|
|
150
|
+
let nextVertex
|
|
151
|
+
for (let vertex = faceVertices; vertex; vertex = nextVertex) {
|
|
152
|
+
nextVertex = vertex.next
|
|
153
|
+
const distance = absorbingFace.distanceToPlane(vertex.point)
|
|
154
|
+
|
|
155
|
+
// check if `vertex` is able to see `absorbingFace`
|
|
156
|
+
if (distance > this.tolerance) {
|
|
157
|
+
this.addVertexToFace(vertex, absorbingFace)
|
|
158
|
+
} else {
|
|
159
|
+
this.unclaimed.add(vertex)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Reassigns as many vertices as possible from the unclaimed list to the new
|
|
168
|
+
* faces
|
|
169
|
+
*
|
|
170
|
+
* @param {Faces[]} newFaces
|
|
171
|
+
*/
|
|
172
|
+
resolveUnclaimedPoints (newFaces) {
|
|
173
|
+
// cache next vertex so that if `vertex.next` is destroyed it's still
|
|
174
|
+
// recoverable
|
|
175
|
+
let vertexNext = this.unclaimed.first()
|
|
176
|
+
for (let vertex = vertexNext; vertex; vertex = vertexNext) {
|
|
177
|
+
vertexNext = vertex.next
|
|
178
|
+
let maxDistance = this.tolerance
|
|
179
|
+
let maxFace
|
|
180
|
+
for (let i = 0; i < newFaces.length; i += 1) {
|
|
181
|
+
const face = newFaces[i]
|
|
182
|
+
if (face.mark === VISIBLE) {
|
|
183
|
+
const dist = face.distanceToPlane(vertex.point)
|
|
184
|
+
if (dist > maxDistance) {
|
|
185
|
+
maxDistance = dist
|
|
186
|
+
maxFace = face
|
|
187
|
+
}
|
|
188
|
+
if (maxDistance > 1000 * this.tolerance) {
|
|
189
|
+
break
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (maxFace) {
|
|
195
|
+
this.addVertexToFace(vertex, maxFace)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Computes the extremes of a tetrahedron which will be the initial hull
|
|
202
|
+
*
|
|
203
|
+
* @return {number[]} The min/max vertices in the x,y,z directions
|
|
204
|
+
*/
|
|
205
|
+
computeExtremes () {
|
|
206
|
+
const min = []
|
|
207
|
+
const max = []
|
|
208
|
+
|
|
209
|
+
// min vertex on the x,y,z directions
|
|
210
|
+
const minVertices = []
|
|
211
|
+
// max vertex on the x,y,z directions
|
|
212
|
+
const maxVertices = []
|
|
213
|
+
|
|
214
|
+
let i, j
|
|
215
|
+
|
|
216
|
+
// initially assume that the first vertex is the min/max
|
|
217
|
+
for (i = 0; i < 3; i += 1) {
|
|
218
|
+
minVertices[i] = maxVertices[i] = this.vertices[0]
|
|
219
|
+
}
|
|
220
|
+
// copy the coordinates of the first vertex to min/max
|
|
221
|
+
for (i = 0; i < 3; i += 1) {
|
|
222
|
+
min[i] = max[i] = this.vertices[0].point[i]
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// compute the min/max vertex on all 6 directions
|
|
226
|
+
for (i = 1; i < this.vertices.length; i += 1) {
|
|
227
|
+
const vertex = this.vertices[i]
|
|
228
|
+
const point = vertex.point
|
|
229
|
+
// update the min coordinates
|
|
230
|
+
for (j = 0; j < 3; j += 1) {
|
|
231
|
+
if (point[j] < min[j]) {
|
|
232
|
+
min[j] = point[j]
|
|
233
|
+
minVertices[j] = vertex
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// update the max coordinates
|
|
237
|
+
for (j = 0; j < 3; j += 1) {
|
|
238
|
+
if (point[j] > max[j]) {
|
|
239
|
+
max[j] = point[j]
|
|
240
|
+
maxVertices[j] = vertex
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// compute epsilon
|
|
246
|
+
this.tolerance = 3 * Number.EPSILON * (
|
|
247
|
+
Math.max(Math.abs(min[0]), Math.abs(max[0])) +
|
|
248
|
+
Math.max(Math.abs(min[1]), Math.abs(max[1])) +
|
|
249
|
+
Math.max(Math.abs(min[2]), Math.abs(max[2]))
|
|
250
|
+
)
|
|
251
|
+
return [minVertices, maxVertices]
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Compues the initial tetrahedron assigning to its faces all the points that
|
|
256
|
+
* are candidates to form part of the hull
|
|
257
|
+
*/
|
|
258
|
+
createInitialSimplex () {
|
|
259
|
+
const vertices = this.vertices
|
|
260
|
+
const [min, max] = this.computeExtremes()
|
|
261
|
+
let v2, v3
|
|
262
|
+
let i, j
|
|
263
|
+
|
|
264
|
+
// Find the two vertices with the greatest 1d separation
|
|
265
|
+
// (max.x - min.x)
|
|
266
|
+
// (max.y - min.y)
|
|
267
|
+
// (max.z - min.z)
|
|
268
|
+
let maxDistance = 0
|
|
269
|
+
let indexMax = 0
|
|
270
|
+
for (i = 0; i < 3; i += 1) {
|
|
271
|
+
const distance = max[i].point[i] - min[i].point[i]
|
|
272
|
+
if (distance > maxDistance) {
|
|
273
|
+
maxDistance = distance
|
|
274
|
+
indexMax = i
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const v0 = min[indexMax]
|
|
278
|
+
const v1 = max[indexMax]
|
|
279
|
+
|
|
280
|
+
// the next vertex is the one farthest to the line formed by `v0` and `v1`
|
|
281
|
+
maxDistance = 0
|
|
282
|
+
for (i = 0; i < this.vertices.length; i += 1) {
|
|
283
|
+
const vertex = this.vertices[i]
|
|
284
|
+
if (vertex !== v0 && vertex !== v1) {
|
|
285
|
+
const distance = pointLineDistance(
|
|
286
|
+
vertex.point, v0.point, v1.point
|
|
287
|
+
)
|
|
288
|
+
if (distance > maxDistance) {
|
|
289
|
+
maxDistance = distance
|
|
290
|
+
v2 = vertex
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// the next vertes is the one farthest to the plane `v0`, `v1`, `v2`
|
|
296
|
+
// normalize((v2 - v1) x (v0 - v1))
|
|
297
|
+
const normal = getPlaneNormal([], v0.point, v1.point, v2.point)
|
|
298
|
+
// distance from the origin to the plane
|
|
299
|
+
const distPO = dot(v0.point, normal)
|
|
300
|
+
maxDistance = -1
|
|
301
|
+
for (i = 0; i < this.vertices.length; i += 1) {
|
|
302
|
+
const vertex = this.vertices[i]
|
|
303
|
+
if (vertex !== v0 && vertex !== v1 && vertex !== v2) {
|
|
304
|
+
const distance = Math.abs(dot(normal, vertex.point) - distPO)
|
|
305
|
+
if (distance > maxDistance) {
|
|
306
|
+
maxDistance = distance
|
|
307
|
+
v3 = vertex
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// initial simplex
|
|
313
|
+
// Taken from http://everything2.com/title/How+to+paint+a+tetrahedron
|
|
314
|
+
//
|
|
315
|
+
// v2
|
|
316
|
+
// ,|,
|
|
317
|
+
// ,7``\'VA,
|
|
318
|
+
// ,7` |, `'VA,
|
|
319
|
+
// ,7` `\ `'VA,
|
|
320
|
+
// ,7` |, `'VA,
|
|
321
|
+
// ,7` `\ `'VA,
|
|
322
|
+
// ,7` |, `'VA,
|
|
323
|
+
// ,7` `\ ,..ooOOTK` v3
|
|
324
|
+
// ,7` |,.ooOOT''` AV
|
|
325
|
+
// ,7` ,..ooOOT`\` /7
|
|
326
|
+
// ,7` ,..ooOOT''` |, AV
|
|
327
|
+
// ,T,..ooOOT''` `\ /7
|
|
328
|
+
// v0 `'TTs., |, AV
|
|
329
|
+
// `'TTs., `\ /7
|
|
330
|
+
// `'TTs., |, AV
|
|
331
|
+
// `'TTs., `\ /7
|
|
332
|
+
// `'TTs., |, AV
|
|
333
|
+
// `'TTs.,\/7
|
|
334
|
+
// `'T`
|
|
335
|
+
// v1
|
|
336
|
+
//
|
|
337
|
+
const faces = []
|
|
338
|
+
if (dot(v3.point, normal) - distPO < 0) {
|
|
339
|
+
// the face is not able to see the point so `planeNormal`
|
|
340
|
+
// is pointing outside the tetrahedron
|
|
341
|
+
faces.push(
|
|
342
|
+
Face.createTriangle(v0, v1, v2),
|
|
343
|
+
Face.createTriangle(v3, v1, v0),
|
|
344
|
+
Face.createTriangle(v3, v2, v1),
|
|
345
|
+
Face.createTriangle(v3, v0, v2)
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
// set the opposite edge
|
|
349
|
+
for (i = 0; i < 3; i += 1) {
|
|
350
|
+
const j = (i + 1) % 3
|
|
351
|
+
// join face[i] i > 0, with the first face
|
|
352
|
+
faces[i + 1].getEdge(2).setOpposite(faces[0].getEdge(j))
|
|
353
|
+
// join face[i] with face[i + 1], 1 <= i <= 3
|
|
354
|
+
faces[i + 1].getEdge(1).setOpposite(faces[j + 1].getEdge(0))
|
|
355
|
+
}
|
|
356
|
+
} else {
|
|
357
|
+
// the face is able to see the point so `planeNormal`
|
|
358
|
+
// is pointing inside the tetrahedron
|
|
359
|
+
faces.push(
|
|
360
|
+
Face.createTriangle(v0, v2, v1),
|
|
361
|
+
Face.createTriangle(v3, v0, v1),
|
|
362
|
+
Face.createTriangle(v3, v1, v2),
|
|
363
|
+
Face.createTriangle(v3, v2, v0)
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
// set the opposite edge
|
|
367
|
+
for (i = 0; i < 3; i += 1) {
|
|
368
|
+
const j = (i + 1) % 3
|
|
369
|
+
// join face[i] i > 0, with the first face
|
|
370
|
+
faces[i + 1].getEdge(2).setOpposite(faces[0].getEdge((3 - i) % 3))
|
|
371
|
+
// join face[i] with face[i + 1]
|
|
372
|
+
faces[i + 1].getEdge(0).setOpposite(faces[j + 1].getEdge(1))
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// the initial hull is the tetrahedron
|
|
377
|
+
for (i = 0; i < 4; i += 1) {
|
|
378
|
+
this.faces.push(faces[i])
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// initial assignment of vertices to the faces of the tetrahedron
|
|
382
|
+
for (i = 0; i < vertices.length; i += 1) {
|
|
383
|
+
const vertex = vertices[i]
|
|
384
|
+
if (vertex !== v0 && vertex !== v1 && vertex !== v2 && vertex !== v3) {
|
|
385
|
+
maxDistance = this.tolerance
|
|
386
|
+
let maxFace
|
|
387
|
+
for (j = 0; j < 4; j += 1) {
|
|
388
|
+
const distance = faces[j].distanceToPlane(vertex.point)
|
|
389
|
+
if (distance > maxDistance) {
|
|
390
|
+
maxDistance = distance
|
|
391
|
+
maxFace = faces[j]
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (maxFace) {
|
|
396
|
+
this.addVertexToFace(vertex, maxFace)
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
reindexFaceAndVertices () {
|
|
403
|
+
// remove inactive faces
|
|
404
|
+
const activeFaces = []
|
|
405
|
+
for (let i = 0; i < this.faces.length; i += 1) {
|
|
406
|
+
const face = this.faces[i]
|
|
407
|
+
if (face.mark === VISIBLE) {
|
|
408
|
+
activeFaces.push(face)
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
this.faces = activeFaces
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
collectFaces (skipTriangulation) {
|
|
415
|
+
const faceIndices = []
|
|
416
|
+
for (let i = 0; i < this.faces.length; i += 1) {
|
|
417
|
+
if (this.faces[i].mark !== VISIBLE) {
|
|
418
|
+
throw Error('attempt to include a destroyed face in the hull')
|
|
419
|
+
}
|
|
420
|
+
const indices = this.faces[i].collectIndices()
|
|
421
|
+
if (skipTriangulation) {
|
|
422
|
+
faceIndices.push(indices)
|
|
423
|
+
} else {
|
|
424
|
+
for (let j = 0; j < indices.length - 2; j += 1) {
|
|
425
|
+
faceIndices.push(
|
|
426
|
+
[indices[0], indices[j + 1], indices[j + 2]]
|
|
427
|
+
)
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return faceIndices
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Finds the next vertex to make faces with the current hull
|
|
436
|
+
*
|
|
437
|
+
* - let `face` be the first face existing in the `claimed` vertex list
|
|
438
|
+
* - if `face` doesn't exist then return since there're no vertices left
|
|
439
|
+
* - otherwise for each `vertex` that face sees find the one furthest away
|
|
440
|
+
* from `face`
|
|
441
|
+
*
|
|
442
|
+
* @return {Vertex|undefined} Returns undefined when there're no more
|
|
443
|
+
* visible vertices
|
|
444
|
+
*/
|
|
445
|
+
nextVertexToAdd () {
|
|
446
|
+
if (!this.claimed.isEmpty()) {
|
|
447
|
+
let eyeVertex, vertex
|
|
448
|
+
let maxDistance = 0
|
|
449
|
+
const eyeFace = this.claimed.first().face
|
|
450
|
+
for (vertex = eyeFace.outside; vertex && vertex.face === eyeFace; vertex = vertex.next) {
|
|
451
|
+
const distance = eyeFace.distanceToPlane(vertex.point)
|
|
452
|
+
if (distance > maxDistance) {
|
|
453
|
+
maxDistance = distance
|
|
454
|
+
eyeVertex = vertex
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return eyeVertex
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Computes a chain of half edges in ccw order called the `horizon`, for an
|
|
463
|
+
* edge to be part of the horizon it must join a face that can see
|
|
464
|
+
* `eyePoint` and a face that cannot see `eyePoint`
|
|
465
|
+
*
|
|
466
|
+
* @param {number[]} eyePoint - The coordinates of a point
|
|
467
|
+
* @param {HalfEdge} crossEdge - The edge used to jump to the current `face`
|
|
468
|
+
* @param {Face} face - The current face being tested
|
|
469
|
+
* @param {HalfEdge[]} horizon - The edges that form part of the horizon in
|
|
470
|
+
* ccw order
|
|
471
|
+
*/
|
|
472
|
+
computeHorizon (eyePoint, crossEdge, face, horizon) {
|
|
473
|
+
// moves face's vertices to the `unclaimed` vertex list
|
|
474
|
+
this.deleteFaceVertices(face)
|
|
475
|
+
|
|
476
|
+
face.mark = DELETED
|
|
477
|
+
|
|
478
|
+
let edge
|
|
479
|
+
if (!crossEdge) {
|
|
480
|
+
edge = crossEdge = face.getEdge(0)
|
|
481
|
+
} else {
|
|
482
|
+
// start from the next edge since `crossEdge` was already analyzed
|
|
483
|
+
// (actually `crossEdge.opposite` was the face who called this method
|
|
484
|
+
// recursively)
|
|
485
|
+
edge = crossEdge.next
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// All the faces that are able to see `eyeVertex` are defined as follows
|
|
489
|
+
//
|
|
490
|
+
// v /
|
|
491
|
+
// / <== visible face
|
|
492
|
+
// /
|
|
493
|
+
// |
|
|
494
|
+
// | <== not visible face
|
|
495
|
+
//
|
|
496
|
+
// dot(v, visible face normal) - visible face offset > this.tolerance
|
|
497
|
+
//
|
|
498
|
+
do {
|
|
499
|
+
const oppositeEdge = edge.opposite
|
|
500
|
+
const oppositeFace = oppositeEdge.face
|
|
501
|
+
if (oppositeFace.mark === VISIBLE) {
|
|
502
|
+
if (oppositeFace.distanceToPlane(eyePoint) > this.tolerance) {
|
|
503
|
+
this.computeHorizon(eyePoint, oppositeEdge, oppositeFace, horizon)
|
|
504
|
+
} else {
|
|
505
|
+
horizon.push(edge)
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
edge = edge.next
|
|
509
|
+
} while (edge !== crossEdge)
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Creates a face with the points `eyeVertex.point`, `horizonEdge.tail` and
|
|
514
|
+
* `horizonEdge.tail` in ccw order
|
|
515
|
+
*
|
|
516
|
+
* @param {Vertex} eyeVertex
|
|
517
|
+
* @param {HalfEdge} horizonEdge
|
|
518
|
+
* @return {HalfEdge} The half edge whose vertex is the eyeVertex
|
|
519
|
+
*/
|
|
520
|
+
addAdjoiningFace (eyeVertex, horizonEdge) {
|
|
521
|
+
// all the half edges are created in ccw order thus the face is always
|
|
522
|
+
// pointing outside the hull
|
|
523
|
+
// edges:
|
|
524
|
+
//
|
|
525
|
+
// eyeVertex.point
|
|
526
|
+
// / \
|
|
527
|
+
// / \
|
|
528
|
+
// 1 / \ 0
|
|
529
|
+
// / \
|
|
530
|
+
// / \
|
|
531
|
+
// / \
|
|
532
|
+
// horizon.tail --- horizon.head
|
|
533
|
+
// 2
|
|
534
|
+
//
|
|
535
|
+
const face = Face.createTriangle(
|
|
536
|
+
eyeVertex,
|
|
537
|
+
horizonEdge.tail(),
|
|
538
|
+
horizonEdge.head()
|
|
539
|
+
)
|
|
540
|
+
this.faces.push(face)
|
|
541
|
+
// join face.getEdge(-1) with the horizon's opposite edge
|
|
542
|
+
// face.getEdge(-1) = face.getEdge(2)
|
|
543
|
+
face.getEdge(-1).setOpposite(horizonEdge.opposite)
|
|
544
|
+
return face.getEdge(0)
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Adds horizon.length faces to the hull, each face will be 'linked' with the
|
|
549
|
+
* horizon opposite face and the face on the left/right
|
|
550
|
+
*
|
|
551
|
+
* @param {Vertex} eyeVertex
|
|
552
|
+
* @param {HalfEdge[]} horizon - A chain of half edges in ccw order
|
|
553
|
+
*/
|
|
554
|
+
addNewFaces (eyeVertex, horizon) {
|
|
555
|
+
this.newFaces = []
|
|
556
|
+
let firstSideEdge, previousSideEdge
|
|
557
|
+
for (let i = 0; i < horizon.length; i += 1) {
|
|
558
|
+
const horizonEdge = horizon[i]
|
|
559
|
+
// returns the right side edge
|
|
560
|
+
const sideEdge = this.addAdjoiningFace(eyeVertex, horizonEdge)
|
|
561
|
+
if (!firstSideEdge) {
|
|
562
|
+
firstSideEdge = sideEdge
|
|
563
|
+
} else {
|
|
564
|
+
// joins face.getEdge(1) with previousFace.getEdge(0)
|
|
565
|
+
sideEdge.next.setOpposite(previousSideEdge)
|
|
566
|
+
}
|
|
567
|
+
this.newFaces.push(sideEdge.face)
|
|
568
|
+
previousSideEdge = sideEdge
|
|
569
|
+
}
|
|
570
|
+
firstSideEdge.next.setOpposite(previousSideEdge)
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Computes the distance from `edge` opposite face's centroid to
|
|
575
|
+
* `edge.face`
|
|
576
|
+
*
|
|
577
|
+
* @param {HalfEdge} edge
|
|
578
|
+
* @return {number}
|
|
579
|
+
* - A positive number when the centroid of the opposite face is above the
|
|
580
|
+
* face i.e. when the faces are concave
|
|
581
|
+
* - A negative number when the centroid of the opposite face is below the
|
|
582
|
+
* face i.e. when the faces are convex
|
|
583
|
+
*/
|
|
584
|
+
oppositeFaceDistance (edge) {
|
|
585
|
+
return edge.face.distanceToPlane(edge.opposite.face.centroid)
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Merges a face with none/any/all its neighbors according to the strategy
|
|
590
|
+
* used
|
|
591
|
+
*
|
|
592
|
+
* if `mergeType` is MERGE_NON_CONVEX_WRT_LARGER_FACE then the merge will be
|
|
593
|
+
* decided based on the face with the larger area, the centroid of the face
|
|
594
|
+
* with the smaller area will be checked against the one with the larger area
|
|
595
|
+
* to see if it's in the merge range [tolerance, -tolerance] i.e.
|
|
596
|
+
*
|
|
597
|
+
* dot(centroid smaller face, larger face normal) - larger face offset > -tolerance
|
|
598
|
+
*
|
|
599
|
+
* Note that the first check (with +tolerance) was done on `computeHorizon`
|
|
600
|
+
*
|
|
601
|
+
* If the above is not true then the check is done with respect to the smaller
|
|
602
|
+
* face i.e.
|
|
603
|
+
*
|
|
604
|
+
* dot(centroid larger face, smaller face normal) - smaller face offset > -tolerance
|
|
605
|
+
*
|
|
606
|
+
* If true then it means that two faces are non convex (concave), even if the
|
|
607
|
+
* dot(...) - offset value is > 0 (that's the point of doing the merge in the
|
|
608
|
+
* first place)
|
|
609
|
+
*
|
|
610
|
+
* If two faces are concave then the check must also be done on the other face
|
|
611
|
+
* but this is done in another merge pass, for this to happen the face is
|
|
612
|
+
* marked in a temporal NON_CONVEX state
|
|
613
|
+
*
|
|
614
|
+
* if `mergeType` is MERGE_NON_CONVEX then two faces will be merged only if
|
|
615
|
+
* they pass the following conditions
|
|
616
|
+
*
|
|
617
|
+
* dot(centroid smaller face, larger face normal) - larger face offset > -tolerance
|
|
618
|
+
* dot(centroid larger face, smaller face normal) - smaller face offset > -tolerance
|
|
619
|
+
*
|
|
620
|
+
* @param {Face} face
|
|
621
|
+
* @param {number} mergeType - Either MERGE_NON_CONVEX_WRT_LARGER_FACE or
|
|
622
|
+
* MERGE_NON_CONVEX
|
|
623
|
+
*/
|
|
624
|
+
doAdjacentMerge (face, mergeType) {
|
|
625
|
+
let edge = face.edge
|
|
626
|
+
let convex = true
|
|
627
|
+
let it = 0
|
|
628
|
+
do {
|
|
629
|
+
if (it >= face.nVertices) {
|
|
630
|
+
throw Error('merge recursion limit exceeded')
|
|
631
|
+
}
|
|
632
|
+
const oppositeFace = edge.opposite.face
|
|
633
|
+
let merge = false
|
|
634
|
+
|
|
635
|
+
// Important notes about the algorithm to merge faces
|
|
636
|
+
//
|
|
637
|
+
// - Given a vertex `eyeVertex` that will be added to the hull
|
|
638
|
+
// all the faces that cannot see `eyeVertex` are defined as follows
|
|
639
|
+
//
|
|
640
|
+
// dot(v, not visible face normal) - not visible offset < tolerance
|
|
641
|
+
//
|
|
642
|
+
// - Two faces can be merged when the centroid of one of these faces
|
|
643
|
+
// projected to the normal of the other face minus the other face offset
|
|
644
|
+
// is in the range [tolerance, -tolerance]
|
|
645
|
+
// - Since `face` (given in the input for this method) has passed the
|
|
646
|
+
// check above we only have to check the lower bound e.g.
|
|
647
|
+
//
|
|
648
|
+
// dot(v, not visible face normal) - not visible offset > -tolerance
|
|
649
|
+
//
|
|
650
|
+
if (mergeType === MERGE_NON_CONVEX) {
|
|
651
|
+
if (this.oppositeFaceDistance(edge) > -this.tolerance ||
|
|
652
|
+
this.oppositeFaceDistance(edge.opposite) > -this.tolerance) {
|
|
653
|
+
merge = true
|
|
654
|
+
}
|
|
655
|
+
} else {
|
|
656
|
+
if (face.area > oppositeFace.area) {
|
|
657
|
+
if (this.oppositeFaceDistance(edge) > -this.tolerance) {
|
|
658
|
+
merge = true
|
|
659
|
+
} else if (this.oppositeFaceDistance(edge.opposite) > -this.tolerance) {
|
|
660
|
+
convex = false
|
|
661
|
+
}
|
|
662
|
+
} else {
|
|
663
|
+
if (this.oppositeFaceDistance(edge.opposite) > -this.tolerance) {
|
|
664
|
+
merge = true
|
|
665
|
+
} else if (this.oppositeFaceDistance(edge) > -this.tolerance) {
|
|
666
|
+
convex = false
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
if (merge) {
|
|
672
|
+
// when two faces are merged it might be possible that redundant faces
|
|
673
|
+
// are destroyed, in that case move all the visible vertices from the
|
|
674
|
+
// destroyed faces to the `unclaimed` vertex list
|
|
675
|
+
const discardedFaces = face.mergeAdjacentFaces(edge, [])
|
|
676
|
+
for (let i = 0; i < discardedFaces.length; i += 1) {
|
|
677
|
+
this.deleteFaceVertices(discardedFaces[i], face)
|
|
678
|
+
}
|
|
679
|
+
return true
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
edge = edge.next
|
|
683
|
+
it += 1
|
|
684
|
+
} while (edge !== face.edge)
|
|
685
|
+
if (!convex) {
|
|
686
|
+
face.mark = NON_CONVEX
|
|
687
|
+
}
|
|
688
|
+
return false
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Adds a vertex to the hull with the following algorithm
|
|
693
|
+
*
|
|
694
|
+
* - Compute the `horizon` which is a chain of half edges, for an edge to
|
|
695
|
+
* belong to this group it must be the edge connecting a face that can
|
|
696
|
+
* see `eyeVertex` and a face which cannot see `eyeVertex`
|
|
697
|
+
* - All the faces that can see `eyeVertex` have its visible vertices removed
|
|
698
|
+
* from the claimed VertexList
|
|
699
|
+
* - A new set of faces is created with each edge of the `horizon` and
|
|
700
|
+
* `eyeVertex`, each face is connected with the opposite horizon face and
|
|
701
|
+
* the face on the left/right
|
|
702
|
+
* - The new faces are merged if possible with the opposite horizon face first
|
|
703
|
+
* and then the faces on the right/left
|
|
704
|
+
* - The vertices removed from all the visible faces are assigned to the new
|
|
705
|
+
* faces if possible
|
|
706
|
+
*
|
|
707
|
+
* @param {Vertex} eyeVertex
|
|
708
|
+
*/
|
|
709
|
+
addVertexToHull (eyeVertex) {
|
|
710
|
+
const horizon = []
|
|
711
|
+
|
|
712
|
+
this.unclaimed.clear()
|
|
713
|
+
|
|
714
|
+
// remove `eyeVertex` from `eyeVertex.face` so that it can't be added to the
|
|
715
|
+
// `unclaimed` vertex list
|
|
716
|
+
this.removeVertexFromFace(eyeVertex, eyeVertex.face)
|
|
717
|
+
this.computeHorizon(eyeVertex.point, null, eyeVertex.face, horizon)
|
|
718
|
+
this.addNewFaces(eyeVertex, horizon)
|
|
719
|
+
|
|
720
|
+
// first merge pass
|
|
721
|
+
// Do the merge with respect to the larger face
|
|
722
|
+
for (let i = 0; i < this.newFaces.length; i += 1) {
|
|
723
|
+
const face = this.newFaces[i]
|
|
724
|
+
if (face.mark === VISIBLE) {
|
|
725
|
+
while (this.doAdjacentMerge(face, MERGE_NON_CONVEX_WRT_LARGER_FACE)) {} // eslint-disable-line no-empty
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// second merge pass
|
|
730
|
+
// Do the merge on non convex faces (a face is marked as non convex in the
|
|
731
|
+
// first pass)
|
|
732
|
+
for (let i = 0; i < this.newFaces.length; i += 1) {
|
|
733
|
+
const face = this.newFaces[i]
|
|
734
|
+
if (face.mark === NON_CONVEX) {
|
|
735
|
+
face.mark = VISIBLE
|
|
736
|
+
while (this.doAdjacentMerge(face, MERGE_NON_CONVEX)) {} // eslint-disable-line no-empty
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
// reassign `unclaimed` vertices to the new faces
|
|
741
|
+
this.resolveUnclaimedPoints(this.newFaces)
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
build () {
|
|
745
|
+
let eyeVertex
|
|
746
|
+
this.createInitialSimplex()
|
|
747
|
+
while ((eyeVertex = this.nextVertexToAdd())) {
|
|
748
|
+
this.addVertexToHull(eyeVertex)
|
|
749
|
+
}
|
|
750
|
+
this.reindexFaceAndVertices()
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
module.exports = QuickHull
|