@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,15 @@
|
|
|
1
|
+
import Path2 from './type'
|
|
2
|
+
import Vec2 from '../../maths/vec2/type'
|
|
3
|
+
|
|
4
|
+
export default appendArc
|
|
5
|
+
|
|
6
|
+
export interface AppendArcOptions {
|
|
7
|
+
endpoint: Vec2
|
|
8
|
+
radius?: Vec2
|
|
9
|
+
xaxisrotation?: number
|
|
10
|
+
clockwise?: boolean
|
|
11
|
+
large?: boolean
|
|
12
|
+
segments?: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare function appendArc(options: AppendArcOptions, geometry: Path2): Path2
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
const { TAU } = require('../../maths/constants')
|
|
2
|
+
const vec2 = require('../../maths/vec2')
|
|
3
|
+
|
|
4
|
+
const fromPoints = require('./fromPoints')
|
|
5
|
+
const toPoints = require('./toPoints')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Append a series of points to the given geometry that represent an arc.
|
|
9
|
+
* This implementation follows the SVG specifications.
|
|
10
|
+
* @see http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
|
|
11
|
+
* @param {Object} options - options for construction
|
|
12
|
+
* @param {vec2} options.endpoint - end point of arc (REQUIRED)
|
|
13
|
+
* @param {vec2} [options.radius=[0,0]] - radius of arc (X and Y)
|
|
14
|
+
* @param {Number} [options.xaxisrotation=0] - rotation (RADIANS) of the X axis of the arc with respect to the X axis of the coordinate system
|
|
15
|
+
* @param {Boolean} [options.clockwise=false] - draw an arc clockwise with respect to the center point
|
|
16
|
+
* @param {Boolean} [options.large=false] - draw an arc longer than TAU / 2 radians
|
|
17
|
+
* @param {Number} [options.segments=16] - number of segments per full rotation
|
|
18
|
+
* @param {path2} geometry - the path of which to append the arc
|
|
19
|
+
* @returns {path2} a new path with the appended points
|
|
20
|
+
* @alias module:modeling/geometries/path2.appendArc
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* let p1 = path2.fromPoints({}, [[27.5,-22.96875]]);
|
|
24
|
+
* p1 = path2.appendPoints([[27.5,-3.28125]], p1);
|
|
25
|
+
* p1 = path2.appendArc({endpoint: [12.5, -22.96875], radius: [15, -19.6875]}, p1);
|
|
26
|
+
*/
|
|
27
|
+
const appendArc = (options, geometry) => {
|
|
28
|
+
const defaults = {
|
|
29
|
+
radius: [0, 0], // X and Y radius
|
|
30
|
+
xaxisrotation: 0,
|
|
31
|
+
clockwise: false,
|
|
32
|
+
large: false,
|
|
33
|
+
segments: 16
|
|
34
|
+
}
|
|
35
|
+
let { endpoint, radius, xaxisrotation, clockwise, large, segments } = Object.assign({}, defaults, options)
|
|
36
|
+
|
|
37
|
+
// validate the given options
|
|
38
|
+
if (!Array.isArray(endpoint)) throw new Error('endpoint must be an array of X and Y values')
|
|
39
|
+
if (endpoint.length < 2) throw new Error('endpoint must contain X and Y values')
|
|
40
|
+
endpoint = vec2.clone(endpoint)
|
|
41
|
+
|
|
42
|
+
if (!Array.isArray(radius)) throw new Error('radius must be an array of X and Y values')
|
|
43
|
+
if (radius.length < 2) throw new Error('radius must contain X and Y values')
|
|
44
|
+
|
|
45
|
+
if (segments < 4) throw new Error('segments must be four or more')
|
|
46
|
+
|
|
47
|
+
const decimals = 100000
|
|
48
|
+
|
|
49
|
+
// validate the given geometry
|
|
50
|
+
if (geometry.isClosed) {
|
|
51
|
+
throw new Error('the given path cannot be closed')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const points = toPoints(geometry)
|
|
55
|
+
if (points.length < 1) {
|
|
56
|
+
throw new Error('the given path must contain one or more points (as the starting point for the arc)')
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let xradius = radius[0]
|
|
60
|
+
let yradius = radius[1]
|
|
61
|
+
const startpoint = points[points.length - 1]
|
|
62
|
+
|
|
63
|
+
// round to precision in order to have determinate calculations
|
|
64
|
+
xradius = Math.round(xradius * decimals) / decimals
|
|
65
|
+
yradius = Math.round(yradius * decimals) / decimals
|
|
66
|
+
endpoint = vec2.fromValues(Math.round(endpoint[0] * decimals) / decimals, Math.round(endpoint[1] * decimals) / decimals)
|
|
67
|
+
|
|
68
|
+
const sweepFlag = !clockwise
|
|
69
|
+
let newpoints = []
|
|
70
|
+
if ((xradius === 0) || (yradius === 0)) {
|
|
71
|
+
// http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes:
|
|
72
|
+
// If rx = 0 or ry = 0, then treat this as a straight line from (x1, y1) to (x2, y2) and stop
|
|
73
|
+
newpoints.push(endpoint)
|
|
74
|
+
} else {
|
|
75
|
+
xradius = Math.abs(xradius)
|
|
76
|
+
yradius = Math.abs(yradius)
|
|
77
|
+
|
|
78
|
+
// see http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes :
|
|
79
|
+
const phi = xaxisrotation
|
|
80
|
+
const cosphi = Math.cos(phi)
|
|
81
|
+
const sinphi = Math.sin(phi)
|
|
82
|
+
const minushalfdistance = vec2.subtract(vec2.create(), startpoint, endpoint)
|
|
83
|
+
vec2.scale(minushalfdistance, minushalfdistance, 0.5)
|
|
84
|
+
// F.6.5.1:
|
|
85
|
+
// round to precision in order to have determinate calculations
|
|
86
|
+
const x = Math.round((cosphi * minushalfdistance[0] + sinphi * minushalfdistance[1]) * decimals) / decimals
|
|
87
|
+
const y = Math.round((-sinphi * minushalfdistance[0] + cosphi * minushalfdistance[1]) * decimals) / decimals
|
|
88
|
+
const startTranslated = vec2.fromValues(x, y)
|
|
89
|
+
// F.6.6.2:
|
|
90
|
+
const biglambda = (startTranslated[0] * startTranslated[0]) / (xradius * xradius) + (startTranslated[1] * startTranslated[1]) / (yradius * yradius)
|
|
91
|
+
if (biglambda > 1.0) {
|
|
92
|
+
// F.6.6.3:
|
|
93
|
+
const sqrtbiglambda = Math.sqrt(biglambda)
|
|
94
|
+
xradius *= sqrtbiglambda
|
|
95
|
+
yradius *= sqrtbiglambda
|
|
96
|
+
// round to precision in order to have determinate calculations
|
|
97
|
+
xradius = Math.round(xradius * decimals) / decimals
|
|
98
|
+
yradius = Math.round(yradius * decimals) / decimals
|
|
99
|
+
}
|
|
100
|
+
// F.6.5.2:
|
|
101
|
+
let multiplier1 = Math.sqrt((xradius * xradius * yradius * yradius - xradius * xradius * startTranslated[1] * startTranslated[1] - yradius * yradius * startTranslated[0] * startTranslated[0]) / (xradius * xradius * startTranslated[1] * startTranslated[1] + yradius * yradius * startTranslated[0] * startTranslated[0]))
|
|
102
|
+
if (sweepFlag === large) multiplier1 = -multiplier1
|
|
103
|
+
const centerTranslated = vec2.fromValues(xradius * startTranslated[1] / yradius, -yradius * startTranslated[0] / xradius)
|
|
104
|
+
vec2.scale(centerTranslated, centerTranslated, multiplier1)
|
|
105
|
+
// F.6.5.3:
|
|
106
|
+
let center = vec2.fromValues(cosphi * centerTranslated[0] - sinphi * centerTranslated[1], sinphi * centerTranslated[0] + cosphi * centerTranslated[1])
|
|
107
|
+
center = vec2.add(center, center, vec2.scale(vec2.create(), vec2.add(vec2.create(), startpoint, endpoint), 0.5))
|
|
108
|
+
|
|
109
|
+
// F.6.5.5:
|
|
110
|
+
const vector1 = vec2.fromValues((startTranslated[0] - centerTranslated[0]) / xradius, (startTranslated[1] - centerTranslated[1]) / yradius)
|
|
111
|
+
const vector2 = vec2.fromValues((-startTranslated[0] - centerTranslated[0]) / xradius, (-startTranslated[1] - centerTranslated[1]) / yradius)
|
|
112
|
+
const theta1 = vec2.angleRadians(vector1)
|
|
113
|
+
const theta2 = vec2.angleRadians(vector2)
|
|
114
|
+
let deltatheta = theta2 - theta1
|
|
115
|
+
deltatheta = deltatheta % TAU
|
|
116
|
+
if ((!sweepFlag) && (deltatheta > 0)) {
|
|
117
|
+
deltatheta -= TAU
|
|
118
|
+
} else if ((sweepFlag) && (deltatheta < 0)) {
|
|
119
|
+
deltatheta += TAU
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Ok, we have the center point and angle range (from theta1, deltatheta radians) so we can create the ellipse
|
|
123
|
+
let numsteps = Math.ceil(Math.abs(deltatheta) / TAU * segments) + 1
|
|
124
|
+
if (numsteps < 1) numsteps = 1
|
|
125
|
+
for (let step = 1; step < numsteps; step++) {
|
|
126
|
+
const theta = theta1 + step / numsteps * deltatheta
|
|
127
|
+
const costheta = Math.cos(theta)
|
|
128
|
+
const sintheta = Math.sin(theta)
|
|
129
|
+
// F.6.3.1:
|
|
130
|
+
const point = vec2.fromValues(cosphi * xradius * costheta - sinphi * yradius * sintheta, sinphi * xradius * costheta + cosphi * yradius * sintheta)
|
|
131
|
+
vec2.add(point, point, center)
|
|
132
|
+
newpoints.push(point)
|
|
133
|
+
}
|
|
134
|
+
// ensure end point is precisely what user gave as parameter
|
|
135
|
+
if (numsteps) newpoints.push(options.endpoint)
|
|
136
|
+
}
|
|
137
|
+
newpoints = points.concat(newpoints)
|
|
138
|
+
const result = fromPoints({}, newpoints)
|
|
139
|
+
return result
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
module.exports = appendArc
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
|
|
3
|
+
const { TAU } = require('../../maths/constants')
|
|
4
|
+
|
|
5
|
+
const { appendArc, fromPoints, toPoints } = require('./index')
|
|
6
|
+
|
|
7
|
+
const { comparePoints } = require('../../../test/helpers/')
|
|
8
|
+
|
|
9
|
+
test('appendArc: appending to an empty path produces an error', (t) => {
|
|
10
|
+
const p1 = fromPoints({}, [])
|
|
11
|
+
t.throws(() => appendArc({ endpoint: [12, 12] }, p1),
|
|
12
|
+
{ message: 'the given path must contain one or more points (as the starting point for the arc)' })
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test('appendArc: appending to a path produces a new path', (t) => {
|
|
16
|
+
const p1 = fromPoints({}, [[1, 1], [2, 2]])
|
|
17
|
+
let obs = appendArc({ endpoint: [-2, 2] }, p1)
|
|
18
|
+
let pts = toPoints(obs)
|
|
19
|
+
t.is(pts.length, 3)
|
|
20
|
+
|
|
21
|
+
// test radius
|
|
22
|
+
const p2 = fromPoints({}, [[27, -22], [27, -3]])
|
|
23
|
+
obs = appendArc({ endpoint: [12, -22], radius: [15, -20] }, p2)
|
|
24
|
+
pts = toPoints(obs)
|
|
25
|
+
t.is(pts.length, 7)
|
|
26
|
+
|
|
27
|
+
// test segments
|
|
28
|
+
obs = appendArc({ endpoint: [12, -22], radius: [15, -20], segments: 64 }, p2)
|
|
29
|
+
pts = toPoints(obs)
|
|
30
|
+
t.is(pts.length, 19)
|
|
31
|
+
|
|
32
|
+
// test clockwise
|
|
33
|
+
obs = appendArc({ endpoint: [12, -22], radius: [15, -20], clockwise: true }, p2)
|
|
34
|
+
pts = toPoints(obs)
|
|
35
|
+
let exp = [
|
|
36
|
+
[27, -22],
|
|
37
|
+
[27, -3],
|
|
38
|
+
[26.086451657912605, -8.941047736250177],
|
|
39
|
+
[23.87938869625451, -14.243872270248309],
|
|
40
|
+
[20.58174906029909, -18.420882475791835],
|
|
41
|
+
[16.49674848226545, -21.0880050920699],
|
|
42
|
+
[11.999999999999998, -22]
|
|
43
|
+
]
|
|
44
|
+
t.is(pts.length, 7)
|
|
45
|
+
t.true(comparePoints(pts, exp))
|
|
46
|
+
|
|
47
|
+
// test large
|
|
48
|
+
obs = appendArc({ endpoint: [12, -22], radius: [15, -20], large: true }, p2)
|
|
49
|
+
pts = toPoints(obs)
|
|
50
|
+
t.is(pts.length, 16)
|
|
51
|
+
|
|
52
|
+
// test xaxisrotation
|
|
53
|
+
obs = appendArc({ endpoint: [12, -22], radius: [15, -20], xaxisrotation: TAU / 4 }, p2)
|
|
54
|
+
pts = toPoints(obs)
|
|
55
|
+
exp = [
|
|
56
|
+
[27, -22],
|
|
57
|
+
[27, -3],
|
|
58
|
+
[21.830323320631795, -4.401628923214028],
|
|
59
|
+
[17.364704977487236, -6.805886946199115],
|
|
60
|
+
[13.940501387124588, -10.031143708098092],
|
|
61
|
+
[11.816394990371812, -13.833746263211978],
|
|
62
|
+
[11.15285201325494, -17.926425912558045],
|
|
63
|
+
[12, -22.000000000000004]
|
|
64
|
+
]
|
|
65
|
+
t.is(pts.length, 8)
|
|
66
|
+
t.true(comparePoints(pts, exp))
|
|
67
|
+
|
|
68
|
+
// test small arc between far points
|
|
69
|
+
obs = appendArc({ endpoint: [120, -220], radius: [5, -5] }, p2)
|
|
70
|
+
pts = toPoints(obs)
|
|
71
|
+
t.is(pts.length, 2)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('appendArc: appending to a path produces exact endpoint', (t) => {
|
|
75
|
+
let p1 = fromPoints({}, [[18, 1.8], [1, 3]])
|
|
76
|
+
const endpoint = [1, -3]
|
|
77
|
+
|
|
78
|
+
p1 = appendArc({
|
|
79
|
+
endpoint,
|
|
80
|
+
radius: [4, 4],
|
|
81
|
+
segments: 36,
|
|
82
|
+
large: true
|
|
83
|
+
}, p1)
|
|
84
|
+
|
|
85
|
+
const pts = toPoints(p1)
|
|
86
|
+
|
|
87
|
+
t.deepEqual(pts[pts.length - 1], endpoint)
|
|
88
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Path2 from './type'
|
|
2
|
+
import Vec2 from '../../maths/vec2/type'
|
|
3
|
+
|
|
4
|
+
export default appendBezier
|
|
5
|
+
|
|
6
|
+
export interface AppendBezierOptions {
|
|
7
|
+
controlPoints: Array<Vec2 | null>
|
|
8
|
+
segments?: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare function appendBezier(options: AppendBezierOptions, geometry: Path2): Path2
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
const { TAU } = require('../../maths/constants')
|
|
2
|
+
const vec2 = require('../../maths/vec2')
|
|
3
|
+
const vec3 = require('../../maths/vec2')
|
|
4
|
+
|
|
5
|
+
const appendPoints = require('./appendPoints')
|
|
6
|
+
const toPoints = require('./toPoints')
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Append a series of points to the given geometry that represent a Bezier curve.
|
|
10
|
+
* The Bézier curve starts at the last point in the given geometry, and ends at the last control point.
|
|
11
|
+
* The other control points are intermediate control points to transition the curve from start to end points.
|
|
12
|
+
* The first control point may be null to ensure a smooth transition occurs. In this case,
|
|
13
|
+
* the second to last point of the given geometry is mirrored into the control points of the Bezier curve.
|
|
14
|
+
* In other words, the trailing gradient of the geometry matches the new gradient of the curve.
|
|
15
|
+
* @param {Object} options - options for construction
|
|
16
|
+
* @param {Array} options.controlPoints - list of control points (2D) for the bezier curve
|
|
17
|
+
* @param {Number} [options.segment=16] - number of segments per 360 rotation
|
|
18
|
+
* @param {path2} geometry - the path of which to appended points
|
|
19
|
+
* @returns {path2} a new path with the appended points
|
|
20
|
+
* @alias module:modeling/geometries/path2.appendBezier
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* let p5 = path2.create({}, [[10,-20]])
|
|
24
|
+
* p5 = path2.appendBezier({controlPoints: [[10,-10],[25,-10],[25,-20]]}, p5);
|
|
25
|
+
* p5 = path2.appendBezier({controlPoints: [null, [25,-30],[40,-30],[40,-20]]}, p5)
|
|
26
|
+
*/
|
|
27
|
+
const appendBezier = (options, geometry) => {
|
|
28
|
+
const defaults = {
|
|
29
|
+
segments: 16
|
|
30
|
+
}
|
|
31
|
+
let { controlPoints, segments } = Object.assign({}, defaults, options)
|
|
32
|
+
|
|
33
|
+
// validate the given options
|
|
34
|
+
if (!Array.isArray(controlPoints)) throw new Error('controlPoints must be an array of one or more points')
|
|
35
|
+
if (controlPoints.length < 1) throw new Error('controlPoints must be an array of one or more points')
|
|
36
|
+
|
|
37
|
+
if (segments < 4) throw new Error('segments must be four or more')
|
|
38
|
+
|
|
39
|
+
// validate the given geometry
|
|
40
|
+
if (geometry.isClosed) {
|
|
41
|
+
throw new Error('the given geometry cannot be closed')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const points = toPoints(geometry)
|
|
45
|
+
if (points.length < 1) {
|
|
46
|
+
throw new Error('the given path must contain one or more points (as the starting point for the bezier curve)')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// make a copy of the control points
|
|
50
|
+
controlPoints = controlPoints.slice()
|
|
51
|
+
|
|
52
|
+
// special handling of null control point (only first is allowed)
|
|
53
|
+
const firstControlPoint = controlPoints[0]
|
|
54
|
+
if (firstControlPoint === null) {
|
|
55
|
+
if (controlPoints.length < 2) {
|
|
56
|
+
throw new Error('a null control point must be passed with one more control points')
|
|
57
|
+
}
|
|
58
|
+
// special handling of a previous bezier curve
|
|
59
|
+
let lastBezierControlPoint = points[points.length - 2]
|
|
60
|
+
if ('lastBezierControlPoint' in geometry) {
|
|
61
|
+
lastBezierControlPoint = geometry.lastBezierControlPoint
|
|
62
|
+
}
|
|
63
|
+
if (!Array.isArray(lastBezierControlPoint)) {
|
|
64
|
+
throw new Error('the given path must contain TWO or more points if given a null control point')
|
|
65
|
+
}
|
|
66
|
+
// replace the first control point with the mirror of the last bezier control point
|
|
67
|
+
const controlpoint = vec2.scale(vec2.create(), points[points.length - 1], 2)
|
|
68
|
+
vec2.subtract(controlpoint, controlpoint, lastBezierControlPoint)
|
|
69
|
+
|
|
70
|
+
controlPoints[0] = controlpoint
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// add a control point for the previous end point
|
|
74
|
+
controlPoints.unshift(points[points.length - 1])
|
|
75
|
+
|
|
76
|
+
const bezierOrder = controlPoints.length - 1
|
|
77
|
+
const factorials = []
|
|
78
|
+
let fact = 1
|
|
79
|
+
for (let i = 0; i <= bezierOrder; ++i) {
|
|
80
|
+
if (i > 0) fact *= i
|
|
81
|
+
factorials.push(fact)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const binomials = []
|
|
85
|
+
for (let i = 0; i <= bezierOrder; ++i) {
|
|
86
|
+
const binomial = factorials[bezierOrder] / (factorials[i] * factorials[bezierOrder - i])
|
|
87
|
+
binomials.push(binomial)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const v0 = vec2.create()
|
|
91
|
+
const v1 = vec2.create()
|
|
92
|
+
const v3 = vec3.create()
|
|
93
|
+
const getPointForT = (t) => {
|
|
94
|
+
let tk = 1 // = pow(t,k)
|
|
95
|
+
let oneMinusTNMinusK = Math.pow(1 - t, bezierOrder) // = pow( 1-t, bezierOrder - k)
|
|
96
|
+
const invOneMinusT = (t !== 1) ? (1 / (1 - t)) : 1
|
|
97
|
+
const point = vec2.create() // 0, 0, 0
|
|
98
|
+
for (let k = 0; k <= bezierOrder; ++k) {
|
|
99
|
+
if (k === bezierOrder) oneMinusTNMinusK = 1
|
|
100
|
+
const bernsteinCoefficient = binomials[k] * tk * oneMinusTNMinusK
|
|
101
|
+
const derivativePoint = vec2.scale(v0, controlPoints[k], bernsteinCoefficient)
|
|
102
|
+
vec2.add(point, point, derivativePoint)
|
|
103
|
+
tk *= t
|
|
104
|
+
oneMinusTNMinusK *= invOneMinusT
|
|
105
|
+
}
|
|
106
|
+
return point
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const newpoints = []
|
|
110
|
+
const newpointsT = []
|
|
111
|
+
const numsteps = bezierOrder + 1
|
|
112
|
+
for (let i = 0; i < numsteps; ++i) {
|
|
113
|
+
const t = i / (numsteps - 1)
|
|
114
|
+
const point = getPointForT(t)
|
|
115
|
+
newpoints.push(point)
|
|
116
|
+
newpointsT.push(t)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// subdivide each segment until the angle at each vertex becomes small enough:
|
|
120
|
+
let subdivideBase = 1
|
|
121
|
+
const maxangle = TAU / segments
|
|
122
|
+
const maxsinangle = Math.sin(maxangle)
|
|
123
|
+
while (subdivideBase < newpoints.length - 1) {
|
|
124
|
+
const dir1 = vec2.subtract(v0, newpoints[subdivideBase], newpoints[subdivideBase - 1])
|
|
125
|
+
vec2.normalize(dir1, dir1)
|
|
126
|
+
const dir2 = vec2.subtract(v1, newpoints[subdivideBase + 1], newpoints[subdivideBase])
|
|
127
|
+
vec2.normalize(dir2, dir2)
|
|
128
|
+
const sinangle = vec2.cross(v3, dir1, dir2) // the sine of the angle
|
|
129
|
+
if (Math.abs(sinangle[2]) > maxsinangle) {
|
|
130
|
+
// angle is too big, we need to subdivide
|
|
131
|
+
const t0 = newpointsT[subdivideBase - 1]
|
|
132
|
+
const t1 = newpointsT[subdivideBase + 1]
|
|
133
|
+
const newt0 = t0 + (t1 - t0) * 1 / 3
|
|
134
|
+
const newt1 = t0 + (t1 - t0) * 2 / 3
|
|
135
|
+
const point0 = getPointForT(newt0)
|
|
136
|
+
const point1 = getPointForT(newt1)
|
|
137
|
+
// remove the point at subdivideBase and replace with 2 new points:
|
|
138
|
+
newpoints.splice(subdivideBase, 1, point0, point1)
|
|
139
|
+
newpointsT.splice(subdivideBase, 1, newt0, newt1)
|
|
140
|
+
// re - evaluate the angles, starting at the previous junction since it has changed:
|
|
141
|
+
subdivideBase--
|
|
142
|
+
if (subdivideBase < 1) subdivideBase = 1
|
|
143
|
+
} else {
|
|
144
|
+
++subdivideBase
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// append to the new points to the given path
|
|
149
|
+
// but skip the first new point because it is identical to the last point in the given path
|
|
150
|
+
newpoints.shift()
|
|
151
|
+
const result = appendPoints(newpoints, geometry)
|
|
152
|
+
result.lastBezierControlPoint = controlPoints[controlPoints.length - 2]
|
|
153
|
+
return result
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
module.exports = appendBezier
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
|
|
3
|
+
const { appendBezier, fromPoints, toPoints } = require('./index')
|
|
4
|
+
|
|
5
|
+
const { comparePoints } = require('../../../test/helpers/')
|
|
6
|
+
|
|
7
|
+
test('appendBezier: appending to an empty path produces an error', (t) => {
|
|
8
|
+
const p1 = fromPoints({}, [])
|
|
9
|
+
t.throws(() => appendBezier({ controlPoints: [[12, 12]] }, p1),
|
|
10
|
+
{ message: 'the given path must contain one or more points (as the starting point for the bezier curve)' })
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('appendBezier: appending to a path produces a new path', (t) => {
|
|
14
|
+
const p1 = fromPoints({}, [[10, -20]])
|
|
15
|
+
const obs1 = appendBezier({ controlPoints: [[10, -10], [25, -10], [25, -20]], segments: 16 }, p1)
|
|
16
|
+
const pts = toPoints(obs1)
|
|
17
|
+
const exp = [
|
|
18
|
+
[10, -20],
|
|
19
|
+
[10.410054926134793, -17.32967535436671],
|
|
20
|
+
[11.524609505100285, -15.244627343392775],
|
|
21
|
+
[13.170248437738149, -13.74485596707819],
|
|
22
|
+
[15.709947106075743, -12.693187014174669],
|
|
23
|
+
[18.469801915922933, -12.556012802926382],
|
|
24
|
+
[20.665245172410074, -13.128305870265937],
|
|
25
|
+
[22.5922740239998, -14.318842543198585],
|
|
26
|
+
[23.857263873597326, -15.783225858248295],
|
|
27
|
+
[24.69615704524313, -17.676945010515432],
|
|
28
|
+
[25, -20]
|
|
29
|
+
]
|
|
30
|
+
t.is(pts.length, 11)
|
|
31
|
+
t.true(comparePoints(pts, exp))
|
|
32
|
+
|
|
33
|
+
const obs2 = appendBezier({ controlPoints: [null, [25, -30], [40, -30], [40, -20]], segments: 16 }, obs1)
|
|
34
|
+
const pts2 = toPoints(obs2)
|
|
35
|
+
t.is(pts2.length, 23)
|
|
36
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const concat = require('./concat')
|
|
2
|
+
const create = require('./create')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Append the given list of points to the end of the given geometry.
|
|
6
|
+
* @param {Array} points - the points (2D) to append to the given path
|
|
7
|
+
* @param {path2} geometry - the given path
|
|
8
|
+
* @returns {path2} a new path with the appended points
|
|
9
|
+
* @alias module:modeling/geometries/path2.appendPoints
|
|
10
|
+
* @example
|
|
11
|
+
* let newpath = appendPoints([[3, 4], [4, 5]], oldpath)
|
|
12
|
+
*/
|
|
13
|
+
const appendPoints = (points, geometry) => concat(geometry, create(points))
|
|
14
|
+
|
|
15
|
+
module.exports = appendPoints
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
|
|
3
|
+
const { appendPoints, fromPoints, toPoints } = require('./index')
|
|
4
|
+
|
|
5
|
+
test('appendPoints: appending to an empty path produces a new path with expected points', (t) => {
|
|
6
|
+
const p1 = fromPoints({}, [])
|
|
7
|
+
const obs = appendPoints([[1, 1]], p1)
|
|
8
|
+
const pts = toPoints(obs)
|
|
9
|
+
t.not(p1, obs)
|
|
10
|
+
t.is(pts.length, 1)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('appendPoints: appending to a path produces a new path with expected points', (t) => {
|
|
14
|
+
const p1 = fromPoints({}, [[1, 1], [2, 2]])
|
|
15
|
+
const obs = appendPoints([[3, 3], [4, 4]], p1)
|
|
16
|
+
const pts = toPoints(obs)
|
|
17
|
+
t.not(p1, obs)
|
|
18
|
+
t.is(pts.length, 4)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test('appendPoints: appending empty points to a path produces a new path with expected points', (t) => {
|
|
22
|
+
const p1 = fromPoints({}, [[1, 1], [2, 2]])
|
|
23
|
+
const obs = appendPoints([], p1)
|
|
24
|
+
const pts = toPoints(obs)
|
|
25
|
+
t.not(p1, obs)
|
|
26
|
+
t.is(pts.length, 2)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('appendPoints: appending same points to a path produces a new path with expected points', (t) => {
|
|
30
|
+
const p1 = fromPoints({}, [[1, 1], [2, 2]])
|
|
31
|
+
const obs = appendPoints([[2, 2], [3, 3]], p1)
|
|
32
|
+
const pts = toPoints(obs)
|
|
33
|
+
t.not(p1, obs)
|
|
34
|
+
t.is(pts.length, 3)
|
|
35
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const mat4 = require('../../maths/mat4')
|
|
2
|
+
const vec2 = require('../../maths/vec2')
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Apply the transforms of the given geometry.
|
|
6
|
+
* NOTE: This function must be called BEFORE exposing any data. See toPoints.
|
|
7
|
+
* @param {path} geometry - the geometry to transform
|
|
8
|
+
* @returns {path} the given geometry
|
|
9
|
+
* @example
|
|
10
|
+
* geometry = applyTransforms(geometry)
|
|
11
|
+
*/
|
|
12
|
+
const applyTransforms = (geometry) => {
|
|
13
|
+
if (mat4.isIdentity(geometry.transforms)) return geometry
|
|
14
|
+
|
|
15
|
+
geometry.points = geometry.points.map((point) => vec2.transform(vec2.create(), point, geometry.transforms))
|
|
16
|
+
geometry.transforms = mat4.create()
|
|
17
|
+
return geometry
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = applyTransforms
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
|
|
3
|
+
const { fromPoints } = require('./index')
|
|
4
|
+
|
|
5
|
+
const applyTransforms = require('./applyTransforms')
|
|
6
|
+
|
|
7
|
+
const { comparePoints, compareVectors } = require('../../../test/helpers/')
|
|
8
|
+
|
|
9
|
+
test('applyTransforms: Updates a populated path with transformed points', (t) => {
|
|
10
|
+
const points = [[0, 0], [1, 0], [0, 1]]
|
|
11
|
+
const expected = {
|
|
12
|
+
points: [[0, 0], [1, 0], [0, 1]],
|
|
13
|
+
isClosed: false,
|
|
14
|
+
transforms: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
|
|
15
|
+
}
|
|
16
|
+
const geometry = fromPoints({}, points)
|
|
17
|
+
const updated = applyTransforms(geometry)
|
|
18
|
+
t.is(geometry, updated)
|
|
19
|
+
t.true(comparePoints(updated.points, expected.points))
|
|
20
|
+
t.false(updated.isClosed)
|
|
21
|
+
t.true(compareVectors(updated.transforms, expected.transforms))
|
|
22
|
+
|
|
23
|
+
const updated2 = applyTransforms(updated)
|
|
24
|
+
t.is(updated, updated2)
|
|
25
|
+
t.true(comparePoints(updated2.points, expected.points))
|
|
26
|
+
t.false(updated2.isClosed)
|
|
27
|
+
t.true(compareVectors(updated2.transforms, expected.transforms))
|
|
28
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performs a shallow clone of the give geometry.
|
|
3
|
+
* @param {path2} geometry - the geometry to clone
|
|
4
|
+
* @returns {path2} a new path
|
|
5
|
+
* @alias module:modeling/geometries/path2.clone
|
|
6
|
+
*/
|
|
7
|
+
const clone = (geometry) => Object.assign({}, geometry)
|
|
8
|
+
|
|
9
|
+
module.exports = clone
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const { EPS } = require('../../maths/constants')
|
|
2
|
+
|
|
3
|
+
const vec2 = require('../../maths/vec2')
|
|
4
|
+
|
|
5
|
+
const clone = require('./clone')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Close the given geometry.
|
|
9
|
+
* @param {path2} geometry - the path to close
|
|
10
|
+
* @returns {path2} a new path
|
|
11
|
+
* @alias module:modeling/geometries/path2.close
|
|
12
|
+
*/
|
|
13
|
+
const close = (geometry) => {
|
|
14
|
+
if (geometry.isClosed) return geometry
|
|
15
|
+
|
|
16
|
+
const cloned = clone(geometry)
|
|
17
|
+
cloned.isClosed = true
|
|
18
|
+
|
|
19
|
+
if (cloned.points.length > 1) {
|
|
20
|
+
// make sure the paths are formed properly
|
|
21
|
+
const points = cloned.points
|
|
22
|
+
const p0 = points[0]
|
|
23
|
+
let pn = points[points.length - 1]
|
|
24
|
+
while (vec2.distance(p0, pn) < (EPS * EPS)) {
|
|
25
|
+
points.pop()
|
|
26
|
+
if (points.length === 1) break
|
|
27
|
+
pn = points[points.length - 1]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return cloned
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = close
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
|
|
3
|
+
const { close, create, fromPoints } = require('./index')
|
|
4
|
+
|
|
5
|
+
test('close: closes an empty path', (t) => {
|
|
6
|
+
const p1 = create()
|
|
7
|
+
t.false(p1.isClosed)
|
|
8
|
+
|
|
9
|
+
const p2 = close(p1)
|
|
10
|
+
t.true(p2.isClosed)
|
|
11
|
+
t.not(p1, p2)
|
|
12
|
+
|
|
13
|
+
const p3 = close(p2)
|
|
14
|
+
t.true(p3.isClosed)
|
|
15
|
+
t.is(p2, p3)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('close: closes various paths', (t) => {
|
|
19
|
+
let p1 = create()
|
|
20
|
+
p1 = close(p1)
|
|
21
|
+
t.true(p1.isClosed)
|
|
22
|
+
t.is(0, p1.points.length)
|
|
23
|
+
|
|
24
|
+
let p2 = fromPoints({ closed: false }, [])
|
|
25
|
+
p2 = close(p2)
|
|
26
|
+
t.true(p2.isClosed)
|
|
27
|
+
t.is(0, p2.points.length)
|
|
28
|
+
|
|
29
|
+
let p3 = fromPoints({ closed: true }, [[0, 0]])
|
|
30
|
+
p3 = close(p3)
|
|
31
|
+
t.true(p3.isClosed)
|
|
32
|
+
t.is(1, p3.points.length)
|
|
33
|
+
|
|
34
|
+
let p4 = fromPoints({ closed: true }, [[0, 0], [0, 0]])
|
|
35
|
+
p4 = close(p4)
|
|
36
|
+
t.true(p4.isClosed)
|
|
37
|
+
t.is(1, p4.points.length) // the last point is removed
|
|
38
|
+
|
|
39
|
+
let p5 = fromPoints({ closed: true }, [[0, 0], [1, 1], [0, 0]])
|
|
40
|
+
p5 = close(p5)
|
|
41
|
+
t.true(p5.isClosed)
|
|
42
|
+
t.is(2, p5.points.length) // the last point is removed
|
|
43
|
+
})
|