@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.
Files changed (185) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/jscad-modeling.min.js +142 -139
  3. package/package.json +2 -2
  4. package/src/colors/hslToRgb.js +1 -1
  5. package/src/colors/hueToColorComponent.js +1 -0
  6. package/src/curves/bezier/create.js +3 -8
  7. package/src/curves/bezier/tangentAt.js +2 -2
  8. package/src/curves/bezier/tangentAt.test.js +1 -1
  9. package/src/curves/bezier/valueAt.test.js +1 -1
  10. package/src/curves/index.js +1 -1
  11. package/src/geometries/geom2/index.js +10 -0
  12. package/src/geometries/geom2/isA.js +2 -2
  13. package/src/geometries/geom2/toCompactBinary.js +4 -4
  14. package/src/geometries/geom2/toOutlines.js +6 -11
  15. package/src/geometries/geom2/toString.js +1 -1
  16. package/src/geometries/geom2/transform.test.js +1 -1
  17. package/src/geometries/geom3/create.js +1 -1
  18. package/src/geometries/geom3/fromCompactBinary.js +1 -1
  19. package/src/geometries/geom3/index.js +17 -0
  20. package/src/geometries/geom3/invert.js +2 -2
  21. package/src/geometries/geom3/isA.js +2 -2
  22. package/src/geometries/geom3/toCompactBinary.js +4 -4
  23. package/src/geometries/geom3/toPoints.js +1 -0
  24. package/src/geometries/geom3/toString.js +1 -1
  25. package/src/geometries/geom3/transform.test.js +1 -1
  26. package/src/geometries/index.js +8 -1
  27. package/src/geometries/path2/eachPoint.js +3 -3
  28. package/src/geometries/path2/index.js +11 -0
  29. package/src/geometries/path2/isA.js +2 -2
  30. package/src/geometries/path2/reverse.js +4 -4
  31. package/src/geometries/path2/toCompactBinary.js +6 -6
  32. package/src/geometries/path2/toString.js +1 -1
  33. package/src/geometries/path2/transform.test.js +1 -1
  34. package/src/geometries/poly2/arePointsInside.test.js +1 -1
  35. package/src/geometries/poly2/index.js +6 -0
  36. package/src/geometries/poly3/index.js +7 -1
  37. package/src/geometries/poly3/isA.js +2 -2
  38. package/src/geometries/poly3/isConvex.js +2 -2
  39. package/src/geometries/poly3/measureArea.js +4 -4
  40. package/src/geometries/poly3/measureBoundingBox.js +2 -2
  41. package/src/geometries/poly3/measureBoundingSphere.js +2 -2
  42. package/src/geometries/poly3/measureSignedVolume.js +4 -4
  43. package/src/geometries/poly3/toPoints.js +2 -2
  44. package/src/geometries/poly3/toString.js +2 -2
  45. package/src/geometries/poly3/transform.js +2 -2
  46. package/src/maths/index.js +1 -1
  47. package/src/maths/line2/equals.js +2 -2
  48. package/src/maths/line2/fromValues.js +2 -2
  49. package/src/maths/line2/intersectPointOfLines.js +1 -1
  50. package/src/maths/line2/intersectPointOfLines.test.js +1 -1
  51. package/src/maths/line2/reverse.test.js +1 -1
  52. package/src/maths/line2/transform.test.js +1 -1
  53. package/src/maths/line3/create.js +2 -1
  54. package/src/maths/line3/equals.js +2 -2
  55. package/src/maths/line3/reverse.test.js +1 -1
  56. package/src/maths/line3/transform.test.js +1 -1
  57. package/src/maths/mat4/fromRotation.js +1 -1
  58. package/src/maths/mat4/fromVectorRotation.js +1 -1
  59. package/src/maths/mat4/fromVectorRotation.test.js +1 -1
  60. package/src/maths/mat4/identity.test.js +1 -1
  61. package/src/maths/mat4/invert.js +18 -18
  62. package/src/maths/mat4/isIdentity.js +1 -1
  63. package/src/maths/mat4/isIdentity.test.js +0 -2
  64. package/src/maths/mat4/isMirroring.js +4 -4
  65. package/src/maths/mat4/isMirroring.test.js +1 -1
  66. package/src/maths/mat4/isOnlyTransformScale.js +5 -4
  67. package/src/maths/mat4/leftMultiplyVec3.js +2 -2
  68. package/src/maths/mat4/rotate.js +1 -1
  69. package/src/maths/mat4/toString.js +2 -2
  70. package/src/maths/mat4/translate.test.js +1 -1
  71. package/src/maths/plane/flip.test.js +1 -1
  72. package/src/maths/plane/fromPoints.d.ts +1 -1
  73. package/src/maths/plane/fromPoints.js +1 -3
  74. package/src/maths/plane/signedDistanceToPoint.js +1 -1
  75. package/src/maths/plane/transform.test.js +1 -1
  76. package/src/maths/utils/aboutEqualNormals.js +2 -2
  77. package/src/maths/vec2/abs.d.ts +1 -1
  78. package/src/maths/vec2/add.test.js +1 -1
  79. package/src/maths/vec2/angleDegrees.d.ts +1 -1
  80. package/src/maths/vec2/angleRadians.d.ts +1 -1
  81. package/src/maths/vec2/create.js +1 -1
  82. package/src/maths/vec2/cross.test.js +1 -1
  83. package/src/maths/vec2/divide.test.js +1 -1
  84. package/src/maths/vec2/fromAngleDegrees.js +1 -1
  85. package/src/maths/vec2/fromScalar.js +1 -1
  86. package/src/maths/vec2/length.d.ts +1 -1
  87. package/src/maths/vec2/length.js +1 -1
  88. package/src/maths/vec2/length.test.js +10 -0
  89. package/src/maths/vec2/lerp.test.js +1 -1
  90. package/src/maths/vec2/multiply.test.js +1 -1
  91. package/src/maths/vec2/negate.test.js +1 -1
  92. package/src/maths/vec2/normal.js +1 -1
  93. package/src/maths/vec2/normalize.d.ts +1 -1
  94. package/src/maths/vec2/normalize.test.js +1 -1
  95. package/src/maths/vec2/rotate.test.js +1 -1
  96. package/src/maths/vec2/squaredLength.d.ts +1 -1
  97. package/src/maths/vec2/squaredLength.js +3 -3
  98. package/src/maths/vec2/subtract.test.js +1 -1
  99. package/src/maths/vec2/toString.js +1 -1
  100. package/src/maths/vec2/transform.test.js +1 -1
  101. package/src/maths/vec3/abs.d.ts +1 -1
  102. package/src/maths/vec3/add.test.js +1 -1
  103. package/src/maths/vec3/angle.js +2 -2
  104. package/src/maths/vec3/angle.test.js +17 -0
  105. package/src/maths/vec3/cross.test.js +1 -1
  106. package/src/maths/vec3/divide.test.js +1 -1
  107. package/src/maths/vec3/fromScalar.js +1 -1
  108. package/src/maths/vec3/fromVec2.d.ts +1 -1
  109. package/src/maths/vec3/fromVec2.js +3 -3
  110. package/src/maths/vec3/length.d.ts +1 -1
  111. package/src/maths/vec3/length.js +4 -4
  112. package/src/maths/vec3/length.test.js +10 -0
  113. package/src/maths/vec3/lerp.test.js +1 -1
  114. package/src/maths/vec3/multiply.test.js +1 -1
  115. package/src/maths/vec3/negate.d.ts +1 -1
  116. package/src/maths/vec3/negate.test.js +1 -1
  117. package/src/maths/vec3/normalize.d.ts +1 -1
  118. package/src/maths/vec3/normalize.test.js +1 -1
  119. package/src/maths/vec3/rotateX.test.js +1 -1
  120. package/src/maths/vec3/rotateY.test.js +1 -1
  121. package/src/maths/vec3/rotateZ.test.js +1 -1
  122. package/src/maths/vec3/scale.test.js +1 -1
  123. package/src/maths/vec3/squaredLength.d.ts +1 -1
  124. package/src/maths/vec3/squaredLength.js +4 -4
  125. package/src/maths/vec3/subtract.test.js +1 -1
  126. package/src/maths/vec3/toString.js +1 -1
  127. package/src/maths/vec3/transform.test.js +1 -1
  128. package/src/maths/vec4/toString.js +1 -1
  129. package/src/maths/vec4/transform.test.js +1 -1
  130. package/src/measurements/measureBoundingBox.js +38 -128
  131. package/src/measurements/measureBoundingSphere.js +4 -4
  132. package/src/measurements/measureCenterOfMass.js +1 -1
  133. package/src/operations/booleans/mayOverlap.js +3 -3
  134. package/src/operations/booleans/retessellate.js +3 -5
  135. package/src/operations/booleans/scission.js +1 -1
  136. package/src/operations/booleans/subtract.js +1 -1
  137. package/src/operations/booleans/union.test.js +1 -1
  138. package/src/operations/booleans/unionGeom3Sub.js +1 -1
  139. package/src/operations/expansions/expand.js +3 -1
  140. package/src/operations/expansions/expand.test.js +3 -35
  141. package/src/operations/expansions/expandShell.js +24 -18
  142. package/src/operations/expansions/offset.js +2 -1
  143. package/src/operations/expansions/offset.test.js +25 -89
  144. package/src/operations/expansions/offsetFromPoints.js +11 -6
  145. package/src/operations/extrusions/extrudeLinear.js +7 -3
  146. package/src/operations/extrusions/extrudeLinear.test.js +25 -1
  147. package/src/operations/extrusions/extrudeLinearPath2.js +24 -0
  148. package/src/operations/extrusions/extrudeRectangular.js +3 -2
  149. package/src/operations/extrusions/extrudeRectangular.test.js +2 -2
  150. package/src/operations/extrusions/project.js +1 -1
  151. package/src/operations/extrusions/slice/isA.js +2 -2
  152. package/src/operations/extrusions/slice/toPolygons.js +1 -1
  153. package/src/operations/hulls/hull.test.js +1 -1
  154. package/src/operations/hulls/hullChain.js +1 -1
  155. package/src/operations/hulls/hullGeom2.js +1 -1
  156. package/src/operations/hulls/hullPath2.js +6 -4
  157. package/src/operations/hulls/hullPath2.test.js +16 -0
  158. package/src/operations/hulls/hullPoints2.test.js +1 -1
  159. package/src/operations/hulls/quickhull/QuickHull.js +2 -2
  160. package/src/operations/modifiers/edges.js +2 -4
  161. package/src/operations/modifiers/generalize.js +4 -7
  162. package/src/operations/modifiers/snap.test.js +3 -3
  163. package/src/operations/transforms/align.d.ts +1 -1
  164. package/src/operations/transforms/center.js +17 -17
  165. package/src/operations/transforms/mirror.js +11 -11
  166. package/src/operations/transforms/rotate.js +12 -12
  167. package/src/operations/transforms/scale.js +19 -19
  168. package/src/operations/transforms/transform.js +3 -3
  169. package/src/operations/transforms/translate.js +14 -14
  170. package/src/primitives/arc.js +1 -1
  171. package/src/primitives/cylinderElliptic.test.js +0 -2
  172. package/src/primitives/ellipse.js +1 -1
  173. package/src/primitives/ellipsoid.js +1 -1
  174. package/src/primitives/ellipsoid.test.js +0 -2
  175. package/src/primitives/geodesicSphere.d.ts +0 -1
  176. package/src/primitives/geodesicSphere.js +2 -2
  177. package/src/primitives/polyhedron.js +1 -1
  178. package/src/primitives/roundedCylinder.js +1 -1
  179. package/src/primitives/torus.d.ts +0 -1
  180. package/src/primitives/triangle.js +2 -2
  181. package/src/text/vectorText.js +2 -2
  182. package/src/utils/insertSorted.js +1 -0
  183. package/src/utils/padArrayToLength.js +1 -1
  184. package/test/helpers/comparePolygons.js +1 -3
  185. 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} a - first line to compare
