@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,345 @@
|
|
|
1
|
+
const { EPS } = require('../../maths/constants')
|
|
2
|
+
|
|
3
|
+
const line2 = require('../../maths/line2')
|
|
4
|
+
const vec2 = require('../../maths/vec2')
|
|
5
|
+
const OrthoNormalBasis = require('../../maths/OrthoNormalBasis')
|
|
6
|
+
const interpolateBetween2DPointsForY = require('../../maths/utils/interpolateBetween2DPointsForY')
|
|
7
|
+
|
|
8
|
+
const { insertSorted, fnNumberSort } = require('../../utils')
|
|
9
|
+
|
|
10
|
+
const poly3 = require('../../geometries/poly3')
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Retesselation for a set of COPLANAR polygons.
|
|
14
|
+
* @param {poly3[]} sourcepolygons - list of polygons
|
|
15
|
+
* @returns {poly3[]} new set of polygons
|
|
16
|
+
*/
|
|
17
|
+
const reTesselateCoplanarPolygons = (sourcepolygons) => {
|
|
18
|
+
if (sourcepolygons.length < 2) return sourcepolygons
|
|
19
|
+
|
|
20
|
+
const destpolygons = []
|
|
21
|
+
const numpolygons = sourcepolygons.length
|
|
22
|
+
const plane = poly3.plane(sourcepolygons[0])
|
|
23
|
+
const orthobasis = new OrthoNormalBasis(plane)
|
|
24
|
+
const polygonvertices2d = [] // array of array of Vector2D
|
|
25
|
+
const polygontopvertexindexes = [] // array of indexes of topmost vertex per polygon
|
|
26
|
+
const topy2polygonindexes = new Map()
|
|
27
|
+
const ycoordinatetopolygonindexes = new Map()
|
|
28
|
+
|
|
29
|
+
// convert all polygon vertices to 2D
|
|
30
|
+
// Make a list of all encountered y coordinates
|
|
31
|
+
// And build a map of all polygons that have a vertex at a certain y coordinate:
|
|
32
|
+
const ycoordinatebins = new Map()
|
|
33
|
+
const ycoordinateBinningFactor = 10 / EPS
|
|
34
|
+
for (let polygonindex = 0; polygonindex < numpolygons; polygonindex++) {
|
|
35
|
+
const poly3d = sourcepolygons[polygonindex]
|
|
36
|
+
let vertices2d = []
|
|
37
|
+
let numvertices = poly3d.vertices.length
|
|
38
|
+
let minindex = -1
|
|
39
|
+
if (numvertices > 0) {
|
|
40
|
+
let miny
|
|
41
|
+
let maxy
|
|
42
|
+
for (let i = 0; i < numvertices; i++) {
|
|
43
|
+
let pos2d = orthobasis.to2D(poly3d.vertices[i])
|
|
44
|
+
// perform binning of y coordinates: If we have multiple vertices very
|
|
45
|
+
// close to each other, give them the same y coordinate:
|
|
46
|
+
const ycoordinatebin = Math.floor(pos2d[1] * ycoordinateBinningFactor)
|
|
47
|
+
let newy
|
|
48
|
+
if (ycoordinatebins.has(ycoordinatebin)) {
|
|
49
|
+
newy = ycoordinatebins.get(ycoordinatebin)
|
|
50
|
+
} else if (ycoordinatebins.has(ycoordinatebin + 1)) {
|
|
51
|
+
newy = ycoordinatebins.get(ycoordinatebin + 1)
|
|
52
|
+
} else if (ycoordinatebins.has(ycoordinatebin - 1)) {
|
|
53
|
+
newy = ycoordinatebins.get(ycoordinatebin - 1)
|
|
54
|
+
} else {
|
|
55
|
+
newy = pos2d[1]
|
|
56
|
+
ycoordinatebins.set(ycoordinatebin, pos2d[1])
|
|
57
|
+
}
|
|
58
|
+
pos2d = vec2.fromValues(pos2d[0], newy)
|
|
59
|
+
vertices2d.push(pos2d)
|
|
60
|
+
const y = pos2d[1]
|
|
61
|
+
if ((i === 0) || (y < miny)) {
|
|
62
|
+
miny = y
|
|
63
|
+
minindex = i
|
|
64
|
+
}
|
|
65
|
+
if ((i === 0) || (y > maxy)) {
|
|
66
|
+
maxy = y
|
|
67
|
+
}
|
|
68
|
+
let polygonindexes = ycoordinatetopolygonindexes.get(y)
|
|
69
|
+
if (!polygonindexes) {
|
|
70
|
+
polygonindexes = {} // PERF
|
|
71
|
+
ycoordinatetopolygonindexes.set(y, polygonindexes)
|
|
72
|
+
}
|
|
73
|
+
polygonindexes[polygonindex] = true
|
|
74
|
+
}
|
|
75
|
+
if (miny >= maxy) {
|
|
76
|
+
// degenerate polygon, all vertices have same y coordinate. Just ignore it from now:
|
|
77
|
+
vertices2d = []
|
|
78
|
+
numvertices = 0
|
|
79
|
+
minindex = -1
|
|
80
|
+
} else {
|
|
81
|
+
let polygonindexes = topy2polygonindexes.get(miny)
|
|
82
|
+
if (!polygonindexes) {
|
|
83
|
+
polygonindexes = []
|
|
84
|
+
topy2polygonindexes.set(miny, polygonindexes)
|
|
85
|
+
}
|
|
86
|
+
polygonindexes.push(polygonindex)
|
|
87
|
+
}
|
|
88
|
+
} // if(numvertices > 0)
|
|
89
|
+
// reverse the vertex order:
|
|
90
|
+
vertices2d.reverse()
|
|
91
|
+
minindex = numvertices - minindex - 1
|
|
92
|
+
polygonvertices2d.push(vertices2d)
|
|
93
|
+
polygontopvertexindexes.push(minindex)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const ycoordinates = []
|
|
97
|
+
ycoordinatetopolygonindexes.forEach((polylist, y) => ycoordinates.push(y))
|
|
98
|
+
ycoordinates.sort(fnNumberSort)
|
|
99
|
+
|
|
100
|
+
// Now we will iterate over all y coordinates, from lowest to highest y coordinate
|
|
101
|
+
// activepolygons: source polygons that are 'active', i.e. intersect with our y coordinate
|
|
102
|
+
// Is sorted so the polygons are in left to right order
|
|
103
|
+
// Each element in activepolygons has these properties:
|
|
104
|
+
// polygonindex: the index of the source polygon (i.e. an index into the sourcepolygons
|
|
105
|
+
// and polygonvertices2d arrays)
|
|
106
|
+
// leftvertexindex: the index of the vertex at the left side of the polygon (lowest x)
|
|
107
|
+
// that is at or just above the current y coordinate
|
|
108
|
+
// rightvertexindex: dito at right hand side of polygon
|
|
109
|
+
// topleft, bottomleft: coordinates of the left side of the polygon crossing the current y coordinate
|
|
110
|
+
// topright, bottomright: coordinates of the right hand side of the polygon crossing the current y coordinate
|
|
111
|
+
let activepolygons = []
|
|
112
|
+
let prevoutpolygonrow = []
|
|
113
|
+
for (let yindex = 0; yindex < ycoordinates.length; yindex++) {
|
|
114
|
+
const newoutpolygonrow = []
|
|
115
|
+
const ycoordinate = ycoordinates[yindex]
|
|
116
|
+
|
|
117
|
+
// update activepolygons for this y coordinate:
|
|
118
|
+
// - Remove any polygons that end at this y coordinate
|
|
119
|
+
// - update leftvertexindex and rightvertexindex (which point to the current vertex index
|
|
120
|
+
// at the the left and right side of the polygon
|
|
121
|
+
// Iterate over all polygons that have a corner at this y coordinate:
|
|
122
|
+
const polygonindexeswithcorner = ycoordinatetopolygonindexes.get(ycoordinate)
|
|
123
|
+
for (let activepolygonindex = 0; activepolygonindex < activepolygons.length; ++activepolygonindex) {
|
|
124
|
+
const activepolygon = activepolygons[activepolygonindex]
|
|
125
|
+
const polygonindex = activepolygon.polygonindex
|
|
126
|
+
if (polygonindexeswithcorner[polygonindex]) {
|
|
127
|
+
// this active polygon has a corner at this y coordinate:
|
|
128
|
+
const vertices2d = polygonvertices2d[polygonindex]
|
|
129
|
+
const numvertices = vertices2d.length
|
|
130
|
+
let newleftvertexindex = activepolygon.leftvertexindex
|
|
131
|
+
let newrightvertexindex = activepolygon.rightvertexindex
|
|
132
|
+
// See if we need to increase leftvertexindex or decrease rightvertexindex:
|
|
133
|
+
while (true) {
|
|
134
|
+
let nextleftvertexindex = newleftvertexindex + 1
|
|
135
|
+
if (nextleftvertexindex >= numvertices) nextleftvertexindex = 0
|
|
136
|
+
if (vertices2d[nextleftvertexindex][1] !== ycoordinate) break
|
|
137
|
+
newleftvertexindex = nextleftvertexindex
|
|
138
|
+
}
|
|
139
|
+
let nextrightvertexindex = newrightvertexindex - 1
|
|
140
|
+
if (nextrightvertexindex < 0) nextrightvertexindex = numvertices - 1
|
|
141
|
+
if (vertices2d[nextrightvertexindex][1] === ycoordinate) {
|
|
142
|
+
newrightvertexindex = nextrightvertexindex
|
|
143
|
+
}
|
|
144
|
+
if ((newleftvertexindex !== activepolygon.leftvertexindex) && (newleftvertexindex === newrightvertexindex)) {
|
|
145
|
+
// We have increased leftvertexindex or decreased rightvertexindex, and now they point to the same vertex
|
|
146
|
+
// This means that this is the bottom point of the polygon. We'll remove it:
|
|
147
|
+
activepolygons.splice(activepolygonindex, 1)
|
|
148
|
+
--activepolygonindex
|
|
149
|
+
} else {
|
|
150
|
+
activepolygon.leftvertexindex = newleftvertexindex
|
|
151
|
+
activepolygon.rightvertexindex = newrightvertexindex
|
|
152
|
+
activepolygon.topleft = vertices2d[newleftvertexindex]
|
|
153
|
+
activepolygon.topright = vertices2d[newrightvertexindex]
|
|
154
|
+
let nextleftvertexindex = newleftvertexindex + 1
|
|
155
|
+
if (nextleftvertexindex >= numvertices) nextleftvertexindex = 0
|
|
156
|
+
activepolygon.bottomleft = vertices2d[nextleftvertexindex]
|
|
157
|
+
let nextrightvertexindex = newrightvertexindex - 1
|
|
158
|
+
if (nextrightvertexindex < 0) nextrightvertexindex = numvertices - 1
|
|
159
|
+
activepolygon.bottomright = vertices2d[nextrightvertexindex]
|
|
160
|
+
}
|
|
161
|
+
} // if polygon has corner here
|
|
162
|
+
} // for activepolygonindex
|
|
163
|
+
let nextycoordinate
|
|
164
|
+
if (yindex >= ycoordinates.length - 1) {
|
|
165
|
+
// last row, all polygons must be finished here:
|
|
166
|
+
activepolygons = []
|
|
167
|
+
nextycoordinate = null
|
|
168
|
+
} else { // yindex < ycoordinates.length-1
|
|
169
|
+
nextycoordinate = Number(ycoordinates[yindex + 1])
|
|
170
|
+
const middleycoordinate = 0.5 * (ycoordinate + nextycoordinate)
|
|
171
|
+
// update activepolygons by adding any polygons that start here:
|
|
172
|
+
const startingpolygonindexes = topy2polygonindexes.get(ycoordinate)
|
|
173
|
+
for (const polygonindexKey in startingpolygonindexes) {
|
|
174
|
+
const polygonindex = startingpolygonindexes[polygonindexKey]
|
|
175
|
+
const vertices2d = polygonvertices2d[polygonindex]
|
|
176
|
+
const numvertices = vertices2d.length
|
|
177
|
+
const topvertexindex = polygontopvertexindexes[polygonindex]
|
|
178
|
+
// the top of the polygon may be a horizontal line. In that case topvertexindex can point to any point on this line.
|
|
179
|
+
// Find the left and right topmost vertices which have the current y coordinate:
|
|
180
|
+
let topleftvertexindex = topvertexindex
|
|
181
|
+
while (true) {
|
|
182
|
+
let i = topleftvertexindex + 1
|
|
183
|
+
if (i >= numvertices) i = 0
|
|
184
|
+
if (vertices2d[i][1] !== ycoordinate) break
|
|
185
|
+
if (i === topvertexindex) break // should not happen, but just to prevent endless loops
|
|
186
|
+
topleftvertexindex = i
|
|
187
|
+
}
|
|
188
|
+
let toprightvertexindex = topvertexindex
|
|
189
|
+
while (true) {
|
|
190
|
+
let i = toprightvertexindex - 1
|
|
191
|
+
if (i < 0) i = numvertices - 1
|
|
192
|
+
if (vertices2d[i][1] !== ycoordinate) break
|
|
193
|
+
if (i === topleftvertexindex) break // should not happen, but just to prevent endless loops
|
|
194
|
+
toprightvertexindex = i
|
|
195
|
+
}
|
|
196
|
+
let nextleftvertexindex = topleftvertexindex + 1
|
|
197
|
+
if (nextleftvertexindex >= numvertices) nextleftvertexindex = 0
|
|
198
|
+
let nextrightvertexindex = toprightvertexindex - 1
|
|
199
|
+
if (nextrightvertexindex < 0) nextrightvertexindex = numvertices - 1
|
|
200
|
+
const newactivepolygon = {
|
|
201
|
+
polygonindex: polygonindex,
|
|
202
|
+
leftvertexindex: topleftvertexindex,
|
|
203
|
+
rightvertexindex: toprightvertexindex,
|
|
204
|
+
topleft: vertices2d[topleftvertexindex],
|
|
205
|
+
topright: vertices2d[toprightvertexindex],
|
|
206
|
+
bottomleft: vertices2d[nextleftvertexindex],
|
|
207
|
+
bottomright: vertices2d[nextrightvertexindex]
|
|
208
|
+
}
|
|
209
|
+
insertSorted(activepolygons, newactivepolygon, (el1, el2) => {
|
|
210
|
+
const x1 = interpolateBetween2DPointsForY(el1.topleft, el1.bottomleft, middleycoordinate)
|
|
211
|
+
const x2 = interpolateBetween2DPointsForY(el2.topleft, el2.bottomleft, middleycoordinate)
|
|
212
|
+
if (x1 > x2) return 1
|
|
213
|
+
if (x1 < x2) return -1
|
|
214
|
+
return 0
|
|
215
|
+
})
|
|
216
|
+
} // for(let polygonindex in startingpolygonindexes)
|
|
217
|
+
} // yindex < ycoordinates.length-1
|
|
218
|
+
|
|
219
|
+
// Now activepolygons is up to date
|
|
220
|
+
// Build the output polygons for the next row in newoutpolygonrow:
|
|
221
|
+
for (const activepolygonKey in activepolygons) {
|
|
222
|
+
const activepolygon = activepolygons[activepolygonKey]
|
|
223
|
+
|
|
224
|
+
let x = interpolateBetween2DPointsForY(activepolygon.topleft, activepolygon.bottomleft, ycoordinate)
|
|
225
|
+
const topleft = vec2.fromValues(x, ycoordinate)
|
|
226
|
+
x = interpolateBetween2DPointsForY(activepolygon.topright, activepolygon.bottomright, ycoordinate)
|
|
227
|
+
const topright = vec2.fromValues(x, ycoordinate)
|
|
228
|
+
x = interpolateBetween2DPointsForY(activepolygon.topleft, activepolygon.bottomleft, nextycoordinate)
|
|
229
|
+
const bottomleft = vec2.fromValues(x, nextycoordinate)
|
|
230
|
+
x = interpolateBetween2DPointsForY(activepolygon.topright, activepolygon.bottomright, nextycoordinate)
|
|
231
|
+
const bottomright = vec2.fromValues(x, nextycoordinate)
|
|
232
|
+
const outpolygon = {
|
|
233
|
+
topleft: topleft,
|
|
234
|
+
topright: topright,
|
|
235
|
+
bottomleft: bottomleft,
|
|
236
|
+
bottomright: bottomright,
|
|
237
|
+
leftline: line2.fromPoints(line2.create(), topleft, bottomleft),
|
|
238
|
+
rightline: line2.fromPoints(line2.create(), bottomright, topright)
|
|
239
|
+
}
|
|
240
|
+
if (newoutpolygonrow.length > 0) {
|
|
241
|
+
const prevoutpolygon = newoutpolygonrow[newoutpolygonrow.length - 1]
|
|
242
|
+
const d1 = vec2.distance(outpolygon.topleft, prevoutpolygon.topright)
|
|
243
|
+
const d2 = vec2.distance(outpolygon.bottomleft, prevoutpolygon.bottomright)
|
|
244
|
+
if ((d1 < EPS) && (d2 < EPS)) {
|
|
245
|
+
// we can join this polygon with the one to the left:
|
|
246
|
+
outpolygon.topleft = prevoutpolygon.topleft
|
|
247
|
+
outpolygon.leftline = prevoutpolygon.leftline
|
|
248
|
+
outpolygon.bottomleft = prevoutpolygon.bottomleft
|
|
249
|
+
newoutpolygonrow.splice(newoutpolygonrow.length - 1, 1)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
newoutpolygonrow.push(outpolygon)
|
|
253
|
+
} // for(activepolygon in activepolygons)
|
|
254
|
+
if (yindex > 0) {
|
|
255
|
+
// try to match the new polygons against the previous row:
|
|
256
|
+
const prevcontinuedindexes = new Set()
|
|
257
|
+
const matchedindexes = new Set()
|
|
258
|
+
for (let i = 0; i < newoutpolygonrow.length; i++) {
|
|
259
|
+
const thispolygon = newoutpolygonrow[i]
|
|
260
|
+
for (let ii = 0; ii < prevoutpolygonrow.length; ii++) {
|
|
261
|
+
if (!matchedindexes.has(ii)) { // not already processed?
|
|
262
|
+
// We have a match if the sidelines are equal or if the top coordinates
|
|
263
|
+
// are on the sidelines of the previous polygon
|
|
264
|
+
const prevpolygon = prevoutpolygonrow[ii]
|
|
265
|
+
if (vec2.distance(prevpolygon.bottomleft, thispolygon.topleft) < EPS) {
|
|
266
|
+
if (vec2.distance(prevpolygon.bottomright, thispolygon.topright) < EPS) {
|
|
267
|
+
// Yes, the top of this polygon matches the bottom of the previous:
|
|
268
|
+
matchedindexes.add(ii)
|
|
269
|
+
// Now check if the joined polygon would remain convex:
|
|
270
|
+
const v1 = line2.direction(thispolygon.leftline)
|
|
271
|
+
const v2 = line2.direction(prevpolygon.leftline)
|
|
272
|
+
const d1 = v1[0] - v2[0]
|
|
273
|
+
|
|
274
|
+
const v3 = line2.direction(thispolygon.rightline)
|
|
275
|
+
const v4 = line2.direction(prevpolygon.rightline)
|
|
276
|
+
const d2 = v3[0] - v4[0]
|
|
277
|
+
|
|
278
|
+
const leftlinecontinues = Math.abs(d1) < EPS
|
|
279
|
+
const rightlinecontinues = Math.abs(d2) < EPS
|
|
280
|
+
const leftlineisconvex = leftlinecontinues || (d1 >= 0)
|
|
281
|
+
const rightlineisconvex = rightlinecontinues || (d2 >= 0)
|
|
282
|
+
if (leftlineisconvex && rightlineisconvex) {
|
|
283
|
+
// yes, both sides have convex corners:
|
|
284
|
+
// This polygon will continue the previous polygon
|
|
285
|
+
thispolygon.outpolygon = prevpolygon.outpolygon
|
|
286
|
+
thispolygon.leftlinecontinues = leftlinecontinues
|
|
287
|
+
thispolygon.rightlinecontinues = rightlinecontinues
|
|
288
|
+
prevcontinuedindexes.add(ii)
|
|
289
|
+
}
|
|
290
|
+
break
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
} // if(!prevcontinuedindexes.has(ii))
|
|
294
|
+
} // for ii
|
|
295
|
+
} // for i
|
|
296
|
+
for (let ii = 0; ii < prevoutpolygonrow.length; ii++) {
|
|
297
|
+
if (!prevcontinuedindexes.has(ii)) {
|
|
298
|
+
// polygon ends here
|
|
299
|
+
// Finish the polygon with the last point(s):
|
|
300
|
+
const prevpolygon = prevoutpolygonrow[ii]
|
|
301
|
+
prevpolygon.outpolygon.rightpoints.push(prevpolygon.bottomright)
|
|
302
|
+
if (vec2.distance(prevpolygon.bottomright, prevpolygon.bottomleft) > EPS) {
|
|
303
|
+
// polygon ends with a horizontal line:
|
|
304
|
+
prevpolygon.outpolygon.leftpoints.push(prevpolygon.bottomleft)
|
|
305
|
+
}
|
|
306
|
+
// reverse the left half so we get a counterclockwise circle:
|
|
307
|
+
prevpolygon.outpolygon.leftpoints.reverse()
|
|
308
|
+
const points2d = prevpolygon.outpolygon.rightpoints.concat(prevpolygon.outpolygon.leftpoints)
|
|
309
|
+
const vertices3d = points2d.map((point2d) => orthobasis.to3D(point2d))
|
|
310
|
+
const polygon = poly3.fromPointsAndPlane(vertices3d, plane) // TODO support shared
|
|
311
|
+
|
|
312
|
+
// if we let empty polygon out, next retesselate will crash
|
|
313
|
+
if (polygon.vertices.length) destpolygons.push(polygon)
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
} // if(yindex > 0)
|
|
317
|
+
for (let i = 0; i < newoutpolygonrow.length; i++) {
|
|
318
|
+
const thispolygon = newoutpolygonrow[i]
|
|
319
|
+
if (!thispolygon.outpolygon) {
|
|
320
|
+
// polygon starts here:
|
|
321
|
+
thispolygon.outpolygon = {
|
|
322
|
+
leftpoints: [],
|
|
323
|
+
rightpoints: []
|
|
324
|
+
}
|
|
325
|
+
thispolygon.outpolygon.leftpoints.push(thispolygon.topleft)
|
|
326
|
+
if (vec2.distance(thispolygon.topleft, thispolygon.topright) > EPS) {
|
|
327
|
+
// we have a horizontal line at the top:
|
|
328
|
+
thispolygon.outpolygon.rightpoints.push(thispolygon.topright)
|
|
329
|
+
}
|
|
330
|
+
} else {
|
|
331
|
+
// continuation of a previous row
|
|
332
|
+
if (!thispolygon.leftlinecontinues) {
|
|
333
|
+
thispolygon.outpolygon.leftpoints.push(thispolygon.topleft)
|
|
334
|
+
}
|
|
335
|
+
if (!thispolygon.rightlinecontinues) {
|
|
336
|
+
thispolygon.outpolygon.rightpoints.push(thispolygon.topright)
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
prevoutpolygonrow = newoutpolygonrow
|
|
341
|
+
} // for yindex
|
|
342
|
+
return destpolygons
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
module.exports = reTesselateCoplanarPolygons
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
|
|
3
|
+
const mat4 = require('../../maths/mat4')
|
|
4
|
+
|
|
5
|
+
const { poly3 } = require('../../geometries')
|
|
6
|
+
|
|
7
|
+
const reTesselateCoplanarPolygons = require('./reTesselateCoplanarPolygons')
|
|
8
|
+
|
|
9
|
+
const translatePoly3 = (offsets, polygon) => {
|
|
10
|
+
const matrix = mat4.fromTranslation(mat4.create(), offsets)
|
|
11
|
+
return poly3.transform(matrix, polygon)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const rotatePoly3 = (angles, polygon) => {
|
|
15
|
+
const matrix = mat4.fromTaitBryanRotation(mat4.create(), (angles[0] * 0.017453292519943295), (angles[1] * 0.017453292519943295), (angles[2] * 0.017453292519943295))
|
|
16
|
+
return poly3.transform(matrix, polygon)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
test.only('retessellateCoplanarPolygons: should merge coplanar polygons', (t) => {
|
|
20
|
+
const polyA = poly3.create([[-5, -5, 0], [5, -5, 0], [5, 5, 0], [-5, 5, 0]])
|
|
21
|
+
const polyB = poly3.create([[5, -5, 0], [8, 0, 0], [5, 5, 0]])
|
|
22
|
+
const polyC = poly3.create([[-5, 5, 0], [-8, 0, 0], [-5, -5, 0]])
|
|
23
|
+
const polyD = poly3.create([[-5, 5, 0], [5, 5, 0], [0, 8, 0]])
|
|
24
|
+
const polyE = poly3.create([[5, -5, 0], [-5, -5, 0], [0, -8, 0]])
|
|
25
|
+
|
|
26
|
+
// combine polygons in each direction
|
|
27
|
+
let obs = reTesselateCoplanarPolygons([polyA, polyB])
|
|
28
|
+
t.is(obs.length, 1)
|
|
29
|
+
obs = reTesselateCoplanarPolygons([polyA, polyC])
|
|
30
|
+
t.is(obs.length, 1)
|
|
31
|
+
obs = reTesselateCoplanarPolygons([polyA, polyD])
|
|
32
|
+
t.is(obs.length, 1)
|
|
33
|
+
obs = reTesselateCoplanarPolygons([polyA, polyE])
|
|
34
|
+
t.is(obs.length, 1)
|
|
35
|
+
|
|
36
|
+
// combine several polygons in each direction
|
|
37
|
+
obs = reTesselateCoplanarPolygons([polyB, polyA, polyC])
|
|
38
|
+
t.is(obs.length, 1)
|
|
39
|
+
obs = reTesselateCoplanarPolygons([polyC, polyA, polyB])
|
|
40
|
+
t.is(obs.length, 1)
|
|
41
|
+
|
|
42
|
+
obs = reTesselateCoplanarPolygons([polyD, polyA, polyE])
|
|
43
|
+
t.is(obs.length, 1)
|
|
44
|
+
obs = reTesselateCoplanarPolygons([polyE, polyA, polyD])
|
|
45
|
+
t.is(obs.length, 1)
|
|
46
|
+
|
|
47
|
+
// combine all polygons
|
|
48
|
+
obs = reTesselateCoplanarPolygons([polyA, polyB, polyC, polyD, polyE])
|
|
49
|
+
t.is(obs.length, 1)
|
|
50
|
+
|
|
51
|
+
// now rotate everything and do again
|
|
52
|
+
let polyH = rotatePoly3([-45, -45, -45], polyA)
|
|
53
|
+
let polyI = rotatePoly3([-45, -45, -45], polyB)
|
|
54
|
+
let polyJ = rotatePoly3([-45, -45, -45], polyC)
|
|
55
|
+
let polyK = rotatePoly3([-45, -45, -45], polyD)
|
|
56
|
+
let polyL = rotatePoly3([-45, -45, -45], polyE)
|
|
57
|
+
|
|
58
|
+
obs = reTesselateCoplanarPolygons([polyH, polyI, polyJ, polyK, polyL])
|
|
59
|
+
t.is(obs.length, 1)
|
|
60
|
+
|
|
61
|
+
// now translate everything and do again
|
|
62
|
+
polyH = translatePoly3([-15, -15, -15], polyA)
|
|
63
|
+
polyI = translatePoly3([-15, -15, -15], polyB)
|
|
64
|
+
polyJ = translatePoly3([-15, -15, -15], polyC)
|
|
65
|
+
polyK = translatePoly3([-15, -15, -15], polyD)
|
|
66
|
+
polyL = translatePoly3([-15, -15, -15], polyE)
|
|
67
|
+
|
|
68
|
+
obs = reTesselateCoplanarPolygons([polyH, polyI, polyJ, polyK, polyL])
|
|
69
|
+
t.is(obs.length, 1)
|
|
70
|
+
})
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const geom3 = require('../../geometries/geom3')
|
|
2
|
+
const poly3 = require('../../geometries/poly3')
|
|
3
|
+
const { NEPS } = require('../../maths/constants')
|
|
4
|
+
const reTesselateCoplanarPolygons = require('./reTesselateCoplanarPolygons')
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
After boolean operations all coplanar polygon fragments are joined by a retesselating
|
|
8
|
+
operation. geom3.reTesselate(geom).
|
|
9
|
+
Retesselation is done through a linear sweep over the polygon surface.
|
|
10
|
+
The sweep line passes over the y coordinates of all vertices in the polygon.
|
|
11
|
+
Polygons are split at each sweep line, and the fragments are joined horizontally and vertically into larger polygons
|
|
12
|
+
(making sure that we will end up with convex polygons).
|
|
13
|
+
*/
|
|
14
|
+
const retessellate = (geometry) => {
|
|
15
|
+
if (geometry.isRetesselated) {
|
|
16
|
+
return geometry
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const polygons = geom3.toPolygons(geometry).map((polygon, index) => ({ vertices: polygon.vertices, plane: poly3.plane(polygon), index: index }))
|
|
20
|
+
const classified = classifyPolygons(polygons)
|
|
21
|
+
|
|
22
|
+
const destPolygons = []
|
|
23
|
+
classified.forEach((group) => {
|
|
24
|
+
if (Array.isArray(group)) {
|
|
25
|
+
const reTessellateCoplanarPolygons = reTesselateCoplanarPolygons(group)
|
|
26
|
+
destPolygons.push(...reTessellateCoplanarPolygons)
|
|
27
|
+
} else {
|
|
28
|
+
destPolygons.push(group)
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const result = geom3.create(destPolygons)
|
|
33
|
+
result.isRetesselated = true
|
|
34
|
+
|
|
35
|
+
return result
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const classifyPolygons = (polygons) => {
|
|
39
|
+
let clusters = [polygons] // a cluster is an array of potentially coplanar polygons
|
|
40
|
+
const nonCoplanar = [] // polygons that are known to be non-coplanar
|
|
41
|
+
// go through each component of the plane starting with the last one (the distance from origin)
|
|
42
|
+
for (let component = 3; component >= 0; component--) {
|
|
43
|
+
const maybeCoplanar = []
|
|
44
|
+
const tolerance = component === 3 ? 0.000000015 : NEPS
|
|
45
|
+
clusters.forEach((cluster) => {
|
|
46
|
+
// sort the cluster by the current component
|
|
47
|
+
cluster.sort(byPlaneComponent(component, tolerance))
|
|
48
|
+
// iterate through the cluster and check if there are polygons which are not coplanar with the others
|
|
49
|
+
// or if there are sub-clusters of coplanar polygons
|
|
50
|
+
let startIndex = 0
|
|
51
|
+
for (let i = 1; i < cluster.length; i++) {
|
|
52
|
+
// if there's a difference larger than the tolerance, split the cluster
|
|
53
|
+
if (cluster[i].plane[component] - cluster[startIndex].plane[component] > tolerance) {
|
|
54
|
+
// if there's a single polygon it's definitely not coplanar with any others
|
|
55
|
+
if (i - startIndex === 1) {
|
|
56
|
+
nonCoplanar.push(cluster[startIndex])
|
|
57
|
+
} else { // we have a new sub cluster of potentially coplanar polygons
|
|
58
|
+
maybeCoplanar.push(cluster.slice(startIndex, i))
|
|
59
|
+
}
|
|
60
|
+
startIndex = i
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// handle the last elements of the cluster
|
|
64
|
+
if (cluster.length - startIndex === 1) {
|
|
65
|
+
nonCoplanar.push(cluster[startIndex])
|
|
66
|
+
} else {
|
|
67
|
+
maybeCoplanar.push(cluster.slice(startIndex))
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
// replace previous clusters with the new ones
|
|
71
|
+
clusters = maybeCoplanar
|
|
72
|
+
}
|
|
73
|
+
// restore the original order of the polygons
|
|
74
|
+
const result = []
|
|
75
|
+
// polygons inside the cluster should already be sorted by index
|
|
76
|
+
clusters.forEach((cluster) => {
|
|
77
|
+
if (cluster[0]) result[cluster[0].index] = cluster
|
|
78
|
+
})
|
|
79
|
+
nonCoplanar.forEach((polygon) => { result[polygon.index] = polygon })
|
|
80
|
+
|
|
81
|
+
return result
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const byPlaneComponent = (component, tolerance) => (a, b) => {
|
|
85
|
+
if (a.plane[component] - b.plane[component] > tolerance) {
|
|
86
|
+
return 1
|
|
87
|
+
} else if (b.plane[component] - a.plane[component] > tolerance) {
|
|
88
|
+
return -1
|
|
89
|
+
}
|
|
90
|
+
return 0
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
module.exports = retessellate
|