@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
@@ -145,8 +145,6 @@ test('ellipsoid (options)', (t) => {
145
145
  // test segments
146
146
  obs = ellipsoid({ segments: 8 })
147
147
  pts = geom3.toPoints(obs)
148
- exp = [
149
- ]
150
148
  t.is(pts.length, 32)
151
149
 
152
150
  obs = ellipsoid({ center: [-3, 5, 7], segments: 8 })
@@ -1,4 +1,3 @@
1
- import Vec3 from '../maths/vec3/type'
2
1
  import Geom3 from '../geometries/geom3/type'
3
2
 
4
3
  export default geodesicSphere
@@ -79,7 +79,7 @@ const geodesicSphere = (options) => {
79
79
 
80
80
  // -- normalize
81
81
  for (let k = 0; k < 3; k++) {
82
- const r = Math.sqrt(q[k][0] * q[k][0] + q[k][1] * q[k][1] + q[k][2] * q[k][2])
82
+ const r = Math.hypot(q[k][0], q[k][1], q[k][2])
83
83
  for (let l = 0; l < 3; l++) {
84
84
  q[k][l] /= r
85
85
  }
@@ -95,7 +95,7 @@ const geodesicSphere = (options) => {
95
95
 
96
96
  // -- normalize
97
97
  for (let k = 0; k < 3; k++) {
98
- const r = Math.sqrt(q[k][0] * q[k][0] + q[k][1] * q[k][1] + q[k][2] * q[k][2])
98
+ const r = Math.hypot(q[k][0], q[k][1], q[k][2])
99
99
  for (let l = 0; l < 3; l++) {
100
100
  q[k][l] /= r
101
101
  }
@@ -11,7 +11,7 @@ const { isNumberArray } = require('./commonChecks')
11
11
  * @param {Array} options.points - list of points in 3D space
12
12
  * @param {Array} options.faces - list of faces, where each face is a set of indexes into the points
13
13
  * @param {Array} [options.colors=undefined] - list of RGBA colors to apply to each face
14
- * @param {Array} [options.orientation='outward'] - orientation of faces
14
+ * @param {String} [options.orientation='outward'] - orientation of faces
15
15
  * @returns {geom3} new 3D geometry
16
16
  * @alias module:modeling/primitives.polyhedron
17
17
  *
@@ -11,7 +11,7 @@ const { isGT, isGTE, isNumberArray } = require('./commonChecks')
11
11
  * Construct a Z axis-aligned solid cylinder in three dimensional space with rounded ends.
12
12
  * @param {Object} [options] - options for construction
13
13
  * @param {Array} [options.center=[0,0,0]] - center of cylinder
14
- * @param {Array} [options.height=2] - height of cylinder
14
+ * @param {Number} [options.height=2] - height of cylinder
15
15
  * @param {Number} [options.radius=1] - radius of cylinder
16
16
  * @param {Number} [options.roundRadius=0.2] - radius of rounded edges
17
17
  * @param {Number} [options.segments=32] - number of segments to create per full rotation
@@ -1,4 +1,3 @@
1
- import Vec3 from '../maths/vec3/type'
2
1
  import Geom3 from '../geometries/geom3/type'
3
2
 
4
3
  export default torus
@@ -30,7 +30,7 @@ test('torus (Simple options)', (t) => {
30
30
  test('torus (complex options)', (t) => {
31
31
  const obs = torus({ innerRadius: 1, outerRadius: 5, innerSegments: 32, outerSegments: 72, startAngle: Math.PI / 2, outerRotation: Math.PI / 2 })
32
32
  const pts = geom3.toPoints(obs)
33
- t.is(pts.length, 1154)
33
+ t.is(pts.length, 1212)
34
34
 
35
35
  const bounds = measureBoundingBox(obs)
36
36
  const expectedBounds = [[-6, 0, -1], [0, 6, 1]]
@@ -119,7 +119,7 @@ const createTriangle = (A, B, C, a, b, c) => {
119
119
  * The triangle is always constructed CCW from the origin, [0, 0, 0].
120
120
  * @see https://www.mathsisfun.com/algebra/trig-solving-triangles.html
121
121
  * @param {Object} [options] - options for construction
122
- * @param {String} [options.type='SSS' - type of triangle to construct; A ~ angle, S ~ side
122
+ * @param {String} [options.type='SSS'] - type of triangle to construct; A ~ angle, S ~ side
123
123
  * @param {Array} [options.values=[1,1,1]] - angle (radians) of corners or length of sides
124
124
  * @returns {geom2} new 2D geometry
125
125
  * @alias module:modeling/primitives.triangle
@@ -26,7 +26,7 @@ const translateLine = (options, line) => {
26
26
  * @param {Float} [options.height=21] - font size (uppercase height)
27
27
  * @param {Float} [options.lineSpacing=1.4] - line spacing expressed as a percentage of font size
28
28
  * @param {Float} [options.letterSpacing=1] - extra letter spacing expressed as a percentage of font size
29
- * @param {String} [options.align='left'] - multi-line text alignement: left, center or right
29
+ * @param {String} [options.align='left'] - multi-line text alignment: left, center, right
30
30
  * @param {Float} [options.extrudeOffset=0] - width of the extrusion that will be applied (manually) after the creation of the character
31
31
  * @param {String} [options.input='?'] - ascii string (ignored/overwrited if provided as seconds parameter)
32
32
  * @param {String} [text='?'] - ascii string
@@ -47,7 +47,7 @@ const vectorText = (options, text) => {
47
47
  xOffset, yOffset, input, font, height, align, extrudeOffset, lineSpacing, letterSpacing
48
48
  } = vectorParams(options, text)
49
49
  let [x, y] = [xOffset, yOffset]
50
- let [i, il, char, vect, width, diff] = []
50
+ let i, il, char, vect, width, diff
51
51
  let line = { width: 0, segments: [] }
52
52
  const lines = []
53
53
  let output = []
@@ -3,7 +3,7 @@
3
3
  * @param {Array} anArray - the source array to copy into the result.
4
4
  * @param {*} padding - the value to add to the new array to reach the desired length.
5
5
  * @param {Number} targetLength - The desired length of the return array.
6
- * @returns {Array} an array of at least 'targetLength" length
6
+ * @returns {Array} an array of at least 'targetLength' length
7
7
  * @alias module:modeling/utils.padArrayToLength
8
8
  */
9
9
  const padArrayToLength = (anArray, padding, targetLength) => {
@@ -8,9 +8,7 @@ const compareVectors = require('./compareVectors')
8
8
  */
9
9
  const comparePolygons = (poly1, poly2) => {
10
10
  if (poly1.vertices.length === poly2.vertices.length) {
11
- return poly1.vertices.reduce((valid, vertex, index) => {
12
- return valid && compareVectors(poly1.vertices[index], poly2.vertices[index])
13
- }, true)
11
+ return poly1.vertices.reduce((valid, vertex, index) => valid && compareVectors(poly1.vertices[index], poly2.vertices[index]), true)
14
12
  }
15
13
  return false
16
14
  }
@@ -1,7 +1,6 @@
1
1
  // Compare two numeric values for near equality.
2
2
  // the given test is fails if the numeric values are outside the given epsilon
3
3
  const nearlyEqual = (t, a, b, epsilon, failMessage) => {
4
- // console.log('nearEqual(t,'+a+','+b+','+epsilon+')')
5
4
  if (a === b) { // shortcut, also handles infinities and NaNs
6
5
  return true
7
6
  }
@@ -10,11 +9,9 @@ const nearlyEqual = (t, a, b, epsilon, failMessage) => {
10
9
  const absB = Math.abs(b)
11
10
  const diff = Math.abs(a - b)
12
11
  if (Number.isNaN(diff)) {
13
- return false
12
+ failMessage = failMessage === undefined ? 'difference is not a number' : failMessage
13
+ t.fail(failMessage + '(' + a + ',' + b + ')')
14
14
  }
15
- // console.log(absA)
16
- // console.log(absB)
17
- // console.log(diff)
18
15
  if (a === 0 || b === 0 || diff < Number.EPSILON) {
19
16
  // a or b is zero or both are extremely close to it
20
17
  // relative error is less meaningful here
@@ -25,7 +22,6 @@ const nearlyEqual = (t, a, b, epsilon, failMessage) => {
25
22
  }
26
23
  // use relative error
27
24
  const relative = (diff / Math.min((absA + absB), Number.MAX_VALUE))
28
- // console.log(relative)
29
25
  if (relative > epsilon) {
30
26
  failMessage = failMessage === undefined ? 'Numbers outside of epsilon' : failMessage
31
27
  t.fail(failMessage + '(' + a + ',' + b + ')')