@jscad/modeling 3.0.1-alpha.0 → 3.0.3-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 (144) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/jscad-modeling.es.js +2 -2
  3. package/dist/jscad-modeling.min.js +2 -2
  4. package/package.json +2 -2
  5. package/src/colors/colorize.test.js +1 -1
  6. package/src/geometries/geom2/index.d.ts +0 -2
  7. package/src/geometries/geom2/index.js +0 -2
  8. package/src/geometries/geom3/applyTransforms.test.js +2 -2
  9. package/src/geometries/geom3/clone.test.js +2 -2
  10. package/src/geometries/geom3/create.js +1 -9
  11. package/src/geometries/geom3/{fromPoints.d.ts → fromVertices.d.ts} +1 -1
  12. package/src/geometries/geom3/{fromPoints.js → fromVertices.js} +3 -2
  13. package/src/geometries/geom3/{fromPoints.test.js → fromVertices.test.js} +6 -6
  14. package/src/geometries/geom3/{fromPointsConvex.d.ts → fromVerticesConvex.d.ts} +1 -1
  15. package/src/geometries/geom3/fromVerticesConvex.js +25 -0
  16. package/src/geometries/geom3/{fromPointsConvex.test.js → fromVerticesConvex.test.js} +3 -3
  17. package/src/geometries/geom3/index.d.ts +3 -5
  18. package/src/geometries/geom3/index.js +4 -6
  19. package/src/geometries/geom3/invert.test.js +2 -2
  20. package/src/geometries/geom3/isA.test.js +2 -2
  21. package/src/geometries/geom3/toString.test.js +2 -2
  22. package/src/geometries/geom3/{toPoints.d.ts → toVertices.d.ts} +1 -1
  23. package/src/geometries/geom3/{toPoints.js → toVertices.js} +3 -2
  24. package/src/geometries/geom3/{toPoints.test.js → toVertices.test.js} +4 -4
  25. package/src/geometries/geom3/transform.test.js +2 -2
  26. package/src/geometries/geom3/validate.test.js +4 -4
  27. package/src/geometries/index.d.ts +1 -0
  28. package/src/geometries/index.js +1 -0
  29. package/src/geometries/path2/appendBezier.js +1 -1
  30. package/src/geometries/path2/create.js +1 -10
  31. package/src/geometries/path2/index.d.ts +0 -2
  32. package/src/geometries/path2/index.js +0 -2
  33. package/src/geometries/path3/applyTransforms.js +22 -0
  34. package/src/geometries/path3/applyTransforms.test.js +28 -0
  35. package/src/geometries/path3/close.d.ts +3 -0
  36. package/src/geometries/path3/close.js +31 -0
  37. package/src/geometries/path3/close.test.js +43 -0
  38. package/src/geometries/path3/concat.d.ts +3 -0
  39. package/src/geometries/path3/concat.js +36 -0
  40. package/src/geometries/path3/concat.test.js +35 -0
  41. package/src/geometries/path3/create.d.ts +4 -0
  42. package/src/geometries/path3/create.js +30 -0
  43. package/src/geometries/path3/create.test.js +8 -0
  44. package/src/geometries/path3/equals.d.ts +3 -0
  45. package/src/geometries/path3/equals.js +48 -0
  46. package/src/geometries/path3/equals.test.js +38 -0
  47. package/src/geometries/path3/fromVertices.d.ts +8 -0
  48. package/src/geometries/path3/fromVertices.js +45 -0
  49. package/src/geometries/path3/fromVertices.test.js +33 -0
  50. package/src/geometries/path3/index.d.ts +13 -0
  51. package/src/geometries/path3/index.js +21 -0
  52. package/src/geometries/path3/isA.d.ts +3 -0
  53. package/src/geometries/path3/isA.js +20 -0
  54. package/src/geometries/path3/isA.test.js +19 -0
  55. package/src/geometries/path3/reverse.d.ts +3 -0
  56. package/src/geometries/path3/reverse.js +19 -0
  57. package/src/geometries/path3/reverse.test.js +9 -0
  58. package/src/geometries/path3/toString.d.ts +3 -0
  59. package/src/geometries/path3/toString.js +24 -0
  60. package/src/geometries/path3/toVertices.d.ts +4 -0
  61. package/src/geometries/path3/toVertices.js +16 -0
  62. package/src/geometries/path3/toVertices.test.js +13 -0
  63. package/src/geometries/path3/transform.d.ts +4 -0
  64. package/src/geometries/path3/transform.js +21 -0
  65. package/src/geometries/path3/transform.test.js +50 -0
  66. package/src/geometries/path3/type.d.ts +10 -0
  67. package/src/geometries/path3/validate.d.ts +1 -0
  68. package/src/geometries/path3/validate.js +41 -0
  69. package/src/geometries/poly2/create.js +1 -6
  70. package/src/geometries/poly3/create.js +1 -6
  71. package/src/geometries/poly3/index.js +1 -1
  72. package/src/geometries/poly3/measureBoundingBox.js +2 -0
  73. package/src/geometries/poly3/measureBoundingSphere.d.ts +2 -1
  74. package/src/geometries/poly3/measureBoundingSphere.js +25 -8
  75. package/src/geometries/poly3/measureBoundingSphere.test.js +12 -8
  76. package/src/index.js +41 -0
  77. package/src/measurements/measureBoundingSphere.js +2 -6
  78. package/src/operations/booleans/intersectGeom3.test.js +4 -4
  79. package/src/operations/booleans/martinez/compareEvents.js +2 -7
  80. package/src/operations/booleans/martinez/connectEdges.js +30 -41
  81. package/src/operations/booleans/martinez/contour.js +1 -1
  82. package/src/operations/booleans/martinez/divideSegment.js +12 -11
  83. package/src/operations/booleans/martinez/fillQueue.js +24 -28
  84. package/src/operations/booleans/martinez/index.js +2 -1
  85. package/src/operations/booleans/martinez/possibleIntersection.js +41 -30
  86. package/src/operations/booleans/martinez/segmentIntersection.js +7 -9
  87. package/src/operations/booleans/martinez/splaytree.js +59 -457
  88. package/src/operations/booleans/martinez/subdivideSegments.js +4 -4
  89. package/src/operations/booleans/martinez/sweepEvent.js +3 -17
  90. package/src/operations/booleans/subtractGeom3.test.js +4 -4
  91. package/src/operations/booleans/trees/Node.js +25 -27
  92. package/src/operations/booleans/trees/PolygonTreeNode.js +153 -106
  93. package/src/operations/booleans/trees/Tree.js +9 -4
  94. package/src/operations/booleans/trees/splitLineSegmentByPlane.js +5 -3
  95. package/src/operations/booleans/trees/splitPolygonByPlane.js +39 -34
  96. package/src/operations/booleans/unionGeom3.test.js +5 -5
  97. package/src/operations/extrusions/extrudeFromSlices.test.js +6 -6
  98. package/src/operations/extrusions/extrudeLinear.test.js +8 -8
  99. package/src/operations/extrusions/extrudeRotate.test.js +12 -12
  100. package/src/operations/extrusions/extrudeWalls.js +3 -1
  101. package/src/operations/hulls/hull.test.js +5 -5
  102. package/src/operations/hulls/hullChain.test.js +5 -5
  103. package/src/operations/hulls/hullPoints2.js +20 -28
  104. package/src/operations/hulls/toUniquePoints.js +2 -2
  105. package/src/operations/modifiers/generalize.test.js +6 -6
  106. package/src/operations/modifiers/insertTjunctions.test.js +2 -2
  107. package/src/operations/modifiers/mergePolygons.js +2 -3
  108. package/src/operations/modifiers/reTesselateCoplanarPolygons.js +7 -7
  109. package/src/operations/modifiers/retessellate.test.js +10 -10
  110. package/src/operations/modifiers/snap.test.js +4 -4
  111. package/src/operations/offsets/offsetGeom3.test.js +4 -4
  112. package/src/operations/transforms/center.test.js +7 -7
  113. package/src/operations/transforms/mirror.test.js +7 -7
  114. package/src/operations/transforms/rotate.test.js +7 -7
  115. package/src/operations/transforms/scale.test.js +7 -7
  116. package/src/operations/transforms/transform.test.js +2 -2
  117. package/src/operations/transforms/translate.test.js +7 -7
  118. package/src/primitives/cube.test.js +4 -4
  119. package/src/primitives/cuboid.test.js +4 -4
  120. package/src/primitives/cylinder.test.js +5 -5
  121. package/src/primitives/cylinderElliptic.test.js +9 -9
  122. package/src/primitives/ellipsoid.test.js +5 -5
  123. package/src/primitives/geodesicSphere.test.js +4 -4
  124. package/src/primitives/polyhedron.test.js +2 -2
  125. package/src/primitives/roundedCuboid.test.js +7 -7
  126. package/src/primitives/roundedCylinder.test.js +9 -9
  127. package/src/primitives/sphere.test.js +5 -5
  128. package/src/primitives/torus.test.js +4 -4
  129. package/src/geometries/geom2/fromCompactBinary.d.ts +0 -3
  130. package/src/geometries/geom2/fromCompactBinary.js +0 -40
  131. package/src/geometries/geom2/fromToCompactBinary.test.js +0 -100
  132. package/src/geometries/geom2/toCompactBinary.d.ts +0 -3
  133. package/src/geometries/geom2/toCompactBinary.js +0 -56
  134. package/src/geometries/geom3/fromCompactBinary.d.ts +0 -3
  135. package/src/geometries/geom3/fromCompactBinary.js +0 -42
  136. package/src/geometries/geom3/fromPointsConvex.js +0 -25
  137. package/src/geometries/geom3/fromToCompactBinary.test.js +0 -139
  138. package/src/geometries/geom3/toCompactBinary.d.ts +0 -3
  139. package/src/geometries/geom3/toCompactBinary.js +0 -66
  140. package/src/geometries/path2/fromCompactBinary.d.ts +0 -3
  141. package/src/geometries/path2/fromCompactBinary.js +0 -31
  142. package/src/geometries/path2/fromToCompactBinary.test.js +0 -114
  143. package/src/geometries/path2/toCompactBinary.d.ts +0 -3
  144. package/src/geometries/path2/toCompactBinary.js +0 -50
