@jscad/modeling 2.9.4 → 2.10.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 (106) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +12 -2
  3. package/dist/jscad-modeling.min.js +148 -151
  4. package/package.json +2 -2
  5. package/src/colors/colorize.d.ts +6 -5
  6. package/src/geometries/geom2/type.d.ts +3 -2
  7. package/src/geometries/geom3/type.d.ts +3 -2
  8. package/src/geometries/path2/appendArc.js +6 -5
  9. package/src/geometries/path2/appendArc.test.js +3 -1
  10. package/src/geometries/path2/appendBezier.js +2 -1
  11. package/src/geometries/path2/appendPoints.js +3 -12
  12. package/src/geometries/path2/appendPoints.test.js +16 -0
  13. package/src/geometries/path2/concat.js +9 -8
  14. package/src/geometries/path2/concat.test.js +13 -7
  15. package/src/geometries/path2/transform.js +1 -1
  16. package/src/geometries/path2/type.d.ts +3 -2
  17. package/src/geometries/poly3/measureBoundingSphere.d.ts +2 -2
  18. package/src/geometries/poly3/measureBoundingSphere.js +46 -8
  19. package/src/geometries/poly3/measureBoundingSphere.test.js +16 -26
  20. package/src/geometries/poly3/type.d.ts +3 -2
  21. package/src/geometries/types.d.ts +4 -2
  22. package/src/index.d.ts +1 -0
  23. package/src/maths/constants.js +10 -0
  24. package/src/maths/mat4/fromRotation.js +10 -8
  25. package/src/maths/mat4/fromTaitBryanRotation.js +9 -7
  26. package/src/maths/mat4/fromXRotation.js +5 -3
  27. package/src/maths/mat4/fromYRotation.js +5 -3
  28. package/src/maths/mat4/fromZRotation.js +5 -3
  29. package/src/maths/mat4/invert.test.js +5 -2
  30. package/src/maths/mat4/isOnlyTransformScale.js +1 -1
  31. package/src/maths/mat4/isOnlyTransformScale.test.js +3 -1
  32. package/src/maths/mat4/rotate.js +9 -5
  33. package/src/maths/mat4/rotateX.js +4 -2
  34. package/src/maths/mat4/rotateY.js +4 -2
  35. package/src/maths/mat4/rotateZ.js +4 -2
  36. package/src/maths/mat4/translate.test.js +2 -3
  37. package/src/maths/rotation.test.js +5 -2
  38. package/src/maths/utils/index.d.ts +1 -0
  39. package/src/maths/utils/index.js +2 -0
  40. package/src/{utils → maths/utils}/trigonometry.d.ts +0 -0
  41. package/src/{utils → maths/utils}/trigonometry.js +7 -7
  42. package/src/{utils → maths/utils}/trigonometry.test.js +10 -8
  43. package/src/maths/vec2/distance.js +1 -1
  44. package/src/maths/vec2/fromAngleDegrees.js +1 -1
  45. package/src/maths/vec2/fromAngleRadians.js +4 -2
  46. package/src/maths/vec2/fromAngleRadians.test.js +4 -1
  47. package/src/maths/vec2/length.js +1 -1
  48. package/src/maths/vec2/length.test.js +0 -10
  49. package/src/maths/vec2/normal.js +3 -1
  50. package/src/maths/vec2/rotate.test.js +4 -1
  51. package/src/maths/vec3/angle.js +2 -2
  52. package/src/maths/vec3/angle.test.js +0 -12
  53. package/src/maths/vec3/distance.js +1 -1
  54. package/src/maths/vec3/length.js +1 -1
  55. package/src/maths/vec3/length.test.js +0 -10
  56. package/src/maths/vec3/rotateX.test.js +4 -1
  57. package/src/maths/vec3/rotateY.test.js +4 -1
  58. package/src/maths/vec3/rotateZ.test.js +4 -1
  59. package/src/operations/booleans/trees/PolygonTreeNode.js +2 -2
  60. package/src/operations/expansions/expand.test.js +3 -1
  61. package/src/operations/expansions/expandShell.js +4 -4
  62. package/src/operations/expansions/offsetFromPoints.js +2 -2
  63. package/src/operations/extrusions/extrudeFromSlices.test.js +3 -2
  64. package/src/operations/extrusions/extrudeLinear.test.js +5 -3
  65. package/src/operations/extrusions/extrudeRectangular.js +1 -1
  66. package/src/operations/extrusions/extrudeRectangular.test.js +5 -3
  67. package/src/operations/extrusions/extrudeRotate.js +14 -13
  68. package/src/operations/extrusions/extrudeRotate.test.js +49 -47
  69. package/src/operations/extrusions/project.test.js +2 -2
  70. package/src/operations/extrusions/slice/calculatePlane.test.js +3 -2
  71. package/src/operations/extrusions/slice/index.js +2 -0
  72. package/src/operations/extrusions/slice/repair.js +1 -1
  73. package/src/operations/modifiers/generalize.d.ts +12 -0
  74. package/src/operations/modifiers/generalize.test.js +3 -1
  75. package/src/operations/modifiers/index.d.ts +2 -0
  76. package/src/operations/modifiers/insertTjunctions.js +34 -35
  77. package/src/operations/modifiers/snap.d.ts +6 -0
  78. package/src/operations/modifiers/snap.test.js +5 -3
  79. package/src/operations/transforms/rotate.js +1 -1
  80. package/src/operations/transforms/rotate.test.js +13 -11
  81. package/src/operations/transforms/transform.js +1 -1
  82. package/src/primitives/arc.js +8 -8
  83. package/src/primitives/arc.test.js +9 -8
  84. package/src/primitives/circle.js +4 -2
  85. package/src/primitives/circle.test.js +12 -4
  86. package/src/primitives/cylinderElliptic.js +13 -11
  87. package/src/primitives/cylinderElliptic.test.js +9 -2
  88. package/src/primitives/ellipse.js +11 -11
  89. package/src/primitives/ellipse.test.js +12 -4
  90. package/src/primitives/ellipsoid.js +4 -3
  91. package/src/primitives/geodesicSphere.js +3 -2
  92. package/src/primitives/roundedCuboid.js +10 -8
  93. package/src/primitives/roundedCylinder.js +4 -4
  94. package/src/primitives/roundedRectangle.js +5 -5
  95. package/src/primitives/star.js +3 -2
  96. package/src/primitives/torus.js +4 -2
  97. package/src/primitives/torus.test.js +11 -5
  98. package/src/primitives/triangle.test.js +2 -1
  99. package/src/utils/degToRad.test.js +5 -5
  100. package/src/utils/index.d.ts +0 -1
  101. package/src/utils/index.js +1 -3
  102. package/src/utils/radToDeg.test.js +6 -6
  103. package/src/utils/radiusToSegments.js +6 -4
  104. package/src/utils/radiusToSegments.test.js +5 -3
  105. package/src/maths/mat4/constants.d.ts +0 -1
  106. package/src/maths/mat4/constants.js +0 -5
