@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,81 @@
|
|
|
1
|
+
const geom2 = require('../geometries/geom2')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Construct a polygon in two dimensional space from a list of points, or a list of points and paths.
|
|
5
|
+
*
|
|
6
|
+
* NOTE: The ordering of points is important, and must define a counter clockwise rotation of points.
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} options - options for construction
|
|
9
|
+
* @param {Array} options.points - points of the polygon : either flat or nested array of 2D points
|
|
10
|
+
* @param {Array} [options.paths] - paths of the polygon : either flat or nested array of point indexes
|
|
11
|
+
* @param {String} [options.orientation='counterclockwise'] - orientation of points
|
|
12
|
+
* @returns {geom2} new 2D geometry
|
|
13
|
+
* @alias module:modeling/primitives.polygon
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* let roof = [[10,11], [0,11], [5,20]]
|
|
17
|
+
* let wall = [[0,0], [10,0], [10,10], [0,10]]
|
|
18
|
+
*
|
|
19
|
+
* let poly = polygon({ points: roof })
|
|
20
|
+
* or
|
|
21
|
+
* let poly = polygon({ points: [roof, wall] })
|
|
22
|
+
* or
|
|
23
|
+
* let poly = polygon({ points: roof, paths: [0, 1, 2] })
|
|
24
|
+
* or
|
|
25
|
+
* let poly = polygon({ points: [roof, wall], paths: [[0, 1, 2], [3, 4, 5, 6]] })
|
|
26
|
+
*/
|
|
27
|
+
const polygon = (options) => {
|
|
28
|
+
const defaults = {
|
|
29
|
+
points: [],
|
|
30
|
+
paths: [],
|
|
31
|
+
orientation: 'counterclockwise'
|
|
32
|
+
}
|
|
33
|
+
const { points, paths, orientation } = Object.assign({}, defaults, options)
|
|
34
|
+
|
|
35
|
+
if (!(Array.isArray(points) && Array.isArray(paths))) throw new Error('points and paths must be arrays')
|
|
36
|
+
|
|
37
|
+
let listofpolys = points
|
|
38
|
+
if (Array.isArray(points[0])) {
|
|
39
|
+
if (!Array.isArray(points[0][0])) {
|
|
40
|
+
// points is an array of something... convert to list
|
|
41
|
+
listofpolys = [points]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
listofpolys.forEach((list, i) => {
|
|
46
|
+
if (!Array.isArray(list)) throw new Error('list of points ' + i + ' must be an array')
|
|
47
|
+
if (list.length < 3) throw new Error('list of points ' + i + ' must contain three or more points')
|
|
48
|
+
list.forEach((point, j) => {
|
|
49
|
+
if (!Array.isArray(point)) throw new Error('list of points ' + i + ', point ' + j + ' must be an array')
|
|
50
|
+
if (point.length < 2) throw new Error('list of points ' + i + ', point ' + j + ' must contain by X and Y values')
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
let listofpaths = paths
|
|
55
|
+
if (paths.length === 0) {
|
|
56
|
+
// create a list of paths based on the points
|
|
57
|
+
let count = 0
|
|
58
|
+
listofpaths = listofpolys.map((list) => list.map((point) => count++))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// flatten the listofpoints for indexed access
|
|
62
|
+
const allpoints = []
|
|
63
|
+
listofpolys.forEach((list) => list.forEach((point) => allpoints.push(point)))
|
|
64
|
+
|
|
65
|
+
// convert the list of paths into a list of sides, and accumulate
|
|
66
|
+
let sides = []
|
|
67
|
+
listofpaths.forEach((path) => {
|
|
68
|
+
const setofpoints = path.map((index) => allpoints[index])
|
|
69
|
+
const geometry = geom2.fromPoints(setofpoints)
|
|
70
|
+
sides = sides.concat(geom2.toSides(geometry))
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
// convert the list of sides into a geometry
|
|
74
|
+
let geometry = geom2.create(sides)
|
|
75
|
+
if (orientation === 'clockwise') {
|
|
76
|
+
geometry = geom2.reverse(geometry)
|
|
77
|
+
}
|
|
78
|
+
return geometry
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = polygon
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
|
|
3
|
+
const geom2 = require('../geometries/geom2')
|
|
4
|
+
const measureArea = require('../measurements/measureArea')
|
|
5
|
+
|
|
6
|
+
const { polygon } = require('./index')
|
|
7
|
+
|
|
8
|
+
const comparePoints = require('../../test/helpers/comparePoints')
|
|
9
|
+
|
|
10
|
+
test('polygon: providing only object.points creates expected geometry', (t) => {
|
|
11
|
+
let geometry = polygon({ points: [[0, 0], [100, 0], [130, 50], [30, 50]] })
|
|
12
|
+
|
|
13
|
+
let obs = geom2.toPoints(geometry)
|
|
14
|
+
let exp = [[0, 0], [100, 0], [130, 50], [30, 50]]
|
|
15
|
+
|
|
16
|
+
t.notThrows(() => geom2.validate(geometry))
|
|
17
|
+
t.true(comparePoints(obs, exp))
|
|
18
|
+
|
|
19
|
+
geometry = polygon({ points: [[[0, 0], [100, 0], [0, 100]], [[10, 10], [80, 10], [10, 80]]] })
|
|
20
|
+
|
|
21
|
+
obs = geom2.toPoints(geometry)
|
|
22
|
+
exp = [[0, 0], [100, 0], [10, 80], [10, 10], [80, 10], [0, 100]]
|
|
23
|
+
|
|
24
|
+
t.notThrows(() => geom2.validate(geometry))
|
|
25
|
+
t.true(comparePoints(obs, exp))
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('polygon: providing object.points (array) and object.path (array) creates expected geometry', (t) => {
|
|
29
|
+
let geometry = polygon({ points: [[0, 0], [100, 0], [130, 50], [30, 50]], paths: [[3, 2, 1, 0]] })
|
|
30
|
+
|
|
31
|
+
let obs = geom2.toPoints(geometry)
|
|
32
|
+
let exp = [[30, 50], [130, 50], [100, 0], [0, 0]]
|
|
33
|
+
|
|
34
|
+
t.notThrows(() => geom2.validate(geometry))
|
|
35
|
+
t.true(comparePoints(obs, exp))
|
|
36
|
+
|
|
37
|
+
// multiple paths
|
|
38
|
+
geometry = polygon({ points: [[0, 0], [100, 0], [0, 100], [10, 10], [80, 10], [10, 80]], paths: [[0, 1, 2], [3, 4, 5]] })
|
|
39
|
+
|
|
40
|
+
obs = geom2.toPoints(geometry)
|
|
41
|
+
exp = [[0, 0], [100, 0], [10, 80], [10, 10], [80, 10], [0, 100]]
|
|
42
|
+
|
|
43
|
+
t.notThrows(() => geom2.validate(geometry))
|
|
44
|
+
t.true(comparePoints(obs, exp))
|
|
45
|
+
|
|
46
|
+
// multiple points and paths
|
|
47
|
+
geometry = polygon({ points: [[[0, 0], [100, 0], [0, 100]], [[10, 10], [80, 10], [10, 80]]], paths: [[0, 1, 2], [3, 4, 5]] })
|
|
48
|
+
|
|
49
|
+
obs = geom2.toPoints(geometry)
|
|
50
|
+
exp = [[0, 0], [100, 0], [10, 80], [10, 10], [80, 10], [0, 100]]
|
|
51
|
+
|
|
52
|
+
t.notThrows(() => geom2.validate(geometry))
|
|
53
|
+
t.true(comparePoints(obs, exp))
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('polygon: clockwise points', (t) => {
|
|
57
|
+
const poly = polygon({
|
|
58
|
+
points: [[-10, -0], [-10, -10], [-15, -5]],
|
|
59
|
+
orientation: 'clockwise'
|
|
60
|
+
})
|
|
61
|
+
t.is(poly.sides.length, 3)
|
|
62
|
+
t.is(measureArea(poly), 25)
|
|
63
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Vec3 from '../maths/vec3/type'
|
|
2
|
+
import Geom3 from '../geometries/geom3/type'
|
|
3
|
+
import { RGB, RGBA } from '../colors/types'
|
|
4
|
+
|
|
5
|
+
export default polyhedron
|
|
6
|
+
|
|
7
|
+
export interface PolyhedronOptions {
|
|
8
|
+
points: Array<Vec3>
|
|
9
|
+
faces: Array<Array<number>>
|
|
10
|
+
colors?: Array<RGB | RGBA>
|
|
11
|
+
orientation?: 'outward' | 'inward'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare function polyhedron(options: PolyhedronOptions): Geom3
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const geom3 = require('../geometries/geom3')
|
|
2
|
+
const poly3 = require('../geometries/poly3')
|
|
3
|
+
|
|
4
|
+
const { isNumberArray } = require('./commonChecks')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Construct a polyhedron in three dimensional space from the given set of 3D points and faces.
|
|
8
|
+
*
|
|
9
|
+
* The faces can define outward or inward facing polygons (orientation).
|
|
10
|
+
* However, each face must define a counter clockwise rotation of points which follows the right hand rule.
|
|
11
|
+
* @param {Object} options - options for construction
|
|
12
|
+
* @param {Array} options.points - list of points in 3D space
|
|
13
|
+
* @param {Array} options.faces - list of faces, where each face is a set of indexes into the points
|
|
14
|
+
* @param {Array} [options.colors=undefined] - list of RGBA colors to apply to each face
|
|
15
|
+
* @param {String} [options.orientation='outward'] - orientation of faces
|
|
16
|
+
* @returns {geom3} new 3D geometry
|
|
17
|
+
* @alias module:modeling/primitives.polyhedron
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* let mypoints = [ [10, 10, 0], [10, -10, 0], [-10, -10, 0], [-10, 10, 0], [0, 0, 10] ]
|
|
21
|
+
* let myfaces = [ [0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4], [1, 0, 3], [2, 1, 3] ]
|
|
22
|
+
* let myshape = polyhedron({points: mypoints, faces: myfaces, orientation: 'inward'})
|
|
23
|
+
*/
|
|
24
|
+
const polyhedron = (options) => {
|
|
25
|
+
const defaults = {
|
|
26
|
+
points: [],
|
|
27
|
+
faces: [],
|
|
28
|
+
colors: undefined,
|
|
29
|
+
orientation: 'outward'
|
|
30
|
+
}
|
|
31
|
+
const { points, faces, colors, orientation } = Object.assign({}, defaults, options)
|
|
32
|
+
|
|
33
|
+
if (!(Array.isArray(points) && Array.isArray(faces))) {
|
|
34
|
+
throw new Error('points and faces must be arrays')
|
|
35
|
+
}
|
|
36
|
+
if (points.length < 3) {
|
|
37
|
+
throw new Error('three or more points are required')
|
|
38
|
+
}
|
|
39
|
+
if (faces.length < 1) {
|
|
40
|
+
throw new Error('one or more faces are required')
|
|
41
|
+
}
|
|
42
|
+
if (colors) {
|
|
43
|
+
if (!Array.isArray(colors)) {
|
|
44
|
+
throw new Error('colors must be an array')
|
|
45
|
+
}
|
|
46
|
+
if (colors.length !== faces.length) {
|
|
47
|
+
throw new Error('faces and colors must have the same length')
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
points.forEach((point, i) => {
|
|
51
|
+
if (!isNumberArray(point, 3)) throw new Error(`point ${i} must be an array of X, Y, Z values`)
|
|
52
|
+
})
|
|
53
|
+
faces.forEach((face, i) => {
|
|
54
|
+
if (face.length < 3) throw new Error(`face ${i} must contain 3 or more indexes`)
|
|
55
|
+
if (!isNumberArray(face, face.length)) throw new Error(`face ${i} must be an array of numbers`)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// invert the faces if orientation is inwards, as all internals expect outwarding facing polygons
|
|
59
|
+
if (orientation !== 'outward') {
|
|
60
|
+
faces.forEach((face) => face.reverse())
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const polygons = faces.map((face, findex) => {
|
|
64
|
+
const polygon = poly3.create(face.map((pindex) => points[pindex]))
|
|
65
|
+
if (colors && colors[findex]) polygon.color = colors[findex]
|
|
66
|
+
return polygon
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
return geom3.create(polygons)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = polyhedron
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
|
|
3
|
+
const { polyhedron } = require('./index')
|
|
4
|
+
|
|
5
|
+
const geom3 = require('../geometries/geom3')
|
|
6
|
+
|
|
7
|
+
const comparePolygonsAsPoints = require('../../test/helpers/comparePolygonsAsPoints')
|
|
8
|
+
|
|
9
|
+
test('polyhedron (points and faces)', (t) => {
|
|
10
|
+
// points and faces form a cube
|
|
11
|
+
let points = [[-1, -1, -1], [-1, -1, 1], [-1, 1, 1], [-1, 1, -1], [1, -1, 1], [1, -1, -1], [1, 1, -1], [1, 1, 1]]
|
|
12
|
+
let faces = [[0, 1, 2, 3], [5, 6, 7, 4], [0, 5, 4, 1], [3, 2, 7, 6], [0, 3, 6, 5], [1, 4, 7, 2]]
|
|
13
|
+
const colors = [[0, 0, 0, 1], [1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1], [0.5, 0.5, 0.5, 1], [1, 1, 1, 1]]
|
|
14
|
+
let obs = polyhedron({ points, faces, colors })
|
|
15
|
+
let pts = geom3.toPoints(obs)
|
|
16
|
+
let exp = [
|
|
17
|
+
[[-1, -1, -1], [-1, -1, 1], [-1, 1, 1], [-1, 1, -1]],
|
|
18
|
+
[[1, -1, -1], [1, 1, -1], [1, 1, 1], [1, -1, 1]],
|
|
19
|
+
[[-1, -1, -1], [1, -1, -1], [1, -1, 1], [-1, -1, 1]],
|
|
20
|
+
[[-1, 1, -1], [-1, 1, 1], [1, 1, 1], [1, 1, -1]],
|
|
21
|
+
[[-1, -1, -1], [-1, 1, -1], [1, 1, -1], [1, -1, -1]],
|
|
22
|
+
[[-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]]
|
|
23
|
+
]
|
|
24
|
+
t.notThrows(() => geom3.validate(obs))
|
|
25
|
+
t.deepEqual(pts.length, 6)
|
|
26
|
+
t.true(comparePolygonsAsPoints(pts, exp))
|
|
27
|
+
|
|
28
|
+
// test orientation
|
|
29
|
+
points = [[10, 10, 0], [10, -10, 0], [-10, -10, 0], [-10, 10, 0], [0, 0, 10]]
|
|
30
|
+
faces = [[0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4], [1, 0, 3], [2, 1, 3]]
|
|
31
|
+
obs = polyhedron({ points: points, faces: faces, orientation: 'inward' })
|
|
32
|
+
pts = geom3.toPoints(obs)
|
|
33
|
+
exp = [
|
|
34
|
+
[[0, 0, 10], [10, -10, 0], [10, 10, 0]],
|
|
35
|
+
[[0, 0, 10], [-10, -10, 0], [10, -10, 0]],
|
|
36
|
+
[[0, 0, 10], [-10, 10, 0], [-10, -10, 0]],
|
|
37
|
+
[[0, 0, 10], [10, 10, 0], [-10, 10, 0]],
|
|
38
|
+
[[-10, 10, 0], [10, 10, 0], [10, -10, 0]],
|
|
39
|
+
[[-10, 10, 0], [10, -10, 0], [-10, -10, 0]]
|
|
40
|
+
]
|
|
41
|
+
t.notThrows(() => geom3.validate(obs))
|
|
42
|
+
t.deepEqual(pts.length, 6)
|
|
43
|
+
t.true(comparePolygonsAsPoints(pts, exp))
|
|
44
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const vec2 = require('../maths/vec2')
|
|
2
|
+
|
|
3
|
+
const geom2 = require('../geometries/geom2')
|
|
4
|
+
|
|
5
|
+
const { isNumberArray } = require('./commonChecks')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Construct an axis-aligned rectangle in two dimensional space with four sides at right angles.
|
|
9
|
+
* @param {Object} [options] - options for construction
|
|
10
|
+
* @param {Array} [options.center=[0,0]] - center of rectangle
|
|
11
|
+
* @param {Array} [options.size=[2,2]] - dimension of rectangle, width and length
|
|
12
|
+
* @returns {geom2} new 2D geometry
|
|
13
|
+
* @alias module:modeling/primitives.rectangle
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* let myshape = rectangle({size: [10, 20]})
|
|
17
|
+
*/
|
|
18
|
+
const rectangle = (options) => {
|
|
19
|
+
const defaults = {
|
|
20
|
+
center: [0, 0],
|
|
21
|
+
size: [2, 2]
|
|
22
|
+
}
|
|
23
|
+
const { center, size } = Object.assign({}, defaults, options)
|
|
24
|
+
|
|
25
|
+
if (!isNumberArray(center, 2)) throw new Error('center must be an array of X and Y values')
|
|
26
|
+
if (!isNumberArray(size, 2)) throw new Error('size must be an array of X and Y values')
|
|
27
|
+
if (!size.every((n) => n >= 0)) throw new Error('size values must be positive')
|
|
28
|
+
|
|
29
|
+
// if any size is zero return empty geometry
|
|
30
|
+
if (size[0] === 0 || size[1] === 0) return geom2.create()
|
|
31
|
+
|
|
32
|
+
const point = [size[0] / 2, size[1] / 2]
|
|
33
|
+
const pswap = [point[0], -point[1]]
|
|
34
|
+
|
|
35
|
+
const points = [
|
|
36
|
+
vec2.subtract(vec2.create(), center, point),
|
|
37
|
+
vec2.add(vec2.create(), center, pswap),
|
|
38
|
+
vec2.add(vec2.create(), center, point),
|
|
39
|
+
vec2.subtract(vec2.create(), center, pswap)
|
|
40
|
+
]
|
|
41
|
+
return geom2.fromPoints(points)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = rectangle
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
|
|
3
|
+
const { rectangle } = require('./index')
|
|
4
|
+
|
|
5
|
+
const geom2 = require('../geometries/geom2')
|
|
6
|
+
|
|
7
|
+
const comparePoints = require('../../test/helpers/comparePoints')
|
|
8
|
+
|
|
9
|
+
test('rectangle (defaults)', (t) => {
|
|
10
|
+
const geometry = rectangle()
|
|
11
|
+
const obs = geom2.toPoints(geometry)
|
|
12
|
+
const exp = [
|
|
13
|
+
[-1, -1],
|
|
14
|
+
[1, -1],
|
|
15
|
+
[1, 1],
|
|
16
|
+
[-1, 1]
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
t.notThrows(() => geom2.validate(geometry))
|
|
20
|
+
t.deepEqual(obs.length, 4)
|
|
21
|
+
t.true(comparePoints(obs, exp))
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('rectangle (options)', (t) => {
|
|
25
|
+
// test center
|
|
26
|
+
let geometry = rectangle({ center: [-4, -4] })
|
|
27
|
+
let obs = geom2.toPoints(geometry)
|
|
28
|
+
let exp = [
|
|
29
|
+
[-5, -5],
|
|
30
|
+
[-3, -5],
|
|
31
|
+
[-3, -3],
|
|
32
|
+
[-5, -3]
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
t.notThrows(() => geom2.validate(geometry))
|
|
36
|
+
t.deepEqual(obs.length, 4)
|
|
37
|
+
t.true(comparePoints(obs, exp))
|
|
38
|
+
|
|
39
|
+
// test size
|
|
40
|
+
geometry = rectangle({ size: [6, 10] })
|
|
41
|
+
obs = geom2.toPoints(geometry)
|
|
42
|
+
exp = [
|
|
43
|
+
[-3, -5],
|
|
44
|
+
[3, -5],
|
|
45
|
+
[3, 5],
|
|
46
|
+
[-3, 5]
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
t.notThrows(() => geom2.validate(geometry))
|
|
50
|
+
t.deepEqual(obs.length, 4)
|
|
51
|
+
t.true(comparePoints(obs, exp))
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('rectangle (zero size)', (t) => {
|
|
55
|
+
const geometry = rectangle({ size: [1, 0] })
|
|
56
|
+
const obs = geom2.toPoints(geometry)
|
|
57
|
+
t.notThrows(() => geom2.validate(geometry))
|
|
58
|
+
t.is(obs.length, 0)
|
|
59
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Vec3 from '../maths/vec3/type'
|
|
2
|
+
import Geom3 from '../geometries/geom3/type'
|
|
3
|
+
|
|
4
|
+
export default roundedCuboid
|
|
5
|
+
|
|
6
|
+
export interface RoundedCuboidOptions {
|
|
7
|
+
center?: Vec3
|
|
8
|
+
size?: Vec3
|
|
9
|
+
roundRadius?: number
|
|
10
|
+
segments?: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare function roundedCuboid(options?: RoundedCuboidOptions): Geom3
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
const { EPS, TAU } = require('../maths/constants')
|
|
2
|
+
|
|
3
|
+
const vec2 = require('../maths/vec2')
|
|
4
|
+
const vec3 = require('../maths/vec3')
|
|
5
|
+
|
|
6
|
+
const geom3 = require('../geometries/geom3')
|
|
7
|
+
const poly3 = require('../geometries/poly3')
|
|
8
|
+
|
|
9
|
+
const { sin, cos } = require('../maths/utils/trigonometry')
|
|
10
|
+
|
|
11
|
+
const { isGTE, isNumberArray } = require('./commonChecks')
|
|
12
|
+
const cuboid = require('./cuboid')
|
|
13
|
+
|
|
14
|
+
const createCorners = (center, size, radius, segments, slice, positive) => {
|
|
15
|
+
const pitch = (TAU / 4) * slice / segments
|
|
16
|
+
const cospitch = cos(pitch)
|
|
17
|
+
const sinpitch = sin(pitch)
|
|
18
|
+
|
|
19
|
+
const layersegments = segments - slice
|
|
20
|
+
let layerradius = radius * cospitch
|
|
21
|
+
let layeroffset = size[2] - (radius - (radius * sinpitch))
|
|
22
|
+
if (!positive) layeroffset = (radius - (radius * sinpitch)) - size[2]
|
|
23
|
+
|
|
24
|
+
layerradius = layerradius > EPS ? layerradius : 0
|
|
25
|
+
|
|
26
|
+
const corner0 = vec3.add(vec3.create(), center, [size[0] - radius, size[1] - radius, layeroffset])
|
|
27
|
+
const corner1 = vec3.add(vec3.create(), center, [radius - size[0], size[1] - radius, layeroffset])
|
|
28
|
+
const corner2 = vec3.add(vec3.create(), center, [radius - size[0], radius - size[1], layeroffset])
|
|
29
|
+
const corner3 = vec3.add(vec3.create(), center, [size[0] - radius, radius - size[1], layeroffset])
|
|
30
|
+
const corner0Points = []
|
|
31
|
+
const corner1Points = []
|
|
32
|
+
const corner2Points = []
|
|
33
|
+
const corner3Points = []
|
|
34
|
+
for (let i = 0; i <= layersegments; i++) {
|
|
35
|
+
const radians = layersegments > 0 ? TAU / 4 * i / layersegments : 0
|
|
36
|
+
const point2d = vec2.fromAngleRadians(vec2.create(), radians)
|
|
37
|
+
vec2.scale(point2d, point2d, layerradius)
|
|
38
|
+
const point3d = vec3.fromVec2(vec3.create(), point2d)
|
|
39
|
+
corner0Points.push(vec3.add(vec3.create(), corner0, point3d))
|
|
40
|
+
vec3.rotateZ(point3d, point3d, [0, 0, 0], TAU / 4)
|
|
41
|
+
corner1Points.push(vec3.add(vec3.create(), corner1, point3d))
|
|
42
|
+
vec3.rotateZ(point3d, point3d, [0, 0, 0], TAU / 4)
|
|
43
|
+
corner2Points.push(vec3.add(vec3.create(), corner2, point3d))
|
|
44
|
+
vec3.rotateZ(point3d, point3d, [0, 0, 0], TAU / 4)
|
|
45
|
+
corner3Points.push(vec3.add(vec3.create(), corner3, point3d))
|
|
46
|
+
}
|
|
47
|
+
if (!positive) {
|
|
48
|
+
corner0Points.reverse()
|
|
49
|
+
corner1Points.reverse()
|
|
50
|
+
corner2Points.reverse()
|
|
51
|
+
corner3Points.reverse()
|
|
52
|
+
return [corner3Points, corner2Points, corner1Points, corner0Points]
|
|
53
|
+
}
|
|
54
|
+
return [corner0Points, corner1Points, corner2Points, corner3Points]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const stitchCorners = (previousCorners, currentCorners) => {
|
|
58
|
+
const polygons = []
|
|
59
|
+
for (let i = 0; i < previousCorners.length; i++) {
|
|
60
|
+
const previous = previousCorners[i]
|
|
61
|
+
const current = currentCorners[i]
|
|
62
|
+
for (let j = 0; j < (previous.length - 1); j++) {
|
|
63
|
+
polygons.push(poly3.create([previous[j], previous[j + 1], current[j]]))
|
|
64
|
+
|
|
65
|
+
if (j < (current.length - 1)) {
|
|
66
|
+
polygons.push(poly3.create([current[j], previous[j + 1], current[j + 1]]))
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return polygons
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const stitchWalls = (previousCorners, currentCorners) => {
|
|
74
|
+
const polygons = []
|
|
75
|
+
for (let i = 0; i < previousCorners.length; i++) {
|
|
76
|
+
let previous = previousCorners[i]
|
|
77
|
+
let current = currentCorners[i]
|
|
78
|
+
const p0 = previous[previous.length - 1]
|
|
79
|
+
const c0 = current[current.length - 1]
|
|
80
|
+
|
|
81
|
+
const j = (i + 1) % previousCorners.length
|
|
82
|
+
previous = previousCorners[j]
|
|
83
|
+
current = currentCorners[j]
|
|
84
|
+
const p1 = previous[0]
|
|
85
|
+
const c1 = current[0]
|
|
86
|
+
|
|
87
|
+
polygons.push(poly3.create([p0, p1, c1, c0]))
|
|
88
|
+
}
|
|
89
|
+
return polygons
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const stitchSides = (bottomCorners, topCorners) => {
|
|
93
|
+
// make a copy and reverse the bottom corners
|
|
94
|
+
bottomCorners = [bottomCorners[3], bottomCorners[2], bottomCorners[1], bottomCorners[0]]
|
|
95
|
+
bottomCorners = bottomCorners.map((corner) => corner.slice().reverse())
|
|
96
|
+
|
|
97
|
+
const bottomPoints = []
|
|
98
|
+
bottomCorners.forEach((corner) => {
|
|
99
|
+
corner.forEach((point) => bottomPoints.push(point))
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const topPoints = []
|
|
103
|
+
topCorners.forEach((corner) => {
|
|
104
|
+
corner.forEach((point) => topPoints.push(point))
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const polygons = []
|
|
108
|
+
for (let i = 0; i < topPoints.length; i++) {
|
|
109
|
+
const j = (i + 1) % topPoints.length
|
|
110
|
+
polygons.push(poly3.create([bottomPoints[i], bottomPoints[j], topPoints[j], topPoints[i]]))
|
|
111
|
+
}
|
|
112
|
+
return polygons
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Construct an axis-aligned solid cuboid in three dimensional space with rounded corners.
|
|
117
|
+
* @param {Object} [options] - options for construction
|
|
118
|
+
* @param {Array} [options.center=[0,0,0]] - center of rounded cube
|
|
119
|
+
* @param {Array} [options.size=[2,2,2]] - dimension of rounded cube; width, depth, height
|
|
120
|
+
* @param {Number} [options.roundRadius=0.2] - radius of rounded edges
|
|
121
|
+
* @param {Number} [options.segments=32] - number of segments to create per full rotation
|
|
122
|
+
* @returns {geom3} new 3D geometry
|
|
123
|
+
* @alias module:modeling/primitives.roundedCuboid
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* let mycube = roundedCuboid({size: [10, 20, 10], roundRadius: 2, segments: 16})
|
|
127
|
+
*/
|
|
128
|
+
const roundedCuboid = (options) => {
|
|
129
|
+
const defaults = {
|
|
130
|
+
center: [0, 0, 0],
|
|
131
|
+
size: [2, 2, 2],
|
|
132
|
+
roundRadius: 0.2,
|
|
133
|
+
segments: 32
|
|
134
|
+
}
|
|
135
|
+
let { center, size, roundRadius, segments } = Object.assign({}, defaults, options)
|
|
136
|
+
|
|
137
|
+
if (!isNumberArray(center, 3)) throw new Error('center must be an array of X, Y and Z values')
|
|
138
|
+
if (!isNumberArray(size, 3)) throw new Error('size must be an array of X, Y and Z values')
|
|
139
|
+
if (!size.every((n) => n >= 0)) throw new Error('size values must be positive')
|
|
140
|
+
if (!isGTE(roundRadius, 0)) throw new Error('roundRadius must be positive')
|
|
141
|
+
if (!isGTE(segments, 4)) throw new Error('segments must be four or more')
|
|
142
|
+
|
|
143
|
+
// if any size is zero return empty geometry
|
|
144
|
+
if (size[0] === 0 || size[1] === 0 || size[2] === 0) return geom3.create()
|
|
145
|
+
|
|
146
|
+
// if roundRadius is zero, return cuboid
|
|
147
|
+
if (roundRadius === 0) return cuboid({ center, size })
|
|
148
|
+
|
|
149
|
+
size = size.map((v) => v / 2) // convert to radius
|
|
150
|
+
|
|
151
|
+
if (roundRadius > (size[0] - EPS) ||
|
|
152
|
+
roundRadius > (size[1] - EPS) ||
|
|
153
|
+
roundRadius > (size[2] - EPS)) throw new Error('roundRadius must be smaller than the radius of all dimensions')
|
|
154
|
+
|
|
155
|
+
segments = Math.floor(segments / 4)
|
|
156
|
+
|
|
157
|
+
let prevCornersPos = null
|
|
158
|
+
let prevCornersNeg = null
|
|
159
|
+
let polygons = []
|
|
160
|
+
for (let slice = 0; slice <= segments; slice++) {
|
|
161
|
+
const cornersPos = createCorners(center, size, roundRadius, segments, slice, true)
|
|
162
|
+
const cornersNeg = createCorners(center, size, roundRadius, segments, slice, false)
|
|
163
|
+
|
|
164
|
+
if (slice === 0) {
|
|
165
|
+
polygons = polygons.concat(stitchSides(cornersNeg, cornersPos))
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (prevCornersPos) {
|
|
169
|
+
polygons = polygons.concat(stitchCorners(prevCornersPos, cornersPos),
|
|
170
|
+
stitchWalls(prevCornersPos, cornersPos))
|
|
171
|
+
}
|
|
172
|
+
if (prevCornersNeg) {
|
|
173
|
+
polygons = polygons.concat(stitchCorners(prevCornersNeg, cornersNeg),
|
|
174
|
+
stitchWalls(prevCornersNeg, cornersNeg))
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (slice === segments) {
|
|
178
|
+
// add the top
|
|
179
|
+
let points = cornersPos.map((corner) => corner[0])
|
|
180
|
+
polygons.push(poly3.create(points))
|
|
181
|
+
// add the bottom
|
|
182
|
+
points = cornersNeg.map((corner) => corner[0])
|
|
183
|
+
polygons.push(poly3.create(points))
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
prevCornersPos = cornersPos
|
|
187
|
+
prevCornersNeg = cornersNeg
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return geom3.create(polygons)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
module.exports = roundedCuboid
|