@jscad/modeling 3.0.4-alpha.0 → 3.0.6-alpha.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 (116) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/jscad-modeling.es.js +2 -2
  3. package/dist/jscad-modeling.min.js +2 -2
  4. package/package.json +4 -4
  5. package/rollup.config.js +1 -1
  6. package/src/colors/colorize.js +17 -1
  7. package/src/colors/hsvToRgb.js +1 -0
  8. package/src/colors/rgbToHsl.js +3 -1
  9. package/src/colors/rgbToHsv.js +1 -0
  10. package/src/curves/bezier/create.js +1 -1
  11. package/src/geometries/geom2/fromPoints.d.ts +4 -0
  12. package/src/geometries/geom2/fromPoints.js +28 -0
  13. package/src/geometries/geom2/fromPoints.test.js +22 -0
  14. package/src/geometries/geom2/index.d.ts +1 -0
  15. package/src/geometries/geom2/index.js +1 -0
  16. package/src/geometries/geom2/transform.js +1 -0
  17. package/src/geometries/geom3/transform.js +1 -0
  18. package/src/geometries/geom3/validate.js +11 -1
  19. package/src/geometries/path2/appendArc.js +19 -25
  20. package/src/geometries/path2/appendBezier.js +8 -11
  21. package/src/geometries/path2/appendPoints.js +21 -3
  22. package/src/geometries/path2/appendPoints.test.js +16 -4
  23. package/src/geometries/path2/close.js +7 -10
  24. package/src/geometries/path2/concat.js +2 -2
  25. package/src/geometries/path2/fromPoints.js +7 -7
  26. package/src/geometries/path2/reverse.js +3 -3
  27. package/src/geometries/path2/transform.js +1 -0
  28. package/src/geometries/path2/validate.js +2 -2
  29. package/src/geometries/path3/clone.d.ts +3 -0
  30. package/src/geometries/path3/clone.js +11 -0
  31. package/src/geometries/path3/close.js +7 -8
  32. package/src/geometries/path3/index.d.ts +1 -0
  33. package/src/geometries/path3/index.js +1 -0
  34. package/src/geometries/path3/transform.js +1 -0
  35. package/src/geometries/poly2/type.d.ts +1 -5
  36. package/src/geometries/slice/earcut/index.js +4 -2
  37. package/src/geometries/slice/earcut/linkedPolygon.js +4 -2
  38. package/src/geometries/slice/fromOutlines.d.ts +5 -0
  39. package/src/geometries/slice/fromOutlines.js +16 -0
  40. package/src/geometries/slice/fromOutlines.test.js +17 -0
  41. package/src/geometries/slice/index.d.ts +1 -1
  42. package/src/geometries/slice/index.js +1 -1
  43. package/src/geometries/slice/transform.js +2 -1
  44. package/src/maths/line2/intersectPointOfLines.js +1 -4
  45. package/src/maths/plane/fromNormalAndPoint.js +4 -6
  46. package/src/maths/plane/fromPoints.js +8 -7
  47. package/src/maths/plane/fromPointsRandom.js +13 -13
  48. package/src/measurements/measureAggregateEpsilon.js +3 -1
  49. package/src/measurements/measureAggregateEpsilon.test.js +1 -1
  50. package/src/measurements/measureArea.js +6 -4
  51. package/src/measurements/measureArea.test.js +4 -1
  52. package/src/measurements/measureBoundingBox.js +16 -2
  53. package/src/measurements/measureBoundingBox.test.js +4 -1
  54. package/src/measurements/measureBoundingSphere.js +38 -29
  55. package/src/measurements/measureBoundingSphere.test.js +4 -1
  56. package/src/measurements/measureCenterOfMass.js +3 -2
  57. package/src/measurements/measureEpsilon.js +4 -2
  58. package/src/operations/booleans/martinez/computeFields.js +6 -0
  59. package/src/operations/booleans/martinez/divideSegment.js +2 -1
  60. package/src/operations/booleans/martinez/fillQueue.js +3 -1
  61. package/src/operations/booleans/martinez/subdivideSegments.js +5 -4
  62. package/src/operations/booleans/subtractGeom3Sub.js +1 -1
  63. package/src/operations/booleans/trees/PolygonTreeNode.js +3 -0
  64. package/src/operations/booleans/trees/splitPolygonByPlane.d.ts +1 -3
  65. package/src/operations/booleans/union.js +1 -1
  66. package/src/operations/extrusions/extrudeFromSlices.js +1 -1
  67. package/src/operations/extrusions/extrudeFromSlices.test.js +1 -1
  68. package/src/operations/extrusions/extrudeHelical.js +2 -1
  69. package/src/operations/extrusions/extrudeLinear.js +1 -1
  70. package/src/operations/extrusions/extrudeLinearGeom2.js +12 -8
  71. package/src/operations/extrusions/extrudeRotate.js +1 -1
  72. package/src/operations/hulls/hull.js +3 -2
  73. package/src/operations/hulls/quickhull/Face.js +8 -3
  74. package/src/operations/hulls/quickhull/QuickHull.js +10 -5
  75. package/src/operations/hulls/quickhull/VertexList.js +2 -1
  76. package/src/operations/hulls/toUniquePoints.js +3 -0
  77. package/src/operations/modifiers/generalize.js +9 -2
  78. package/src/operations/modifiers/reTesselateCoplanarPolygons.js +2 -2
  79. package/src/operations/modifiers/reTesselateCoplanarPolygons.test.js +29 -3
  80. package/src/operations/modifiers/retessellate.js +1 -0
  81. package/src/operations/modifiers/snap.js +22 -3
  82. package/src/operations/modifiers/snap.test.js +12 -2
  83. package/src/operations/offsets/offsetGeom3.test.js +2 -2
  84. package/src/operations/transforms/align.js +2 -1
  85. package/src/operations/transforms/align.test.js +1 -1
  86. package/src/operations/transforms/mirror.js +6 -2
  87. package/src/operations/transforms/rotate.js +6 -2
  88. package/src/operations/transforms/scale.js +6 -2
  89. package/src/operations/transforms/transform.js +6 -2
  90. package/src/operations/transforms/transform.test.js +16 -5
  91. package/src/operations/transforms/translate.js +12 -4
  92. package/src/primitives/arc.js +14 -14
  93. package/src/primitives/circle.js +10 -9
  94. package/src/primitives/cube.js +5 -6
  95. package/src/primitives/cuboid.js +6 -6
  96. package/src/primitives/cylinder.js +8 -8
  97. package/src/primitives/cylinderElliptic.js +11 -11
  98. package/src/primitives/ellipse.js +12 -12
  99. package/src/primitives/ellipsoid.js +8 -8
  100. package/src/primitives/geodesicSphere.js +6 -6
  101. package/src/primitives/line.js +2 -0
  102. package/src/primitives/polygon.js +6 -7
  103. package/src/primitives/polyhedron.js +7 -8
  104. package/src/primitives/rectangle.js +6 -6
  105. package/src/primitives/roundedCuboid.js +8 -8
  106. package/src/primitives/roundedCylinder.js +9 -9
  107. package/src/primitives/roundedRectangle.js +8 -8
  108. package/src/primitives/sphere.js +7 -8
  109. package/src/primitives/square.js +6 -6
  110. package/src/primitives/star.js +12 -14
  111. package/src/primitives/torus.js +11 -11
  112. package/src/primitives/triangle.js +7 -6
  113. package/src/utils/areAllShapesTheSameType.js +4 -0
  114. package/test/helpers/nearlyEqual.js +1 -0
  115. package/src/geometries/slice/fromGeom2.d.ts +0 -5
  116. package/src/geometries/slice/fromGeom2.js +0 -17