@@ -12,7 +12,7 @@ import { comparePolygonsAsPoints } from '../../test/helpers/index.js'
12
12
 
13
13
  test('cylinderElliptic (defaults)', (t) => {
14
14
  const obs = cylinderElliptic()
15
- const pts = geom3.toPoints(obs)
15
+ const pts = geom3.toVertices(obs)
16
16
 
17
17
  t.notThrows(() => geom3.validate(obs))
18
18
  t.is(measureArea(obs), 18.789084266699856)
@@ -23,7 +23,7 @@ test('cylinderElliptic (defaults)', (t) => {
23
23
  test('cylinderElliptic (options)', (t) => {
24
24
  // test height
25
25
  let obs = cylinderElliptic({ height: 10, segments: 12 })
26
- let pts = geom3.toPoints(obs)
26
+ let pts = geom3.toVertices(obs)
27
27
  let exp = [
28
28
  [[0, 0, -5], [0.8660254037844387, 0.49999999999999994, -5], [1, 0, -5]],
29
29
  [[0.8660254037844387, 0.49999999999999994, -5], [0.8660254037844387, 0.49999999999999994, 5],
@@ -83,7 +83,7 @@ test('cylinderElliptic (options)', (t) => {
83
83
 
84
84
  // test startRadius and endRadius
85
85
  obs = cylinderElliptic({ startRadius: [1, 2], endRadius: [2, 1], segments: 12 })
86
- pts = geom3.toPoints(obs)
86
+ pts = geom3.toVertices(obs)
87
87
  exp = [
88
88
  [[0, 0, -1], [0.8660254037844387, 0.9999999999999999, -1], [1, 0, -1]],
89
89
  [[1, 0, -1], [0.8660254037844387, 0.9999999999999999, -1], [2, 0, 1]],
@@ -143,7 +143,7 @@ test('cylinderElliptic (options)', (t) => {
143
143
 
144
144
  // test startAngle and endAngle
145
145
  obs = cylinderElliptic({ startRadius: [1, 2], endRadius: [2, 1], startAngle: TAU / 4, endAngle: TAU * 0.75, segments: 12 })
146
- pts = geom3.toPoints(obs)
146
+ pts = geom3.toVertices(obs)
147
147
 
148
148
  t.notThrows(() => geom3.validate(obs))
149
149
  t.is(measureArea(obs), 22.17105015072561)
@@ -152,7 +152,7 @@ test('cylinderElliptic (options)', (t) => {
152
152
 
153
153
  // test startAngle and endAngle
154
154
  obs = cylinderElliptic({ startAngle: 1, endAngle: 1 + TAU })
155
- pts = geom3.toPoints(obs)
155
+ pts = geom3.toVertices(obs)
156
156
 
157
157
  t.notThrows(() => geom3.validate(obs))
158
158
  t.is(measureArea(obs), 18.78908426669986)
@@ -161,7 +161,7 @@ test('cylinderElliptic (options)', (t) => {
161
161
 
162
162
  // test segments
163
163
  obs = cylinderElliptic({ segments: 8 })
164
- pts = geom3.toPoints(obs)
164
+ pts = geom3.toVertices(obs)
165
165
 
166
166
  t.notThrows(() => geom3.validate(obs))
167
167
  t.is(measureArea(obs), 17.902724085175244)
@@ -170,7 +170,7 @@ test('cylinderElliptic (options)', (t) => {
170
170
 
171
171
  // test center
172
172
  obs = cylinderElliptic({ center: [-5, -5, -5], height: 3, segments: 8 })
173
- pts = geom3.toPoints(obs)
173
+ pts = geom3.toVertices(obs)
174
174
  exp = [
175
175
  [[-5, -5, -6.5], [-4.292893218813452, -4.292893218813452, -6.5], [-4, -5, -6.5]],
176
176
  [[-4.292893218813452, -4.292893218813452, -6.5], [-4.292893218813452, -4.292893218813452, -3.5],
@@ -215,7 +215,7 @@ test('cylinderElliptic (options)', (t) => {
215
215
 
216
216
  test('cylinderElliptic (cone)', (t) => {
217
217
  const obs = cylinderElliptic({ endRadius: [0, 0] })
218
- const pts = geom3.toPoints(obs)
218
+ const pts = geom3.toVertices(obs)
219
219
 
220
220
  t.notThrows(() => geom3.validate(obs))
221
221
  t.is(measureArea(obs), 10.128239395900382)
@@ -225,7 +225,7 @@ test('cylinderElliptic (cone)', (t) => {
225
225
 
226
226
  test('cylinderElliptic (squished)', (t) => {
227
227
  const obs = cylinderElliptic({ startRadius: [1, 0], endRadius: [0, 1], segments: 4 })
228
- const pts = geom3.toPoints(obs)
228
+ const pts = geom3.toVertices(obs)
229
229
 
230
230
  t.notThrows(() => geom3.validate(obs))
231
231
  t.is(measureArea(obs), 8.47213595499958)
@@ -10,7 +10,7 @@ import { comparePolygonsAsPoints } from '../../test/helpers/index.js'
10
10
 
11
11
  test('ellipsoid (defaults)', (t) => {
12
12
  const obs = ellipsoid()
13
- const pts = geom3.toPoints(obs)
13
+ const pts = geom3.toVertices(obs)
14
14
 
15
15
  t.notThrows(() => geom3.validate(obs))
16
16
  t.is(measureArea(obs), 12.465694088650583)
@@ -21,7 +21,7 @@ test('ellipsoid (defaults)', (t) => {
21
21
  test('ellipsoid (options)', (t) => {
22
22
  // test radius
23
23
  let obs = ellipsoid({ radius: [3, 5, 7], segments: 12 })
24
- let pts = geom3.toPoints(obs)
24
+ let pts = geom3.toVertices(obs)
25
25
  let exp = [
26
26
  [[3, 0, 0], [2.598076211353316, -2.4999999999999996, 0],
27
27
  [2.25, -2.1650635094610964, -3.4999999999999996], [2.598076211353316, 0, -3.4999999999999996]],
@@ -152,14 +152,14 @@ test('ellipsoid (options)', (t) => {
152
152
 
153
153
  // test segments
154
154
  obs = ellipsoid({ segments: 8 })
155
- pts = geom3.toPoints(obs)
155
+ pts = geom3.toVertices(obs)
156
156
  t.notThrows(() => geom3.validate(obs))
157
157
  t.is(measureArea(obs), 11.013439076647456)
158
158
  t.is(measureVolume(obs), 3.2189514164974597)
159
159
  t.is(pts.length, 32)
160
160
 
161
161
  obs = ellipsoid({ center: [-3, 5, 7], segments: 8 })
162
- pts = geom3.toPoints(obs)
162
+ pts = geom3.toVertices(obs)
163
163
  exp = [
164
164
  [[-2, 5, 7], [-2.2928932188134525, 4.292893218813452, 7],
165
165
  [-2.5, 4.5, 6.292893218813452], [-2.2928932188134525, 5, 6.292893218813452]],
@@ -220,7 +220,7 @@ test('ellipsoid (options)', (t) => {
220
220
 
221
221
  test('ellipsoid (zero radius)', (t) => {
222
222
  const obs = ellipsoid({ radius: [1, 1, 0] })
223
- const pts = geom3.toPoints(obs)
223
+ const pts = geom3.toVertices(obs)
224
224
  t.notThrows(() => geom3.validate(obs))
225
225
  t.is(measureArea(obs), 0)
226
226
  t.is(measureVolume(obs), 0)
@@ -10,7 +10,7 @@ import { comparePolygonsAsPoints } from '../../test/helpers/index.js'
10
10
 
11
11
  test('geodesicSphere (defaults)', (t) => {
12
12
  const obs = geodesicSphere()
13
- const pts = geom3.toPoints(obs)
13
+ const pts = geom3.toVertices(obs)
14
14
  t.notThrows(() => geom3.validate(obs))
15
15
  t.is(pts.length, 20)
16
16
  })
@@ -18,7 +18,7 @@ test('geodesicSphere (defaults)', (t) => {
18
18
  test('geodesicSphere (options)', (t) => {
19
19
  // test radius
20
20
  let obs = geodesicSphere({ radius: 5 })
21
- let pts = geom3.toPoints(obs)
21
+ let pts = geom3.toVertices(obs)
22
22
  const exp = [
23
23
  [[4.253254557317035, 0, 2.628654726407001], [2.628654726407001, -4.253254557317035, 0], [4.253254557317035, 0, -2.628654726407001]],
24
24
  [[4.253254557317035, 0, -2.628654726407001], [2.628654726407001, 4.253254557317035, 0], [4.253254557317035, 0, 2.628654726407001]],
@@ -50,7 +50,7 @@ test('geodesicSphere (options)', (t) => {
50
50
 
51
51
  // test frequency
52
52
  obs = geodesicSphere({ radius: 5, frequency: 18 })
53
- pts = geom3.toPoints(obs)
53
+ pts = geom3.toVertices(obs)
54
54
 
55
55
  t.notThrows.skip(() => geom3.validate(obs))
56
56
  t.is(measureArea(obs), 303.76605423529395)
@@ -60,7 +60,7 @@ test('geodesicSphere (options)', (t) => {
60
60
 
61
61
  test('geodesicSphere (zero radius)', (t) => {
62
62
  const obs = geodesicSphere({ radius: 0 })
63
- const pts = geom3.toPoints(obs)
63
+ const pts = geom3.toVertices(obs)
64
64
  t.notThrows(() => geom3.validate(obs))
65
65
  t.is(measureArea(obs), 0)
66
66
  t.is(measureVolume(obs), 0)
@@ -14,7 +14,7 @@ test('polyhedron (points and faces)', (t) => {
14
14
  let faces = [[0, 1, 2, 3], [5, 6, 7, 4], [0, 5, 4, 1], [3, 2, 7, 6], [0, 3, 6, 5], [1, 4, 7, 2]]
15
15
  const colors = [[0, 0, 0, 1], [1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1], [0.5, 0.5, 0.5, 1], [1, 1, 1, 1]]
16
16
  let obs = polyhedron({ points, faces, colors })
17
- let pts = geom3.toPoints(obs)
17
+ let pts = geom3.toVertices(obs)
18
18
  let exp = [
19
19
  [[-1, -1, -1], [-1, -1, 1], [-1, 1, 1], [-1, 1, -1]],
20
20
  [[1, -1, -1], [1, 1, -1], [1, 1, 1], [1, -1, 1]],
@@ -33,7 +33,7 @@ test('polyhedron (points and faces)', (t) => {
33
33
  points = [[10, 10, 0], [10, -10, 0], [-10, -10, 0], [-10, 10, 0], [0, 0, 10]]
34
34
  faces = [[0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4], [1, 0, 3], [2, 1, 3]]
35
35
  obs = polyhedron({ points: points, faces: faces, orientation: 'inward' })
36
- pts = geom3.toPoints(obs)
36
+ pts = geom3.toVertices(obs)
37
37
  exp = [
38
38
  [[0, 0, 10], [10, -10, 0], [10, 10, 0]],
39
39
  [[0, 0, 10], [-10, -10, 0], [10, -10, 0]],
@@ -10,7 +10,7 @@ import { comparePolygonsAsPoints } from '../../test/helpers/index.js'
10
10
 
11
11
  test('roundedCuboid (defaults)', (t) => {
12
12
  const obs = roundedCuboid()
13
- const pts = geom3.toPoints(obs)
13
+ const pts = geom3.toVertices(obs)
14
14
 
15
15
  t.notThrows(() => geom3.validate(obs))
16
16
  t.is(measureArea(obs), 21.87859958298585)
@@ -20,7 +20,7 @@ test('roundedCuboid (defaults)', (t) => {
20
20
 
21
21
  test('roundedCuboid (zero size)', (t) => {
22
22
  const obs = roundedCuboid({ size: [1, 1, 0] })
23
- const pts = geom3.toPoints(obs)
23
+ const pts = geom3.toVertices(obs)
24
24
  t.notThrows(() => geom3.validate(obs))
25
25
  t.is(measureArea(obs), 0)
26
26
  t.is(measureVolume(obs), 0)
@@ -29,7 +29,7 @@ test('roundedCuboid (zero size)', (t) => {
29
29
 
30
30
  test('roundedCuboid (zero radius)', (t) => {
31
31
  const obs = roundedCuboid({ roundRadius: 0 })
32
- const pts = geom3.toPoints(obs)
32
+ const pts = geom3.toVertices(obs)
33
33
  t.notThrows(() => geom3.validate(obs))
34
34
  t.is(measureArea(obs), 24)
35
35
  t.is(measureVolume(obs), 7.999999999999999)
@@ -39,7 +39,7 @@ test('roundedCuboid (zero radius)', (t) => {
39
39
  test('roundedCuboid (options)', (t) => {
40
40
  // test segments
41
41
  let obs = roundedCuboid({ segments: 8 })
42
- let pts = geom3.toPoints(obs)
42
+ let pts = geom3.toVertices(obs)
43
43
  let exp = []
44
44
 
45
45
  t.notThrows(() => geom3.validate(obs))
@@ -49,7 +49,7 @@ test('roundedCuboid (options)', (t) => {
49
49
 
50
50
  // test center
51
51
  obs = roundedCuboid({ center: [4, 5, 6], segments: 8 })
52
- pts = geom3.toPoints(obs)
52
+ pts = geom3.toVertices(obs)
53
53
  exp = [
54
54
  ]
55
55
 
@@ -60,7 +60,7 @@ test('roundedCuboid (options)', (t) => {
60
60
 
61
61
  // test size
62
62
  obs = roundedCuboid({ size: [8, 10, 12], segments: 8 })
63
- pts = geom3.toPoints(obs)
63
+ pts = geom3.toVertices(obs)
64
64
  exp = [
65
65
  [[4, 4.8, -5.8], [3.9414213562373095, 4.941421356237309, -5.8],
66
66
  [3.9414213562373095, 4.941421356237309, 5.8], [4, 4.8, 5.8]],
@@ -163,7 +163,7 @@ test('roundedCuboid (options)', (t) => {
163
163
 
164
164
  // test roundRadius
165
165
  obs = roundedCuboid({ size: [8, 10, 12], roundRadius: 2, segments: 8 })
166
- pts = geom3.toPoints(obs)
166
+ pts = geom3.toVertices(obs)
167
167
  exp = [
168
168
  [[4, 3, -4], [3.414213562373095, 4.414213562373095, -4],
169
169
  [3.414213562373095, 4.414213562373095, 4], [4, 3, 4]],
@@ -10,7 +10,7 @@ import { comparePolygonsAsPoints } from '../../test/helpers/index.js'
10
10
 
11
11
  test('roundedCylinder (defaults)', (t) => {
12
12
  const obs = roundedCylinder()
13
- const pts = geom3.toPoints(obs)
13
+ const pts = geom3.toVertices(obs)
14
14
 
15
15
  t.notThrows(() => geom3.validate(obs))
16
16
  t.is(measureArea(obs), 16.844951865908268)
@@ -20,7 +20,7 @@ test('roundedCylinder (defaults)', (t) => {
20
20
 
21
21
  test('roundedCylinder (zero height)', (t) => {
22
22
  const obs = roundedCylinder({ height: 0 })
23
- const pts = geom3.toPoints(obs)
23
+ const pts = geom3.toVertices(obs)
24
24
  t.notThrows(() => geom3.validate(obs))
25
25
  t.is(measureArea(obs), 0)
26
26
  t.is(measureVolume(obs), 0)
@@ -29,7 +29,7 @@ test('roundedCylinder (zero height)', (t) => {
29
29
 
30
30
  test('roundedCylinder (zero radius)', (t) => {
31
31
  const obs = roundedCylinder({ radius: 0, roundRadius: 0 })
32
- const pts = geom3.toPoints(obs)
32
+ const pts = geom3.toVertices(obs)
33
33
  t.notThrows(() => geom3.validate(obs))
34
34
  t.is(measureArea(obs), 0)
35
35
  t.is(measureVolume(obs), 0)
@@ -38,7 +38,7 @@ test('roundedCylinder (zero radius)', (t) => {
38
38
 
39
39
  test('roundedCylinder (zero roundRadius)', (t) => {
40
40
  const obs = roundedCylinder({ roundRadius: 0 })
41
- const pts = geom3.toPoints(obs)
41
+ const pts = geom3.toVertices(obs)
42
42
  t.notThrows(() => geom3.validate(obs))
43
43
  t.is(measureArea(obs), 18.789084266699856)
44
44
  t.is(measureVolume(obs), 6.2428903045161)
@@ -48,7 +48,7 @@ test('roundedCylinder (zero roundRadius)', (t) => {
48
48
  test('roundedCylinder (options)', (t) => {
49
49
  // test segments
50
50
  let obs = roundedCylinder({ segments: 5 })
51
- let pts = geom3.toPoints(obs)
51
+ let pts = geom3.toVertices(obs)
52
52
  let exp = [
53
53
  ]
54
54
 
@@ -59,7 +59,7 @@ test('roundedCylinder (options)', (t) => {
59
59
 
60
60
  // test center
61
61
  obs = roundedCylinder({ segments: 5, center: [-5, -5, -5] })
62
- pts = geom3.toPoints(obs)
62
+ pts = geom3.toVertices(obs)
63
63
  exp = [
64
64
  [[-4.048943483704846, -4.6909830056250525, -5.8], [-5, -4, -5.8],
65
65
  [-5, -4, -4.2], [-4.048943483704846, -4.6909830056250525, -4.2]],
@@ -91,7 +91,7 @@ test('roundedCylinder (options)', (t) => {
91
91
 
92
92
  // test height
93
93
  obs = roundedCylinder({ segments: 5, height: 20 })
94
- pts = geom3.toPoints(obs)
94
+ pts = geom3.toVertices(obs)
95
95
  exp = [
96
96
  [[0.9510565162951535, 0.30901699437494745, -9.8], [0, 1, -9.8],
97
97
  [0, 1, 9.8], [0.9510565162951535, 0.30901699437494745, 9.8]],
@@ -123,7 +123,7 @@ test('roundedCylinder (options)', (t) => {
123
123
 
124
124
  // test radius
125
125
  obs = roundedCylinder({ segments: 5, radius: 10 })
126
- pts = geom3.toPoints(obs)
126
+ pts = geom3.toVertices(obs)
127
127
  exp = [
128
128
  [[9.510565162951535, 3.0901699437494745, -0.8], [0, 10, -0.8],
129
129
  [0, 10, 0.8], [9.510565162951535, 3.0901699437494745, 0.8]],
@@ -154,7 +154,7 @@ test('roundedCylinder (options)', (t) => {
154
154
 
155
155
  // test round radius
156
156
  obs = roundedCylinder({ segments: 5, height: 20, radius: 5, roundRadius: 2 })
157
- pts = geom3.toPoints(obs)
157
+ pts = geom3.toVertices(obs)
158
158
  exp = [
159
159
  [[4.755282581475767, 1.5450849718747373, -8], [0, 5, -8],
160
160
  [0, 5, 8], [4.755282581475767, 1.5450849718747373, 8]],
@@ -10,7 +10,7 @@ import { comparePolygonsAsPoints } from '../../test/helpers/index.js'
10
10
 
11
11
  test('sphere (defaults)', (t) => {
12
12
  const obs = sphere()
13
- const pts = geom3.toPoints(obs)
13
+ const pts = geom3.toVertices(obs)
14
14
 
15
15
  t.notThrows(() => geom3.validate(obs))
16
16
  t.is(measureArea(obs), 12.465694088650583)
@@ -21,7 +21,7 @@ test('sphere (defaults)', (t) => {
21
21
  test('sphere (options)', (t) => {
22
22
  // test radius
23
23
  let obs = sphere({ radius: 5, segments: 12 })
24
- let pts = geom3.toPoints(obs)
24
+ let pts = geom3.toVertices(obs)
25
25
  let exp = []
26
26
  t.notThrows(() => geom3.validate(obs))
27
27
  t.is(measureArea(obs), 296.5322084069296)
@@ -31,7 +31,7 @@ test('sphere (options)', (t) => {
31
31
 
32
32
  // test segments
33
33
  obs = sphere({ segments: 8 })
34
- pts = geom3.toPoints(obs)
34
+ pts = geom3.toVertices(obs)
35
35
  exp = [
36
36
  [[1, 0, 0], [0.7071067811865476, -0.7071067811865475, 0],
37
37
  [0.5000000000000001, -0.5, -0.7071067811865475], [0.7071067811865476, 0, -0.7071067811865475]],
@@ -116,7 +116,7 @@ test('sphere (options)', (t) => {
116
116
 
117
117
  // test center
118
118
  obs = sphere({ center: [-3, 5, 7], segments: 8 })
119
- pts = geom3.toPoints(obs)
119
+ pts = geom3.toVertices(obs)
120
120
  exp = [
121
121
  [[-2, 5, 7], [-2.2928932188134525, 4.292893218813452, 7],
122
122
  [-2.5, 4.5, 6.292893218813452], [-2.2928932188134525, 5, 6.292893218813452]],
@@ -176,7 +176,7 @@ test('sphere (options)', (t) => {
176
176
 
177
177
  test('sphere (zero radius)', (t) => {
178
178
  const obs = sphere({ radius: 0 })
179
- const pts = geom3.toPoints(obs)
179
+ const pts = geom3.toVertices(obs)
180
180
  t.notThrows(() => geom3.validate(obs))
181
181
  t.is(measureArea(obs), 0)
182
182
  t.is(measureVolume(obs), 0)
@@ -12,7 +12,7 @@ import { comparePoints } from '../../test/helpers/index.js'
12
12
 
13
13
  test('torus (defaults)', (t) => {
14
14
  const obs = torus()
15
- const pts = geom3.toPoints(obs)
15
+ const pts = geom3.toVertices(obs)
16
16
 
17
17
  t.notThrows(() => geom3.validate(obs))
18
18
  t.is(measureArea(obs), 157.0282327749074)
@@ -26,7 +26,7 @@ test('torus (defaults)', (t) => {
26
26
 
27
27
  test('torus (simple options)', (t) => {
28
28
  const obs = torus({ innerRadius: 0.5, innerSegments: 4, outerRadius: 5, outerSegments: 8 })
29
- const pts = geom3.toPoints(obs)
29
+ const pts = geom3.toVertices(obs)
30
30
  t.notThrows(() => geom3.validate(obs))
31
31
  t.is(measureArea(obs), 83.36086132479792)
32
32
  t.is(measureVolume(obs), 14.14213562373095)
@@ -39,7 +39,7 @@ test('torus (simple options)', (t) => {
39
39
 
40
40
  test('torus (complex options)', (t) => {
41
41
  const obs = torus({ innerRadius: 1, outerRadius: 5, innerSegments: 32, outerSegments: 72, startAngle: TAU / 4, outerRotation: TAU / 4 })
42
- const pts = geom3.toPoints(obs)
42
+ const pts = geom3.toVertices(obs)
43
43
  t.notThrows(() => geom3.validate(obs))
44
44
  t.is(measureArea(obs), 55.472610544494)
45
45
  t.is(measureVolume(obs), 24.484668362201525)
@@ -52,7 +52,7 @@ test('torus (complex options)', (t) => {
52
52
 
53
53
  test('torus (startAngle)', (t) => {
54
54
  const obs = torus({ startAngle: 1, endAngle: 1 + TAU })
55
- const pts = geom3.toPoints(obs)
55
+ const pts = geom3.toVertices(obs)
56
56
  t.notThrows(() => geom3.validate(obs))
57
57
  t.is(measureArea(obs), 157.0282327749074)
58
58
  t.is(measureVolume(obs), 77.94735870844195)
@@ -1,3 +0,0 @@
1
- import type { Geom2 } from './type.d.ts'
2
-
3
- export function fromCompactBinary(data: Array<number> | Float32Array | Float64Array): Geom2
@@ -1,40 +0,0 @@
1
- import * as mat4 from '../../maths/mat4/index.js'
2
- import * as vec2 from '../../maths/vec2/index.js'
3
-
4
- import { create } from './create.js'
5
-
6
- /**
7
- * Create a new 2D geometry from the given compact binary data.
8
- * @param {Array} data - compact binary data
9
- * @returns {Geom2} a new geometry
10
- * @alias module:modeling/geometries/geom2.fromCompactBinary
11
- */
12
- export const fromCompactBinary = (data) => {
13
- if (data[0] !== 0) throw new Error('invalid compact binary data')
14
-
15
- const created = create()
16
-
17
- created.transforms = mat4.clone(data.slice(1, 17))
18
-
19
- for (let i = 21; i < data.length;) {
20
- const length = data[i++] // number of points for this polygon
21
- if (length < 0 || i + length * 2 > data.length) {
22
- throw new Error('invalid compact binary data')
23
- }
24
- const outline = []
25
- for (let j = 0; j < length; j++) {
26
- const x = data[i + j * 2]
27
- const y = data[i + j * 2 + 1]
28
- outline.push(vec2.fromValues(x, y))
29
- }
30
- created.outlines.push(outline)
31
- i += length * 2
32
- }
33
-
34
- // transfer known properties, i.e. color
35
- if (data[17] >= 0) {
36
- created.color = [data[17], data[18], data[19], data[20]]
37
- }
38
- // TODO: how about custom properties or fields ?
39
- return created
40
- }
@@ -1,100 +0,0 @@
1
- import test from 'ava'
2
-
3
- import { fromCompactBinary, toCompactBinary, create } from './index.js'
4
-
5
- test('toCompactBinary: converts geom2 into a compact form', (t) => {
6
- const geometry1 = create()
7
- const compacted1 = toCompactBinary(geometry1)
8
- const expected1 = new Float32Array([
9
- 0, // type flag
10
- 1, 0, 0, 0, // transforms
11
- 0, 1, 0, 0,
12
- 0, 0, 1, 0,
13
- 0, 0, 0, 1,
14
- -1, -1, -1, -1 // color
15
- ])
16
- t.deepEqual(compacted1, expected1)
17
-
18
- // geometry with a hole
19
- const geometry2 = create([
20
- [[10, 10], [-10, -10], [10, -10]],
21
- [[5, -5], [6, -4], [6, -5]]
22
- ])
23
- const compacted2 = toCompactBinary(geometry2)
24
- const expected2 = new Float32Array([
25
- 0, // type flag
26
- 1, 0, 0, 0, // transforms
27
- 0, 1, 0, 0,
28
- 0, 0, 1, 0,
29
- 0, 0, 0, 1,
30
- -1, -1, -1, -1, // color
31
- 3, 10, 10, -10, -10, 10, -10, // poly1
32
- 3, 5, -5, 6, -4, 6, -5 // poly2
33
- ])
34
- t.deepEqual(compacted2, expected2)
35
-
36
- // test color as well
37
- geometry2.color = [1, 2, 3, 4]
38
- const compacted3 = toCompactBinary(geometry2)
39
- const expected3 = new Float32Array([
40
- 0, // type flag
41
- 1, 0, 0, 0, // transforms
42
- 0, 1, 0, 0,
43
- 0, 0, 1, 0,
44
- 0, 0, 0, 1,
45
- 1, 2, 3, 4, // color
46
- 3, 10, 10, -10, -10, 10, -10, // poly1
47
- 3, 5, -5, 6, -4, 6, -5 // poly2
48
- ])
49
- t.deepEqual(compacted3, expected3)
50
- })
51
-
52
- test('fromCompactBinary: convert a compact form into a geom2', (t) => {
53
- const compacted1 = [
54
- 0, // type flag
55
- 1, 0, 0, 0, // transforms
56
- 0, 1, 0, 0,
57
- 0, 0, 1, 0,
58
- 0, 0, 0, 1,
59
- -1, -1, -1, -1 // color
60
- ]
61
- const expected1 = create()
62
- const geometry1 = fromCompactBinary(compacted1)
63
-
64
- t.deepEqual(geometry1, expected1)
65
-
66
- // geometry with a hole
67
- const compacted2 = [
68
- 0, // type flag
69
- 1, 0, 0, 0, // transforms
70
- 0, 1, 0, 0,
71
- 0, 0, 1, 0,
72
- 0, 0, 0, 1,
73
- -1, -1, -1, -1, // color
74
- 3, 10, 10, -10, -10, 10, -10, // poly1
75
- 3, 5, -5, 6, -5, 6, -4 // poly2
76
- ]
77
- const expected2 = create([
78
- [[10, 10], [-10, -10], [10, -10]],
79
- [[5, -5], [6, -5], [6, -4]]
80
- ])
81
- const geometry2 = fromCompactBinary(compacted2)
82
-
83
- t.deepEqual(geometry2, expected2)
84
-
85
- // test color as well
86
- const compacted3 = [
87
- 0, // type flag
88
- 1, 0, 0, 0, // transforms
89
- 0, 1, 0, 0,
90
- 0, 0, 1, 0,
91
- 0, 0, 0, 1,
92
- 4, 5, 6, 7, // color
93
- 3, 10, 10, -10, -10, 10, -10, // poly1
94
- 3, 5, -5, 6, -5, 6, -4 // poly2
95
- ]
96
- expected2.color = [4, 5, 6, 7]
97
- const geometry3 = fromCompactBinary(compacted3)
98
-
99
- t.deepEqual(geometry3, expected2)
100
- })
@@ -1,3 +0,0 @@
1
- import type { Geom2 } from './type.d.ts'
2
-
3
- export function toCompactBinary(geom: Geom2): Float32Array
@@ -1,56 +0,0 @@
1
- /**
2
- * Produces a compact binary representation from the given geometry.
3
- * @param {Geom2} geometry - the geometry
4
- * @returns {TypedArray} compact binary representation
5
- * @alias module:modeling/geometries/geom2.toCompactBinary
6
- */
7
- export const toCompactBinary = (geometry) => {
8
- const transforms = geometry.transforms
9
- let color = [-1, -1, -1, -1]
10
- if (geometry.color) color = geometry.color
11
-
12
- // Compute array size
13
- let size = 21
14
- geometry.outlines.forEach((outline) => {
15
- size += 2 * outline.length + 1
16
- })
17
-
18
- // FIXME why Float32Array?
19
- const compacted = new Float32Array(size) // type + transforms + color + points
20
-
21
- compacted[0] = 0 // type code: 0 => geom2, 1 => geom3 , 2 => path2
22
-
23
- compacted[1] = transforms[0]
24
- compacted[2] = transforms[1]
25
- compacted[3] = transforms[2]
26
- compacted[4] = transforms[3]
27
- compacted[5] = transforms[4]
28
- compacted[6] = transforms[5]
29
- compacted[7] = transforms[6]
30
- compacted[8] = transforms[7]
31
- compacted[9] = transforms[8]
32
- compacted[10] = transforms[9]
33
- compacted[11] = transforms[10]
34
- compacted[12] = transforms[11]
35
- compacted[13] = transforms[12]
36
- compacted[14] = transforms[13]
37
- compacted[15] = transforms[14]
38
- compacted[16] = transforms[15]
39
-
40
- compacted[17] = color[0]
41
- compacted[18] = color[1]
42
- compacted[19] = color[2]
43
- compacted[20] = color[3]
44
-
45
- let index = 21
46
- geometry.outlines.forEach((outline) => {
47
- compacted[index++] = outline.length
48
- outline.forEach((point) => {
49
- compacted[index++] = point[0]
50
- compacted[index++] = point[1]
51
- })
52
- })
53
-
54
- // TODO: how about custom properties or fields ?
55
- return compacted
56
- }
@@ -1,3 +0,0 @@
1
- import type { Geom3 } from './type.d.ts'
2
-
3
- export function fromCompactBinary(data: Array<number> | Float32Array | Float64Array): Geom3
@@ -1,42 +0,0 @@
1
- import * as vec3 from '../../maths/vec3/index.js'
2
- import * as mat4 from '../../maths/mat4/index.js'
3
-
4
- import * as poly3 from '../poly3/index.js'
5
-
6
- import { create } from './create.js'
7
-
8
- /**
9
- * Construct a new 3D geometry from the given compact binary data.
10
- * @param {TypedArray} data - compact binary data
11
- * @returns {Geom3} a new geometry
12
- * @alias module:modeling/geometries/geom3.fromCompactBinary
13
- */
14
- export const fromCompactBinary = (data) => {
15
- if (data[0] !== 1) throw new Error('invalid compact binary data')
16
-
17
- const created = create()
18
-
19
- created.transforms = mat4.clone(data.slice(1, 17))
20
-
21
- const numberOfVertices = data[21]
22
- let ci = 22
23
- let vi = data.length - (numberOfVertices * 3)
24
- while (vi < data.length) {
25
- const verticesPerPolygon = data[ci]
26
- ci++
27
-
28
- const vertices = []
29
- for (let i = 0; i < verticesPerPolygon; i++) {
30
- vertices.push(vec3.fromValues(data[vi], data[vi + 1], data[vi + 2]))
31
- vi += 3
32
- }
33
- created.polygons.push(poly3.create(vertices))
34
- }
35
-
36
- // transfer known properties, i.e. color
37
- if (data[17] >= 0) {
38
- created.color = [data[17], data[18], data[19], data[20]]
39
- }
40
- // TODO: how about custom properties or fields ?
41
- return created
42
- }
@@ -1,25 +0,0 @@
1
- import { runner } from '../../operations/hulls/quickhull/index.js'
2
- import { create } from './create.js'
3
- import * as poly3 from '../poly3/index.js'
4
-
5
- /**
6
- * Construct a new convex 3D geometry from a list of unique points.
7
- *
8
- * @param {Array} uniquePoints - list of points to construct convex 3D geometry
9
- * @returns {geom3} a new geometry
10
- * @alias module:modeling/geometries/geom3.fromPointsConvex
11
- */
12
- export const fromPointsConvex = (uniquePoints) => {
13
- if (!Array.isArray(uniquePoints)) {
14
- throw new Error('the given points must be an array')
15
- }
16
-
17
- const faces = runner(uniquePoints, { skipTriangulation: true })
18
-
19
- const polygons = faces.map((face) => {
20
- const vertices = face.map((index) => uniquePoints[index])
21
- return poly3.create(vertices)
22
- })
23
-
24
- return create(polygons)
25
- }