@jscad/modeling 2.7.0 → 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 +46 -0
- package/dist/jscad-modeling.min.js +142 -139
- package/package.json +2 -2
- package/src/colors/hslToRgb.js +1 -1
- package/src/colors/hueToColorComponent.js +1 -0
- package/src/curves/bezier/create.js +3 -8
- package/src/curves/bezier/tangentAt.js +2 -2
- package/src/curves/bezier/tangentAt.test.js +1 -1
- package/src/curves/bezier/valueAt.test.js +1 -1
- package/src/curves/index.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/toOutlines.js +6 -11
- package/src/geometries/geom2/toString.js +1 -1
- package/src/geometries/geom2/transform.test.js +1 -1
- package/src/geometries/geom3/create.js +1 -1
- package/src/geometries/geom3/fromCompactBinary.js +1 -1
- package/src/geometries/geom3/index.js +17 -0
- package/src/geometries/geom3/invert.js +2 -2
- package/src/geometries/geom3/isA.js +2 -2
- package/src/geometries/geom3/toCompactBinary.js +4 -4
- package/src/geometries/geom3/toPoints.js +1 -0
- 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/create.js +2 -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/fromRotation.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/isIdentity.test.js +0 -2
- package/src/maths/mat4/isMirroring.js +4 -4
- package/src/maths/mat4/isMirroring.test.js +1 -1
- package/src/maths/mat4/isOnlyTransformScale.js +5 -4
- package/src/maths/mat4/leftMultiplyVec3.js +2 -2
- package/src/maths/mat4/rotate.js +1 -1
- 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/length.test.js +10 -0
- 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/angle.js +2 -2
- package/src/maths/vec3/angle.test.js +17 -0
- 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/length.test.js +10 -0
- 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/measureBoundingBox.js +38 -128
- 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 +3 -5
- 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 +3 -1
- package/src/operations/expansions/expand.test.js +3 -35
- package/src/operations/expansions/expandShell.js +24 -18
- package/src/operations/expansions/offset.js +2 -1
- package/src/operations/expansions/offset.test.js +25 -89
- package/src/operations/expansions/offsetFromPoints.js +11 -6
- package/src/operations/extrusions/extrudeLinear.js +7 -3
- package/src/operations/extrusions/extrudeLinear.test.js +25 -1
- package/src/operations/extrusions/extrudeLinearPath2.js +24 -0
- package/src/operations/extrusions/extrudeRectangular.js +3 -2
- 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/hulls/quickhull/QuickHull.js +2 -2
- package/src/operations/modifiers/edges.js +2 -4
- package/src/operations/modifiers/generalize.js +4 -7
- 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 +11 -11
- 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/ellipse.js +1 -1
- 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/geodesicSphere.js +2 -2
- package/src/primitives/polyhedron.js +1 -1
- package/src/primitives/roundedCylinder.js +1 -1
- package/src/primitives/torus.d.ts +0 -1
- package/src/primitives/triangle.js +2 -2
- package/src/text/vectorText.js +2 -2
- package/src/utils/insertSorted.js +1 -0
- package/src/utils/padArrayToLength.js +1 -1
- package/test/helpers/comparePolygons.js +1 -3
- package/test/helpers/nearlyEqual.js +2 -6
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Compare the given lines for equality.
|
|
3
3
|
*
|
|
4
|
-
* @param {line2}
|
|
5
|
-
* @param {line2}
|
|
4
|
+
* @param {line2} line1 - first line to compare
|
|
5
|
+
* @param {line2} line2 - second line to compare
|
|
6
6
|
* @return {Boolean} true if lines are equal
|
|
7
7
|
* @alias module:modeling/maths/line2.equals
|
|
8
8
|
*/
|
|
@@ -9,11 +9,11 @@ const create = require('./create')
|
|
|
9
9
|
* @returns {line2} a new unbounded line
|
|
10
10
|
* @alias module:modeling/maths/line2.fromValues
|
|
11
11
|
*/
|
|
12
|
-
const fromValues = (x, y,
|
|
12
|
+
const fromValues = (x, y, d) => {
|
|
13
13
|
const out = create()
|
|
14
14
|
out[0] = x
|
|
15
15
|
out[1] = y
|
|
16
|
-
out[2] =
|
|
16
|
+
out[2] = d
|
|
17
17
|
return out
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -5,7 +5,7 @@ const { solve2Linear } = require('../utils')
|
|
|
5
5
|
* Return the point of intersection between the given lines.
|
|
6
6
|
*
|
|
7
7
|
* NOTES:
|
|
8
|
-
* The point will have Infinity values if the lines are
|
|
8
|
+
* The point will have Infinity values if the lines are parallel.
|
|
9
9
|
* The point will have NaN values if the lines are the same.
|
|
10
10
|
*
|
|
11
11
|
* @param {line2} line1 - line of reference
|
|
@@ -15,7 +15,7 @@ test('line2: intersectPointOfLines() should return proper points', (t) => {
|
|
|
15
15
|
const int3 = intersectPointOfLines(line3, line2)
|
|
16
16
|
t.true(compareVectors(int3, [NaN, NaN]))
|
|
17
17
|
|
|
18
|
-
//
|
|
18
|
+
// parallel lines
|
|
19
19
|
const line4 = fromPoints(create(), [0, 6], [6, 0])
|
|
20
20
|
const int4 = intersectPointOfLines(line4, line3)
|
|
21
21
|
t.true(compareVectors(int4, [Infinity, -Infinity]))
|
|
@@ -3,7 +3,7 @@ const { reverse, create, fromPoints } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('line2: reverse() called with two
|
|
6
|
+
test('line2: reverse() called with two parameters should update a line2 with proper values', (t) => {
|
|
7
7
|
const line1 = create()
|
|
8
8
|
const obs1 = create()
|
|
9
9
|
const ret1 = reverse(obs1, line1)
|
|
@@ -3,7 +3,7 @@ const { transform, create, fromPoints } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('line2: transform() called with three
|
|
6
|
+
test('line2: transform() called with three parameters should update a line2 with correct values', (t) => {
|
|
7
7
|
const line1 = create()
|
|
8
8
|
const line2 = fromPoints(create(), [0, 0], [0, 1])
|
|
9
9
|
const line3 = fromPoints(create(), [-3, -3], [3, 3])
|
|
@@ -3,7 +3,8 @@ const vec3 = require('../vec3')
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents a unbounded line in 3D space, positioned at a point of origin.
|
|
5
5
|
* A line is parametrized by a point of origin and a directional vector.
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
|
+
* The array contents are two 3D vectors; origin [0,0,0] and directional vector [0,0,1].
|
|
7
8
|
* @see https://en.wikipedia.org/wiki/Hesse_normal_form
|
|
8
9
|
* @typedef {Array} line3
|
|
9
10
|
*/
|
|
@@ -3,8 +3,8 @@ const vec3 = require('../vec3')
|
|
|
3
3
|
/**
|
|
4
4
|
* Compare the given lines for equality.
|
|
5
5
|
*
|
|
6
|
-
* @param {line3}
|
|
7
|
-
* @param {line3}
|
|
6
|
+
* @param {line3} line1 - first line to compare
|
|
7
|
+
* @param {line3} line2 - second line to compare
|
|
8
8
|
* @return {Boolean} true if lines are equal
|
|
9
9
|
* @alias module:modeling/maths/line3.equals
|
|
10
10
|
*/
|
|
@@ -3,7 +3,7 @@ const { reverse, create, fromPoints } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('line3: reverse() called with two
|
|
6
|
+
test('line3: reverse() called with two parameters should update a line3 with proper values', (t) => {
|
|
7
7
|
const line1 = create()
|
|
8
8
|
const out = create()
|
|
9
9
|
let rev = reverse(out, line1)
|
|
@@ -3,7 +3,7 @@ const { transform, create, fromPoints } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('line3: transform() called with three
|
|
6
|
+
test('line3: transform() called with three parameters should update a line3 with correct values', (t) => {
|
|
7
7
|
const line1 = create()
|
|
8
8
|
const line2 = fromPoints(create(), [1, 0, 0], [0, 1, 0])
|
|
9
9
|
const line3 = fromPoints(create(), [-3, -3, -3], [3, 3, 3])
|
|
@@ -19,7 +19,7 @@ const { EPSILON } = require('./constants')
|
|
|
19
19
|
*/
|
|
20
20
|
const fromRotation = (out, rad, axis) => {
|
|
21
21
|
let [x, y, z] = axis
|
|
22
|
-
let len = Math.
|
|
22
|
+
let len = Math.hypot(x, y, z)
|
|
23
23
|
|
|
24
24
|
if (Math.abs(len) < EPSILON) {
|
|
25
25
|
// axis is 0,0,0 or almost
|
|
@@ -5,7 +5,7 @@ const fromRotation = require('./fromRotation')
|
|
|
5
5
|
/**
|
|
6
6
|
* Create a matrix that rotates the given source to the given target vector.
|
|
7
7
|
*
|
|
8
|
-
* Each vector must be a directional vector with a length greater
|
|
8
|
+
* Each vector must be a directional vector with a length greater than zero.
|
|
9
9
|
* @see https://gist.github.com/kevinmoran/b45980723e53edeb8a5a43c49f134724
|
|
10
10
|
* @param {mat4} out - receiving matrix
|
|
11
11
|
* @param {vec3} source - source vector
|
|
@@ -96,7 +96,7 @@ test('mat4: fromVectorRotation() called with out parameter should return a mat4
|
|
|
96
96
|
t.is(ret, out)
|
|
97
97
|
t.true(compareVectors(out, [1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1]))
|
|
98
98
|
|
|
99
|
-
//
|
|
99
|
+
// different units
|
|
100
100
|
ret = fromVectorRotation(out, [11, 0, 0], [0, 33, 0])
|
|
101
101
|
t.is(ret, out)
|
|
102
102
|
t.true(compareVectors(out, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]))
|
|
@@ -3,7 +3,7 @@ const { identity } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('mat4: identity() called with one
|
|
6
|
+
test('mat4: identity() called with one parameters should update a mat4 with correct values', (t) => {
|
|
7
7
|
const obs1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
8
8
|
const ret1 = identity(obs1)
|
|
9
9
|
t.true(compareVectors(obs1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 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
|
|
@@ -2,8 +2,6 @@ const test = require('ava')
|
|
|
2
2
|
|
|
3
3
|
const { isIdentity, create, fromTranslation } = require('./index')
|
|
4
4
|
|
|
5
|
-
const { compareVectors } = require('../../../test/helpers/index')
|
|
6
|
-
|
|
7
5
|
test('mat4: isIdentity() should return correct values', (t) => {
|
|
8
6
|
const identity = create() // identity matrix
|
|
9
7
|
t.true(isIdentity(identity))
|
|
@@ -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
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
|
-
* Determine whether the given matrix is translate
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* this method is primarily useful for measureBoundingBox
|
|
3
|
+
* Determine whether the given matrix is only translate and/or scale.
|
|
4
|
+
* This code returns true for PI rotation as it can be interpreted as scale.
|
|
7
5
|
*
|
|
6
|
+
* @param {mat4} matrix - the matrix
|
|
7
|
+
* @returns {Boolean} true if matrix is for translate and/or scale
|
|
8
|
+
* @alias module:modeling/maths/mat4.isOnlyTransformScale
|
|
8
9
|
*/
|
|
9
10
|
const isOnlyTransformScale = (matrix) => (
|
|
10
11
|
|
|
@@ -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
|
package/src/maths/mat4/rotate.js
CHANGED
|
@@ -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
|
@@ -25,5 +25,15 @@ test('vec2: length() should return correct values', (t) => {
|
|
|
25
25
|
const length5 = length(vec5)
|
|
26
26
|
nearlyEqual(t, length5, 2.23606, EPS)
|
|
27
27
|
|
|
28
|
+
// huge vector
|
|
29
|
+
const vec6 = fromValues(1e200, 1e200)
|
|
30
|
+
const length6 = length(vec6)
|
|
31
|
+
nearlyEqual(t, length6, Math.SQRT2 * 1e200, EPS)
|
|
32
|
+
|
|
33
|
+
// tiny vector
|
|
34
|
+
const vec7 = fromValues(1e-200, 1e-200)
|
|
35
|
+
const length7 = length(vec7)
|
|
36
|
+
nearlyEqual(t, length7, Math.SQRT2 * 1e-200, EPS)
|
|
37
|
+
|
|
28
38
|
t.true(true)
|
|
29
39
|
})
|
|
@@ -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]))
|