@@ -2,6 +2,8 @@ const test = require('ava')
2
2
 
3
3
  const geom3 = require('../geometries/geom3')
4
4
  const measureBoundingBox = require('../measurements/measureBoundingBox')
5
+ const { TAU } = require('../maths/constants')
6
+
5
7
  const comparePoints = require('../../test/helpers/comparePoints')
6
8
 
7
9
  const { torus } = require('./index')
@@ -15,7 +17,6 @@ test('torus (defaults)', (t) => {
15
17
 
16
18
  const bounds = measureBoundingBox(obs)
17
19
  const expectedBounds = [[-5, -5, -1], [5, 5, 1]]
18
- t.notThrows(() => geom3.validate(obs))
19
20
  t.true(comparePoints(bounds, expectedBounds), 'Bounding box was not as expected: ' + JSON.stringify(bounds))
20
21
  })
21
22
 
@@ -27,24 +28,29 @@ test('torus (simple options)', (t) => {
27
28
 
28
29
  const bounds = measureBoundingBox(obs)
29
30
  const expectedBounds = [[-5.5, -5.5, -0.5], [5.5, 5.5, 0.5]]
30
- t.notThrows(() => geom3.validate(obs))
31
31
  t.true(comparePoints(bounds, expectedBounds), 'Bounding box was not as expected: ' + JSON.stringify(bounds))
32
32
  })
33
33
 