5
- * @param {line2} b - second line to compare
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, w) => {
12
+ const fromValues = (x, y, d) => {
13
13
  const out = create()
14
14
  out[0] = x
15
15
  out[1] = y
16
- out[2] = w
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 paralell.
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
- // paralell lines
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 paramerters should update a line2 with proper values', (t) => {
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 paramerters should update a line2 with correct values', (t) => {
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
- * The array contents are two 3D vectors; origin and directional vector.
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} a - first line to compare
7
- * @param {line3} b - second line to compare
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 paramerters should update a line3 with proper values', (t) => {
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 paramerters should update a line3 with correct values', (t) => {
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.sqrt(x * x + y * y + z * z)
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 then zero.
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
- // differnt units
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 paramerters should update a mat4 with correct values', (t) => {
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]))
@@ -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} m - matrix to invert
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, a) => {
12
- const a00 = a[0]
13
- const a01 = a[1]
14
- const a02 = a[2]
15
- const a03 = a[3]
16
- const a10 = a[4]
17
- const a11 = a[5]
18
- const a12 = a[6]
19
- const a13 = a[7]
20
- const a20 = a[8]
21
- const a21 = a[9]
22
- const a22 = a[10]
23
- const a23 = a[11]
24
- const a30 = a[12]
25
- const a31 = a[13]
26
- const a32 = a[14]
27
- const a33 = a[15]
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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Determine whether the given matris is the identity transform.
2
+ * Determine whether the given matrix is the identity transform.
3
3
  * This is equivalent to (but much faster than):
4
4
  *
5
5
  * mat4.equals(mat4.create(), matrix)
@@ -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 = (mat) => {
13
- const u = fromValues(mat[0], mat[4], mat[8])
14
- const v = fromValues(mat[1], mat[5], mat[9])
15
- const w = fromValues(mat[2], mat[6], mat[10])
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 correctlly', (t) => {
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+scale.
4
- * this code returns true for 180 rotation as it can be interpreted as scale (-1,-1)
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 lefttMultiplyVec3 = (vector, matrix) => {
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 = lefttMultiplyVec3
29
+ module.exports = leftMultiplyVec3
@@ -12,7 +12,7 @@ const copy = require('./copy')
12
12
  */
13
13
  const rotate = (out, matrix, radians, axis) => {
14
14
  let [x, y, z] = axis
15
- let len = Math.sqrt(x * x + y * y + z * z)
15
+ let len = Math.hypot(x, y, z)
16
16
 
17
17
  if (Math.abs(len) < 0.000001) {
18
18
  // axis is 0,0,0 or almost
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Return a string representing the given matrix.
3
3
  *
4
- * @param {mat4} matrix - matrix of reference
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) => `[${mat[0].toFixed(7)}, ${mat[1].toFixed(7)}, ${mat[2].toFixed(7)}, ${mat[3].toFixed(7)}, ${mat[4].toFixed(7)}, ${mat[5].toFixed(7)}, ${mat[6].toFixed(7)}, ${mat[7].toFixed(7)}, ${mat[8].toFixed(7)}, ${mat[9].toFixed(7)}, ${mat[10].toFixed(7)}, ${mat[11].toFixed(7)}, ${mat[12].toFixed(7)}, ${mat[13].toFixed(7)}, ${mat[14].toFixed(7)}, ${mat[15].toFixed(7)}]`
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 paramerters should update a mat4 with correct values', (t) => {
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 paramerters should update a plane with correct values', (t) => {
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]))
@@ -3,4 +3,4 @@ import Vec3 from '../vec3/type'
3
3
 
4
4
  export default fromPoints
5
5
 
6
- declare function fromPoints(out: Plane, a: Vec3, b: Vec3, c: Vec3): Plane
6
+ declare function fromPoints(out: Plane, ...vertices: Array<Vec3>): Plane
@@ -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 {vec3} a - 3D point
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, vector) => vec3.dot(plane, vector) - plane[3]
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 paramerters should return a plane with correct values', (t) => {
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 comparision
2
- // This EPS is derived from a serieas of tests to determine the optimal precision for comparing coplanar polygons,
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
@@ -2,4 +2,4 @@ import Vec2 from './type'
2
2
 
