@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
@@ -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]))
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * @param {vec3} out - receiving vector
6
6
  * @param {Number} scalar
7
- * @returns {Vec3} out
7
+ * @returns {vec3} out
8
8
  * @alias module:modeling/maths/vec3.fromScalar
9
9
  */
10
10
  const fromScalar = (out, scalar) => {
@@ -3,4 +3,4 @@ import Vec2 from '../vec2/type'
3
3
 
4
4
  export default fromVector2
5
5
 
6
- declare function fromVector2(out: Vec3, vec2: Vec2, z?: number): Vec3
6
+ declare function fromVector2(out: Vec3, vector: Vec2, z?: number): Vec3
@@ -7,9 +7,9 @@
7
7
  * @returns {vec3} out
8
8
  * @alias module:modeling/maths/vec3.fromVec2
9
9
  */
10
- const fromVector2 = (out, vec2, z = 0) => {
11
- out[0] = vec2[0]
12
- out[1] = vec2[1]
10
+ const fromVector2 = (out, vector, z = 0) => {
11
+ out[0] = vector[0]
12
+ out[1] = vector[1]
13
13
  out[2] = z
14
14
  return out
15
15
  }
@@ -2,4 +2,4 @@ import Vec3 from './type'
2
2
 
3
3
  export default length
4
4
 
5
- declare function length(a: Vec3): number
5
+ declare function length(vector: Vec3): number
@@ -5,10 +5,10 @@
5
5
  * @returns {Number} length
6
6
  * @alias module:modeling/maths/vec3.length
7
7
  */
8
- const length = (a) => {
9
- const x = a[0]
10
- const y = a[1]
11
- const z = a[2]
8
+ const length = (vector) => {
9
+ const x = vector[0]
10
+ const y = vector[1]
11
+ const z = vector[2]
12
12
  return Math.hypot(x, y, z)
13
13
  }
14
14
 
@@ -41,5 +41,15 @@ test('vec3: length() should return correct values', (t) => {
41
41
  const length9 = length(vec9)
42
42
  nearlyEqual(t, length9, 3.74165, EPS)
43
43
 
44
+ // huge vector
45
+ const vec10 = fromValues(1e200, 0, 1e200)
46
+ const length10 = length(vec10)
47
+ nearlyEqual(t, length10, Math.SQRT2 * 1e200, EPS)
48
+
49
+ // tiny vector
50
+ const vec11 = fromValues(1e-200, 0, 1e-200)
51
+ const length11 = length(vec11)
52
+ nearlyEqual(t, length11, Math.SQRT2 * 1e-200, EPS)
53
+
44
54
  t.true(true)
45
55
  })
@@ -3,7 +3,7 @@ const { lerp, fromValues } = require('./index')
3
3
 
4
4
  const { compareVectors } = require('../../../test/helpers/index')
5
5
 
6
- test('vec3: lerp() called with three paramerters should update a vec3 with correct values', (t) => {
6
+ test('vec3: lerp() called with three parameters should update a vec3 with correct values', (t) => {
7
7
  const obs1 = fromValues(0, 0, 0)
8
8
  const ret1 = lerp(obs1, [0, 0, 0], [0, 0, 0], 0)
9
9
  t.true(compareVectors(obs1, [0, 0, 0]))
@@ -3,7 +3,7 @@ const { multiply, fromValues } = require('./index')
3
3
 
4
4
  const { compareVectors } = require('../../../test/helpers/index')
5
5
 
6
- test('vec3: multiply() called with three paramerters should update a vec3 with correct values', (t) => {
6
+ test('vec3: multiply() called with three parameters should update a vec3 with correct values', (t) => {
7
7
  const obs1 = fromValues(0, 0, 0)
8
8
  const ret1 = multiply(obs1, [0, 0, 0], [0, 0, 0])
9
9
  t.true(compareVectors(obs1, [0, 0, 0]))
@@ -2,4 +2,4 @@ import Vec3 from './type'
2
2
 
3
3
  export default negate
4
4
 
5
- declare function negate(out: Vec3, vec: Vec3): Vec3
5
+ declare function negate(out: Vec3, vector: Vec3): Vec3
@@ -3,7 +3,7 @@ const { negate, fromValues } = require('./index')
3
3
 
4
4
  const { compareVectors } = require('../../../test/helpers/index')
5
5
 
6
- test('vec3: negate() called with two paramerters should update a vec3 with correct values', (t) => {
6
+ test('vec3: negate() called with two parameters should update a vec3 with correct values', (t) => {
7
7
  const obs1 = fromValues(0, 0, 0)
8
8
  const ret1 = negate(obs1, [0, 0, 0])
9
9
  t.true(compareVectors(obs1, [-0, -0, -0]))
@@ -2,4 +2,4 @@ import Vec3 from './type'
2
2
 
3
3
  export default normalize
4
4
 
5
- declare function normalize(out: Vec3, vec: Vec3): Vec3
5
+ declare function normalize(out: Vec3, vector: Vec3): Vec3
@@ -3,7 +3,7 @@ const { normalize, fromValues } = require('./index')
3
3
 
4
4
  const { compareVectors } = require('../../../test/helpers/index')
5
5
 
6
- test('vec3: normalize() called with two paramerters should update a vec3 with correct values', (t) => {
6
+ test('vec3: normalize() called with two parameters should update a vec3 with correct values', (t) => {
7
7
  const obs1 = fromValues(0, 0, 0)
8
8
  const ret1 = normalize(obs1, [0, 0, 0])
9
9
  t.true(compareVectors(obs1, [0, 0, 0]))
@@ -3,7 +3,7 @@ const { rotateX, fromValues } = require('./index')
3
3
 
4
4
  const { compareVectors } = require('../../../test/helpers/index')
5
5
 
6
- test('vec3: rotateX() called with four paramerters should update a vec3 with correct values', (t) => {
6
+ test('vec3: rotateX() called with four parameters should update a vec3 with correct values', (t) => {
7
7
  const radians = 90 * Math.PI / 180
8
8
 
9
9
  const obs1 = fromValues(0, 0, 0)
@@ -3,7 +3,7 @@ const { rotateY, fromValues } = require('./index')
3
3
 
4
4
  const { compareVectors } = require('../../../test/helpers/index')
5
5
 
6
- test('vec3: rotateY() called with three paramerters should update a vec3 with correct values', (t) => {
6
+ test('vec3: rotateY() called with three parameters should update a vec3 with correct values', (t) => {
7
7
  const radians = 90 * Math.PI / 180
8
8
 
9
9
  const obs1 = fromValues(0, 0, 0)
@@ -3,7 +3,7 @@ const { rotateZ, fromValues } = require('./index')
3
3
 
4
4
  const { compareVectors } = require('../../../test/helpers/index')
5
5
 
6
- test('vec3: rotateZ() called with four paramerters should update a vec3 with correct values', (t) => {
6
+ test('vec3: rotateZ() called with four parameters should update a vec3 with correct values', (t) => {
7
7
  const radians = 90 * Math.PI / 180
8
8
 
9
9
  const obs1 = fromValues(0, 0, 0)
@@ -3,7 +3,7 @@ const { scale, fromValues } = require('./index')
3
3
 
4
4
  const { compareVectors } = require('../../../test/helpers/index')
5
5
 
6
- test('vec3: scale() called with three paramerters should update a vec3 with correct values', (t) => {
6
+ test('vec3: scale() called with three parameters should update a vec3 with correct values', (t) => {
7
7
  const obs1 = fromValues(0, 0, 0)
8
8
  const ret1 = scale(obs1, [0, 0, 0], 0)
9
9
  t.true(compareVectors(obs1, [0, 0, 0]))
@@ -2,4 +2,4 @@ import Vec3 from './type'
2
2
 
3
3
  export default squaredLength
4
4
 
5
- declare function squaredLength(vec: Vec3): number
5
+ declare function squaredLength(vector: Vec3): number
@@ -5,10 +5,10 @@
5
5
  * @returns {Number} squared length
6
6
  * @alias module:modeling/maths/vec3.squaredLength
7
7
  */
8
- const squaredLength = (a) => {
9
- const x = a[0]
10
- const y = a[1]
11
- const z = a[2]
8
+ const squaredLength = (vector) => {
9
+ const x = vector[0]
10
+ const y = vector[1]
11
+ const z = vector[2]
12
12
  return x * x + y * y + z * z
13
13
  }
14
14
 
@@ -3,7 +3,7 @@ const { subtract, fromValues } = require('./index')
3
3
 
4
4
  const { compareVectors } = require('../../../test/helpers/index')
5
5
 
6
- test('vec3: subtract() called with three paramerters should update a vec3 with correct values', (t) => {
6
+ test('vec3: subtract() called with three parameters should update a vec3 with correct values', (t) => {
7
7
  const obs1 = fromValues(0, 0, 0)
8
8
  const ret1 = subtract(obs1, [0, 0, 0], [0, 0, 0])
9
9
  t.true(compareVectors(obs1, [0, 0, 0]))
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Convert the given vector to a representative string.
3
- * @param {vec3} vector - vector of reference
3
+ * @param {vec3} vec - vector of reference
4
4
  * @returns {String} string representation
5
5
  * @alias module:modeling/maths/vec3.toString
6
6
  */
@@ -3,7 +3,7 @@ const { transform, fromValues } = require('./index')
3
3
 
4
4
  const { compareVectors } = require('../../../test/helpers/index')
5
5
 
6
- test('vec3: transform() called with three paramerters should update a vec3 with correct values', (t) => {
6
+ test('vec3: transform() called with three parameters should update a vec3 with correct values', (t) => {
7
7
  const identityMatrix = [
8
8
  1, 0, 0, 0,
9
9
  0, 1, 0, 0,
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Convert the given vector to a representative string.
3
3
  *
4
- * @param {vec4} vector - vector to convert
4
+ * @param {vec4} vec - vector to convert
5
5
  * @returns {String} representative string
6
6
  * @alias module:modeling/maths/vec4.toString
7
7
  */
@@ -3,7 +3,7 @@ const { transform, fromValues } = require('./index')
3
3
 
4
4
  const { compareVectors } = require('../../../test/helpers/index')
5
5
 
6
- test('vec4: transform() called with three paramerters should update a vec4 with correct values', (t) => {
6
+ test('vec4: transform() called with three parameters should update a vec4 with correct values', (t) => {
7
7
  const identityMatrix = [
8
8
  1, 0, 0, 0,
9
9
  0, 1, 0, 0,
@@ -2,7 +2,6 @@ const flatten = require('../utils/flatten')
2
2
 
3
3
  const vec2 = require('../maths/vec2')
4
4
  const vec3 = require('../maths/vec3')
5
- const mat4 = require('../maths/mat4')
6
5
 
7
6
  const geom2 = require('../geometries/geom2')
8
7
  const geom3 = require('../geometries/geom3')
@@ -12,129 +11,86 @@ const poly3 = require('../geometries/poly3')
12
11
  const cache = new WeakMap()
13
12
 
14
13
  /*
15
- * Measure the min and max bounds of the given (path2) geometry.points.
16
- * @return {Array[]} the min and max bounds for the geometry.points
14
+ * Measure the min and max bounds of the given (path2) geometry.
15
+ * @return {Array[]} the min and max bounds for the geometry
17
16
  */
18
- const measureBoundingBoxOfPath2Points = (points) => {
19
- let boundingBox = cache.get(points)
17
+ const measureBoundingBoxOfPath2 = (geometry) => {
18
+ let boundingBox = cache.get(geometry)
20
19
  if (boundingBox) return boundingBox
21
20
 
21
+ const points = path2.toPoints(geometry)
22
+
22
23
  let minpoint
23
24
  if (points.length === 0) {
24
25
  minpoint = vec2.create()
25
26
  } else {
26
27
  minpoint = vec2.clone(points[0])
27
28
  }
28
- const maxpoint = vec2.clone(minpoint)
29
+ let maxpoint = vec2.clone(minpoint)
29
30
 
30
31
  points.forEach((point) => {
31
32
  vec2.min(minpoint, minpoint, point)
32
33
  vec2.max(maxpoint, maxpoint, point)
33
34
  })
34
- boundingBox = [[minpoint[0], minpoint[1], 0], [maxpoint[0], maxpoint[1], 0]]
35
+ minpoint = [minpoint[0], minpoint[1], 0]
36
+ maxpoint = [maxpoint[0], maxpoint[1], 0]
37
+
38
+ boundingBox = [minpoint, maxpoint]
39
+
40
+ cache.set(geometry, boundingBox)
35
41
 
36
- cache.set(points, boundingBox)
37
42
  return boundingBox
38
43
  }
39
44
 
40
45
  /*
41
- * Measure the min and max bounds of the given (path2) geometry.
46
+ * Measure the min and max bounds of the given (geom2) geometry.
42
47
  * @return {Array[]} the min and max bounds for the geometry
43
48
  */
44
- const measureBoundingBoxOfPath2 = (geometry) => {
49
+ const measureBoundingBoxOfGeom2 = (geometry) => {
45
50
  let boundingBox = cache.get(geometry)
46
51
  if (boundingBox) return boundingBox
47
52
 
48
- if (mat4.isOnlyTransformScale(geometry.transforms)) {
49
- // get boundingBox of original points and transform it
50
- boundingBox = transformBoundingBox(measureBoundingBoxOfPath2Points(geometry.points), geometry.transforms)
53
+ const points = geom2.toPoints(geometry)
54
+
55
+ let minpoint
56
+ if (points.length === 0) {
57
+ minpoint = vec2.create()
51
58
  } else {
52
- // transform the points and then caclulate the boundingBox
53
- boundingBox = measureBoundingBoxOfPath2Points(path2.toPoints(geometry))
59
+ minpoint = vec2.clone(points[0])
54
60
  }
61
+ let maxpoint = vec2.clone(minpoint)
55
62
 
56
- cache.set(geometry, boundingBox)
57
- return boundingBox
58
- }
59
-
60
- /*
61
- * Measure the min and max bounds of the given (geom2) geometry.points/sides.
62
- * @return {Array[]} the min and max bounds for the geometr.points/sidesy
63
- */
64
- const measureBoundingBoxOfGeom2Points = ({ points, sides }) => {
65
- const cacheKey = points || sides
66
-
67
- let boundingBox = cache.get(cacheKey)
68
- if (boundingBox) return boundingBox
63
+ points.forEach((point) => {
64
+ vec2.min(minpoint, minpoint, point)
65
+ vec2.max(maxpoint, maxpoint, point)
66
+ })
69
67
 
70
- let minpoint, maxpoint
68
+ minpoint = [minpoint[0], minpoint[1], 0]
69
+ maxpoint = [maxpoint[0], maxpoint[1], 0]
71
70
 
72
- if (points) {
73
- if (points.length === 0) {
74
- minpoint = vec2.create()
75
- } else {
76
- minpoint = vec2.clone(points[0])
77
- }
78
- maxpoint = vec2.clone(minpoint)
71
+ boundingBox = [minpoint, maxpoint]
79
72
 
80
- points.forEach((point) => {
81
- vec2.min(minpoint, minpoint, point)
82
- vec2.max(maxpoint, maxpoint, point)
83
- })
84
- } else { // sides
85
- // to avoid calling costly toPoints, we take advantage of the knowlege how the toPoints works
86
- if (sides.length === 0) {
87
- minpoint = vec2.create()
88
- } else {
89
- minpoint = vec2.clone(sides[0][0])
90
- }
91
- maxpoint = vec2.clone(minpoint)
92
-
93
- sides.forEach((side) => {
94
- vec2.min(minpoint, minpoint, side[0])
95
- vec2.max(maxpoint, maxpoint, side[0])
96
- })
97
- }
98
- boundingBox = [[minpoint[0], minpoint[1], 0], [maxpoint[0], maxpoint[1], 0]]
73
+ cache.set(geometry, boundingBox)
99
74
 
100
- cache.set(cacheKey, boundingBox)
101
75
  return boundingBox
102
76
  }
103
77
 
104
78
  /*
105
- * Measure the min and max bounds of the given (geom2) geometry.
79
+ * Measure the min and max bounds of the given (geom3) geometry.
106
80
  * @return {Array[]} the min and max bounds for the geometry
107
81
  */
108
- const measureBoundingBoxOfGeom2 = (geometry) => {
82
+ const measureBoundingBoxOfGeom3 = (geometry) => {
109
83
  let boundingBox = cache.get(geometry)
110
84
  if (boundingBox) return boundingBox
111
85
 
112
- if (mat4.isOnlyTransformScale(geometry.transforms)) {
113
- // get boundingBox of original points and transform it
114
- boundingBox = transformBoundingBox(measureBoundingBoxOfGeom2Points(geometry), geometry.transforms)
115
- } else {
116
- // transform the points and then caclulate the boundingBox
117
- boundingBox = measureBoundingBoxOfGeom2Points({ points: geom2.toPoints(geometry) })
118
- }
119
-
120
- cache.set(geometry, boundingBox)
121
- return boundingBox
122
- }
123
-
124
- /*
125
- * Measure the min and max bounds of the given (geom3) geometry.polygons.
126
- * @return {Array[]} the min and max bounds for the geometry.polygons
127
- */
128
- const measureBoundingBoxOfGeom3Polygons = (polygons) => {
129
- let boundingBox = cache.get(polygons)
130
- if (boundingBox) return boundingBox
86
+ const polygons = geom3.toPolygons(geometry)
131
87
 
132
- const minpoint = vec3.create()
88
+ let minpoint = vec3.create()
133
89
  if (polygons.length > 0) {
134
90
  const points = poly3.toPoints(polygons[0])
135
91
  vec3.copy(minpoint, points[0])
136
92
  }
137
- const maxpoint = vec3.clone(minpoint)
93
+ let maxpoint = vec3.clone(minpoint)
138
94
 
139
95
  polygons.forEach((polygon) => {
140
96
  poly3.toPoints(polygon).forEach((point) => {
@@ -143,59 +99,13 @@ const measureBoundingBoxOfGeom3Polygons = (polygons) => {
143
99
  })
144
100
  })
145
101
 
146
- boundingBox = [[minpoint[0], minpoint[1], minpoint[2]], [maxpoint[0], maxpoint[1], maxpoint[2]]]
102
+ minpoint = [minpoint[0], minpoint[1], minpoint[2]]
103
+ maxpoint = [maxpoint[0], maxpoint[1], maxpoint[2]]
147
104
 
148
- cache.set(polygons, boundingBox)
149
- return boundingBox
150
- }
151
-
152
- /*
153
- * Measure the min and max bounds of the given (geom3) geometry.
154
- * @return {Array[]} the min and max bounds for the geometry
155
- */
156
- const measureBoundingBoxOfGeom3 = (geometry) => {
157
- let boundingBox = cache.get(geometry)
158
- if (boundingBox) return boundingBox
159
-
160
- if (mat4.isOnlyTransformScale(geometry.transforms)) {
161
- // get boundingBox of original points and transform it
162
- boundingBox = transformBoundingBox(measureBoundingBoxOfGeom3Polygons(geometry.polygons), geometry.transforms)
163
- } else {
164
- // transform the points and then caclulate the boundingBox
165
- boundingBox = measureBoundingBoxOfGeom3Polygons(geom3.toPolygons(geometry))
166
- }
105
+ boundingBox = [minpoint, maxpoint]
167
106
 
168
107
  cache.set(geometry, boundingBox)
169
- return boundingBox
170
- }
171
108
 
172
- /*
173
- * swap values if specific axis value in the second vector has lower value than the axis value in first vector
174
- */
175
- const fixBound = (i, v1, v2) => {
176
- if (v1[i] > v2[i]) {
177
- const tmp = v1[i]
178
- v1[i] = v2[i]
179
- v2[i] = tmp
180
- }
181
- }
182
-
183
- /*
184
- * Transform the given bounding box
185
- */
186
- const transformBoundingBox = (boundingBox, transforms) => {
187
- if (!mat4.isIdentity(transforms)) {
188
- vec3.transform(boundingBox[0], boundingBox[0], transforms)
189
- vec3.transform(boundingBox[1], boundingBox[1], transforms)
190
-
191
- // we now have a new 2 vectors: [v1,v2] => [ [x1,y1,z1], [x2,y2,z2] ]
192
- // transform can move bounding box corner in such way that it is no longer true that
193
- // - v1 = [min(x1,x2),min(y1,y2),min(z1,z2)]
194
- // - v2 = [max(x1,x2),max(y1,y2),max(z1,z2)]
195
- fixBound(0, ...boundingBox) // swap x, if higher value is in first vector
196
- fixBound(1, ...boundingBox) // swap y, if higher value is in first vector
197
- fixBound(2, ...boundingBox) // swap z, if higher value is in first vector
198
- }
199
109
  return boundingBox
200
110
  }
201
111
 
@@ -24,7 +24,7 @@ const measureBoundingSphereOfPath2 = (geometry) => {
24
24
  const points = path2.toPoints(geometry)
25
25
 
26
26
  if (points.length > 0) {
27
- // calculate the centriod of the geometry
27
+ // calculate the centroid of the geometry
28
28
  let numPoints = 0
29
29
  const temp = vec3.create()
30
30
  points.forEach((point) => {
@@ -60,7 +60,7 @@ const measureBoundingSphereOfGeom2 = (geometry) => {
60
60
  const sides = geom2.toSides(geometry)
61
61
 
62
62
  if (sides.length > 0) {
63
- // calculate the centriod of the geometry
63
+ // calculate the centroid of the geometry
64
64
  let numPoints = 0
65
65
  const temp = vec3.create()
66
66
  sides.forEach((side) => {
@@ -96,7 +96,7 @@ const measureBoundingSphereOfGeom3 = (geometry) => {
96
96
  const polygons = geom3.toPolygons(geometry)
97
97
 
98
98
  if (polygons.length > 0) {
99
- // calculate the centriod of the geometry
99
+ // calculate the centroid of the geometry
100
100
  let numPoints = 0
101
101
  polygons.forEach((polygon) => {
102
102
  poly3.toPoints(polygon).forEach((point) => {
@@ -122,7 +122,7 @@ const measureBoundingSphereOfGeom3 = (geometry) => {
122
122
  }
123
123
 
124
124
  /**
125
- * Measure the (aproximate) bounding sphere of the given geometries.
125
+ * Measure the (approximate) bounding sphere of the given geometries.
126
126
  * @see https://en.wikipedia.org/wiki/Bounding_sphere
127
127
  * @param {...Object} geometries - the geometries to measure
128
128
  * @return {Array} the bounding sphere for each geometry, i.e. [centroid, radius]
@@ -61,7 +61,7 @@ const measureCenterOfMassGeom3 = (geometry) => {
61
61
  let totalVolume = 0
62
62
  const vector = vec3.create() // for speed
63
63
  polygons.forEach((polygon) => {
64
- // calculate volume and center of each tetrahedon
64
+ // calculate volume and center of each tetrahedron
65
65
  const vertices = polygon.vertices
66
66
  for (let i = 0; i < vertices.length - 2; i++) {
67
67
  vec3.cross(vector, vertices[i + 1], vertices[i + 2])
@@ -4,9 +4,9 @@ const measureBoundingBox = require('../../measurements/measureBoundingBox')
4
4
 
5
5
  /*
6
6
  * Determine if the given geometries overlap by comparing min and max bounds.
7
- * NOTE: This is used in union for performace gains.
8
- * @param {geom3} geometry1 - geometry for comparision
9
- * @param {geom3} geometry2 - geometry for comparision
7
+ * NOTE: This is used in union for performance gains.
8
+ * @param {geom3} geometry1 - geometry for comparison
9
+ * @param {geom3} geometry2 - geometry for comparison
10
10
  * @returns {boolean} true if the geometries overlap
11
11
  */
12
12
  const mayOverlap = (geometry1, geometry2) => {
@@ -3,16 +3,14 @@ const poly3 = require('../../geometries/poly3')
3
3
 
4
4
  const reTesselateCoplanarPolygons = require('./reTesselateCoplanarPolygons')
5
5
 
6
- // Normals are directional vectors with component values from 0 to 1.0, requiring specialized comparision
7
- // This EPS is derived from a serieas of tests to determine the optimal precision for comparing coplanar polygons,
6
+ // Normals are directional vectors with component values from 0 to 1.0, requiring specialized comparison
7
+ // This EPS is derived from a series of tests to determine the optimal precision for comparing coplanar polygons,
8
8
  // as provided by the sphere primitive at high segmentation
9
9
  // This EPS is for 64 bit Number values
10
10
  const NEPS = 1e-13
11
11
 
12
12
  // Compare two normals (unit vectors) for equality.
13
- const aboutEqualNormals = (a, b) => {
14
- return (Math.abs(a[0] - b[0]) <= NEPS && Math.abs(a[1] - b[1]) <= NEPS && Math.abs(a[2] - b[2]) <= NEPS)
15
- }
13
+ const aboutEqualNormals = (a, b) => (Math.abs(a[0] - b[0]) <= NEPS && Math.abs(a[1] - b[1]) <= NEPS && Math.abs(a[2] - b[2]) <= NEPS)
16
14
 
17
15
  const coplanar = (plane1, plane2) => {
18
16
  // expect the same distance from the origin, within tolerance
@@ -9,7 +9,7 @@ const scissionGeom3 = require('./scissionGeom3')
9
9
  /**
10
10
  * Scission (divide) the given geometry into the component pieces.
11
11
  *
12
- * @param {...Object} geometries - list of geometries
12
+ * @param {...Object} objects - list of geometries
13
13
  * @returns {Array} list of pieces from each geometry
14
14
  * @alias module:modeling/booleans.scission
15
15
  *
@@ -17,7 +17,7 @@ const subtractGeom3 = require('./subtractGeom3')
17
17
  * @alias module:modeling/booleans.subtract
18
18
  *
19
19
  * @example
20
- * let myshape = subtract(cubiod({size: [5,5,5]}), cubiod({size: [5,5,5], center: [5,5,5]}))
20
+ * let myshape = subtract(cuboid({size: [5,5,5]}), cuboid({size: [5,5,5], center: [5,5,5]}))
21
21
  *
22
22
  * @example
23
23
  * +-------+ +-------+
@@ -198,7 +198,7 @@ test('union of one or more geom3 objects produces expected geometry', (t) => {
198
198
 
199
199
  test('union of geom3 with rounding issues #137', (t) => {
200
200
  const geometry1 = center({ relativeTo: [0, 0, -1] }, cuboid({ size: [44, 26, 5] }))
201
- const geometry2 = center({ relativeTo: [0, 0, -4.400001] }, cuboid({ size: [44, 26, 1.8] })) // introduce percision error
201
+ const geometry2 = center({ relativeTo: [0, 0, -4.400001] }, cuboid({ size: [44, 26, 1.8] })) // introduce precision error
202
202
 
203
203
  const obs = union(geometry1, geometry2)
204
204
  const pts = geom3.toPoints(obs)