@jscad/modeling 2.7.1 → 2.9.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 (194) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/jscad-modeling.min.js +174 -144
  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/tangentAt.js +2 -2
  7. package/src/curves/bezier/tangentAt.test.js +1 -1
  8. package/src/curves/bezier/valueAt.test.js +1 -1
  9. package/src/geometries/geom2/index.js +10 -0
  10. package/src/geometries/geom2/isA.js +2 -2
  11. package/src/geometries/geom2/toCompactBinary.js +4 -4
  12. package/src/geometries/geom2/toOutlines.js +6 -11
  13. package/src/geometries/geom2/toString.js +1 -1
  14. package/src/geometries/geom2/transform.test.js +1 -1
  15. package/src/geometries/geom3/fromCompactBinary.js +1 -1
  16. package/src/geometries/geom3/index.js +17 -0
  17. package/src/geometries/geom3/invert.js +2 -2
  18. package/src/geometries/geom3/isA.js +2 -2
  19. package/src/geometries/geom3/toCompactBinary.js +4 -4
  20. package/src/geometries/geom3/toPoints.js +1 -0
  21. package/src/geometries/geom3/toString.js +1 -1
  22. package/src/geometries/geom3/transform.test.js +1 -1
  23. package/src/geometries/index.js +8 -1
  24. package/src/geometries/path2/eachPoint.js +3 -3
  25. package/src/geometries/path2/index.js +11 -0
  26. package/src/geometries/path2/isA.js +2 -2
  27. package/src/geometries/path2/reverse.js +4 -4
  28. package/src/geometries/path2/toCompactBinary.js +6 -6
  29. package/src/geometries/path2/toString.js +1 -1
  30. package/src/geometries/path2/transform.test.js +1 -1
  31. package/src/geometries/poly2/arePointsInside.test.js +1 -1
  32. package/src/geometries/poly2/index.js +6 -0
  33. package/src/geometries/poly3/index.js +7 -1
  34. package/src/geometries/poly3/invert.js +7 -1
  35. package/src/geometries/poly3/isA.js +2 -2
  36. package/src/geometries/poly3/isConvex.js +2 -2
  37. package/src/geometries/poly3/measureArea.js +4 -4
  38. package/src/geometries/poly3/measureBoundingBox.js +2 -2
  39. package/src/geometries/poly3/measureBoundingSphere.js +2 -2
  40. package/src/geometries/poly3/measureSignedVolume.js +4 -4
  41. package/src/geometries/poly3/toPoints.js +2 -2
  42. package/src/geometries/poly3/toString.js +2 -2
  43. package/src/geometries/poly3/transform.js +2 -2
  44. package/src/maths/index.js +1 -1
  45. package/src/maths/line2/equals.js +2 -2
  46. package/src/maths/line2/fromValues.js +2 -2
  47. package/src/maths/line2/intersectPointOfLines.js +1 -1
  48. package/src/maths/line2/intersectPointOfLines.test.js +1 -1
  49. package/src/maths/line2/reverse.test.js +1 -1
  50. package/src/maths/line2/transform.test.js +1 -1
  51. package/src/maths/line3/equals.js +2 -2
  52. package/src/maths/line3/reverse.test.js +1 -1
  53. package/src/maths/line3/transform.test.js +1 -1
  54. package/src/maths/mat4/fromRotation.js +1 -1
  55. package/src/maths/mat4/fromVectorRotation.js +1 -1
  56. package/src/maths/mat4/fromVectorRotation.test.js +1 -1
  57. package/src/maths/mat4/identity.test.js +1 -1
  58. package/src/maths/mat4/invert.js +18 -18
  59. package/src/maths/mat4/isIdentity.js +1 -1
  60. package/src/maths/mat4/isIdentity.test.js +0 -2
  61. package/src/maths/mat4/isMirroring.js +4 -4
  62. package/src/maths/mat4/isMirroring.test.js +1 -1
  63. package/src/maths/mat4/leftMultiplyVec3.js +2 -2
  64. package/src/maths/mat4/rotate.js +1 -1
  65. package/src/maths/mat4/toString.js +2 -2
  66. package/src/maths/mat4/translate.test.js +1 -1
  67. package/src/maths/plane/flip.test.js +1 -1
  68. package/src/maths/plane/fromPoints.d.ts +1 -1
  69. package/src/maths/plane/fromPoints.js +1 -3
  70. package/src/maths/plane/signedDistanceToPoint.js +1 -1
  71. package/src/maths/plane/transform.test.js +1 -1
  72. package/src/maths/utils/aboutEqualNormals.js +2 -2
  73. package/src/maths/vec2/abs.d.ts +1 -1
  74. package/src/maths/vec2/add.test.js +1 -1
  75. package/src/maths/vec2/angleDegrees.d.ts +1 -1
  76. package/src/maths/vec2/angleRadians.d.ts +1 -1
  77. package/src/maths/vec2/create.js +1 -1
  78. package/src/maths/vec2/cross.test.js +1 -1
  79. package/src/maths/vec2/divide.test.js +1 -1
  80. package/src/maths/vec2/fromAngleDegrees.js +1 -1
  81. package/src/maths/vec2/fromScalar.js +1 -1
  82. package/src/maths/vec2/length.d.ts +1 -1
  83. package/src/maths/vec2/length.js +1 -1
  84. package/src/maths/vec2/length.test.js +10 -0
  85. package/src/maths/vec2/lerp.test.js +1 -1
  86. package/src/maths/vec2/multiply.test.js +1 -1
  87. package/src/maths/vec2/negate.test.js +1 -1
  88. package/src/maths/vec2/normal.js +1 -1
  89. package/src/maths/vec2/normalize.d.ts +1 -1
  90. package/src/maths/vec2/normalize.test.js +1 -1
  91. package/src/maths/vec2/rotate.test.js +1 -1
  92. package/src/maths/vec2/squaredLength.d.ts +1 -1
  93. package/src/maths/vec2/squaredLength.js +3 -3
  94. package/src/maths/vec2/subtract.test.js +1 -1
  95. package/src/maths/vec2/toString.js +1 -1
  96. package/src/maths/vec2/transform.test.js +1 -1
  97. package/src/maths/vec3/abs.d.ts +1 -1
  98. package/src/maths/vec3/add.test.js +1 -1
  99. package/src/maths/vec3/angle.js +2 -2
  100. package/src/maths/vec3/angle.test.js +17 -0
  101. package/src/maths/vec3/cross.test.js +1 -1
  102. package/src/maths/vec3/divide.test.js +1 -1
  103. package/src/maths/vec3/fromScalar.js +1 -1
  104. package/src/maths/vec3/fromVec2.d.ts +1 -1
  105. package/src/maths/vec3/fromVec2.js +3 -3
  106. package/src/maths/vec3/length.d.ts +1 -1
  107. package/src/maths/vec3/length.js +4 -4
  108. package/src/maths/vec3/length.test.js +10 -0
  109. package/src/maths/vec3/lerp.test.js +1 -1
  110. package/src/maths/vec3/multiply.test.js +1 -1
  111. package/src/maths/vec3/negate.d.ts +1 -1
  112. package/src/maths/vec3/negate.test.js +1 -1
  113. package/src/maths/vec3/normalize.d.ts +1 -1
  114. package/src/maths/vec3/normalize.test.js +1 -1
  115. package/src/maths/vec3/rotateX.test.js +1 -1
  116. package/src/maths/vec3/rotateY.test.js +1 -1
  117. package/src/maths/vec3/rotateZ.test.js +1 -1
  118. package/src/maths/vec3/scale.test.js +1 -1
  119. package/src/maths/vec3/squaredLength.d.ts +1 -1
  120. package/src/maths/vec3/squaredLength.js +4 -4
  121. package/src/maths/vec3/subtract.test.js +1 -1
  122. package/src/maths/vec3/toString.js +1 -1
  123. package/src/maths/vec3/transform.test.js +1 -1
  124. package/src/maths/vec4/toString.js +1 -1
  125. package/src/maths/vec4/transform.test.js +1 -1
  126. package/src/measurements/measureBoundingSphere.js +4 -4
  127. package/src/measurements/measureCenterOfMass.js +1 -1
  128. package/src/operations/booleans/mayOverlap.js +3 -3
  129. package/src/operations/booleans/retessellate.js +3 -5
  130. package/src/operations/booleans/scission.js +1 -1
  131. package/src/operations/booleans/subtract.js +1 -1
  132. package/src/operations/booleans/union.test.js +1 -1
  133. package/src/operations/booleans/unionGeom3Sub.js +1 -1
  134. package/src/operations/expansions/expand.js +2 -2
  135. package/src/operations/expansions/expand.test.js +3 -35
  136. package/src/operations/expansions/expandShell.js +24 -18
  137. package/src/operations/expansions/offset.js +1 -1
  138. package/src/operations/expansions/offset.test.js +25 -89
  139. package/src/operations/expansions/offsetFromPoints.js +11 -6
  140. package/src/operations/extrusions/earcut/assignHoles.js +87 -0
  141. package/src/operations/extrusions/earcut/assignHoles.test.js +28 -0
  142. package/src/operations/extrusions/earcut/eliminateHoles.js +131 -0
  143. package/src/operations/extrusions/earcut/index.js +252 -0
  144. package/src/operations/extrusions/earcut/linkedList.js +58 -0
  145. package/src/operations/extrusions/earcut/linkedListSort.js +54 -0
  146. package/src/operations/extrusions/earcut/linkedPolygon.js +197 -0
  147. package/src/operations/extrusions/earcut/polygonHierarchy.js +64 -0
  148. package/src/operations/extrusions/earcut/triangle.js +16 -0
  149. package/src/operations/extrusions/extrudeFromSlices.js +10 -3
  150. package/src/operations/extrusions/extrudeFromSlices.test.js +33 -23
  151. package/src/operations/extrusions/extrudeLinear.js +11 -6
  152. package/src/operations/extrusions/extrudeLinear.test.js +77 -27
  153. package/src/operations/extrusions/extrudeLinearGeom2.js +5 -2
  154. package/src/operations/extrusions/extrudeLinearPath2.js +24 -0
  155. package/src/operations/extrusions/extrudeRectangular.js +1 -1
  156. package/src/operations/extrusions/extrudeRectangular.test.js +7 -7
  157. package/src/operations/extrusions/extrudeRotate.test.js +19 -27
  158. package/src/operations/extrusions/project.js +1 -1
  159. package/src/operations/extrusions/slice/calculatePlane.js +7 -4
  160. package/src/operations/extrusions/slice/isA.js +2 -2
  161. package/src/operations/extrusions/slice/repairSlice.js +47 -0
  162. package/src/operations/extrusions/slice/toPolygons.js +24 -60
  163. package/src/operations/hulls/hull.test.js +1 -1
  164. package/src/operations/hulls/hullChain.js +1 -1
  165. package/src/operations/hulls/hullGeom2.js +1 -1
  166. package/src/operations/hulls/hullPath2.js +6 -4
  167. package/src/operations/hulls/hullPath2.test.js +16 -0
  168. package/src/operations/hulls/hullPoints2.test.js +1 -1
  169. package/src/operations/hulls/quickhull/QuickHull.js +2 -2
  170. package/src/operations/modifiers/edges.js +2 -4
  171. package/src/operations/modifiers/generalize.js +4 -7
  172. package/src/operations/modifiers/snap.test.js +3 -3
  173. package/src/operations/transforms/align.d.ts +1 -1
  174. package/src/operations/transforms/center.js +17 -17
  175. package/src/operations/transforms/mirror.js +11 -11
  176. package/src/operations/transforms/rotate.js +12 -12
  177. package/src/operations/transforms/scale.js +19 -19
  178. package/src/operations/transforms/transform.js +3 -3
  179. package/src/operations/transforms/translate.js +14 -14
  180. package/src/primitives/arc.js +1 -1
  181. package/src/primitives/cylinderElliptic.test.js +0 -2
  182. package/src/primitives/ellipsoid.js +1 -1
  183. package/src/primitives/ellipsoid.test.js +0 -2
  184. package/src/primitives/geodesicSphere.d.ts +0 -1
  185. package/src/primitives/geodesicSphere.js +2 -2
  186. package/src/primitives/polyhedron.js +1 -1
  187. package/src/primitives/roundedCylinder.js +1 -1
  188. package/src/primitives/torus.d.ts +0 -1
  189. package/src/primitives/torus.test.js +1 -1
  190. package/src/primitives/triangle.js +1 -1
  191. package/src/text/vectorText.js +2 -2
  192. package/src/utils/padArrayToLength.js +1 -1
  193. package/test/helpers/comparePolygons.js +1 -3
  194. package/test/helpers/nearlyEqual.js +2 -6
