@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,28 @@
|
|
|
1
|
+
const vec3 = require('../maths/vec3')
|
|
2
|
+
|
|
3
|
+
const fromPointAxisNormal = require('./fromPointAxisNormal')
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Transform the give connector using the given matrix.
|
|
7
|
+
* @param {mat4} matrix - a transform matrix
|
|
8
|
+
* @param {connector} connector - the connector to transform
|
|
9
|
+
* @returns {connector} a new connector
|
|
10
|
+
* @alias module:modeling/connectors.transform
|
|
11
|
+
*/
|
|
12
|
+
const transform = (matrix, connector) => {
|
|
13
|
+
// OPTIMIZE
|
|
14
|
+
const newpoint = vec3.transform(vec3.create(), connector.point, matrix)
|
|
15
|
+
const newaxis = vec3.subtract(
|
|
16
|
+
vec3.create(),
|
|
17
|
+
vec3.transform(vec3.create(), vec3.add(vec3.create(), connector.point, connector.axis), matrix),
|
|
18
|
+
newpoint
|
|
19
|
+
)
|
|
20
|
+
const newnormal = vec3.subtract(
|
|
21
|
+
vec3.create(),
|
|
22
|
+
vec3.transform(vec3.create(), vec3.add(vec3.create(), connector.point, connector.normal), matrix),
|
|
23
|
+
newpoint
|
|
24
|
+
)
|
|
25
|
+
return fromPointAxisNormal(newpoint, newaxis, newnormal)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = transform
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
|
|
3
|
+
const { transform, create, fromPointAxisNormal } = require('./index')
|
|
4
|
+
|
|
5
|
+
const { compareVectors } = require('../../test/helpers/')
|
|
6
|
+
|
|
7
|
+
test('connector: transform() should return a connector with correct values', (t) => {
|
|
8
|
+
const connector1 = create()
|
|
9
|
+
const connector2 = fromPointAxisNormal([1, 0, 0], [0, 1, 0], [0, 0, 1])
|
|
10
|
+
const connector3 = fromPointAxisNormal([-3, -3, -3], [3, 3, 3], [3, -3, 3])
|
|
11
|
+
|
|
12
|
+
const identityMatrix = [
|
|
13
|
+
1, 0, 0, 0,
|
|
14
|
+
0, 1, 0, 0,
|
|
15
|
+
0, 0, 1, 0,
|
|
16
|
+
0, 0, 0, 1
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
let obs1 = transform(identityMatrix, connector1)
|
|
20
|
+
t.true(compareVectors(obs1.point, [0, 0, 0]))
|
|
21
|
+
t.true(compareVectors(obs1.axis, [0, 0, 1]))
|
|
22
|
+
t.true(compareVectors(obs1.normal, [1, 0, 0]))
|
|
23
|
+
|
|
24
|
+
obs1 = transform(identityMatrix, connector2)
|
|
25
|
+
t.true(compareVectors(obs1.point, [1, 0, 0]))
|
|
26
|
+
t.true(compareVectors(obs1.axis, [0, 1, 0]))
|
|
27
|
+
t.true(compareVectors(obs1.normal, [0, 0, 1]))
|
|
28
|
+
|
|
29
|
+
obs1 = transform(identityMatrix, connector3)
|
|
30
|
+
t.true(compareVectors(obs1.point, [-3, -3, -3]))
|
|
31
|
+
t.true(compareVectors(obs1.axis, [0.5773502691896258, 0.5773502691896258, 0.5773502691896258]))
|
|
32
|
+
t.true(compareVectors(obs1.normal, [0.5773502691896258, -0.5773502691896258, 0.5773502691896258]))
|
|
33
|
+
|
|
34
|
+
const x = 1
|
|
35
|
+
const y = 5
|
|
36
|
+
const z = 7
|
|
37
|
+
const translationMatrix = [
|
|
38
|
+
1, 0, 0, 0,
|
|
39
|
+
0, 1, 0, 0,
|
|
40
|
+
0, 0, 1, 0,
|
|
41
|
+
x, y, z, 1
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
let obs2 = transform(translationMatrix, connector1)
|
|
45
|
+
t.true(compareVectors(obs2.point, [1, 5, 7]))
|
|
46
|
+
t.true(compareVectors(obs2.axis, [0, 0, 1]))
|
|
47
|
+
t.true(compareVectors(obs2.normal, [1, 0, 0]))
|
|
48
|
+
|
|
49
|
+
obs2 = transform(translationMatrix, connector2)
|
|
50
|
+
t.true(compareVectors(obs2.point, [2, 5, 7]))
|
|
51
|
+
t.true(compareVectors(obs2.axis, [0, 1, 0]))
|
|
52
|
+
t.true(compareVectors(obs2.normal, [0, 0, 1]))
|
|
53
|
+
|
|
54
|
+
obs2 = transform(translationMatrix, connector3)
|
|
55
|
+
t.true(compareVectors(obs2.point, [-2, 2, 4]))
|
|
56
|
+
t.true(compareVectors(obs2.axis, [0.5773502691896256, 0.5773502691896256, 0.5773502691896261]))
|
|
57
|
+
t.true(compareVectors(obs2.normal, [0.5773502691896256, -0.5773502691896256, 0.5773502691896261]))
|
|
58
|
+
|
|
59
|
+
const w = 1
|
|
60
|
+
const h = 3
|
|
61
|
+
const d = 5
|
|
62
|
+
const scaleMatrix = [
|
|
63
|
+
w, 0, 0, 0,
|
|
64
|
+
0, h, 0, 0,
|
|
65
|
+
0, 0, d, 0,
|
|
66
|
+
0, 0, 0, 1
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
let obs3 = transform(scaleMatrix, connector1)
|
|
70
|
+
t.true(compareVectors(obs3.point, [0, 0, 0]))
|
|
71
|
+
t.true(compareVectors(obs3.axis, [0, 0, 1]))
|
|
72
|
+
t.true(compareVectors(obs3.normal, [1, 0, 0]))
|
|
73
|
+
|
|
74
|
+
obs3 = transform(scaleMatrix, connector2)
|
|
75
|
+
t.true(compareVectors(obs3.point, [1, 0, 0]))
|
|
76
|
+
t.true(compareVectors(obs3.axis, [0, 1, 0]))
|
|
77
|
+
t.true(compareVectors(obs3.normal, [0, 0, 1]))
|
|
78
|
+
|
|
79
|
+
obs3 = transform(scaleMatrix, connector3)
|
|
80
|
+
t.true(compareVectors(obs3.point, [-3, -9, -15]))
|
|
81
|
+
t.true(compareVectors(obs3.axis, [0.1690308509457033, 0.5070925528371097, 0.8451542547285166]))
|
|
82
|
+
t.true(compareVectors(obs3.normal, [0.1690308509457033, -0.5070925528371097, 0.8451542547285166]))
|
|
83
|
+
|
|
84
|
+
const r = (90 * 0.017453292519943295)
|
|
85
|
+
const rotateZMatrix = [
|
|
86
|
+
Math.cos(r), Math.sin(r), 0, 0,
|
|
87
|
+
-Math.sin(r), Math.cos(r), 0, 0,
|
|
88
|
+
0, 0, 1, 0,
|
|
89
|
+
0, 0, 0, 1
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
let obs4 = transform(rotateZMatrix, connector1)
|
|
93
|
+
t.true(compareVectors(obs4.point, [0, 0, 0]))
|
|
94
|
+
t.true(compareVectors(obs4.axis, [0, 0, 1]))
|
|
95
|
+
t.true(compareVectors(obs4.normal, [6.123234262925839e-17, 1, 0]))
|
|
96
|
+
|
|
97
|
+
obs4 = transform(rotateZMatrix, connector2)
|
|
98
|
+
t.true(compareVectors(obs4.point, [0, 1, 0]))
|
|
99
|
+
t.true(compareVectors(obs4.axis, [-1, 0, 0]))
|
|
100
|
+
t.true(compareVectors(obs4.normal, [0, 0, 1]))
|
|
101
|
+
|
|
102
|
+
obs4 = transform(rotateZMatrix, connector3)
|
|
103
|
+
t.true(compareVectors(obs4.point, [3, -3, -3]))
|
|
104
|
+
t.true(compareVectors(obs4.axis, [-0.5773502691896258, 0.5773502691896258, 0.5773502691896258]))
|
|
105
|
+
t.true(compareVectors(obs4.normal, [0.5773502691896258, 0.5773502691896258, 0.5773502691896258]))
|
|
106
|
+
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const mat4 = require('../maths/mat4')
|
|
2
|
+
const plane = require('../maths/plane')
|
|
3
|
+
const vec2 = require('../maths/vec2')
|
|
4
|
+
const vec3 = require('../maths/vec3')
|
|
5
|
+
|
|
6
|
+
const OrthoNormalBasis = require('../maths/OrthoNormalBasis')
|
|
7
|
+
|
|
8
|
+
const transform = require('./transform')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get the transformation matrix that connects the given connectors.
|
|
12
|
+
* @param {Object} options
|
|
13
|
+
* @param {Boolean} [options.mirror=false] - the 'axis' vectors should point in the same direction
|
|
14
|
+
* true: the 'axis' vectors should point in opposite direction
|
|
15
|
+
* @param {Number} [options.normalRotation=0] - the angle (RADIANS) of rotation between the 'normal' vectors
|
|
16
|
+
* @param {connector} from - connector from which to connect
|
|
17
|
+
* @param {connector} to - connector to which to connected
|
|
18
|
+
* @returns {mat4} - the matrix that transforms (connects) one connector to another
|
|
19
|
+
* @alias module:modeling/connectors.transformationBetween
|
|
20
|
+
*/
|
|
21
|
+
const transformationBetween = (options, from, to) => {
|
|
22
|
+
const defaults = {
|
|
23
|
+
mirror: false,
|
|
24
|
+
normalRotation: 0
|
|
25
|
+
}
|
|
26
|
+
// mirror = !!mirror
|
|
27
|
+
const { mirror, normalRotation } = Object.assign({}, defaults, options)
|
|
28
|
+
|
|
29
|
+
// shift to the 0,0 origin
|
|
30
|
+
const matrix = mat4.fromTranslation(mat4.create(), vec3.negate(vec3.create(), from.point))
|
|
31
|
+
|
|
32
|
+
// align the axis
|
|
33
|
+
const axesplane = plane.fromPointsRandom(plane.create(), vec3.create(), from.axis, to.axis)
|
|
34
|
+
const axesbasis = new OrthoNormalBasis(axesplane)
|
|
35
|
+
|
|
36
|
+
let angle1 = vec2.angleRadians(axesbasis.to2D(from.axis))
|
|
37
|
+
let angle2 = vec2.angleRadians(axesbasis.to2D(to.axis))
|
|
38
|
+
|
|
39
|
+
let rotation = angle2 - angle1
|
|
40
|
+
if (mirror) rotation += Math.PI // 180 degrees
|
|
41
|
+
|
|
42
|
+
// TODO: understand and explain this
|
|
43
|
+
mat4.multiply(matrix, matrix, axesbasis.getProjectionMatrix())
|
|
44
|
+
mat4.multiply(matrix, matrix, mat4.fromZRotation(mat4.create(), rotation))
|
|
45
|
+
mat4.multiply(matrix, matrix, axesbasis.getInverseProjectionMatrix())
|
|
46
|
+
const usAxesAligned = transform(matrix, from)
|
|
47
|
+
// Now we have done the transformation for aligning the axes.
|
|
48
|
+
|
|
49
|
+
// align the normals
|
|
50
|
+
const normalsplane = plane.fromNormalAndPoint(plane.create(), to.axis, vec3.create())
|
|
51
|
+
const normalsbasis = new OrthoNormalBasis(normalsplane)
|
|
52
|
+
|
|
53
|
+
angle1 = vec2.angleRadians(normalsbasis.to2D(usAxesAligned.normal))
|
|
54
|
+
angle2 = vec2.angleRadians(normalsbasis.to2D(to.normal))
|
|
55
|
+
|
|
56
|
+
rotation = angle2 - angle1 + normalRotation
|
|
57
|
+
|
|
58
|
+
mat4.multiply(matrix, matrix, normalsbasis.getProjectionMatrix())
|
|
59
|
+
mat4.multiply(matrix, matrix, mat4.fromZRotation(mat4.create(), rotation))
|
|
60
|
+
mat4.multiply(matrix, matrix, normalsbasis.getInverseProjectionMatrix())
|
|
61
|
+
|
|
62
|
+
// translate to the destination point
|
|
63
|
+
mat4.multiply(matrix, matrix, mat4.fromTranslation(mat4.create(), to.point))
|
|
64
|
+
|
|
65
|
+
return matrix
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = transformationBetween
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
|
|
3
|
+
const { transformationBetween, create, fromPointAxisNormal } = require('./index')
|
|
4
|
+
|
|
5
|
+
const { compareVectors } = require('../../test/helpers')
|
|
6
|
+
|
|
7
|
+
test('connector: transformationBetween() should return correct transform matrices', (t) => {
|
|
8
|
+
const connector1 = create()
|
|
9
|
+
const connector2 = create()
|
|
10
|
+
const connector3 = fromPointAxisNormal([0, 0, 0], [0, 0, 1], [0, 1, 0]) // Y axis as normal
|
|
11
|
+
|
|
12
|
+
let obs = transformationBetween({}, connector1, connector2)
|
|
13
|
+
let exp = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
|
|
14
|
+
t.true(compareVectors(obs, exp))
|
|
15
|
+
|
|
16
|
+
obs = transformationBetween({}, connector1, connector3)
|
|
17
|
+
exp = [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
|
|
18
|
+
t.true(compareVectors(obs, exp))
|
|
19
|
+
|
|
20
|
+
// connectors as taken from V1 cube
|
|
21
|
+
const facecenter0 = fromPointAxisNormal([3, 0, 0], [1, 0, 0], [0, 0, 1])
|
|
22
|
+
const facecenter1 = fromPointAxisNormal([-3, 0, 0], [-1, 0, 0], [0, 0, 1])
|
|
23
|
+
const facecenter2 = fromPointAxisNormal([0, 3, 0], [0, 1, 0], [0, 0, 1])
|
|
24
|
+
// const facecenter3 = fromPointAxisNormal([0, -3, 0], [0, -1, 0], [0, 0, 1])
|
|
25
|
+
// const facecenter4 = fromPointAxisNormal([0, 0, 3], [0, 0, 1], [1, 0, 0])
|
|
26
|
+
const facecenter5 = fromPointAxisNormal([0, 0, -3], [0, 0, -1], [1, 0, 0])
|
|
27
|
+
|
|
28
|
+
obs = transformationBetween({}, facecenter0, facecenter1) // opposing faces
|
|
29
|
+
exp = [-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, -3.6739405577555036e-16, 0, 1]
|
|
30
|
+
t.true(compareVectors(obs, exp))
|
|
31
|
+
|
|
32
|
+
obs = transformationBetween({}, facecenter2, facecenter5) // adjacent faces
|
|
33
|
+
exp = [0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 3, -3, 0, 1]
|
|
34
|
+
t.true(compareVectors(obs, exp))
|
|
35
|
+
|
|
36
|
+
// test mirror option
|
|
37
|
+
obs = transformationBetween({ mirror: true }, facecenter0, facecenter1) // opposing faces
|
|
38
|
+
exp = [1, -2.4492937051703357e-16, 0, 0, 2.4492937051703357e-16, 1, 0, 0, 0, 0, 1, 0, -6, 7.347881115511007e-16, 0, 1]
|
|
39
|
+
t.true(compareVectors(obs, exp))
|
|
40
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const lengths = require('./lengths')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Convert a given arc length along a bezier curve to a t value.
|
|
5
|
+
* Useful for generating equally spaced points along a bezier curve.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const points = [];
|
|
9
|
+
* const segments = 9; // this will generate 10 equally spaced points
|
|
10
|
+
* const increment = bezier.length(100, bezierCurve) / segments;
|
|
11
|
+
* for(let i = 0; i <= segments; i++) {
|
|
12
|
+
* const t = bezier.arcLengthToT({distance: i * increment}, bezierCurve);
|
|
13
|
+
* const point = bezier.valueAt(t, bezierCurve);
|
|
14
|
+
* points.push(point);
|
|
15
|
+
* }
|
|
16
|
+
* return points;
|
|
17
|
+
*
|
|
18
|
+
* @param {Object} [options] options for construction
|
|
19
|
+
* @param {Number} [options.distance=0] the distance along the bezier curve for which we want to find the corresponding t value.
|
|
20
|
+
* @param {Number} [options.segments=100] the number of segments to use when approximating the curve length.
|
|
21
|
+
* @param {Object} bezier a bezier curve.
|
|
22
|
+
* @returns a number in the [0, 1] interval or NaN if the arcLength is negative or greater than the total length of the curve.
|
|
23
|
+
* @alias module:modeling/curves/bezier.arcLengthToT
|
|
24
|
+
*/
|
|
25
|
+
const arcLengthToT = (options, bezier) => {
|
|
26
|
+
const defaults = {
|
|
27
|
+
distance: 0,
|
|
28
|
+
segments: 100
|
|
29
|
+
}
|
|
30
|
+
const { distance, segments } = Object.assign({}, defaults, options)
|
|
31
|
+
|
|
32
|
+
const arcLengths = lengths(segments, bezier)
|
|
33
|
+
// binary search for the index with largest value smaller than target arcLength
|
|
34
|
+
let startIndex = 0
|
|
35
|
+
let endIndex = segments
|
|
36
|
+
while (startIndex <= endIndex) {
|
|
37
|
+
const middleIndex = Math.floor(startIndex + (endIndex - startIndex) / 2)
|
|
38
|
+
const diff = arcLengths[middleIndex] - distance
|
|
39
|
+
if (diff < 0) {
|
|
40
|
+
startIndex = middleIndex + 1
|
|
41
|
+
} else if (diff > 0) {
|
|
42
|
+
endIndex = middleIndex - 1
|
|
43
|
+
} else {
|
|
44
|
+
endIndex = middleIndex
|
|
45
|
+
break
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// if we have an exact match, return it
|
|
49
|
+
const targetIndex = endIndex
|
|
50
|
+
if (arcLengths[targetIndex] === distance) {
|
|
51
|
+
return targetIndex / segments
|
|
52
|
+
}
|
|
53
|
+
// we could get finer grain at lengths, or use simple interpolation between two points
|
|
54
|
+
const lengthBefore = arcLengths[targetIndex]
|
|
55
|
+
const lengthAfter = arcLengths[targetIndex + 1]
|
|
56
|
+
const segmentLength = lengthAfter - lengthBefore
|
|
57
|
+
// determine where we are between the 'before' and 'after' points
|
|
58
|
+
const segmentFraction = (distance - lengthBefore) / segmentLength
|
|
59
|
+
// add that fractional amount and return
|
|
60
|
+
return (targetIndex + segmentFraction) / segments
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = arcLengthToT
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
|
|
3
|
+
const { bezier } = require('../index')
|
|
4
|
+
const length = require('./length')
|
|
5
|
+
const arcLengthToT = require('./arcLengthToT')
|
|
6
|
+
|
|
7
|
+
const { nearlyEqual } = require('../../../test/helpers/index')
|
|
8
|
+
|
|
9
|
+
test('calculate arcLengthToT for an 1D linear bezier with numeric control points', (t) => {
|
|
10
|
+
const bezierCurve = bezier.create([0, 10])
|
|
11
|
+
const len = length(100, bezierCurve)
|
|
12
|
+
nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001)
|
|
13
|
+
nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.5, 0.0001)
|
|
14
|
+
nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001)
|
|
15
|
+
t.true(true)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('calculate arcLengthToT for an 1D linear bezier with array control points', (t) => {
|
|
19
|
+
const bezierCurve = bezier.create([[0], [10]])
|
|
20
|
+
const len = length(100, bezierCurve)
|
|
21
|
+
nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001)
|
|
22
|
+
nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.5, 0.0001)
|
|
23
|
+
nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001)
|
|
24
|
+
t.true(true)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('calculate arcLengthToT for a 2D linear bezier', (t) => {
|
|
28
|
+
const bezierCurve = bezier.create([[0, 0], [10, 10]])
|
|
29
|
+
const len = length(100, bezierCurve)
|
|
30
|
+
nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001)
|
|
31
|
+
nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.5, 0.0001)
|
|
32
|
+
nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001)
|
|
33
|
+
t.true(true)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('calculate arcLengthToT for a 2D quadratic (3 control points) bezier', (t) => {
|
|
37
|
+
const bezierCurve = bezier.create([[0, 0], [0, 10], [10, 10]])
|
|
38
|
+
const len = length(100, bezierCurve)
|
|
39
|
+
nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001)
|
|
40
|
+
nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.50001, 0.0001)
|
|
41
|
+
nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001)
|
|
42
|
+
t.true(true)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('calculate arcLengthToT for a 2D cubic (4 control points) bezier', (t) => {
|
|
46
|
+
const bezierCurve = bezier.create([[0, 0], [0, 10], [10, 10], [10, 0]])
|
|
47
|
+
const len = length(100, bezierCurve)
|
|
48
|
+
nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001)
|
|
49
|
+
nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.49999, 0.0001)
|
|
50
|
+
nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001)
|
|
51
|
+
t.true(true)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('calculate arcLengthToT for a 3D linear bezier', (t) => {
|
|
55
|
+
const bezierCurve = bezier.create([[0, 0, 0], [10, 10, 10]])
|
|
56
|
+
const len = length(100, bezierCurve)
|
|
57
|
+
nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001)
|
|
58
|
+
nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.49999, 0.0001)
|
|
59
|
+
nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001)
|
|
60
|
+
t.true(true)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('calculate arcLengthToT for a 3D quadratic (3 control points) bezier', (t) => {
|
|
64
|
+
const bezierCurve = bezier.create([[0, 0, 0], [5, 5, 5], [0, 0, 10]])
|
|
65
|
+
const len = length(100, bezierCurve)
|
|
66
|
+
nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001)
|
|
67
|
+
nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.49999, 0.0001)
|
|
68
|
+
nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001)
|
|
69
|
+
t.true(true)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('calculate arcLengthToT for a 3D cubic (4 control points) bezier', (t) => {
|
|
73
|
+
const bezierCurve = bezier.create([[0, 0, 0], [5, 5, 5], [0, 0, 10], [-5, -5, 5]])
|
|
74
|
+
const len = length(100, bezierCurve)
|
|
75
|
+
nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001)
|
|
76
|
+
nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.5621, 0.0001)
|
|
77
|
+
nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001)
|
|
78
|
+
t.true(true)
|
|
79
|
+
})
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a bezier easing function.
|
|
3
|
+
* @typedef {Object} bezier
|
|
4
|
+
* @property {Array} points - The control points for the bezier curve. The first and last point will also be the start and end of the curve
|
|
5
|
+
* @property {string} pointType - A reference to the type and dimensionality of the points that the curve was created from
|
|
6
|
+
* @property {number} dimensions - The dimensionality of the bezier
|
|
7
|
+
* @property {Array} permutations - A pre-calculation of the bezier algorithm's co-efficients
|
|
8
|
+
* @property {Array} tangentPermutations - A pre-calculation of the bezier algorithm's tangent co-efficients
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Creates an object representing a bezier easing curve.
|
|
14
|
+
* Curves can have both an arbitrary number of control points, and an arbitrary number of dimensions.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const b = bezier.create([0,10]) // a linear progression from 0 to 10
|
|
18
|
+
* const b = bezier.create([0, 0, 10, 10]) // a symmetrical cubic easing curve that starts slowly and ends slowly from 0 to 10
|
|
19
|
+
* const b = bezier.create([0,0,0], [0,5,10], [10,0,-5], [10,10,10]]) // a cubic 3 dimensional easing curve that can generate position arrays for modelling
|
|
20
|
+
* // Usage
|
|
21
|
+
* let position = bezier.valueAt(t,b) // where 0 < t < 1
|
|
22
|
+
* let tangent = bezier.tangentAt(t,b) // where 0 < t < 1
|
|
23
|
+
*
|
|
24
|
+
* @param {Array} points An array with at least 2 elements of either all numbers, or all arrays of numbers that are the same size.
|
|
25
|
+
* @returns {bezier} a new bezier data object
|
|
26
|
+
* @alias module:modeling/curves/bezier.create
|
|
27
|
+
*/
|
|
28
|
+
const create = (points) => {
|
|
29
|
+
if (!Array.isArray(points)) throw new Error('Bezier points must be a valid array/')
|
|
30
|
+
if (points.length < 2) throw new Error('Bezier points must contain at least 2 values.')
|
|
31
|
+
const pointType = getPointType(points)
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
points: points,
|
|
35
|
+
pointType: pointType,
|
|
36
|
+
dimensions: pointType === 'float_single' ? 0 : points[0].length,
|
|
37
|
+
permutations: getPermutations(points.length - 1),
|
|
38
|
+
tangentPermutations: getPermutations(points.length - 2)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const getPointType = function (points) {
|
|
43
|
+
let firstPointType = null
|
|
44
|
+
points.forEach((point) => {
|
|
45
|
+
let pType = ''
|
|
46
|
+
if (Number.isFinite(point)) {
|
|
47
|
+
pType = 'float_single'
|
|
48
|
+
} else if (Array.isArray(point)) {
|
|
49
|
+
point.forEach((val) => {
|
|
50
|
+
if (!Number.isFinite(val)) throw new Error('Bezier point values must all be numbers.')
|
|
51
|
+
})
|
|
52
|
+
pType = 'float_' + point.length
|
|
53
|
+
} else throw new Error('Bezier points must all be numbers or arrays of number.')
|
|
54
|
+
if (firstPointType == null) {
|
|
55
|
+
firstPointType = pType
|
|
56
|
+
} else {
|
|
57
|
+
if (firstPointType !== pType) {
|
|
58
|
+
throw new Error('Bezier points must be either all numbers or all arrays of numbers of the same size.')
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
return firstPointType
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const getPermutations = function (c) {
|
|
66
|
+
const permutations = []
|
|
67
|
+
for (let i = 0; i <= c; i++) {
|
|
68
|
+
permutations.push(factorial(c) / (factorial(i) * factorial(c - i)))
|
|
69
|
+
}
|
|
70
|
+
return permutations
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const factorial = function (b) {
|
|
74
|
+
let out = 1
|
|
75
|
+
for (let i = 2; i <= b; i++) {
|
|
76
|
+
out *= i
|
|
77
|
+
}
|
|
78
|
+
return out
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = create
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
|
|
3
|
+
const { bezier } = require('../index')
|
|
4
|
+
|
|
5
|
+
test('Linear bezier (straight line between two points)', (t) => {
|
|
6
|
+
const straightLine = bezier.create([10, 20])
|
|
7
|
+
t.deepEqual(straightLine.points, [10, 20])
|
|
8
|
+
t.is(straightLine.pointType, 'float_single')
|
|
9
|
+
t.deepEqual(straightLine.permutations, [1, 1])
|
|
10
|
+
t.deepEqual(straightLine.tangentPermutations, [1])
|
|
11
|
+
t.is(straightLine.dimensions, 0)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('bezier with non-numbers throws error', (t) => {
|
|
15
|
+
t.throws(() => bezier.create(['what', 20]), { instanceOf: Error })
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('quadratic bezier (3 control points)', (t) => {
|
|
19
|
+
const OneDCurve = bezier.create([0, 10, 20])
|
|
20
|
+
t.deepEqual(OneDCurve.points, [0, 10, 20])
|
|
21
|
+
t.is(OneDCurve.pointType, 'float_single')
|
|
22
|
+
t.deepEqual(OneDCurve.permutations, [1, 2, 1])
|
|
23
|
+
t.deepEqual(OneDCurve.tangentPermutations, [1, 1])
|
|
24
|
+
t.is(OneDCurve.dimensions, 0)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('quadratic bezier (4 control points)', (t) => {
|
|
28
|
+
const OneDCurve = bezier.create([0, 0, 20, 20])
|
|
29
|
+
t.deepEqual(OneDCurve.points, [0, 0, 20, 20])
|
|
30
|
+
t.is(OneDCurve.pointType, 'float_single')
|
|
31
|
+
t.deepEqual(OneDCurve.permutations, [1, 3, 3, 1])
|
|
32
|
+
t.deepEqual(OneDCurve.tangentPermutations, [1, 2, 1])
|
|
33
|
+
t.is(OneDCurve.dimensions, 0)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('bezier with numbers and array of numbers throws error', (t) => {
|
|
37
|
+
t.throws(() => bezier.create([[0, 5, 10], 20]), { instanceOf: Error })
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('bezier with array of numbers of different size throws error', (t) => {
|
|
41
|
+
t.throws(() => bezier.create([[0, 5, 10], [20, 0]]), { instanceOf: Error })
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('quadratic bezier one dimension, 3 control points', (t) => {
|
|
45
|
+
const OneDCurve = bezier.create([[0], [10], [20]])
|
|
46
|
+
t.deepEqual(OneDCurve.points, [[0], [10], [20]])
|
|
47
|
+
t.is(OneDCurve.pointType, 'float_1')
|
|
48
|
+
t.deepEqual(OneDCurve.permutations, [1, 2, 1])
|
|
49
|
+
t.deepEqual(OneDCurve.tangentPermutations, [1, 1])
|
|
50
|
+
t.is(OneDCurve.dimensions, 1)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('quadratic bezier 2 dimensions, 3 control points', (t) => {
|
|
54
|
+
const TwoDCurve = bezier.create([[0, 10], [30, 10], [60, 20]])
|
|
55
|
+
t.deepEqual(TwoDCurve.points, [[0, 10], [30, 10], [60, 20]])
|
|
56
|
+
t.is(TwoDCurve.pointType, 'float_2')
|
|
57
|
+
t.deepEqual(TwoDCurve.permutations, [1, 2, 1])
|
|
58
|
+
t.deepEqual(TwoDCurve.tangentPermutations, [1, 1])
|
|
59
|
+
t.is(TwoDCurve.dimensions, 2)
|
|
60
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { default as create } from './create'
|
|
2
|
+
export { default as tangentAt } from './tangentAt'
|
|
3
|
+
export { default as valueAt } from './valueAt'
|
|
4
|
+
export { default as lengths } from './lengths'
|
|
5
|
+
export { default as length } from './length'
|
|
6
|
+
export { default as arcLengthToT } from './arcLengthToT'
|
|
7
|
+
|
|
8
|
+
export { default as Bezier } from './type'
|
|
9
|
+
export as namespace bezier
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a bezier easing function.
|
|
3
|
+
* @see {@link bezier} for data structure information.
|
|
4
|
+
* @module modeling/curves/bezier
|
|
5
|
+
*/
|
|
6
|
+
module.exports = {
|
|
7
|
+
create: require('./create'),
|
|
8
|
+
valueAt: require('./valueAt'),
|
|
9
|
+
tangentAt: require('./tangentAt'),
|
|
10
|
+
lengths: require('./lengths'),
|
|
11
|
+
length: require('./length'),
|
|
12
|
+
arcLengthToT: require('./arcLengthToT')
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const lengths = require('./lengths')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Approximates the length of the bezier curve by sampling it at a sequence of points, then adding up all the distances.
|
|
5
|
+
* This is equivalent to flattening the curve into lines and adding up all the line lengths.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const b = bezier.create([[0, 0], [0, 10]]);
|
|
9
|
+
* console.log(length(100, b)) // output 10
|
|
10
|
+
*
|
|
11
|
+
* @param {Number} segments the number of segments to use when approximating the curve length.
|
|
12
|
+
* @param {Object} bezier a bezier curve.
|
|
13
|
+
* @returns an approximation of the curve's length.
|
|
14
|
+
* @alias module:modeling/curves/bezier.length
|
|
15
|
+
*/
|
|
16
|
+
const length = (segments, bezier) => lengths(segments, bezier)[segments]
|
|
17
|
+
|
|
18
|
+
module.exports = length
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
|
|
3
|
+
const { bezier } = require('../index')
|
|
4
|
+
const length = require('./length')
|
|
5
|
+
|
|
6
|
+
const { nearlyEqual } = require('../../../test/helpers/index')
|
|
7
|
+
|
|
8
|
+
test('calculate the length of an 1D linear bezier with numeric control points', (t) => {
|
|
9
|
+
const bezierCurve = bezier.create([0, 10])
|
|
10
|
+
nearlyEqual(t, length(100, bezierCurve), 10, 0.0001)
|
|
11
|
+
t.true(true)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('calculate the length of an 1D linear bezier with array control points', (t) => {
|
|
15
|
+
const bezierCurve = bezier.create([[0], [10]])
|
|
16
|
+
nearlyEqual(t, length(100, bezierCurve), 10, 0.0001)
|
|
17
|
+
t.true(true)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('calculate the length of a 2D linear bezier', (t) => {
|
|
21
|
+
const bezierCurve = bezier.create([[0, 0], [10, 10]])
|
|
22
|
+
nearlyEqual(t, length(100, bezierCurve), 14.1421, 0.0001)
|
|
23
|
+
t.true(true)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('calculate the length of a 2D quadratic (3 control points) bezier', (t) => {
|
|
27
|
+
const bezierCurve = bezier.create([[0, 0], [0, 10], [10, 10]])
|
|
28
|
+
nearlyEqual(t, length(100, bezierCurve), 16.2320, 0.0001)
|
|
29
|
+
t.true(true)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('calculate the length of a 2D cubic (4 control points) bezier', (t) => {
|
|
33
|
+
const bezierCurve = bezier.create([[0, 0], [0, 10], [10, 10], [10, 0]])
|
|
34
|
+
nearlyEqual(t, length(100, bezierCurve), 19.9992, 0.0001)
|
|
35
|
+
t.true(true)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('calculate the length of a 3D linear bezier', (t) => {
|
|
39
|
+
const bezierCurve = bezier.create([[0, 0, 0], [10, 10, 10]])
|
|
40
|
+
nearlyEqual(t, length(100, bezierCurve), 17.3205, 0.0001)
|
|
41
|
+
t.true(true)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('calculate the length of a 3D quadratic (3 control points) bezier', (t) => {
|
|
45
|
+
const bezierCurve = bezier.create([[0, 0, 0], [5, 5, 5], [0, 0, 10]])
|
|
46
|
+
nearlyEqual(t, length(100, bezierCurve), 12.7125, 0.0001)
|
|
47
|
+
t.true(true)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('calculate the length of a 3D cubic (4 control points) bezier', (t) => {
|
|
51
|
+
const bezierCurve = bezier.create([[0, 0, 0], [5, 5, 5], [0, 0, 10], [-5, -5, 5]])
|
|
52
|
+
nearlyEqual(t, length(100, bezierCurve), 17.2116, 0.0001)
|
|
53
|
+
t.true(true)
|
|
54
|
+
})
|