@jscad/modeling 2.7.2 → 2.9.1
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/CHANGELOG.md +48 -0
- package/dist/jscad-modeling.min.js +443 -398
- package/package.json +2 -2
- package/src/curves/bezier/tangentAt.test.js +1 -1
- package/src/curves/bezier/valueAt.test.js +1 -1
- package/src/geometries/geom2/index.d.ts +1 -0
- package/src/geometries/geom2/index.js +12 -1
- package/src/geometries/geom2/isA.js +2 -2
- package/src/geometries/geom2/toCompactBinary.js +4 -4
- package/src/geometries/geom2/toString.js +1 -1
- package/src/geometries/geom2/transform.test.js +1 -1
- package/src/geometries/geom2/validate.d.ts +3 -0
- package/src/geometries/geom2/validate.js +36 -0
- package/src/geometries/geom3/fromCompactBinary.js +1 -1
- package/src/geometries/geom3/index.d.ts +1 -0
- package/src/geometries/geom3/index.js +19 -1
- package/src/geometries/geom3/isA.js +2 -2
- package/src/geometries/geom3/toCompactBinary.js +4 -4
- package/src/geometries/geom3/toString.js +1 -1
- package/src/geometries/geom3/transform.test.js +1 -1
- package/src/geometries/geom3/validate.d.ts +3 -0
- package/src/geometries/geom3/validate.js +62 -0
- package/src/geometries/index.js +8 -1
- package/src/geometries/path2/eachPoint.js +3 -3
- package/src/geometries/path2/index.d.ts +1 -0
- package/src/geometries/path2/index.js +13 -1
- package/src/geometries/path2/isA.js +2 -2
- package/src/geometries/path2/reverse.js +4 -4
- package/src/geometries/path2/toCompactBinary.js +6 -6
- package/src/geometries/path2/toString.js +1 -1
- package/src/geometries/path2/transform.test.js +1 -1
- package/src/geometries/path2/validate.d.ts +3 -0
- package/src/geometries/path2/validate.js +41 -0
- package/src/geometries/poly2/arePointsInside.js +0 -35
- package/src/geometries/poly2/arePointsInside.test.js +1 -1
- package/src/geometries/poly2/index.js +6 -0
- package/src/geometries/poly3/index.d.ts +1 -0
- package/src/geometries/poly3/index.js +9 -2
- package/src/geometries/poly3/invert.js +7 -1
- package/src/geometries/poly3/isA.js +2 -2
- package/src/geometries/poly3/isConvex.js +2 -2
- package/src/geometries/poly3/measureArea.js +4 -4
- package/src/geometries/poly3/measureArea.test.js +16 -16
- package/src/geometries/poly3/measureBoundingBox.js +2 -2
- package/src/geometries/poly3/measureBoundingSphere.js +2 -2
- package/src/geometries/poly3/measureBoundingSphere.test.js +8 -8
- package/src/geometries/poly3/measureSignedVolume.js +4 -4
- package/src/geometries/poly3/toPoints.js +2 -2
- package/src/geometries/poly3/toString.js +2 -2
- package/src/geometries/poly3/transform.js +2 -2
- package/src/geometries/poly3/validate.d.ts +4 -0
- package/src/geometries/poly3/validate.js +50 -0
- package/src/maths/index.js +1 -1
- package/src/maths/line2/equals.js +2 -2
- package/src/maths/line2/fromValues.js +2 -2
- package/src/maths/line2/intersectPointOfLines.js +1 -1
- package/src/maths/line2/intersectPointOfLines.test.js +1 -1
- package/src/maths/line2/reverse.test.js +1 -1
- package/src/maths/line2/transform.test.js +1 -1
- package/src/maths/line3/equals.js +2 -2
- package/src/maths/line3/reverse.test.js +1 -1
- package/src/maths/line3/transform.test.js +1 -1
- package/src/maths/mat4/fromVectorRotation.js +1 -1
- package/src/maths/mat4/fromVectorRotation.test.js +1 -1
- package/src/maths/mat4/identity.test.js +1 -1
- package/src/maths/mat4/invert.js +18 -18
- package/src/maths/mat4/isIdentity.js +1 -1
- package/src/maths/mat4/isMirroring.js +4 -4
- package/src/maths/mat4/isMirroring.test.js +1 -1
- package/src/maths/mat4/leftMultiplyVec3.js +2 -2
- package/src/maths/mat4/toString.js +2 -2
- package/src/maths/mat4/translate.test.js +1 -1
- package/src/maths/plane/flip.test.js +1 -1
- package/src/maths/plane/fromPoints.d.ts +1 -1
- package/src/maths/plane/fromPoints.js +1 -3
- package/src/maths/plane/signedDistanceToPoint.js +1 -1
- package/src/maths/plane/transform.test.js +1 -1
- package/src/maths/utils/aboutEqualNormals.js +2 -2
- package/src/maths/vec2/abs.d.ts +1 -1
- package/src/maths/vec2/add.test.js +1 -1
- package/src/maths/vec2/angleDegrees.d.ts +1 -1
- package/src/maths/vec2/angleRadians.d.ts +1 -1
- package/src/maths/vec2/create.js +1 -1
- package/src/maths/vec2/cross.test.js +1 -1
- package/src/maths/vec2/divide.test.js +1 -1
- package/src/maths/vec2/fromAngleDegrees.js +1 -1
- package/src/maths/vec2/fromScalar.js +1 -1
- package/src/maths/vec2/length.d.ts +1 -1
- package/src/maths/vec2/length.js +1 -1
- package/src/maths/vec2/lerp.test.js +1 -1
- package/src/maths/vec2/multiply.test.js +1 -1
- package/src/maths/vec2/negate.test.js +1 -1
- package/src/maths/vec2/normal.js +1 -1
- package/src/maths/vec2/normalize.d.ts +1 -1
- package/src/maths/vec2/normalize.test.js +1 -1
- package/src/maths/vec2/rotate.test.js +1 -1
- package/src/maths/vec2/squaredLength.d.ts +1 -1
- package/src/maths/vec2/squaredLength.js +3 -3
- package/src/maths/vec2/subtract.test.js +1 -1
- package/src/maths/vec2/toString.js +1 -1
- package/src/maths/vec2/transform.test.js +1 -1
- package/src/maths/vec3/abs.d.ts +1 -1
- package/src/maths/vec3/add.test.js +1 -1
- package/src/maths/vec3/cross.test.js +1 -1
- package/src/maths/vec3/divide.test.js +1 -1
- package/src/maths/vec3/fromScalar.js +1 -1
- package/src/maths/vec3/fromVec2.d.ts +1 -1
- package/src/maths/vec3/fromVec2.js +3 -3
- package/src/maths/vec3/length.d.ts +1 -1
- package/src/maths/vec3/length.js +4 -4
- package/src/maths/vec3/lerp.test.js +1 -1
- package/src/maths/vec3/multiply.test.js +1 -1
- package/src/maths/vec3/negate.d.ts +1 -1
- package/src/maths/vec3/negate.test.js +1 -1
- package/src/maths/vec3/normalize.d.ts +1 -1
- package/src/maths/vec3/normalize.test.js +1 -1
- package/src/maths/vec3/rotateX.test.js +1 -1
- package/src/maths/vec3/rotateY.test.js +1 -1
- package/src/maths/vec3/rotateZ.test.js +1 -1
- package/src/maths/vec3/scale.test.js +1 -1
- package/src/maths/vec3/squaredLength.d.ts +1 -1
- package/src/maths/vec3/squaredLength.js +4 -4
- package/src/maths/vec3/subtract.test.js +1 -1
- package/src/maths/vec3/toString.js +1 -1
- package/src/maths/vec3/transform.test.js +1 -1
- package/src/maths/vec4/toString.js +1 -1
- package/src/maths/vec4/transform.test.js +1 -1
- package/src/measurements/measureBoundingSphere.js +4 -4
- package/src/measurements/measureCenterOfMass.js +1 -1
- package/src/measurements/measureCenterOfMass.test.js +2 -2
- package/src/operations/booleans/intersect.test.js +8 -0
- package/src/operations/booleans/mayOverlap.js +3 -3
- package/src/operations/booleans/retessellate.js +2 -2
- package/src/operations/booleans/scission.js +1 -1
- package/src/operations/booleans/scission.test.js +4 -4
- package/src/operations/booleans/subtract.js +1 -1
- package/src/operations/booleans/subtract.test.js +8 -0
- package/src/operations/booleans/trees/Node.js +10 -16
- package/src/operations/booleans/trees/PolygonTreeNode.js +13 -14
- package/src/operations/booleans/trees/Tree.js +1 -2
- package/src/operations/booleans/trees/splitPolygonByPlane.js +2 -3
- package/src/operations/booleans/union.test.js +28 -1
- package/src/operations/booleans/unionGeom3Sub.js +1 -1
- package/src/operations/expansions/expand.js +2 -2
- package/src/operations/expansions/expand.test.js +32 -55
- package/src/operations/expansions/expandShell.js +24 -18
- package/src/operations/expansions/offset.js +1 -1
- package/src/operations/expansions/offset.test.js +50 -89
- package/src/operations/expansions/offsetFromPoints.js +11 -6
- 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.js +10 -3
- package/src/operations/extrusions/extrudeFromSlices.test.js +47 -31
- package/src/operations/extrusions/extrudeLinear.js +10 -5
- package/src/operations/extrusions/extrudeLinear.test.js +91 -35
- package/src/operations/extrusions/extrudeLinearGeom2.js +5 -2
- package/src/operations/extrusions/extrudeLinearPath2.js +24 -0
- package/src/operations/extrusions/extrudeRectangular.js +1 -1
- package/src/operations/extrusions/extrudeRectangular.test.js +22 -15
- package/src/operations/extrusions/extrudeRotate.test.js +31 -27
- package/src/operations/extrusions/project.js +1 -1
- package/src/operations/extrusions/project.test.js +5 -5
- package/src/operations/extrusions/slice/calculatePlane.js +7 -4
- package/src/operations/extrusions/slice/isA.js +2 -2
- package/src/operations/extrusions/slice/repairSlice.js +47 -0
- package/src/operations/extrusions/slice/toPolygons.js +24 -60
- package/src/operations/hulls/hull.test.js +25 -2
- package/src/operations/hulls/hullChain.js +1 -1
- package/src/operations/hulls/hullChain.test.js +6 -4
- package/src/operations/hulls/hullGeom2.js +1 -1
- package/src/operations/hulls/hullPath2.js +6 -4
- package/src/operations/hulls/hullPath2.test.js +16 -0
- package/src/operations/hulls/hullPoints2.test.js +1 -1
- package/src/operations/modifiers/edges.js +1 -1
- package/src/operations/modifiers/generalize.js +1 -1
- package/src/operations/modifiers/generalize.test.js +6 -0
- package/src/operations/modifiers/snap.test.js +3 -3
- package/src/operations/transforms/align.d.ts +1 -1
- package/src/operations/transforms/align.test.js +12 -0
- package/src/operations/transforms/center.js +17 -17
- package/src/operations/transforms/center.test.js +12 -0
- package/src/operations/transforms/mirror.js +12 -12
- package/src/operations/transforms/mirror.test.js +16 -0
- package/src/operations/transforms/rotate.js +12 -12
- package/src/operations/transforms/rotate.test.js +10 -0
- package/src/operations/transforms/scale.js +19 -19
- package/src/operations/transforms/scale.test.js +15 -0
- package/src/operations/transforms/transform.js +3 -3
- package/src/operations/transforms/transform.test.js +5 -0
- package/src/operations/transforms/translate.js +14 -14
- package/src/operations/transforms/translate.test.js +16 -0
- package/src/primitives/arc.js +1 -1
- package/src/primitives/arc.test.js +11 -0
- package/src/primitives/circle.test.js +15 -9
- package/src/primitives/cube.test.js +3 -0
- package/src/primitives/cuboid.test.js +9 -24
- package/src/primitives/cylinder.test.js +7 -4
- package/src/primitives/cylinderElliptic.js +13 -6
- package/src/primitives/cylinderElliptic.test.js +72 -52
- package/src/primitives/ellipse.js +3 -1
- package/src/primitives/ellipse.test.js +14 -8
- package/src/primitives/ellipsoid.js +7 -5
- package/src/primitives/ellipsoid.test.js +84 -82
- package/src/primitives/geodesicSphere.d.ts +0 -1
- package/src/primitives/geodesicSphere.test.js +3 -0
- package/src/primitives/line.test.js +1 -0
- package/src/primitives/polygon.test.js +15 -10
- package/src/primitives/polyhedron.js +1 -1
- package/src/primitives/polyhedron.test.js +14 -42
- package/src/primitives/rectangle.test.js +3 -0
- package/src/primitives/roundedCuboid.test.js +5 -0
- package/src/primitives/roundedCylinder.js +6 -4
- package/src/primitives/roundedCylinder.test.js +40 -36
- package/src/primitives/roundedRectangle.test.js +5 -0
- package/src/primitives/sphere.test.js +52 -73
- package/src/primitives/square.test.js +3 -0
- package/src/primitives/star.test.js +6 -0
- package/src/primitives/torus.d.ts +0 -1
- package/src/primitives/torus.test.js +8 -1
- package/src/primitives/triangle.js +1 -1
- package/src/primitives/triangle.test.js +7 -0
- package/src/text/vectorText.js +2 -2
- package/src/utils/areAllShapesTheSameType.js +2 -2
- package/src/utils/areAllShapesTheSameType.test.js +17 -0
- package/src/utils/index.d.ts +1 -0
- package/src/utils/index.js +3 -1
- package/src/utils/padArrayToLength.js +1 -1
- package/src/utils/trigonometry.d.ts +2 -0
- package/src/utils/trigonometry.js +35 -0
- package/src/utils/trigonometry.test.js +25 -0
- package/test/helpers/nearlyEqual.js +4 -1
package/src/maths/vec2/create.js
CHANGED
|
@@ -3,7 +3,7 @@ const { cross } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec2: cross() called with three
|
|
6
|
+
test('vec2: cross() called with three parameters should update a vec2 with correct values', (t) => {
|
|
7
7
|
const obs1 = [0, 0, 0]
|
|
8
8
|
const ret1 = cross(obs1, [0, 0], [0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0, 0]))
|
|
@@ -3,7 +3,7 @@ const { divide, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec2: divide() called with three
|
|
6
|
+
test('vec2: divide() called with three parameters should update a vec2 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0)
|
|
8
8
|
const ret1 = divide(obs1, [0, 0], [0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [0 / 0, 0 / 0]))
|
|
@@ -4,7 +4,7 @@ const fromAngleRadians = require('./fromAngleRadians')
|
|
|
4
4
|
* Create a new vector in the direction of the given angle.
|
|
5
5
|
*
|
|
6
6
|
* @param {vec2} out - receiving vector
|
|
7
|
-
* @param {Number}
|
|
7
|
+
* @param {Number} degrees - angle in degrees
|
|
8
8
|
* @returns {vec2} out
|
|
9
9
|
* @alias module:modeling/maths/vec2.fromAngleDegrees
|
|
10
10
|
*/
|
package/src/maths/vec2/length.js
CHANGED
|
@@ -3,7 +3,7 @@ const { lerp, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec2: lerp() called with three
|
|
6
|
+
test('vec2: lerp() called with three parameters should update a vec2 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0)
|
|
8
8
|
const ret1 = lerp(obs1, [0, 0], [0, 0], 0)
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0]))
|
|
@@ -3,7 +3,7 @@ const { multiply, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec2: multiply() called with three
|
|
6
|
+
test('vec2: multiply() called with three parameters should update a vec2 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0)
|
|
8
8
|
const ret1 = multiply(obs1, [0, 0], [0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0]))
|
|
@@ -3,7 +3,7 @@ const { negate, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec2: negate() called with two
|
|
6
|
+
test('vec2: negate() called with two parameters should update a vec2 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0)
|
|
8
8
|
const ret1 = negate(obs1, [0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0]))
|
package/src/maths/vec2/normal.js
CHANGED
|
@@ -3,7 +3,7 @@ const rotate = require('./rotate')
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Calculates the normal of the given vector.
|
|
6
|
-
* The normal value is the given vector rotated 90
|
|
6
|
+
* The normal value is the given vector rotated 90 degrees.
|
|
7
7
|
*
|
|
8
8
|
* @param {vec2} out - receiving vector
|
|
9
9
|
* @param {vec2} vector - given value
|
|
@@ -3,7 +3,7 @@ const { normalize, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec2: normalize() called with two
|
|
6
|
+
test('vec2: normalize() called with two parameters should update a vec2 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0)
|
|
8
8
|
const ret1 = normalize(obs1, [0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0]))
|
|
@@ -3,7 +3,7 @@ const { rotate, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec2: rotate() called with three
|
|
6
|
+
test('vec2: rotate() called with three parameters should update a vec2 with correct values', (t) => {
|
|
7
7
|
const radians = 90 * Math.PI / 180
|
|
8
8
|
|
|
9
9
|
const obs1 = fromValues(0, 0)
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* @returns {Number} squared length
|
|
6
6
|
* @alias module:modeling/maths/vec2.squaredLength
|
|
7
7
|
*/
|
|
8
|
-
const squaredLength = (
|
|
9
|
-
const x =
|
|
10
|
-
const y =
|
|
8
|
+
const squaredLength = (vector) => {
|
|
9
|
+
const x = vector[0]
|
|
10
|
+
const y = vector[1]
|
|
11
11
|
return x * x + y * y
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -3,7 +3,7 @@ const { subtract, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec2: subtract() called with three
|
|
6
|
+
test('vec2: subtract() called with three parameters should update a vec2 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0)
|
|
8
8
|
const ret1 = subtract(obs1, [0, 0], [0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0]))
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* @returns {String} string representation
|
|
6
6
|
* @alias module:modeling/maths/vec2.toString
|
|
7
7
|
*/
|
|
8
|
-
const toString = (
|
|
8
|
+
const toString = (vector) => `[${vector[0].toFixed(7)}, ${vector[1].toFixed(7)}]`
|
|
9
9
|
|
|
10
10
|
module.exports = toString
|
|
@@ -3,7 +3,7 @@ const { transform, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec2: transform() called with three
|
|
6
|
+
test('vec2: transform() called with three parameters should update a vec2 with correct values', (t) => {
|
|
7
7
|
const identityMatrix = [
|
|
8
8
|
1, 0, 0, 0,
|
|
9
9
|
0, 1, 0, 0,
|
package/src/maths/vec3/abs.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ const { add, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec3: add() called with three
|
|
6
|
+
test('vec3: add() called with three parameters should update a vec3 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0, 0)
|
|
8
8
|
const ret1 = add(obs1, [0, 0, 0], [0, 0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0, 0]))
|
|
@@ -3,7 +3,7 @@ const { cross, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec3: cross() called with three
|
|
6
|
+
test('vec3: cross() called with three parameters should update a vec3 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0, 0)
|
|
8
8
|
const ret1 = cross(obs1, [0, 0, 0], [0, 0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0, 0]))
|
|
@@ -3,7 +3,7 @@ const { divide, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec3: divide() called with three
|
|
6
|
+
test('vec3: divide() called with three parameters should update a vec3 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0, 0)
|
|
8
8
|
const ret1 = divide(obs1, [0, 0, 0], [0, 0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [0 / 0, 0 / 0, 0 / 0]))
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* @returns {vec3} out
|
|
8
8
|
* @alias module:modeling/maths/vec3.fromVec2
|
|
9
9
|
*/
|
|
10
|
-
const fromVector2 = (out,
|
|
11
|
-
out[0] =
|
|
12
|
-
out[1] =
|
|
10
|
+
const fromVector2 = (out, vector, z = 0) => {
|
|
11
|
+
out[0] = vector[0]
|
|
12
|
+
out[1] = vector[1]
|
|
13
13
|
out[2] = z
|
|
14
14
|
return out
|
|
15
15
|
}
|
package/src/maths/vec3/length.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* @returns {Number} length
|
|
6
6
|
* @alias module:modeling/maths/vec3.length
|
|
7
7
|
*/
|
|
8
|
-
const length = (
|
|
9
|
-
const x =
|
|
10
|
-
const y =
|
|
11
|
-
const z =
|
|
8
|
+
const length = (vector) => {
|
|
9
|
+
const x = vector[0]
|
|
10
|
+
const y = vector[1]
|
|
11
|
+
const z = vector[2]
|
|
12
12
|
return Math.hypot(x, y, z)
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -3,7 +3,7 @@ const { lerp, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec3: lerp() called with three
|
|
6
|
+
test('vec3: lerp() called with three parameters should update a vec3 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0, 0)
|
|
8
8
|
const ret1 = lerp(obs1, [0, 0, 0], [0, 0, 0], 0)
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0, 0]))
|
|
@@ -3,7 +3,7 @@ const { multiply, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec3: multiply() called with three
|
|
6
|
+
test('vec3: multiply() called with three parameters should update a vec3 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0, 0)
|
|
8
8
|
const ret1 = multiply(obs1, [0, 0, 0], [0, 0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0, 0]))
|
|
@@ -3,7 +3,7 @@ const { negate, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec3: negate() called with two
|
|
6
|
+
test('vec3: negate() called with two parameters should update a vec3 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0, 0)
|
|
8
8
|
const ret1 = negate(obs1, [0, 0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [-0, -0, -0]))
|
|
@@ -3,7 +3,7 @@ const { normalize, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec3: normalize() called with two
|
|
6
|
+
test('vec3: normalize() called with two parameters should update a vec3 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0, 0)
|
|
8
8
|
const ret1 = normalize(obs1, [0, 0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0, 0]))
|
|
@@ -3,7 +3,7 @@ const { rotateX, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec3: rotateX() called with four
|
|
6
|
+
test('vec3: rotateX() called with four parameters should update a vec3 with correct values', (t) => {
|
|
7
7
|
const radians = 90 * Math.PI / 180
|
|
8
8
|
|
|
9
9
|
const obs1 = fromValues(0, 0, 0)
|
|
@@ -3,7 +3,7 @@ const { rotateY, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec3: rotateY() called with three
|
|
6
|
+
test('vec3: rotateY() called with three parameters should update a vec3 with correct values', (t) => {
|
|
7
7
|
const radians = 90 * Math.PI / 180
|
|
8
8
|
|
|
9
9
|
const obs1 = fromValues(0, 0, 0)
|
|
@@ -3,7 +3,7 @@ const { rotateZ, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec3: rotateZ() called with four
|
|
6
|
+
test('vec3: rotateZ() called with four parameters should update a vec3 with correct values', (t) => {
|
|
7
7
|
const radians = 90 * Math.PI / 180
|
|
8
8
|
|
|
9
9
|
const obs1 = fromValues(0, 0, 0)
|
|
@@ -3,7 +3,7 @@ const { scale, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec3: scale() called with three
|
|
6
|
+
test('vec3: scale() called with three parameters should update a vec3 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0, 0)
|
|
8
8
|
const ret1 = scale(obs1, [0, 0, 0], 0)
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0, 0]))
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* @returns {Number} squared length
|
|
6
6
|
* @alias module:modeling/maths/vec3.squaredLength
|
|
7
7
|
*/
|
|
8
|
-
const squaredLength = (
|
|
9
|
-
const x =
|
|
10
|
-
const y =
|
|
11
|
-
const z =
|
|
8
|
+
const squaredLength = (vector) => {
|
|
9
|
+
const x = vector[0]
|
|
10
|
+
const y = vector[1]
|
|
11
|
+
const z = vector[2]
|
|
12
12
|
return x * x + y * y + z * z
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -3,7 +3,7 @@ const { subtract, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec3: subtract() called with three
|
|
6
|
+
test('vec3: subtract() called with three parameters should update a vec3 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0, 0)
|
|
8
8
|
const ret1 = subtract(obs1, [0, 0, 0], [0, 0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0, 0]))
|
|
@@ -3,7 +3,7 @@ const { transform, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec3: transform() called with three
|
|
6
|
+
test('vec3: transform() called with three parameters should update a vec3 with correct values', (t) => {
|
|
7
7
|
const identityMatrix = [
|
|
8
8
|
1, 0, 0, 0,
|
|
9
9
|
0, 1, 0, 0,
|
|
@@ -3,7 +3,7 @@ const { transform, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec4: transform() called with three
|
|
6
|
+
test('vec4: transform() called with three parameters should update a vec4 with correct values', (t) => {
|
|
7
7
|
const identityMatrix = [
|
|
8
8
|
1, 0, 0, 0,
|
|
9
9
|
0, 1, 0, 0,
|
|
@@ -24,7 +24,7 @@ const measureBoundingSphereOfPath2 = (geometry) => {
|
|
|
24
24
|
const points = path2.toPoints(geometry)
|
|
25
25
|
|
|
26
26
|
if (points.length > 0) {
|
|
27
|
-
// calculate the
|
|
27
|
+
// calculate the centroid of the geometry
|
|
28
28
|
let numPoints = 0
|
|
29
29
|
const temp = vec3.create()
|
|
30
30
|
points.forEach((point) => {
|
|
@@ -60,7 +60,7 @@ const measureBoundingSphereOfGeom2 = (geometry) => {
|
|
|
60
60
|
const sides = geom2.toSides(geometry)
|
|
61
61
|
|
|
62
62
|
if (sides.length > 0) {
|
|
63
|
-
// calculate the
|
|
63
|
+
// calculate the centroid of the geometry
|
|
64
64
|
let numPoints = 0
|
|
65
65
|
const temp = vec3.create()
|
|
66
66
|
sides.forEach((side) => {
|
|
@@ -96,7 +96,7 @@ const measureBoundingSphereOfGeom3 = (geometry) => {
|
|
|
96
96
|
const polygons = geom3.toPolygons(geometry)
|
|
97
97
|
|
|
98
98
|
if (polygons.length > 0) {
|
|
99
|
-
// calculate the
|
|
99
|
+
// calculate the centroid of the geometry
|
|
100
100
|
let numPoints = 0
|
|
101
101
|
polygons.forEach((polygon) => {
|
|
102
102
|
poly3.toPoints(polygon).forEach((point) => {
|
|
@@ -122,7 +122,7 @@ const measureBoundingSphereOfGeom3 = (geometry) => {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
|
-
* Measure the (
|
|
125
|
+
* Measure the (approximate) bounding sphere of the given geometries.
|
|
126
126
|
* @see https://en.wikipedia.org/wiki/Bounding_sphere
|
|
127
127
|
* @param {...Object} geometries - the geometries to measure
|
|
128
128
|
* @return {Array} the bounding sphere for each geometry, i.e. [centroid, radius]
|
|
@@ -61,7 +61,7 @@ const measureCenterOfMassGeom3 = (geometry) => {
|
|
|
61
61
|
let totalVolume = 0
|
|
62
62
|
const vector = vec3.create() // for speed
|
|
63
63
|
polygons.forEach((polygon) => {
|
|
64
|
-
// calculate volume and center of each
|
|
64
|
+
// calculate volume and center of each tetrahedron
|
|
65
65
|
const vertices = polygon.vertices
|
|
66
66
|
for (let i = 0; i < vertices.length - 2; i++) {
|
|
67
67
|
vec3.cross(vector, vertices[i + 1], vertices[i + 2])
|
|
@@ -51,8 +51,8 @@ test('measureCenterOfMass (multiple objects)', (t) => {
|
|
|
51
51
|
const o = {}
|
|
52
52
|
|
|
53
53
|
let allcenters = measureCenterOfMass(aline, arect, asphere, o)
|
|
54
|
-
t.deepEqual(allcenters, [[0, 0, 0], [10, -10, 0], [4.
|
|
54
|
+
t.deepEqual(allcenters, [[0, 0, 0], [10, -10, 0], [4.999999999999991, -5.000000000000006, 49.999999999999915], [0, 0, 0]])
|
|
55
55
|
|
|
56
56
|
allcenters = measureCenterOfMass(aline, arect, asphere, o)
|
|
57
|
-
t.deepEqual(allcenters, [[0, 0, 0], [10, -10, 0], [4.
|
|
57
|
+
t.deepEqual(allcenters, [[0, 0, 0], [10, -10, 0], [4.999999999999991, -5.000000000000006, 49.999999999999915], [0, 0, 0]])
|
|
58
58
|
})
|
|
@@ -36,6 +36,7 @@ test('intersect: intersect of one or more geom2 objects produces expected geomet
|
|
|
36
36
|
[0, -2],
|
|
37
37
|
[1.4142000000000001, -1.4142000000000001]
|
|
38
38
|
]
|
|
39
|
+
t.notThrows(() => geom2.validate(result1))
|
|
39
40
|
t.is(obs.length, 8)
|
|
40
41
|
t.true(comparePoints(obs, exp))
|
|
41
42
|
|
|
@@ -44,6 +45,7 @@ test('intersect: intersect of one or more geom2 objects produces expected geomet
|
|
|
44
45
|
|
|
45
46
|
const result2 = intersect(geometry1, geometry2)
|
|
46
47
|
obs = geom2.toPoints(result2)
|
|
48
|
+
t.notThrows(() => geom2.validate(result2))
|
|
47
49
|
t.is(obs.length, 0)
|
|
48
50
|
|
|
49
51
|
// intersect of two partially overlapping objects
|
|
@@ -54,6 +56,7 @@ test('intersect: intersect of one or more geom2 objects produces expected geomet
|
|
|
54
56
|
exp = [
|
|
55
57
|
[9, 9], [8, 9], [8, 8], [9, 8]
|
|
56
58
|
]
|
|
59
|
+
t.notThrows(() => geom2.validate(result3))
|
|
57
60
|
t.is(obs.length, 4)
|
|
58
61
|
t.true(comparePoints(obs, exp))
|
|
59
62
|
|
|
@@ -70,6 +73,7 @@ test('intersect: intersect of one or more geom2 objects produces expected geomet
|
|
|
70
73
|
[0, -2],
|
|
71
74
|
[1.4142000000000001, -1.4142000000000001]
|
|
72
75
|
]
|
|
76
|
+
t.notThrows(() => geom2.validate(result4))
|
|
73
77
|
t.is(obs.length, 8)
|
|
74
78
|
t.true(comparePoints(obs, exp))
|
|
75
79
|
})
|
|
@@ -130,6 +134,7 @@ test('intersect: intersect of one or more geom3 objects produces expected geomet
|
|
|
130
134
|
[[0.9999999999999998, 1.0000000000000002, -1.414213562373095], [1.4142135623730951, 3.4638242249419736e-16, -1.414213562373095], [8.65956056235493e-17, 8.659560562354935e-17, -2]],
|
|
131
135
|
[[8.65956056235493e-17, 8.659560562354935e-17, 2], [1.4142135623730951, 3.4638242249419736e-16, 1.414213562373095], [0.9999999999999998, 1.0000000000000002, 1.414213562373095]]
|
|
132
136
|
]
|
|
137
|
+
t.notThrows.skip(() => geom3.validate(result1))
|
|
133
138
|
t.is(obs.length, 32)
|
|
134
139
|
t.true(comparePolygonsAsPoints(obs, exp))
|
|
135
140
|
|
|
@@ -138,6 +143,7 @@ test('intersect: intersect of one or more geom3 objects produces expected geomet
|
|
|
138
143
|
|
|
139
144
|
const result2 = intersect(geometry1, geometry2)
|
|
140
145
|
obs = geom3.toPoints(result2)
|
|
146
|
+
t.notThrows(() => geom3.validate(result2))
|
|
141
147
|
t.is(obs.length, 0)
|
|
142
148
|
|
|
143
149
|
// intersect of two partially overlapping objects
|
|
@@ -166,11 +172,13 @@ test('intersect: intersect of one or more geom3 objects produces expected geomet
|
|
|
166
172
|
[[9, 8, 8], [8, 8, 8], [8, 9, 8], [9, 9, 8]]
|
|
167
173
|
]
|
|
168
174
|
|
|
175
|
+
t.notThrows(() => geom3.validate(result3))
|
|
169
176
|
t.is(obs.length, 6)
|
|
170
177
|
t.true(comparePolygonsAsPoints(obs, exp))
|
|
171
178
|
|
|
172
179
|
// intersect of two completely overlapping objects
|
|
173
180
|
const result4 = intersect(geometry1, geometry3)
|
|
174
181
|
obs = geom3.toPoints(result4)
|
|
182
|
+
t.notThrows.skip(() => geom3.validate(result4))
|
|
175
183
|
t.is(obs.length, 32)
|
|
176
184
|
})
|
|
@@ -4,9 +4,9 @@ const measureBoundingBox = require('../../measurements/measureBoundingBox')
|
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
6
|
* Determine if the given geometries overlap by comparing min and max bounds.
|
|
7
|
-
* NOTE: This is used in union for
|
|
8
|
-
* @param {geom3} geometry1 - geometry for
|
|
9
|
-
* @param {geom3} geometry2 - geometry for
|
|
7
|
+
* NOTE: This is used in union for performance gains.
|
|
8
|
+
* @param {geom3} geometry1 - geometry for comparison
|
|
9
|
+
* @param {geom3} geometry2 - geometry for comparison
|
|
10
10
|
* @returns {boolean} true if the geometries overlap
|
|
11
11
|
*/
|
|
12
12
|
const mayOverlap = (geometry1, geometry2) => {
|
|
@@ -3,8 +3,8 @@ const poly3 = require('../../geometries/poly3')
|
|
|
3
3
|
|
|
4
4
|
const reTesselateCoplanarPolygons = require('./reTesselateCoplanarPolygons')
|
|
5
5
|
|
|
6
|
-
// Normals are directional vectors with component values from 0 to 1.0, requiring specialized
|
|
7
|
-
// This EPS is derived from a
|
|
6
|
+
// Normals are directional vectors with component values from 0 to 1.0, requiring specialized comparison
|
|
7
|
+
// This EPS is derived from a series of tests to determine the optimal precision for comparing coplanar polygons,
|
|
8
8
|
// as provided by the sphere primitive at high segmentation
|
|
9
9
|
// This EPS is for 64 bit Number values
|
|
10
10
|
const NEPS = 1e-13
|
|
@@ -9,7 +9,7 @@ const scissionGeom3 = require('./scissionGeom3')
|
|
|
9
9
|
/**
|
|
10
10
|
* Scission (divide) the given geometry into the component pieces.
|
|
11
11
|
*
|
|
12
|
-
* @param {...Object}
|
|
12
|
+
* @param {...Object} objects - list of geometries
|
|
13
13
|
* @returns {Array} list of pieces from each geometry
|
|
14
14
|
* @alias module:modeling/booleans.scission
|
|
15
15
|
*
|