@@ -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,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
 
@@ -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]))
@@ -15,8 +15,8 @@ const angle = (a, b) => {
15
15
  const bx = b[0]
16
16
  const by = b[1]
17
17
  const bz = b[2]
18
- const mag1 = Math.sqrt(ax * ax + ay * ay + az * az)
19
- const mag2 = Math.sqrt(bx * bx + by * by + bz * bz)
18
+ const mag1 = Math.hypot(ax, ay, az)
19
+ const mag2 = Math.hypot(bx, by, bz)
20
20
  const mag = mag1 * mag2
21
21
  const cosine = mag && dot(a, b) / mag
22
22
  return Math.acos(Math.min(Math.max(cosine, -1), 1))
@@ -25,5 +25,22 @@ test('vec3: angle() should return correct values', (t) => {
25
25
  const angle4 = angle(veca4, vec4)
26
26
  nearlyEqual(t, angle4, 3.14159, EPS)
27
27
 
28
+ const vec5a = fromValues(1, 0, 0)
29
+ const vec5b = fromValues(1, 1, 0)
30
+ const angle5 = angle(vec5a, vec5b)
31
+ nearlyEqual(t, angle5, 0.785398, EPS)
32
+
33
+ // tiny values
34
+ const vec6a = fromValues(1, 0, 0)
35
+ const vec6b = fromValues(1e-200, 1e-200, 0)
36
+ const angle6 = angle(vec6a, vec6b)
37
+ nearlyEqual(t, angle6, 0.785398, EPS)
38
+
39
+ // huge values
40
+ const vec7a = fromValues(1, 0, 0)
41
+ const vec7b = fromValues(1e200, 1e200, 0)
42
+ const angle7 = angle(vec7a, vec7b)
43
+ nearlyEqual(t, angle7, 0.785398, EPS)
44
+
28
45
  t.true(true)
29
46
  })
@@ -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 paramerters should update a vec3 with correct values', (t) => {
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 paramerters should update a vec3 with correct values', (t) => {
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]))