3
3
  export default abs
4
4
 
5
- declare function abs(out: Vec2, vec: Vec2): Vec2
5
+ declare function abs(out: Vec2, vector: Vec2): Vec2
@@ -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 paramerters should update a vec2 with correct values', (t) => {
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]))
@@ -2,4 +2,4 @@ import Vec2 from './type'
2
2
 
3
3
  export default angleDegrees
4
4
 
5
- declare function angleDegrees(vec: Vec2): number
5
+ declare function angleDegrees(vector: Vec2): number
@@ -2,4 +2,4 @@ import Vec2 from './type'
2
2
 
3
3
  export default angleRadians
4
4
 
5
- declare function angleRadians(vec: Vec2): number
5
+ declare function angleRadians(vector: Vec2): number
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  /**
8
- * Creates a new vector, intialized to [0,0].
8
+ * Creates a new vector, initialized to [0,0].
9
9
  *
10
10
  * @returns {vec2} a new vector
11
11
  * @alias module:modeling/maths/vec2.create
@@ -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 paramerters should update a vec2 with correct values', (t) => {
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 paramerters should update a vec2 with correct values', (t) => {
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} angle - angle in degrees
7
+ * @param {Number} degrees - angle in degrees
8
8
  * @returns {vec2} out
9
9
  * @alias module:modeling/maths/vec2.fromAngleDegrees
10
10
  */
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @param {vec2} out - receiving vector
5
5
  * @param {Number} scalar - the scalar value
