@jscad/modeling 3.0.3-alpha.0 → 3.0.4-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 (148) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/jscad-modeling.es.js +2 -7
  3. package/dist/jscad-modeling.min.js +2 -7
  4. package/package.json +6 -7
  5. package/rollup.config.js +8 -4
  6. package/src/curves/bezier/arcLengthToT.js +1 -1
  7. package/src/curves/bezier/create.js +1 -1
  8. package/src/curves/bezier/index.js +7 -7
  9. package/src/curves/bezier/length.js +1 -1
  10. package/src/curves/bezier/lengths.js +2 -1
  11. package/src/curves/bezier/tangentAt.js +1 -1
  12. package/src/curves/bezier/valueAt.js +1 -1
  13. package/src/curves/index.js +3 -3
  14. package/src/geometries/geom2/applyTransforms.js +3 -1
  15. package/src/geometries/geom2/clone.js +5 -1
  16. package/src/geometries/geom2/create.js +4 -14
  17. package/src/geometries/geom2/fromSides.js +4 -2
  18. package/src/geometries/geom2/index.js +21 -5
  19. package/src/geometries/geom2/isA.js +5 -1
  20. package/src/geometries/geom2/reverse.js +4 -2
  21. package/src/geometries/geom2/toOutlines.js +2 -1
  22. package/src/geometries/geom2/toPoints.js +5 -2
  23. package/src/geometries/geom2/toSides.js +4 -3
  24. package/src/geometries/geom2/toString.js +3 -2
  25. package/src/geometries/geom2/transform.js +4 -2
  26. package/src/geometries/geom2/validate.js +6 -2
  27. package/src/geometries/geom3/clone.js +5 -1
  28. package/src/geometries/geom3/create.js +5 -19
  29. package/src/geometries/geom3/fromVertices.js +13 -1
  30. package/src/geometries/geom3/fromVerticesConvex.js +1 -1
  31. package/src/geometries/geom3/index.d.ts +1 -0
  32. package/src/geometries/geom3/index.js +26 -4
  33. package/src/geometries/geom3/invert.js +5 -1
  34. package/src/geometries/geom3/isA.js +5 -1
  35. package/src/geometries/geom3/isConvex.d.ts +3 -0
  36. package/src/geometries/geom3/isConvex.js +65 -0
  37. package/src/geometries/geom3/isConvex.test.js +44 -0
  38. package/src/geometries/geom3/toPolygons.js +4 -2
  39. package/src/geometries/geom3/toString.js +3 -2
  40. package/src/geometries/geom3/toVertices.js +8 -4
  41. package/src/geometries/geom3/transform.js +5 -2
  42. package/src/geometries/geom3/validate.js +6 -2
  43. package/src/geometries/index.js +9 -7
  44. package/src/geometries/path2/appendArc.js +7 -5
  45. package/src/geometries/path2/appendArc.test.js +11 -15
  46. package/src/geometries/path2/appendBezier.js +6 -4
  47. package/src/geometries/path2/appendPoints.js +4 -2
  48. package/src/geometries/path2/applyTransforms.js +3 -0
  49. package/src/geometries/path2/clone.js +5 -1
  50. package/src/geometries/path2/close.js +5 -1
  51. package/src/geometries/path2/concat.js +3 -2
  52. package/src/geometries/path2/create.js +4 -15
  53. package/src/geometries/path2/equals.js +12 -7
  54. package/src/geometries/path2/fromPoints.js +5 -3
  55. package/src/geometries/path2/index.js +21 -4
  56. package/src/geometries/path2/isA.js +5 -1
  57. package/src/geometries/path2/reverse.js +4 -2
  58. package/src/geometries/path2/toPoints.js +5 -3
  59. package/src/geometries/path2/toString.js +3 -2
  60. package/src/geometries/path2/transform.js +4 -2
  61. package/src/geometries/path2/validate.js +5 -1
  62. package/src/geometries/path3/applyTransforms.js +1 -1
  63. package/src/geometries/path3/close.js +4 -2
  64. package/src/geometries/path3/concat.js +2 -3
  65. package/src/geometries/path3/create.js +4 -20
  66. package/src/geometries/path3/equals.js +4 -2
  67. package/src/geometries/path3/fromVertices.js +2 -3
  68. package/src/geometries/path3/index.js +17 -1
  69. package/src/geometries/path3/isA.js +4 -2
  70. package/src/geometries/path3/reverse.js +2 -3
  71. package/src/geometries/path3/toString.js +2 -3
  72. package/src/geometries/path3/toVertices.js +2 -3
  73. package/src/geometries/path3/transform.js +2 -3
  74. package/src/geometries/path3/validate.js +6 -3
  75. package/src/geometries/poly2/arePointsInside.js +4 -1
  76. package/src/geometries/poly2/clone.js +4 -1
  77. package/src/geometries/poly2/create.js +2 -9
  78. package/src/geometries/poly2/index.js +16 -4
  79. package/src/geometries/poly2/isA.js +5 -1
  80. package/src/geometries/poly2/isConvex.js +5 -1
  81. package/src/geometries/poly2/isSimple.js +5 -1
  82. package/src/geometries/poly2/measureArea.js +4 -1
  83. package/src/geometries/poly2/measureBoundingBox.js +6 -1
  84. package/src/geometries/poly2/reverse.js +4 -1
  85. package/src/geometries/poly2/toPoints.js +6 -1
  86. package/src/geometries/poly2/toString.js +5 -1
  87. package/src/geometries/poly2/transform.js +5 -1
  88. package/src/geometries/poly2/validate.js +6 -2
  89. package/src/geometries/poly3/clone.js +4 -1
  90. package/src/geometries/poly3/create.js +3 -11
  91. package/src/geometries/poly3/fromVerticesAndPlane.js +3 -1
  92. package/src/geometries/poly3/index.js +19 -4
  93. package/src/geometries/poly3/invert.js +4 -1
  94. package/src/geometries/poly3/isA.js +5 -1
  95. package/src/geometries/poly3/isConvex.js +5 -1
  96. package/src/geometries/poly3/measureArea.js +5 -1
  97. package/src/geometries/poly3/measureBoundingBox.js +4 -1
  98. package/src/geometries/poly3/measureBoundingSphere.js +4 -3
  99. package/src/geometries/poly3/measureSignedVolume.js +6 -1
  100. package/src/geometries/poly3/plane.js +6 -0
  101. package/src/geometries/poly3/toString.js +5 -1
  102. package/src/geometries/poly3/toVertices.js +6 -1
  103. package/src/geometries/poly3/transform.js +5 -1
  104. package/src/geometries/poly3/validate.js +6 -2
  105. package/src/geometries/slice/calculatePlane.js +3 -3
  106. package/src/geometries/slice/clone.js +4 -1
  107. package/src/geometries/slice/create.js +5 -10
  108. package/src/geometries/slice/equals.js +5 -1
  109. package/src/geometries/slice/fromGeom2.js +1 -1
  110. package/src/geometries/slice/fromVertices.js +3 -3
  111. package/src/geometries/slice/index.js +19 -4
  112. package/src/geometries/slice/isA.js +5 -1
  113. package/src/geometries/slice/reverse.js +5 -2
  114. package/src/geometries/slice/toEdges.js +5 -3
  115. package/src/geometries/slice/toPolygons.js +5 -1
  116. package/src/geometries/slice/toString.js +5 -1
  117. package/src/geometries/slice/toVertices.js +5 -3
  118. package/src/geometries/slice/transform.js +4 -3
  119. package/src/geometries/slice/validate.js +3 -2
  120. package/src/index.d.ts +1 -0
  121. package/src/index.js +4 -0
  122. package/src/maths/constants.js +11 -7
  123. package/src/maths/index.js +2 -1
  124. package/src/maths/mat4/isOnlyTransformScale.js +1 -1
  125. package/src/operations/booleans/index.js +2 -0
  126. package/src/operations/booleans/intersect.js +0 -1
  127. package/src/operations/booleans/scission.js +0 -1
  128. package/src/operations/booleans/trees/splitLineSegmentByPlane.js +1 -4
  129. package/src/operations/booleans/trees/splitPolygonByPlane.test.js +138 -0
  130. package/src/operations/booleans/unionGeom3.test.js +35 -0
  131. package/src/operations/extrusions/extrudeFromSlices.js +15 -5
  132. package/src/operations/extrusions/extrudeRotate.js +2 -1
  133. package/src/operations/extrusions/extrudeRotate.test.js +34 -0
  134. package/src/operations/extrusions/extrudeWalls.test.js +60 -0
  135. package/src/operations/minkowski/index.d.ts +1 -0
  136. package/src/operations/minkowski/index.js +15 -0
  137. package/src/operations/minkowski/minkowskiSum.d.ts +4 -0
  138. package/src/operations/minkowski/minkowskiSum.js +223 -0
  139. package/src/operations/minkowski/minkowskiSum.test.js +199 -0
  140. package/src/operations/modifiers/reTesselateCoplanarPolygons.js +10 -3
  141. package/src/operations/modifiers/reTesselateCoplanarPolygons.test.js +36 -1
  142. package/src/operations/modifiers/retessellate.js +4 -2
  143. package/src/operations/modifiers/snap.test.js +24 -15
  144. package/src/operations/offsets/offsetGeom3.test.js +5 -7
  145. package/src/primitives/arc.js +2 -2
  146. package/src/primitives/arc.test.js +104 -113
  147. package/src/utils/flatten.js +1 -1
  148. package/src/utils/flatten.test.js +94 -0