@@ -10,6 +10,7 @@ import { isGT, isGTE } from './commonChecks.js'
10
10
 
11
11
  /**
12
12
  * Construct a torus by revolving a small circle (inner) about the circumference of a large (outer) circle.
13
+ *
13
14
  * @param {object} [options] - options for construction
14
15
  * @param {number} [options.innerRadius=1] - radius of small (inner) circle
15
16
  * @param {number} [options.outerRadius=4] - radius of large (outer) circle
@@ -24,17 +25,16 @@ import { isGT, isGTE } from './commonChecks.js'
24
25
  * @example
25
26
  * let myshape = torus({ innerRadius: 10, outerRadius: 100 })
26
27
  */
27
- export const torus = (options) => {
28
- const defaults = {
29
- innerRadius: 1,
30
- innerSegments: 32,
31
- outerRadius: 4,
32
- outerSegments: 32,
33
- innerRotation: 0,
34
- startAngle: 0,
35
- outerRotation: TAU
36
- }
37
- const { innerRadius, innerSegments, outerRadius, outerSegments, innerRotation, startAngle, outerRotation } = Object.assign({}, defaults, options)
28
+ export const torus = (options = {}) => {
29
+ const {
30
+ innerRadius = 1,
31
+ innerSegments = 32,
32
+ outerRadius = 4,
33
+ outerSegments = 32,
34
+ innerRotation = 0,
35
+ startAngle = 0,
36
+ outerRotation = TAU
37
+ } = options
38
38
 
39
39
  if (!isGT(innerRadius, 0)) throw new Error('innerRadius must be greater than zero')
40
40
  if (!isGTE(innerSegments, 3)) throw new Error('innerSegments must be three or more')
@@ -115,7 +115,9 @@ const createTriangle = (A, B, C, a, b, c) => {
115
115
 
116
116
  /**
117
117
  * Construct a triangle in two dimensional space from the given options.
118
+ *
118
119
  * The triangle is always constructed CCW from the origin, [0, 0, 0].
120
+ *
119
121
  * @see https://www.mathsisfun.com/algebra/trig-solving-triangles.html
120
122
  * @param {object} [options] - options for construction
121
123
  * @param {string} [options.type='SSS'] - type of triangle to construct; A ~ angle, S ~ side
@@ -126,12 +128,11 @@ const createTriangle = (A, B, C, a, b, c) => {
126
128
  * @example
127
129
  * let myshape = triangle({type: 'AAS', values: [degToRad(62), degToRad(35), 7]})
128
130
  */
129
- export const triangle = (options) => {
130
- const defaults = {
131
- type: 'SSS',
132
- values: [1, 1, 1]
133
- }
134
- let { type, values } = Object.assign({}, defaults, options)
131
+ export const triangle = (options = {}) => {
132
+ let {
133
+ type = 'SSS',
134
+ values = [1, 1, 1]
135
+ } = options
135
136
 
136
137
  if (typeof (type) !== 'string') throw new Error('triangle type must be a string')
137
138
  type = type.toUpperCase()
@@ -2,6 +2,8 @@
2
2
  import * as geom2 from '../geometries/geom2/index.js'
3
3
  import * as geom3 from '../geometries/geom3/index.js'
4
4
  import * as path2 from '../geometries/path2/index.js'
5
+ import * as path3 from '../geometries/path3/index.js'
6
+ import * as slice from '../geometries/slice/index.js'
5
7
 
6
8
  /**
7
9
  * @param {Array} shapes - list of shapes to compare
@@ -15,6 +17,8 @@ export const areAllShapesTheSameType = (shapes) => {
15
17
  if (geom2.isA(shape)) currentType = 1
16
18
  if (geom3.isA(shape)) currentType = 2
17
19
  if (path2.isA(shape)) currentType = 3
20
+ if (path3.isA(shape)) currentType = 4
21
+ if (slice.isA(shape)) currentType = 5
18
22
 
19
23
  if (previousType && currentType !== previousType) return false
20
24
  previousType = currentType
@@ -29,4 +29,5 @@ export const nearlyEqual = (t, a, b, epsilon, failMessage) => {
29
29
  failMessage = failMessage === undefined ? 'Numbers outside of epsilon' : failMessage
30
30
  t.fail(failMessage + '(' + a + ',' + b + ')')
31
31
  }
32
+ return true
32
33
  }
@@ -1,5 +0,0 @@
1
- import type { Geom2 } from '../geom2/type.d.ts'
2
-
3
- import type { Slice } from './type.d.ts'
4
-
5
- export function fromGeom2(geometry: Geom2): Slice
@@ -1,17 +0,0 @@
1
- import * as vec3 from '../../maths/vec3/index.js'
2
- import { toOutlines } from '../geom2/index.js'
3
-
4
- import { create } from './create.js'
5
-
6
- /**
7
- * Create a slice from a geom2.
8
- *
9
- * @param {object} geometry - the 2D geometry to create a slice from
10
- * @returns {Slice} a new slice
11
- * @alias module:modeling/slice.fromGeom2
12
- */
13
- export const fromGeom2 = (geometry) => {
14
- // Convert from 2D points to 3D vertices
15
- const contours = toOutlines(geometry).map((outline) => outline.map((point) => vec3.fromVec2(vec3.create(), point)))
16
- return create(contours)
17
- }