6
- * @returns {Vec2} out
6
+ * @returns {vec2} out
7
7
  * @alias module:modeling/maths/vec2.fromScalar
8
8
  */
9
9
  const fromScalar = (out, scalar) => {
@@ -2,4 +2,4 @@ import Vec2 from './type'
2
2
 
3
3
  export default length
4
4
 
5
- declare function length(a: Vec2): number
5
+ declare function length(vector: Vec2): number
@@ -5,6 +5,6 @@
5
5
  * @returns {Number} length
6
6
  * @alias module:modeling/maths/vec2.length
7
7
  */
8
- const length = (a) => Math.hypot(a[0], a[1])
8
+ const length = (vector) => Math.hypot(vector[0], vector[1])
9
9
 
10
10
  module.exports = length
@@ -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 paramerters should update a vec2 with correct values', (t) => {
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 paramerters should update a vec2 with correct values', (t) => {
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 paramerters should update a vec2 with correct values', (t) => {
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]))
@@ -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 degress.
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
@@ -2,4 +2,4 @@ import Vec2 from './type'
2
2
 
3
3
  export default normalize
4
4
 
5
- declare function normalize(out: Vec2, vec: Vec2): Vec2
5
+ declare function normalize(out: Vec2, vector: Vec2): Vec2
@@ -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 paramerters should update a vec2 with correct values', (t) => {
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 paramerters should update a vec2 with correct values', (t) => {
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)
@@ -2,4 +2,4 @@ import Vec2 from './type'
2
2
 
3
3
  export default squaredLength
4
4
 
5
- declare function squaredLength(vec: Vec2): number
5
+ declare function squaredLength(vector: Vec2): number
@@ -5,9 +5,9 @@
5
5
  * @returns {Number} squared length
6
6
  * @alias module:modeling/maths/vec2.squaredLength
7
7
  */
8
- const squaredLength = (a) => {
9
- const x = a[0]
10
- const y = a[1]
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 paramerters should update a vec2 with correct values', (t) => {
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 = (vec) => `[${vec[0].toFixed(7)}, ${vec[1].toFixed(7)}]`
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 paramerters should update a vec2 with correct values', (t) => {
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,
@@ -2,4 +2,4 @@ import Vec3 from './type'
2
2
 
3
3
  export default abs
4
4
 
5
- declare function abs(out: Vec3, vec: Vec3): Vec3
5
+ declare function abs(out: Vec3, vector: Vec3): Vec3
@@ -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 paramerters should update a vec3 with correct values', (t) => {
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]))