@@ -0,0 +1,199 @@
1
+ import test from 'ava'
2
+
3
+ import { geom3 } from '../../geometries/index.js'
4
+ import { cuboid, sphere, torus } from '../../primitives/index.js'
5
+ import { subtract } from '../booleans/index.js'
6
+ import { measureBoundingBox } from '../../measurements/index.js'
7
+
8
+ import { minkowskiSum } from './index.js'
9
+
10
+ test('minkowskiSum: throws for non-geom3 inputs', (t) => {
11
+ t.throws(() => minkowskiSum('invalid', cuboid()), { message: /requires geom3/ })
12
+ t.throws(() => minkowskiSum(cuboid(), 'invalid'), { message: /requires geom3/ })
13
+ })
14
+
15
+ test('minkowskiSum: throws for wrong number of geometries', (t) => {
16
+ t.throws(() => minkowskiSum(), { message: /exactly two/ })
17
+ t.throws(() => minkowskiSum(cuboid()), { message: /exactly two/ })
18
+ t.throws(() => minkowskiSum(cuboid(), cuboid(), cuboid()), { message: /exactly two/ })
19
+ })
20
+
21
+ test('minkowskiSum: cube + cube produces correct bounds', (t) => {
22
+ // Cube1: size 10 (±5 from origin)
23
+ // Cube2: size 4 (±2 from origin)
24
+ // Minkowski sum should be size 14 (±7 from origin)
25
+ const cube1 = cuboid({ size: [10, 10, 10] })
26
+ const cube2 = cuboid({ size: [4, 4, 4] })
27
+
28
+ const result = minkowskiSum(cube1, cube2)
29
+
30
+ t.notThrows(() => geom3.validate(result))
31
+
32
+ const bounds = measureBoundingBox(result)
33
+ // Allow small tolerance for floating point
34
+ t.true(Math.abs(bounds[0][0] - (-7)) < 0.001)
35
+ t.true(Math.abs(bounds[0][1] - (-7)) < 0.001)
36
+ t.true(Math.abs(bounds[0][2] - (-7)) < 0.001)
37
+ t.true(Math.abs(bounds[1][0] - 7) < 0.001)
38
+ t.true(Math.abs(bounds[1][1] - 7) < 0.001)
39
+ t.true(Math.abs(bounds[1][2] - 7) < 0.001)
40
+ })
41
+
42
+ test('minkowskiSum: cube + sphere produces correct bounds', (t) => {
43
+ // Cube: size 10 (±5 from origin)
44
+ // Sphere: radius 2
45
+ // Minkowski sum should be ±7 from origin
46
+ const cube = cuboid({ size: [10, 10, 10] })
47
+ const sph = sphere({ radius: 2, segments: 16 })
48
+
49
+ const result = minkowskiSum(cube, sph)
50
+
51
+ t.notThrows(() => geom3.validate(result))
52
+
53
+ const bounds = measureBoundingBox(result)
54
+ // Allow small tolerance
55
+ t.true(Math.abs(bounds[0][0] - (-7)) < 0.1)
56
+ t.true(Math.abs(bounds[1][0] - 7) < 0.1)
57
+ })
58
+
59
+ test('minkowskiSum: sphere + sphere produces correct bounds', (t) => {
60
+ // Sphere1: radius 3
61
+ // Sphere2: radius 2
62
+ // Minkowski sum should be a sphere-like shape with radius ~5
63
+ const sph1 = sphere({ radius: 3, segments: 16 })
64
+ const sph2 = sphere({ radius: 2, segments: 16 })
65
+
66
+ const result = minkowskiSum(sph1, sph2)
67
+
68
+ t.notThrows(() => geom3.validate(result))
69
+
70
+ const bounds = measureBoundingBox(result)
71
+ // Should be approximately ±5
72
+ t.true(Math.abs(bounds[0][0] - (-5)) < 0.2)
73
+ t.true(Math.abs(bounds[1][0] - 5) < 0.2)
74
+ })
75
+
76
+ test('minkowskiSum: empty geometry returns empty', (t) => {
77
+ const empty = geom3.create()
78
+ const cube = cuboid({ size: [10, 10, 10] })
79
+
80
+ const result = minkowskiSum(empty, cube)
81
+
82
+ t.notThrows(() => geom3.validate(result))
83
+ t.is(geom3.toPolygons(result).length, 0)
84
+ })
85
+
86
+ test('minkowskiSum: result is convex', (t) => {
87
+ const cube = cuboid({ size: [10, 10, 10] })
88
+ const sph = sphere({ radius: 2, segments: 12 })
89
+
90
+ const result = minkowskiSum(cube, sph)
91
+
92
+ t.notThrows(() => geom3.validate(result))
93
+ t.true(geom3.isConvex(result))
94
+ })
95
+
96
+ // Non-convex tests
97
+
98
+ test('minkowskiSum: non-convex + convex produces valid geometry', (t) => {
99
+ // Create L-shaped non-convex geometry
100
+ const big = cuboid({ size: [10, 10, 10] })
101
+ const corner = cuboid({ size: [6, 6, 12], center: [3, 3, 0] })
102
+ const lShape = subtract(big, corner)
103
+
104
+ t.false(geom3.isConvex(lShape))
105
+
106
+ const sph = sphere({ radius: 1, segments: 8 })
107
+
108
+ const result = minkowskiSum(lShape, sph)
109
+
110
+ t.true(geom3.toPolygons(result).length > 0)
111
+ t.true(geom3.isA(result))
112
+ })
113
+
114
+ test('minkowskiSum: non-convex + convex produces correct bounds', (t) => {
115
+ // Cube with hole through it
116
+ const cube = cuboid({ size: [10, 10, 10] })
117
+ const hole = cuboid({ size: [4, 4, 20] })
118
+ const cubeWithHole = subtract(cube, hole)
119
+
120
+ t.false(geom3.isConvex(cubeWithHole))
121
+
122
+ // Offset by sphere of radius 1
123
+ const sph = sphere({ radius: 1, segments: 8 })
124
+ const result = minkowskiSum(cubeWithHole, sph)
125
+
126
+ t.true(geom3.isA(result))
127
+
128
+ const bounds = measureBoundingBox(result)
129
+
130
+ // Original cube is ±5, plus sphere radius 1 = ±6
131
+ t.true(Math.abs(bounds[0][0] - (-6)) < 0.2)
132
+ t.true(Math.abs(bounds[1][0] - 6) < 0.2)
133
+ })
134
+
135
+ test('minkowskiSum: convex + non-convex swaps operands', (t) => {
136
+ // Minkowski sum is commutative, so A⊕B = B⊕A
137
+ const cube = cuboid({ size: [10, 10, 10] })
138
+ const hole = cuboid({ size: [4, 4, 20] })
139
+ const cubeWithHole = subtract(cube, hole)
140
+
141
+ const sph = sphere({ radius: 1, segments: 8 })
142
+
143
+ // convex + non-convex should work (swaps internally)
144
+ const result = minkowskiSum(sph, cubeWithHole)
145
+
146
+ t.true(geom3.isA(result))
147
+ t.true(geom3.toPolygons(result).length > 0)
148
+ })
149
+
150
+ test('minkowskiSum: throws for two non-convex geometries', (t) => {
151
+ const cube1 = cuboid({ size: [10, 10, 10] })
152
+ const hole1 = cuboid({ size: [4, 4, 20] })
153
+ const nonConvex1 = subtract(cube1, hole1)
154
+
155
+ const cube2 = cuboid({ size: [8, 8, 8] })
156
+ const hole2 = cuboid({ size: [3, 3, 16] })
157
+ const nonConvex2 = subtract(cube2, hole2)
158
+
159
+ t.throws(() => minkowskiSum(nonConvex1, nonConvex2), { message: /two non-convex/ })
160
+ })
161
+
162
+ test('minkowskiSum: torus + sphere preserves hole (face-local apex)', (t) => {
163
+ // Torus with innerRadius=3 (tube radius) and outerRadius=8 (distance to tube center)
164
+ // At z=0, the torus extends from radius 5 to 11 (8-3 to 8+3)
165
+ // Adding sphere of radius 1 should give 4 to 12
166
+ const torusShape = torus({
167
+ innerRadius: 3,
168
+ outerRadius: 8,
169
+ innerSegments: 16,
170
+ outerSegments: 24
171
+ })
172
+
173
+ const sph = sphere({ radius: 1, segments: 8 })
174
+
175
+ t.false(geom3.isConvex(torusShape))
176
+
177
+ const result = minkowskiSum(torusShape, sph)
178
+
179
+ t.true(geom3.isA(result))
180
+ t.true(geom3.toPolygons(result).length > 0)
181
+
182
+ // Check that the hole is preserved by examining vertices at z≈0
183
+ const polygons = geom3.toPolygons(result)
184
+ let minRadius = Infinity
185
+
186
+ for (const poly of polygons) {
187
+ for (const v of poly.vertices) {
188
+ if (Math.abs(v[2]) < 0.5) {
189
+ const r = Math.sqrt(v[0] * v[0] + v[1] * v[1])
190
+ if (r < minRadius) minRadius = r
191
+ }
192
+ }
193
+ }
194
+
195
+ // With face-local apex, hole should be preserved
196
+ // Inner radius should be around 4 (8-3-1 = 4)
197
+ // If centroid-based (buggy), hole would be filled and minRadius would be ~0
198
+ t.true(minRadius > 3, `hole should be preserved, got minRadius=${minRadius}`)
199
+ })
@@ -121,6 +121,7 @@ export const reTesselateCoplanarPolygons = (sourcePolygons) => {
121
121
  // at the left and right side of the polygon
122
122
  // Iterate over all polygons that have a corner at this y coordinate:
123
123
  const polygonIndexesWithCorner = yCoordinateToPolygonIndexes.get(yCoordinate)
124
+ let removeCount = 0 // track removals to filter at end (avoids O(n²) splice)
124
125
  for (let activePolygonIndex = 0; activePolygonIndex < activePolygons.length; ++activePolygonIndex) {
125
126
  const activePolygon = activePolygons[activePolygonIndex]
126
127
  const polygonIndex = activePolygon.polygonIndex
@@ -144,9 +145,9 @@ export const reTesselateCoplanarPolygons = (sourcePolygons) => {
144
145
  }
145
146
  if ((newLeftVertexIndex !== activePolygon.leftVertexIndex) && (newLeftVertexIndex === newRightVertexIndex)) {
146
147
  // We have increased leftVertexIndex or decreased rightVertexIndex, and now they point to the same vertex
147
- // This means that this is the bottom point of the polygon. We'll remove it:
148
- activePolygons.splice(activePolygonIndex, 1)
149
- --activePolygonIndex
148
+ // This means that this is the bottom point of the polygon, so Mark it for removal
149
+ activePolygon.remove = true
150
+ removeCount++
150
151
  } else {
151
152
  activePolygon.leftVertexIndex = newLeftVertexIndex
152
153
  activePolygon.rightVertexIndex = newRightVertexIndex
@@ -161,6 +162,12 @@ export const reTesselateCoplanarPolygons = (sourcePolygons) => {
161
162
  }
162
163
  } // if polygon has corner here
163
164
  } // for activePolygonIndex
165
+
166
+ // Filter out marked polygons in single pass (O(n) instead of O(n²) splice)
167
+ if (removeCount > 0) {
168
+ activePolygons = activePolygons.filter((p) => !p.remove)
169
+ }
170
+
164
171
  let nextYcoordinate
165
172
  if (yIndex >= yCoordinates.length - 1) {
166
173
  // last row, all polygons must be finished here:
@@ -16,7 +16,7 @@ const rotatePoly3 = (angles, polygon) => {
16
16
  return poly3.transform(matrix, polygon)
17
17
  }
18
18
 
19
- test.only('retessellateCoplanarPolygons: should merge coplanar polygons', (t) => {
19
+ test('retessellateCoplanarPolygons: should merge coplanar polygons', (t) => {
20
20
  const polyA = poly3.create([[-5, -5, 0], [5, -5, 0], [5, 5, 0], [-5, 5, 0]])
21
21
  const polyB = poly3.create([[5, -5, 0], [8, 0, 0], [5, 5, 0]])
22
22
  const polyC = poly3.create([[-5, 5, 0], [-8, 0, 0], [-5, -5, 0]])
@@ -68,3 +68,38 @@ test.only('retessellateCoplanarPolygons: should merge coplanar polygons', (t) =>
68
68
  obs = reTesselateCoplanarPolygons([polyH, polyI, polyJ, polyK, polyL])
69
69
  t.is(obs.length, 1)
70
70
  })
71
+
72
+ // Test for mark-and-filter optimization: multiple polygons that reach their
73
+ // bottom point at the same y-coordinate (triggering the removal code path)
74
+ test('retessellateCoplanarPolygons: should correctly handle multiple polygon removals', (t) => {
75
+ // Create multiple triangular polygons that all end at the same y-coordinate
76
+ // This exercises the mark-and-filter removal optimization
77
+ const poly1 = poly3.create([[0, 0, 0], [2, 0, 0], [1, 3, 0]]) // triangle pointing up
78
+ const poly2 = poly3.create([[3, 0, 0], [5, 0, 0], [4, 3, 0]]) // triangle pointing up
79
+ const poly3a = poly3.create([[6, 0, 0], [8, 0, 0], [7, 3, 0]]) // triangle pointing up
80
+
81
+ // These polygons share the same plane and have vertices at y=0 and y=3
82
+ // During retessellation, all three will be active and then removed at y=3
83
+ const obs = reTesselateCoplanarPolygons([poly1, poly2, poly3a])
84
+
85
+ // Each triangle should be preserved (they don't overlap)
86
+ t.is(obs.length, 3)
87
+
88
+ // Verify each polygon has 3 vertices (triangles)
89
+ obs.forEach((polygon) => {
90
+ t.is(polygon.vertices.length, 3)
91
+ })
92
+ })
93
+
94
+ // Test for mark-and-filter with overlapping polygons that get merged
95
+ test('retessellateCoplanarPolygons: should merge adjacent polygons with shared edges', (t) => {
96
+ // Two adjacent squares sharing an edge at x=5
97
+ const poly1 = poly3.create([[0, 0, 0], [5, 0, 0], [5, 5, 0], [0, 5, 0]])
98
+ const poly2 = poly3.create([[5, 0, 0], [10, 0, 0], [10, 5, 0], [5, 5, 0]])
99
+
100
+ const obs = reTesselateCoplanarPolygons([poly1, poly2])
101
+
102
+ // Should merge into a single rectangle
103
+ t.is(obs.length, 1)
104
+ t.is(obs[0].vertices.length, 4) // rectangle has 4 vertices
105
+ })
@@ -24,8 +24,10 @@ export const retessellate = (geometry) => {
24
24
  const destPolygons = []
25
25
  classified.forEach((group) => {
26
26
  if (Array.isArray(group)) {
27
- const reTessellateCoplanarPolygons = reTesselateCoplanarPolygons(group)
28
- destPolygons.push(...reTessellateCoplanarPolygons)
27
+ const coplanarPolygons = reTesselateCoplanarPolygons(group)
28
+ for (let i = 0; i < coplanarPolygons.length; i++) {
29
+ destPolygons.push(coplanarPolygons[i])
30
+ }
29
31
  } else {
30
32
  destPolygons.push(group)
31
33
  }
@@ -25,31 +25,40 @@ test('snap: snap of a path2 produces an expected path2', (t) => {
25
25
 
26
26
  pts = path2.toPoints(results[1])
27
27
  exp = [
28
- [0.5, 0], [0.383022221559489, 0.3213938048432696],
29
- [0.08682408883346521, 0.492403876506104], [-0.2499999999999999, 0.43301270189221935],
30
- [-0.46984631039295416, 0.17101007166283444], [-0.4698463103929542, -0.17101007166283433],
31
- [-0.2500000000000002, -0.43301270189221924], [0.08682408883346499, -0.49240387650610407],
32
- [0.3830222215594889, -0.3213938048432698]
28
+ [0.5, 0],
29
+ [0.35355000000000003, 0.35355000000000003],
30
+ [0, 0.5],
31
+ [-0.35355000000000003, 0.35355000000000003],
32
+ [-0.5, 0],
33
+ [-0.35355000000000003, -0.35355000000000003],
34
+ [0, -0.5],
35
+ [0.35355000000000003, -0.35355000000000003]
33
36
  ]
34
37
  t.true(comparePoints(pts, exp))
35
38
 
36
39
  pts = path2.toPoints(results[2])
37
40
  exp = [
38
- [0.6666666666666666, 0], [0.5106962954126519, 0.4285250731243595],
39
- [0.11576545177795361, 0.6565385020081387], [-0.33333333333333315, 0.5773502691896257],
40
- [-0.6264617471906055, 0.22801342888377923], [-0.6264617471906055, -0.2280134288837791],
41
- [-0.3333333333333336, -0.5773502691896256], [0.1157654517779533, -0.6565385020081387],
42
- [0.5106962954126518, -0.4285250731243597]
41
+ [0.6666666666666666, 0],
42
+ [0.4714, 0.4714],
43
+ [0, 0.6666666666666666],
44
+ [-0.4714, 0.4714],
45
+ [-0.6666666666666666, 0],
46
+ [-0.4714, -0.4714],
47
+ [0, -0.6666666666666666],
48
+ [0.4714, -0.4714]
43
49
  ]
44
50
  t.true(comparePoints(pts, exp))
45
51
 
46
52
  pts = path2.toPoints(results[3])
47
53
  exp = [
48
- [1570.7979271820118, 0], [1203.3061290889411, 1009.6890116376164],
49
- [272.7710864950155, 1546.9412033856784], [-785.3989635910059, 1360.3552181729126],
50
- [-1476.0772155839566, 537.2521917480618], [-1476.0772155839566, -537.2521917480618],
51
- [-785.3989635910059, -1360.3552181729126], [272.7710864950155, -1546.9412033856784],
52
- [1203.3061290889411, -1009.6890116376164]
54
+ [1570.7963267948967, 0],
55
+ [1110.7100826766714, 1110.7100826766714],
56
+ [0, 1570.7963267948967],
57
+ [-1110.7100826766714, 1110.7100826766714],
58
+ [-1570.7963267948967, 0],
59
+ [-1110.7100826766714, -1110.7100826766714],
60
+ [0, -1570.7963267948967],
61
+ [1110.7100826766714, -1110.7100826766714]
53
62
  ]
54
63
  t.true(comparePoints(pts, exp))
55
64
  })
@@ -69,8 +69,7 @@ test('offset: offset of a geom3 produces expected changes to polygons', (t) => {
69
69
  t.is(pts2.length, 864)
70
70
  })
71
71
 
72
- test('offsetGeom3: offset completes properly, issue 876', async (t) => {
73
- setTimeout(() => t.fail(), 1000)
72
+ test('offsetGeom3: offset completes properly, issue 876', (t) => {
74
73
  const polies = [
75
74
  poly3.create([[-19.61, -0.7999999999999986, 11.855], [-19.61, -0.8000000000000015, -11.855], [-19.61, -2.7500000000000018, -11.855], [-19.61, -2.7499999999999982, 11.855]]),
76
75
  poly3.create([[-17.32, -2.75, 10], [-17.32, -2.7500000000000013, -10], [-17.32, -0.8000000000000014, -10], [-17.32, -0.7999999999999987, 10]]),
@@ -90,9 +89,8 @@ test('offsetGeom3: offset completes properly, issue 876', async (t) => {
90
89
 
91
90
  const sub = geom3.create(polies)
92
91
 
93
- return new Promise((resolve, reject) => {
94
- offset({ delta: 1.3, corners: 'round', segments: 12 }, sub)
95
- t.pass()
96
- resolve()
97
- })
92
+ const obs = offset({ delta: 1.3, corners: 'round', segments: 12 }, sub)
93
+ t.notThrows.skip(() => geom3.validate(obs))
94
+ t.is(measureArea(obs), 524.9674760547548)
95
+ t.is(measureVolume(obs), 604.0599465573156)
98
96
  })
@@ -60,8 +60,8 @@ export const arc = (options) => {
60
60
  vec2.add(point, point, centerV)
61
61
  pointArray.push(point)
62
62
  } else {
63
- // note: add one additional step to achieve full rotation
64
- const numSteps = Math.max(1, Math.floor(segments * (rotation / TAU))) + 1
63
+ const numSteps = Math.floor(segments * (Math.abs(rotation) / TAU))
64
+
65
65
  let edgeStepSize = numSteps * 0.5 / rotation // step size for half a degree
66
66
  if (edgeStepSize > 0.25) edgeStepSize = 0.25
67
67