34
34
  test('torus (complex options)', (t) => {
35
- const obs = torus({ innerRadius: 1, outerRadius: 5, innerSegments: 32, outerSegments: 72, startAngle: Math.PI / 2, outerRotation: Math.PI / 2 })
35
+ const obs = torus({ innerRadius: 1, outerRadius: 5, innerSegments: 32, outerSegments: 72, startAngle: TAU / 4, outerRotation: TAU / 4 })
36
36
  const pts = geom3.toPoints(obs)
37
37
  t.notThrows(() => geom3.validate(obs))
38
38
  t.is(pts.length, 1212)
39
39
 
40
40
  const bounds = measureBoundingBox(obs)
41
41
  const expectedBounds = [[-6, 0, -1], [0, 6, 1]]
42
- t.notThrows(() => geom3.validate(obs))
43
42
  t.true(comparePoints(bounds, expectedBounds), 'Bounding box was not as expected: ' + JSON.stringify(bounds))
44
43
  })
45
44
 
45
+ test('torus (startAngle)', (t) => {
46
+ const obs = torus({ startAngle: 1, endAngle: 1 + TAU })
47
+ const pts = geom3.toPoints(obs)
48
+ t.notThrows(() => geom3.validate(obs))
49
+ t.is(pts.length, 2048)
50
+ })
51
+
46
52
  test('torus (square by square)', (t) => {
47
- const obs = torus({ innerSegments: 4, outerSegments: 4, innerRotation: Math.PI / 2 })
53
+ const obs = torus({ innerSegments: 4, outerSegments: 4, innerRotation: TAU / 4 })
48
54
 
49
55
  const bounds = measureBoundingBox(obs)
50
56
  const expectedBounds = [[-5, -5, -1], [5, 5, 1]]
@@ -4,6 +4,7 @@ const { triangle } = require('./index')
4
4
 
5
5
  const degToRad = require('../utils/degToRad')
6
6
  const geom2 = require('../geometries/geom2')
7
+ const { TAU } = require('../maths/constants')
7
8
 
8
9
  const comparePoints = require('../../test/helpers/comparePoints')
9
10
 
@@ -36,7 +37,7 @@ test('triangle (options)', (t) => {
36
37
  t.true(comparePoints(obs, exp))
37
38
 
38
39
  // test AAA
39
- geometry = triangle({ type: 'AAA', values: [Math.PI / 2, Math.PI / 4, Math.PI / 4] })
40
+ geometry = triangle({ type: 'AAA', values: [TAU / 4, TAU / 8, TAU / 8] })
40
41
  obs = geom2.toPoints(geometry)
41
42
  exp = [
42
43
  [0, 0],
@@ -1,19 +1,19 @@
1
1
  const test = require('ava')
2
2
 
3
+ const { TAU } = require('../maths/constants')
4
+
3
5
  const { degToRad } = require('./index')
4
6
 
5
7
  test('utils: degToRad() should return correct values', (t) => {
6
- const radians = Math.PI / 180
7
-
8
8
  const obs1 = degToRad(0)
9
9
  t.true(obs1 === 0)
10
10
 
11
11
  const obs2 = degToRad(90)
12
- t.true(obs2 === (90 * radians))
12
+ t.true(obs2 === (TAU / 4))
13
13
 
14
14
  const obs3 = degToRad(180)
15
- t.true(obs3 === (180 * radians))
15
+ t.true(obs3 === (TAU / 2))
16
16
 
17
17
  const obs4 = degToRad(270)
18
- t.true(obs4 === (270 * radians))
18
+ t.true(obs4 === (TAU * 0.75))
19
19
  })
@@ -5,6 +5,5 @@ export { default as fnNumberSort } from './fnNumberSort'
5
5
  export { default as insertSorted } from './insertSorted'
6
6
  export { default as radiusToSegments } from './radiusToSegments'
7
7
  export { default as radToDeg } from './radToDeg'
8
- export * from './trigonometry'
9
8
 
10
9
  export as namespace utils
@@ -6,12 +6,10 @@
6
6
  */
7
7
  module.exports = {
8
8
  areAllShapesTheSameType: require('./areAllShapesTheSameType'),
9
- cos: require('./trigonometry').cos,
10
9
  degToRad: require('./degToRad'),
11
10
  flatten: require('./flatten'),
12
11
  fnNumberSort: require('./fnNumberSort'),
13
12
  insertSorted: require('./insertSorted'),
14
13
  radiusToSegments: require('./radiusToSegments'),
15
- radToDeg: require('./radToDeg'),
16
- sin: require('./trigonometry').sin
14
+ radToDeg: require('./radToDeg')
17
15
  }
@@ -1,19 +1,19 @@
1
1
  const test = require('ava')
2
2
 
3
+ const { TAU } = require('../maths/constants')
4
+
3
5
  const { radToDeg } = require('./index')
4
6
 
5
7
  test('utils: radToDeg() should return correct values', (t) => {
6
- const radians = Math.PI / 180
7
-
8
- const obs1 = radToDeg(radians * 0)
8
+ const obs1 = radToDeg(0)
9
9
  t.true(obs1 === 0)
10
10
 
11
- const obs2 = radToDeg(radians * 90)
11
+ const obs2 = radToDeg(TAU / 4)
12
12
  t.true(obs2 === 90)
13
13
 
14
- const obs3 = radToDeg(radians * 180)
14
+ const obs3 = radToDeg(TAU / 2)
15
15
  t.true(obs3 === 180)
16
16
 
17
- const obs4 = radToDeg(radians * 270)
17
+ const obs4 = radToDeg(TAU * 0.75)
18
18
  t.true(obs4 === 270)
19
19
  })
@@ -1,14 +1,16 @@
1
+ const { TAU } = require('../maths/constants')
2
+
1
3
  /**
2
4
  * Calculate the number of segments from the given radius based on minimum length or angle.
3
5
  * @param {Number} radius - radius of the requested shape
4
- * @param {Number} minimumLength - minimum length of segments; 0 > length
5
- * @param {Number} minimumAngle - minimum angle (radians) between segments; 0 > angle < Math.PI * 2
6
+ * @param {Number} minimumLength - minimum length of segments; length > 0
7
+ * @param {Number} minimumAngle - minimum angle (radians) between segments; 0 > angle < TAU
6
8
  * @returns {Number} number of segments to complete the radius
7
9
  * @alias module:modeling/utils.radiusToSegments
8
10
  */
9
11
  const radiusToSegments = (radius, minimumLength, minimumAngle) => {
10
- const ss = minimumLength > 0 ? radius * 2 * Math.PI / minimumLength : 0
11
- const as = minimumAngle > 0 ? Math.PI * 2 / minimumAngle : 0
12
+ const ss = minimumLength > 0 ? radius * TAU / minimumLength : 0
13
+ const as = minimumAngle > 0 ? TAU / minimumAngle : 0
12
14
  // minimum segments is four(4) for round primitives
13
15
  return Math.ceil(Math.max(ss, as, 4))
14
16
  }
@@ -1,5 +1,7 @@
1
1
  const test = require('ava')
2
2
 
3
+ const { TAU } = require('../maths/constants')
4
+
3
5
  const { radiusToSegments } = require('./index')
4
6
 
5
7
  test('utils: radiusToSegments() should return correct values', (t) => {
@@ -14,13 +16,13 @@ test('utils: radiusToSegments() should return correct values', (t) => {
14
16
  segments = radiusToSegments(100.0, 2.0, 0)
15
17
  t.is(segments, 315)
16
18
 
17
- segments = radiusToSegments(100.0, 0, Math.PI * 2 / 20.0)
19
+ segments = radiusToSegments(100.0, 0, TAU / 20.0)
18
20
  t.is(segments, 20.0)
19
21
 
20
22
  // test minimum length versus minimum angle
21
- segments = radiusToSegments(100.0, 31, Math.PI * 2 / 20.0)
23
+ segments = radiusToSegments(100.0, 31, TAU / 20.0)
22
24
  t.is(segments, 21.0)
23
25
 
24
- segments = radiusToSegments(100.0, 32, Math.PI * 2 / 20.0)
26
+ segments = radiusToSegments(100.0, 32, TAU / 20.0)
25
27
  t.is(segments, 20.0)
26
28
  })
@@ -1 +0,0 @@
1
- export const EPSILON: number
@@ -1,5 +0,0 @@
1
- const EPSILON = 0.000001
2
-
3
- module.exports = {
4
- EPSILON
5
- }