@jscad/modeling 2.7.2 → 2.8.0
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 +23 -0
- package/dist/jscad-modeling.min.js +136 -133
- 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.js +10 -0
- 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/geom3/fromCompactBinary.js +1 -1
- package/src/geometries/geom3/index.js +17 -0
- 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/index.js +8 -1
- package/src/geometries/path2/eachPoint.js +3 -3
- package/src/geometries/path2/index.js +11 -0
- 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/poly2/arePointsInside.test.js +1 -1
- package/src/geometries/poly2/index.js +6 -0
- package/src/geometries/poly3/index.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/measureBoundingBox.js +2 -2
- package/src/geometries/poly3/measureBoundingSphere.js +2 -2
- 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/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/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/subtract.js +1 -1
- package/src/operations/booleans/union.test.js +1 -1
- package/src/operations/booleans/unionGeom3Sub.js +1 -1
- package/src/operations/expansions/expand.js +2 -2
- package/src/operations/expansions/expand.test.js +3 -35
- package/src/operations/expansions/expandShell.js +24 -18
- package/src/operations/expansions/offset.js +1 -1
- package/src/operations/expansions/offset.test.js +25 -89
- package/src/operations/expansions/offsetFromPoints.js +11 -6
- package/src/operations/extrusions/extrudeLinear.js +6 -2
- package/src/operations/extrusions/extrudeLinear.test.js +25 -1
- package/src/operations/extrusions/extrudeLinearPath2.js +24 -0
- package/src/operations/extrusions/extrudeRectangular.js +1 -1
- package/src/operations/extrusions/extrudeRectangular.test.js +2 -2
- package/src/operations/extrusions/project.js +1 -1
- package/src/operations/extrusions/slice/isA.js +2 -2
- package/src/operations/extrusions/slice/toPolygons.js +1 -1
- package/src/operations/hulls/hull.test.js +1 -1
- package/src/operations/hulls/hullChain.js +1 -1
- 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/snap.test.js +3 -3
- package/src/operations/transforms/align.d.ts +1 -1
- package/src/operations/transforms/center.js +17 -17
- package/src/operations/transforms/mirror.js +12 -12
- package/src/operations/transforms/rotate.js +12 -12
- package/src/operations/transforms/scale.js +19 -19
- package/src/operations/transforms/transform.js +3 -3
- package/src/operations/transforms/translate.js +14 -14
- package/src/primitives/arc.js +1 -1
- package/src/primitives/cylinderElliptic.test.js +0 -2
- package/src/primitives/ellipsoid.js +1 -1
- package/src/primitives/ellipsoid.test.js +0 -2
- package/src/primitives/geodesicSphere.d.ts +0 -1
- package/src/primitives/polyhedron.js +1 -1
- package/src/primitives/torus.d.ts +0 -1
- package/src/primitives/triangle.js +1 -1
- package/src/text/vectorText.js +2 -2
- package/src/utils/padArrayToLength.js +1 -1
package/src/maths/mat4/invert.js
CHANGED
|
@@ -4,27 +4,27 @@
|
|
|
4
4
|
* code from https://github.com/jlmakes/rematrix/blob/master/src/index.js
|
|
5
5
|
*
|
|
6
6
|
* @param {mat4} out - receiving matrix
|
|
7
|
-
* @param {mat4}
|
|
7
|
+
* @param {mat4} matrix - matrix to invert
|
|
8
8
|
* @returns {mat4} out
|
|
9
9
|
* @alias module:modeling/maths/mat4.invert
|
|
10
10
|
*/
|
|
11
|
-
const invert = (out,
|
|
12
|
-
const a00 =
|
|
13
|
-
const a01 =
|
|
14
|
-
const a02 =
|
|
15
|
-
const a03 =
|
|
16
|
-
const a10 =
|
|
17
|
-
const a11 =
|
|
18
|
-
const a12 =
|
|
19
|
-
const a13 =
|
|
20
|
-
const a20 =
|
|
21
|
-
const a21 =
|
|
22
|
-
const a22 =
|
|
23
|
-
const a23 =
|
|
24
|
-
const a30 =
|
|
25
|
-
const a31 =
|
|
26
|
-
const a32 =
|
|
27
|
-
const a33 =
|
|
11
|
+
const invert = (out, matrix) => {
|
|
12
|
+
const a00 = matrix[0]
|
|
13
|
+
const a01 = matrix[1]
|
|
14
|
+
const a02 = matrix[2]
|
|
15
|
+
const a03 = matrix[3]
|
|
16
|
+
const a10 = matrix[4]
|
|
17
|
+
const a11 = matrix[5]
|
|
18
|
+
const a12 = matrix[6]
|
|
19
|
+
const a13 = matrix[7]
|
|
20
|
+
const a20 = matrix[8]
|
|
21
|
+
const a21 = matrix[9]
|
|
22
|
+
const a22 = matrix[10]
|
|
23
|
+
const a23 = matrix[11]
|
|
24
|
+
const a30 = matrix[12]
|
|
25
|
+
const a31 = matrix[13]
|
|
26
|
+
const a32 = matrix[14]
|
|
27
|
+
const a33 = matrix[15]
|
|
28
28
|
|
|
29
29
|
const b00 = a00 * a11 - a01 * a10
|
|
30
30
|
const b01 = a00 * a12 - a02 * a10
|
|
@@ -9,10 +9,10 @@ const fromValues = require('../vec3/fromValues')
|
|
|
9
9
|
* @returns {Boolean} true if matrix is a mirroring transformation
|
|
10
10
|
* @alias module:modeling/maths/mat4.isMirroring
|
|
11
11
|
*/
|
|
12
|
-
const isMirroring = (
|
|
13
|
-
const u = fromValues(
|
|
14
|
-
const v = fromValues(
|
|
15
|
-
const w = fromValues(
|
|
12
|
+
const isMirroring = (matrix) => {
|
|
13
|
+
const u = fromValues(matrix[0], matrix[4], matrix[8])
|
|
14
|
+
const v = fromValues(matrix[1], matrix[5], matrix[9])
|
|
15
|
+
const w = fromValues(matrix[2], matrix[6], matrix[10])
|
|
16
16
|
|
|
17
17
|
// for a true orthogonal, non-mirrored base, u.cross(v) == w
|
|
18
18
|
// If they have an opposite direction then we are mirroring
|
|
@@ -4,7 +4,7 @@ const plane = require('../plane')
|
|
|
4
4
|
|
|
5
5
|
const { isMirroring, fromScaling, create, mirrorByPlane, rotate, scale, translate } = require('./index')
|
|
6
6
|
|
|
7
|
-
test('mat4: isMirroring() should determine
|
|
7
|
+
test('mat4: isMirroring() should determine correctly', (t) => {
|
|
8
8
|
let matrix = create()
|
|
9
9
|
t.false(isMirroring(matrix))
|
|
10
10
|
|
|
@@ -8,7 +8,7 @@ const fromValues = require('../vec3/fromValues')
|
|
|
8
8
|
* @param {mat4} matrix the input matrix
|
|
9
9
|
* @returns {vec3} output
|
|
10
10
|
*/
|
|
11
|
-
const
|
|
11
|
+
const leftMultiplyVec3 = (vector, matrix) => {
|
|
12
12
|
const [v0, v1, v2] = vector
|
|
13
13
|
const v3 = 1
|
|
14
14
|
let x = v0 * matrix[0] + v1 * matrix[4] + v2 * matrix[8] + v3 * matrix[12]
|
|
@@ -26,4 +26,4 @@ const lefttMultiplyVec3 = (vector, matrix) => {
|
|
|
26
26
|
return fromValues(x, y, z)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
module.exports =
|
|
29
|
+
module.exports = leftMultiplyVec3
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Return a string representing the given matrix.
|
|
3
3
|
*
|
|
4
|
-
* @param {mat4}
|
|
4
|
+
* @param {mat4} mat - matrix of reference
|
|
5
5
|
* @returns {String} string representation
|
|
6
6
|
* @alias module:modeling/maths/mat4.toString
|
|
7
7
|
*/
|
|
8
|
-
const toString = (mat) =>
|
|
8
|
+
const toString = (mat) => mat.map((n) => n.toFixed(7)).toString()
|
|
9
9
|
|
|
10
10
|
module.exports = toString
|
|
@@ -3,7 +3,7 @@ const { translate, create } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('mat4: translate() called with three
|
|
6
|
+
test('mat4: translate() called with three parameters should update a mat4 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 { create, flip } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('plane: flip() called with two
|
|
6
|
+
test('plane: flip() called with two parameters should update a plane with correct values', (t) => {
|
|
7
7
|
const org1 = create()
|
|
8
8
|
const ret1 = flip(org1, [0, 0, 0, 0])
|
|
9
9
|
t.true(compareVectors(org1, [-0, -0, -0, -0]))
|
|
@@ -4,9 +4,7 @@ const vec3 = require('../vec3')
|
|
|
4
4
|
* Create a plane from the given points.
|
|
5
5
|
*
|
|
6
6
|
* @param {plane} out - receiving plane
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {vec3} b - 3D point
|
|
9
|
-
* @param {vec3} c - 3D point
|
|
7
|
+
* @param {Array} vertices - points on the plane
|
|
10
8
|
* @returns {plane} out
|
|
11
9
|
* @alias module:modeling/maths/plane.fromPoints
|
|
12
10
|
*/
|
|
@@ -8,6 +8,6 @@ const vec3 = require('../vec3')
|
|
|
8
8
|
* @return {Number} signed distance to point
|
|
9
9
|
* @alias module:modeling/maths/plane.signedDistanceToPoint
|
|
10
10
|
*/
|
|
11
|
-
const signedDistanceToPoint = (plane,
|
|
11
|
+
const signedDistanceToPoint = (plane, point) => vec3.dot(plane, point) - plane[3]
|
|
12
12
|
|
|
13
13
|
module.exports = signedDistanceToPoint
|
|
@@ -3,7 +3,7 @@ const { transform, create, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('plane: transform() called with three
|
|
6
|
+
test('plane: transform() called with three parameters should return a plane with correct values', (t) => {
|
|
7
7
|
const identityMatrix = [
|
|
8
8
|
1, 0, 0, 0,
|
|
9
9
|
0, 1, 0, 0,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Normals are directional vectors with component values from 0 to 1.0, requiring specialized
|
|
2
|
-
// This EPS is derived from a
|
|
1
|
+
// Normals are directional vectors with component values from 0 to 1.0, requiring specialized comparison
|
|
2
|
+
// This EPS is derived from a series of tests to determine the optimal precision for comparing coplanar polygons,
|
|
3
3
|
// as provided by the sphere primitive at high segmentation
|
|
4
4
|
// This EPS is for 64 bit Number values
|
|
5
5
|
const NEPS = 1e-13
|
package/src/maths/vec2/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('vec2: add() called with three
|
|
6
|
+
test('vec2: add() called with three parameters should update a vec2 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0)
|
|
8
8
|
const ret1 = add(obs1, [0, 0], [0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0]))
|
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]))
|