@jscad/modeling 2.8.0 → 2.9.2

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 (100) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/jscad-modeling.min.js +433 -391
  3. package/package.json +2 -2
  4. package/src/geometries/geom2/index.d.ts +1 -0
  5. package/src/geometries/geom2/index.js +2 -1
  6. package/src/geometries/geom2/validate.d.ts +3 -0
  7. package/src/geometries/geom2/validate.js +36 -0
  8. package/src/geometries/geom3/index.d.ts +1 -0
  9. package/src/geometries/geom3/index.js +2 -1
  10. package/src/geometries/geom3/isA.js +1 -1
  11. package/src/geometries/geom3/validate.d.ts +3 -0
  12. package/src/geometries/geom3/validate.js +62 -0
  13. package/src/geometries/path2/index.d.ts +1 -0
  14. package/src/geometries/path2/index.js +2 -1
  15. package/src/geometries/path2/validate.d.ts +3 -0
  16. package/src/geometries/path2/validate.js +41 -0
  17. package/src/geometries/poly2/arePointsInside.js +0 -35
  18. package/src/geometries/poly3/index.d.ts +1 -0
  19. package/src/geometries/poly3/index.js +2 -1
  20. package/src/geometries/poly3/invert.js +7 -1
  21. package/src/geometries/poly3/measureArea.test.js +16 -16
  22. package/src/geometries/poly3/measureBoundingSphere.test.js +8 -8
  23. package/src/geometries/poly3/validate.d.ts +4 -0
  24. package/src/geometries/poly3/validate.js +50 -0
  25. package/src/measurements/measureCenterOfMass.test.js +2 -2
  26. package/src/operations/booleans/intersect.test.js +8 -0
  27. package/src/operations/booleans/scission.test.js +4 -4
  28. package/src/operations/booleans/subtract.test.js +8 -0
  29. package/src/operations/booleans/trees/Node.js +10 -16
  30. package/src/operations/booleans/trees/PolygonTreeNode.js +13 -14
  31. package/src/operations/booleans/trees/Tree.js +1 -2
  32. package/src/operations/booleans/trees/splitPolygonByPlane.js +2 -3
  33. package/src/operations/booleans/union.test.js +27 -0
  34. package/src/operations/expansions/expand.test.js +30 -21
  35. package/src/operations/expansions/expandShell.js +2 -2
  36. package/src/operations/expansions/offset.test.js +25 -0
  37. package/src/operations/extrusions/earcut/assignHoles.js +91 -0
  38. package/src/operations/extrusions/earcut/assignHoles.test.js +74 -0
  39. package/src/operations/extrusions/earcut/eliminateHoles.js +131 -0
  40. package/src/operations/extrusions/earcut/index.js +252 -0
  41. package/src/operations/extrusions/earcut/linkedList.js +58 -0
  42. package/src/operations/extrusions/earcut/linkedListSort.js +54 -0
  43. package/src/operations/extrusions/earcut/linkedPolygon.js +197 -0
  44. package/src/operations/extrusions/earcut/polygonHierarchy.js +64 -0
  45. package/src/operations/extrusions/earcut/triangle.js +16 -0
  46. package/src/operations/extrusions/extrudeFromSlices.js +10 -3
  47. package/src/operations/extrusions/extrudeFromSlices.test.js +47 -31
  48. package/src/operations/extrusions/extrudeLinear.js +4 -3
  49. package/src/operations/extrusions/extrudeLinear.test.js +69 -37
  50. package/src/operations/extrusions/extrudeLinearGeom2.js +5 -2
  51. package/src/operations/extrusions/extrudeRectangular.test.js +22 -15
  52. package/src/operations/extrusions/extrudeRotate.test.js +31 -27
  53. package/src/operations/extrusions/project.test.js +5 -5
  54. package/src/operations/extrusions/slice/calculatePlane.js +7 -4
  55. package/src/operations/extrusions/slice/repairSlice.js +47 -0
  56. package/src/operations/extrusions/slice/toPolygons.js +24 -60
  57. package/src/operations/hulls/hull.test.js +24 -1
  58. package/src/operations/hulls/hullChain.test.js +6 -4
  59. package/src/operations/hulls/hullPath2.test.js +1 -1
  60. package/src/operations/modifiers/generalize.test.js +6 -0
  61. package/src/operations/transforms/align.test.js +12 -0
  62. package/src/operations/transforms/center.test.js +12 -0
  63. package/src/operations/transforms/mirror.test.js +16 -0
  64. package/src/operations/transforms/rotate.test.js +10 -0
  65. package/src/operations/transforms/scale.test.js +15 -0
  66. package/src/operations/transforms/transform.test.js +5 -0
  67. package/src/operations/transforms/translate.test.js +16 -0
  68. package/src/primitives/arc.test.js +11 -0
  69. package/src/primitives/circle.test.js +15 -9
  70. package/src/primitives/cube.test.js +3 -0
  71. package/src/primitives/cuboid.test.js +9 -24
  72. package/src/primitives/cylinder.test.js +7 -4
  73. package/src/primitives/cylinderElliptic.js +13 -6
  74. package/src/primitives/cylinderElliptic.test.js +72 -50
  75. package/src/primitives/ellipse.js +3 -1
  76. package/src/primitives/ellipse.test.js +14 -8
  77. package/src/primitives/ellipsoid.js +6 -4
  78. package/src/primitives/ellipsoid.test.js +84 -80
  79. package/src/primitives/geodesicSphere.test.js +3 -0
  80. package/src/primitives/line.test.js +1 -0
  81. package/src/primitives/polygon.test.js +15 -10
  82. package/src/primitives/polyhedron.test.js +14 -42
  83. package/src/primitives/rectangle.test.js +3 -0
  84. package/src/primitives/roundedCuboid.test.js +5 -0
  85. package/src/primitives/roundedCylinder.js +6 -4
  86. package/src/primitives/roundedCylinder.test.js +40 -36
  87. package/src/primitives/roundedRectangle.test.js +5 -0
  88. package/src/primitives/sphere.test.js +52 -73
  89. package/src/primitives/square.test.js +3 -0
  90. package/src/primitives/star.test.js +6 -0
  91. package/src/primitives/torus.test.js +8 -1
  92. package/src/primitives/triangle.test.js +7 -0
  93. package/src/utils/areAllShapesTheSameType.js +2 -2
  94. package/src/utils/areAllShapesTheSameType.test.js +17 -0
  95. package/src/utils/index.d.ts +1 -0
  96. package/src/utils/index.js +3 -1
  97. package/src/utils/trigonometry.d.ts +2 -0
  98. package/src/utils/trigonometry.js +35 -0
  99. package/src/utils/trigonometry.test.js +25 -0
  100. package/test/helpers/nearlyEqual.js +4 -1
@@ -10,6 +10,7 @@ test('circle (defaults)', (t) => {
10
10
  const geometry = circle()
11
11
  const pts = geom2.toPoints(geometry)
12
12
 
13
+ t.notThrows(() => geom2.validate(geometry))
13
14
  t.deepEqual(pts.length, 32)
14
15
  })
15
16
 
@@ -42,7 +43,7 @@ test('circle (options)', (t) => {
42
43
  [4.555504184431392, 3.5898563569410915],
43
44
  [5.160607986722184, 3.266421636210497],
44
45
  [5.817183872943549, 3.067251518588694],
45
- [6.499999999999999, 3],
46
+ [6.5, 3],
46
47
  [7.182816127056449, 3.0672515185886935],
47
48
  [7.8393920132778145, 3.266421636210497],
48
49
  [8.444495815568606, 3.589856356941091],
@@ -52,6 +53,7 @@ test('circle (options)', (t) => {
52
53
  [9.932748481411306, 5.817183872943549]
53
54
  ]
54
55
 
56
+ t.notThrows(() => geom2.validate(geometry))
55
57
  t.deepEqual(pts.length, 32)
56
58
  t.true(comparePoints(pts, exp))
57
59
 
@@ -63,20 +65,21 @@ test('circle (options)', (t) => {
63
65
  [3.2335783637895035, 1.3393920132778143],
64
66
  [2.4748737341529163, 2.474873734152916],
65
67
  [1.3393920132778145, 3.2335783637895035],
66
- [2.143131898507868e-16, 3.5],
68
+ [0, 3.5],
67
69
  [-1.339392013277814, 3.2335783637895035],
68
70
  [-2.474873734152916, 2.4748737341529163],
69
71
  [-3.2335783637895035, 1.3393920132778145],
70
- [-3.5, 4.286263797015736e-16],
72
+ [-3.5, 0],
71
73
  [-3.233578363789504, -1.3393920132778139],
72
74
  [-2.474873734152917, -2.474873734152916],
73
75
  [-1.339392013277816, -3.233578363789503],
74
- [-6.429395695523604e-16, -3.5],
76
+ [0, -3.5],
75
77
  [1.339392013277815, -3.233578363789503],
76
78
  [2.474873734152916, -2.474873734152917],
77
79
  [3.233578363789503, -1.3393920132778163]
78
80
  ]
79
81
 
82
+ t.notThrows(() => geom2.validate(geometry))
80
83
  t.deepEqual(pts.length, 16)
81
84
  t.true(comparePoints(pts, exp))
82
85
 
@@ -84,22 +87,23 @@ test('circle (options)', (t) => {
84
87
  geometry = circle({ radius: 3.5, startAngle: Math.PI / 2, segments: 16 })
85
88
  pts = geom2.toPoints(geometry)
86
89
  exp = [
87
- [2.143131898507868e-16, 3.5],
90
+ [0, 3.5],
88
91
  [-1.339392013277814, 3.2335783637895035],
89
92
  [-2.474873734152916, 2.4748737341529163],
90
93
  [-3.2335783637895035, 1.3393920132778145],
91
- [-3.5, 4.286263797015736e-16],
94
+ [-3.5, 0],
92
95
  [-3.233578363789504, -1.3393920132778139],
93
96
  [-2.474873734152917, -2.474873734152916],
94
97
  [-1.339392013277816, -3.233578363789503],
95
- [-6.429395695523604e-16, -3.5],
98
+ [0, -3.5],
96
99
  [1.339392013277815, -3.233578363789503],
97
100
  [2.474873734152916, -2.474873734152917],
98
101
  [3.233578363789503, -1.3393920132778163],
99
- [3.5, -8.572527594031472e-16],
102
+ [3.5, 0],
100
103
  [0, 0]
101
104
  ]
102
105
 
106
+ t.notThrows(() => geom2.validate(geometry))
103
107
  t.deepEqual(pts.length, 14)
104
108
  t.true(comparePoints(pts, exp))
105
109
 
@@ -111,10 +115,11 @@ test('circle (options)', (t) => {
111
115
  [3.2335783637895035, 1.3393920132778143],
112
116
  [2.4748737341529163, 2.474873734152916],
113
117
  [1.3393920132778145, 3.2335783637895035],
114
- [2.143131898507868e-16, 3.5],
118
+ [0, 3.5],
115
119
  [0, 0]
116
120
  ]
117
121
 
122
+ t.notThrows(() => geom2.validate(geometry))
118
123
  t.deepEqual(pts.length, 6)
119
124
  t.true(comparePoints(pts, exp))
120
125
 
@@ -129,6 +134,7 @@ test('circle (options)', (t) => {
129
134
  [1.0815594803123152, -3.3286978070330377]
130
135
  ]
131
136
 
137
+ t.notThrows(() => geom2.validate(geometry))
132
138
  t.deepEqual(pts.length, 5)
133
139
  t.true(comparePoints(pts, exp))
134
140
  })
@@ -9,6 +9,7 @@ const comparePolygonsAsPoints = require('../../test/helpers/comparePolygonsAsPoi
9
9
  test('cube (defaults)', (t) => {
10
10
  const obs = cube()
11
11
  const pts = geom3.toPoints(obs)
12
+ t.notThrows(() => geom3.validate(obs))
12
13
  t.is(pts.length, 6)
13
14
  })
14
15
 
@@ -25,6 +26,7 @@ test('cube (options)', (t) => {
25
26
  [[3, 3, 10], [10, 3, 10], [10, 10, 10], [3, 10, 10]]
26
27
  ]
27
28
 
29
+ t.notThrows(() => geom3.validate(obs))
28
30
  t.is(pts.length, 6)
29
31
  t.true(comparePolygonsAsPoints(pts, exp))
30
32
 
@@ -40,6 +42,7 @@ test('cube (options)', (t) => {
40
42
  [[-3.5, -3.5, 3.5], [3.5, -3.5, 3.5], [3.5, 3.5, 3.5], [-3.5, 3.5, 3.5]]
41
43
  ]
42
44
 
45
+ t.notThrows(() => geom3.validate(obs))
43
46
  t.is(pts.length, 6)
44
47
  t.true(comparePolygonsAsPoints(pts, exp))
45
48
  })
@@ -10,31 +10,14 @@ test('cuboid (defaults)', (t) => {
10
10
  const obs = cuboid()
11
11
  const pts = geom3.toPoints(obs)
12
12
  const exp = [
13
- [[-1.0000000, -1.0000000, -1.0000000],
14
- [-1.0000000, -1.0000000, 1.0000000],
15
- [-1.0000000, 1.0000000, 1.0000000],
16
- [-1.0000000, 1.0000000, -1.0000000]],
17
- [[1.0000000, -1.0000000, -1.0000000],
18
- [1.0000000, 1.0000000, -1.0000000],
19
- [1.0000000, 1.0000000, 1.0000000],
20
- [1.0000000, -1.0000000, 1.0000000]],
21
- [[-1.0000000, -1.0000000, -1.0000000],
22
- [1.0000000, -1.0000000, -1.0000000],
23
- [1.0000000, -1.0000000, 1.0000000],
24
- [-1.0000000, -1.0000000, 1.0000000]],
25
- [[-1.0000000, 1.0000000, -1.0000000],
26
- [-1.0000000, 1.0000000, 1.0000000],
27
- [1.0000000, 1.0000000, 1.0000000],
28
- [1.0000000, 1.0000000, -1.0000000]],
29
- [[-1.0000000, -1.0000000, -1.0000000],
30
- [-1.0000000, 1.0000000, -1.0000000],
31
- [1.0000000, 1.0000000, -1.0000000],
32
- [1.0000000, -1.0000000, -1.0000000]],
33
- [[-1.0000000, -1.0000000, 1.0000000],
34
- [1.0000000, -1.0000000, 1.0000000],
35
- [1.0000000, 1.0000000, 1.0000000],
36
- [-1.0000000, 1.0000000, 1.0000000]]
13
+ [[-1, -1, -1], [-1, -1, 1], [-1, 1, 1], [-1, 1, -1]],
14
+ [[1, -1, -1], [1, 1, -1], [1, 1, 1], [1, -1, 1]],
15
+ [[-1, -1, -1], [1, -1, -1], [1, -1, 1], [-1, -1, 1]],
16
+ [[-1, 1, -1], [-1, 1, 1], [1, 1, 1], [1, 1, -1]],
17
+ [[-1, -1, -1], [-1, 1, -1], [1, 1, -1], [1, -1, -1]],
18
+ [[-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]]
37
19
  ]
20
+ t.notThrows(() => geom3.validate(obs))
38
21
  t.is(pts.length, 6)
39
22
  t.true(comparePolygonsAsPoints(pts, exp))
40
23
  })
@@ -52,6 +35,7 @@ test('cuboid (options)', (t) => {
52
35
  [[0, 2, 10], [6, 2, 10], [6, 8, 10], [0, 8, 10]]
53
36
  ]
54
37
 
38
+ t.notThrows(() => geom3.validate(obs))
55
39
  t.is(pts.length, 6)
56
40
  t.true(comparePolygonsAsPoints(pts, exp))
57
41
 
@@ -67,6 +51,7 @@ test('cuboid (options)', (t) => {
67
51
  [[-2.25, -0.75, 3.5], [2.25, -0.75, 3.5], [2.25, 0.75, 3.5], [-2.25, 0.75, 3.5]]
68
52
  ]
69
53
 
54
+ t.notThrows(() => geom3.validate(obs))
70
55
  t.is(pts.length, 6)
71
56
  t.true(comparePolygonsAsPoints(pts, exp))
72
57
  })
@@ -10,6 +10,7 @@ test('cylinder (defaults)', (t) => {
10
10
  const obs = cylinder()
11
11
  const pts = geom3.toPoints(obs)
12
12
 
13
+ t.notThrows(() => geom3.validate(obs))
13
14
  t.is(pts.length, 96)
14
15
  })
15
16
 
@@ -33,12 +34,13 @@ test('cylinder (options)', (t) => {
33
34
  [[1.236067977499789, -3.8042260651806146, -5], [1.236067977499789, -3.8042260651806146, 5],
34
35
  [-3.23606797749979, -2.351141009169892, 5], [-3.23606797749979, -2.351141009169892, -5]],
35
36
  [[0, 0, 5], [-3.23606797749979, -2.351141009169892, 5], [1.236067977499789, -3.8042260651806146, 5]],
36
- [[0, 0, -5], [4, -9.797174393178826e-16, -5], [1.236067977499789, -3.8042260651806146, -5]],
37
- [[4, -9.797174393178826e-16, -5], [4, -9.797174393178826e-16, 5],
38
- [1.236067977499789, -3.8042260651806146, 5], [1.236067977499789, -3.8042260651806146, -5]],
39
- [[0, 0, 5], [1.236067977499789, -3.8042260651806146, 5], [4, -9.797174393178826e-16, 5]]
37
+ [[0, 0, -5], [4, 0, -5], [1.236067977499789, -3.8042260651806146, -5]],
38
+ [[4, 0, -5], [4, 0, 5], [1.236067977499789, -3.8042260651806146, 5],
39
+ [1.236067977499789, -3.8042260651806146, -5]],
40
+ [[0, 0, 5], [1.236067977499789, -3.8042260651806146, 5], [4, 0, 5]]
40
41
  ]
41
42
 
43
+ t.notThrows(() => geom3.validate(obs))
42
44
  t.is(pts.length, 15)
43
45
  t.true(comparePolygonsAsPoints(pts, exp))
44
46
 
@@ -68,6 +70,7 @@ test('cylinder (options)', (t) => {
68
70
  [[-5, -5, -4], [-4.6909830056250525, -5.951056516295154, -4], [-4, -5, -4]]
69
71
  ]
70
72
 
73
+ t.notThrows(() => geom3.validate(obs))
71
74
  t.is(pts.length, 15)
72
75
  t.true(comparePolygonsAsPoints(pts, exp))
73
76
  })
@@ -5,6 +5,8 @@ const vec3 = require('../maths/vec3')
5
5
  const geom3 = require('../geometries/geom3')
6
6
  const poly3 = require('../geometries/poly3')
7
7
 
8
+ const { sin, cos } = require('../utils/trigonometry')
9
+
8
10
  const { isGT, isGTE, isNumberArray } = require('./commonChecks')
9
11
 
10
12
  /**
@@ -38,9 +40,10 @@ const cylinderElliptic = (options) => {
38
40
  if (!isNumberArray(center, 3)) throw new Error('center must be an array of X, Y and Z values')
39
41
  if (!isGT(height, 0)) throw new Error('height must be greater then zero')
40
42
  if (!isNumberArray(startRadius, 2)) throw new Error('startRadius must be an array of X and Y values')
41
- if (!startRadius.every((n) => n > 0)) throw new Error('startRadius values must be greater than zero')
43
+ if (!startRadius.every((n) => n >= 0)) throw new Error('startRadius values must be positive')
42
44
  if (!isNumberArray(endRadius, 2)) throw new Error('endRadius must be an array of X and Y values')
43
- if (!endRadius.every((n) => n > 0)) throw new Error('endRadius values must be greater than zero')
45
+ if (!endRadius.every((n) => n >= 0)) throw new Error('endRadius values must be positive')
46
+ if (endRadius.every((n) => n === 0) && startRadius.every((n) => n === 0)) throw new Error('at least one radius must be positive')
44
47
  if (!isGTE(startAngle, 0)) throw new Error('startAngle must be positive')
45
48
  if (!isGTE(endAngle, 0)) throw new Error('endAngle must be positive')
46
49
  if (!isGTE(segments, 4)) throw new Error('segments must be four or more')
@@ -75,8 +78,8 @@ const cylinderElliptic = (options) => {
75
78
  const v3 = vec3.create()
76
79
  const point = (stack, slice, radius) => {
77
80
  const angle = slice * rotation + startAngle
78
- vec3.scale(v1, axisX, radius[0] * Math.cos(angle))
79
- vec3.scale(v2, axisY, radius[1] * Math.sin(angle))
81
+ vec3.scale(v1, axisX, radius[0] * cos(angle))
82
+ vec3.scale(v2, axisY, radius[1] * sin(angle))
80
83
  vec3.add(v1, v1, v2)
81
84
 
82
85
  vec3.scale(v3, ray, stack)
@@ -100,12 +103,16 @@ const cylinderElliptic = (options) => {
100
103
  polygons.push(fromPoints(point(0, t1, endRadius), point(1, t1, endRadius), point(1, t0, endRadius), point(0, t0, endRadius)))
101
104
  polygons.push(fromPoints(end, point(1, t0, endRadius), point(1, t1, endRadius)))
102
105
  } else {
103
- if (startRadius[0] > 0) {
106
+ if (startRadius[0] > 0 && startRadius[1] > 0) {
104
107
  polygons.push(fromPoints(start, point(0, t1, startRadius), point(0, t0, startRadius)))
108
+ }
109
+ if (startRadius[0] > 0 || startRadius[1] > 0) {
105
110
  polygons.push(fromPoints(point(0, t0, startRadius), point(0, t1, startRadius), point(1, t0, endRadius)))
106
111
  }
107
- if (endRadius[0] > 0) {
112
+ if (endRadius[0] > 0 && endRadius[1] > 0) {
108
113
  polygons.push(fromPoints(end, point(1, t0, endRadius), point(1, t1, endRadius)))
114
+ }
115
+ if (endRadius[0] > 0 || endRadius[1] > 0) {
109
116
  polygons.push(fromPoints(point(1, t0, endRadius), point(0, t1, startRadius), point(1, t1, endRadius)))
110
117
  }
111
118
  }
@@ -10,6 +10,7 @@ test('cylinderElliptic (defaults)', (t) => {
10
10
  const obs = cylinderElliptic()
11
11
  const pts = geom3.toPoints(obs)
12
12
 
13
+ t.notThrows(() => geom3.validate(obs))
13
14
  t.is(pts.length, 96)
14
15
  })
15
16
 
@@ -26,48 +27,49 @@ test('cylinderElliptic (options)', (t) => {
26
27
  [[0.5000000000000001, 0.8660254037844386, -5], [0.5000000000000001, 0.8660254037844386, 5],
27
28
  [0.8660254037844387, 0.49999999999999994, 5], [0.8660254037844387, 0.49999999999999994, -5]],
28
29
  [[0, 0, 5], [0.8660254037844387, 0.49999999999999994, 5], [0.5000000000000001, 0.8660254037844386, 5]],
29
- [[0, 0, -5], [6.123233995736766e-17, 1, -5], [0.5000000000000001, 0.8660254037844386, -5]],
30
- [[6.123233995736766e-17, 1, -5], [6.123233995736766e-17, 1, 5],
30
+ [[0, 0, -5], [0, 1, -5], [0.5000000000000001, 0.8660254037844386, -5]],
31
+ [[0, 1, -5], [0, 1, 5],
31
32
  [0.5000000000000001, 0.8660254037844386, 5], [0.5000000000000001, 0.8660254037844386, -5]],
32
- [[0, 0, 5], [0.5000000000000001, 0.8660254037844386, 5], [6.123233995736766e-17, 1, 5]],
33
- [[0, 0, -5], [-0.4999999999999998, 0.8660254037844387, -5], [6.123233995736766e-17, 1, -5]],
33
+ [[0, 0, 5], [0.5000000000000001, 0.8660254037844386, 5], [0, 1, 5]],
34
+ [[0, 0, -5], [-0.4999999999999998, 0.8660254037844387, -5], [0, 1, -5]],
34
35
  [[-0.4999999999999998, 0.8660254037844387, -5], [-0.4999999999999998, 0.8660254037844387, 5],
35
- [6.123233995736766e-17, 1, 5], [6.123233995736766e-17, 1, -5]],
36
- [[0, 0, 5], [6.123233995736766e-17, 1, 5], [-0.4999999999999998, 0.8660254037844387, 5]],
36
+ [0, 1, 5], [0, 1, -5]],
37
+ [[0, 0, 5], [0, 1, 5], [-0.4999999999999998, 0.8660254037844387, 5]],
37
38
  [[0, 0, -5], [-0.8660254037844387, 0.49999999999999994, -5], [-0.4999999999999998, 0.8660254037844387, -5]],
38
39
  [[-0.8660254037844387, 0.49999999999999994, -5], [-0.8660254037844387, 0.49999999999999994, 5],
39
40
  [-0.4999999999999998, 0.8660254037844387, 5], [-0.4999999999999998, 0.8660254037844387, -5]],
40
41
  [[0, 0, 5], [-0.4999999999999998, 0.8660254037844387, 5], [-0.8660254037844387, 0.49999999999999994, 5]],
41
- [[0, 0, -5], [-1, 1.2246467991473532e-16, -5], [-0.8660254037844387, 0.49999999999999994, -5]],
42
- [[-1, 1.2246467991473532e-16, -5], [-1, 1.2246467991473532e-16, 5],
42
+ [[0, 0, -5], [-1, 0, -5], [-0.8660254037844387, 0.49999999999999994, -5]],
43
+ [[-1, 0, -5], [-1, 0, 5],
43
44
  [-0.8660254037844387, 0.49999999999999994, 5], [-0.8660254037844387, 0.49999999999999994, -5]],
44
- [[0, 0, 5], [-0.8660254037844387, 0.49999999999999994, 5], [-1, 1.2246467991473532e-16, 5]],
45
- [[0, 0, -5], [-0.8660254037844386, -0.5000000000000001, -5], [-1, 1.2246467991473532e-16, -5]],
45
+ [[0, 0, 5], [-0.8660254037844387, 0.49999999999999994, 5], [-1, 0, 5]],
46
+ [[0, 0, -5], [-0.8660254037844386, -0.5000000000000001, -5], [-1, 0, -5]],
46
47
  [[-0.8660254037844386, -0.5000000000000001, -5], [-0.8660254037844386, -0.5000000000000001, 5],
47
- [-1, 1.2246467991473532e-16, 5], [-1, 1.2246467991473532e-16, -5]],
48
- [[0, 0, 5], [-1, 1.2246467991473532e-16, 5], [-0.8660254037844386, -0.5000000000000001, 5]],
48
+ [-1, 0, 5], [-1, 0, -5]],
49
+ [[0, 0, 5], [-1, 0, 5], [-0.8660254037844386, -0.5000000000000001, 5]],
49
50
  [[0, 0, -5], [-0.5000000000000004, -0.8660254037844385, -5], [-0.8660254037844386, -0.5000000000000001, -5]],
50
51
  [[-0.5000000000000004, -0.8660254037844385, -5], [-0.5000000000000004, -0.8660254037844385, 5],
51
52
  [-0.8660254037844386, -0.5000000000000001, 5], [-0.8660254037844386, -0.5000000000000001, -5]],
52
53
  [[0, 0, 5], [-0.8660254037844386, -0.5000000000000001, 5], [-0.5000000000000004, -0.8660254037844385, 5]],
53
- [[0, 0, -5], [-1.8369701987210297e-16, -1, -5], [-0.5000000000000004, -0.8660254037844385, -5]],
54
- [[-1.8369701987210297e-16, -1, -5], [-1.8369701987210297e-16, -1, 5],
54
+ [[0, 0, -5], [0, -1, -5], [-0.5000000000000004, -0.8660254037844385, -5]],
55
+ [[0, -1, -5], [0, -1, 5],
55
56
  [-0.5000000000000004, -0.8660254037844385, 5], [-0.5000000000000004, -0.8660254037844385, -5]],
56
- [[0, 0, 5], [-0.5000000000000004, -0.8660254037844385, 5], [-1.8369701987210297e-16, -1, 5]],
57
- [[0, 0, -5], [0.5000000000000001, -0.8660254037844386, -5], [-1.8369701987210297e-16, -1, -5]],
57
+ [[0, 0, 5], [-0.5000000000000004, -0.8660254037844385, 5], [0, -1, 5]],
58
+ [[0, 0, -5], [0.5000000000000001, -0.8660254037844386, -5], [0, -1, -5]],
58
59
  [[0.5000000000000001, -0.8660254037844386, -5], [0.5000000000000001, -0.8660254037844386, 5],
59
- [-1.8369701987210297e-16, -1, 5], [-1.8369701987210297e-16, -1, -5]],
60
- [[0, 0, 5], [-1.8369701987210297e-16, -1, 5], [0.5000000000000001, -0.8660254037844386, 5]],
60
+ [0, -1, 5], [0, -1, -5]],
61
+ [[0, 0, 5], [0, -1, 5], [0.5000000000000001, -0.8660254037844386, 5]],
61
62
  [[0, 0, -5], [0.8660254037844384, -0.5000000000000004, -5], [0.5000000000000001, -0.8660254037844386, -5]],
62
63
  [[0.8660254037844384, -0.5000000000000004, -5], [0.8660254037844384, -0.5000000000000004, 5],
63
64
  [0.5000000000000001, -0.8660254037844386, 5], [0.5000000000000001, -0.8660254037844386, -5]],
64
65
  [[0, 0, 5], [0.5000000000000001, -0.8660254037844386, 5], [0.8660254037844384, -0.5000000000000004, 5]],
65
- [[0, 0, -5], [1, -2.4492935982947064e-16, -5], [0.8660254037844384, -0.5000000000000004, -5]],
66
- [[1, -2.4492935982947064e-16, -5], [1, -2.4492935982947064e-16, 5],
67
- [0.8660254037844384, -0.5000000000000004, 5], [0.8660254037844384, -0.5000000000000004, -5]],
68
- [[0, 0, 5], [0.8660254037844384, -0.5000000000000004, 5], [1, -2.4492935982947064e-16, 5]]
66
+ [[0, 0, -5], [1, 0, -5], [0.8660254037844384, -0.5000000000000004, -5]],
67
+ [[1, 0, -5], [1, 0, 5], [0.8660254037844384, -0.5000000000000004, 5],
68
+ [0.8660254037844384, -0.5000000000000004, -5]],
69
+ [[0, 0, 5], [0.8660254037844384, -0.5000000000000004, 5], [1, 0, 5]]
69
70
  ]
70
71
 
72
+ t.notThrows(() => geom3.validate(obs))
71
73
  t.is(pts.length, 36)
72
74
  t.true(comparePolygonsAsPoints(pts, exp))
73
75
 
@@ -83,48 +85,49 @@ test('cylinderElliptic (options)', (t) => {
83
85
  [[0.8660254037844387, 0.9999999999999999, -1], [0.5000000000000001, 1.7320508075688772, -1], [1.7320508075688774, 0.49999999999999994, 1]],
84
86
  [[0, 0, 1], [1.7320508075688774, 0.49999999999999994, 1], [1.0000000000000002, 0.8660254037844386, 1]],
85
87
  [[1.7320508075688774, 0.49999999999999994, 1], [0.5000000000000001, 1.7320508075688772, -1], [1.0000000000000002, 0.8660254037844386, 1]],
86
- [[0, 0, -1], [6.123233995736766e-17, 2, -1], [0.5000000000000001, 1.7320508075688772, -1]],
87
- [[0.5000000000000001, 1.7320508075688772, -1], [6.123233995736766e-17, 2, -1], [1.0000000000000002, 0.8660254037844386, 1]],
88
- [[0, 0, 1], [1.0000000000000002, 0.8660254037844386, 1], [1.2246467991473532e-16, 1, 1]],
89
- [[1.0000000000000002, 0.8660254037844386, 1], [6.123233995736766e-17, 2, -1], [1.2246467991473532e-16, 1, 1]],
90
- [[0, 0, -1], [-0.4999999999999998, 1.7320508075688774, -1], [6.123233995736766e-17, 2, -1]],
91
- [[6.123233995736766e-17, 2, -1], [-0.4999999999999998, 1.7320508075688774, -1], [1.2246467991473532e-16, 1, 1]],
92
- [[0, 0, 1], [1.2246467991473532e-16, 1, 1], [-0.9999999999999996, 0.8660254037844387, 1]],
93
- [[1.2246467991473532e-16, 1, 1], [-0.4999999999999998, 1.7320508075688774, -1], [-0.9999999999999996, 0.8660254037844387, 1]],
88
+ [[0, 0, -1], [0, 2, -1], [0.5000000000000001, 1.7320508075688772, -1]],
89
+ [[0.5000000000000001, 1.7320508075688772, -1], [0, 2, -1], [1.0000000000000002, 0.8660254037844386, 1]],
90
+ [[0, 0, 1], [1.0000000000000002, 0.8660254037844386, 1], [0, 1, 1]],
91
+ [[1.0000000000000002, 0.8660254037844386, 1], [0, 2, -1], [0, 1, 1]],
92
+ [[0, 0, -1], [-0.4999999999999998, 1.7320508075688774, -1], [0, 2, -1]],
93
+ [[0, 2, -1], [-0.4999999999999998, 1.7320508075688774, -1], [0, 1, 1]],
94
+ [[0, 0, 1], [0, 1, 1], [-0.9999999999999996, 0.8660254037844387, 1]],
95
+ [[0, 1, 1], [-0.4999999999999998, 1.7320508075688774, -1], [-0.9999999999999996, 0.8660254037844387, 1]],
94
96
  [[0, 0, -1], [-0.8660254037844387, 0.9999999999999999, -1], [-0.4999999999999998, 1.7320508075688774, -1]],
95
97
  [[-0.4999999999999998, 1.7320508075688774, -1], [-0.8660254037844387, 0.9999999999999999, -1], [-0.9999999999999996, 0.8660254037844387, 1]],
96
98
  [[0, 0, 1], [-0.9999999999999996, 0.8660254037844387, 1], [-1.7320508075688774, 0.49999999999999994, 1]],
97
99
  [[-0.9999999999999996, 0.8660254037844387, 1], [-0.8660254037844387, 0.9999999999999999, -1], [-1.7320508075688774, 0.49999999999999994, 1]],
98
- [[0, 0, -1], [-1, 2.4492935982947064e-16, -1], [-0.8660254037844387, 0.9999999999999999, -1]],
99
- [[-0.8660254037844387, 0.9999999999999999, -1], [-1, 2.4492935982947064e-16, -1], [-1.7320508075688774, 0.49999999999999994, 1]],
100
- [[0, 0, 1], [-1.7320508075688774, 0.49999999999999994, 1], [-2, 1.2246467991473532e-16, 1]],
101
- [[-1.7320508075688774, 0.49999999999999994, 1], [-1, 2.4492935982947064e-16, -1], [-2, 1.2246467991473532e-16, 1]],
102
- [[0, 0, -1], [-0.8660254037844386, -1.0000000000000002, -1], [-1, 2.4492935982947064e-16, -1]],
103
- [[-1, 2.4492935982947064e-16, -1], [-0.8660254037844386, -1.0000000000000002, -1], [-2, 1.2246467991473532e-16, 1]],
104
- [[0, 0, 1], [-2, 1.2246467991473532e-16, 1], [-1.7320508075688772, -0.5000000000000001, 1]],
105
- [[-2, 1.2246467991473532e-16, 1], [-0.8660254037844386, -1.0000000000000002, -1], [-1.7320508075688772, -0.5000000000000001, 1]],
100
+ [[0, 0, -1], [-1, 0, -1], [-0.8660254037844387, 0.9999999999999999, -1]],
101
+ [[-0.8660254037844387, 0.9999999999999999, -1], [-1, 0, -1], [-1.7320508075688774, 0.49999999999999994, 1]],
102
+ [[0, 0, 1], [-1.7320508075688774, 0.49999999999999994, 1], [-2, 0, 1]],
103
+ [[-1.7320508075688774, 0.49999999999999994, 1], [-1, 0, -1], [-2, 0, 1]],
104
+ [[0, 0, -1], [-0.8660254037844386, -1.0000000000000002, -1], [-1, 0, -1]],
105
+ [[-1, 0, -1], [-0.8660254037844386, -1.0000000000000002, -1], [-2, 0, 1]],
106
+ [[0, 0, 1], [-2, 0, 1], [-1.7320508075688772, -0.5000000000000001, 1]],
107
+ [[-2, 0, 1], [-0.8660254037844386, -1.0000000000000002, -1], [-1.7320508075688772, -0.5000000000000001, 1]],
106
108
  [[0, 0, -1], [-0.5000000000000004, -1.732050807568877, -1], [-0.8660254037844386, -1.0000000000000002, -1]],
107
109
  [[-0.8660254037844386, -1.0000000000000002, -1], [-0.5000000000000004, -1.732050807568877, -1], [-1.7320508075688772, -0.5000000000000001, 1]],
108
110
  [[0, 0, 1], [-1.7320508075688772, -0.5000000000000001, 1], [-1.0000000000000009, -0.8660254037844385, 1]],
109
111
  [[-1.7320508075688772, -0.5000000000000001, 1], [-0.5000000000000004, -1.732050807568877, -1], [-1.0000000000000009, -0.8660254037844385, 1]],
110
- [[0, 0, -1], [-1.8369701987210297e-16, -2, -1], [-0.5000000000000004, -1.732050807568877, -1]],
111
- [[-0.5000000000000004, -1.732050807568877, -1], [-1.8369701987210297e-16, -2, -1], [-1.0000000000000009, -0.8660254037844385, 1]],
112
- [[0, 0, 1], [-1.0000000000000009, -0.8660254037844385, 1], [-3.6739403974420594e-16, -1, 1]],
113
- [[-1.0000000000000009, -0.8660254037844385, 1], [-1.8369701987210297e-16, -2, -1], [-3.6739403974420594e-16, -1, 1]],
114
- [[0, 0, -1], [0.5000000000000001, -1.7320508075688772, -1], [-1.8369701987210297e-16, -2, -1]],
115
- [[-1.8369701987210297e-16, -2, -1], [0.5000000000000001, -1.7320508075688772, -1], [-3.6739403974420594e-16, -1, 1]],
116
- [[0, 0, 1], [-3.6739403974420594e-16, -1, 1], [1.0000000000000002, -0.8660254037844386, 1]],
117
- [[-3.6739403974420594e-16, -1, 1], [0.5000000000000001, -1.7320508075688772, -1], [1.0000000000000002, -0.8660254037844386, 1]],
112
+ [[0, 0, -1], [0, -2, -1], [-0.5000000000000004, -1.732050807568877, -1]],
113
+ [[-0.5000000000000004, -1.732050807568877, -1], [0, -2, -1], [-1.0000000000000009, -0.8660254037844385, 1]],
114
+ [[0, 0, 1], [-1.0000000000000009, -0.8660254037844385, 1], [0, -1, 1]],
115
+ [[-1.0000000000000009, -0.8660254037844385, 1], [0, -2, -1], [0, -1, 1]],
116
+ [[0, 0, -1], [0.5000000000000001, -1.7320508075688772, -1], [0, -2, -1]],
117
+ [[0, -2, -1], [0.5000000000000001, -1.7320508075688772, -1], [0, -1, 1]],
118
+ [[0, 0, 1], [0, -1, 1], [1.0000000000000002, -0.8660254037844386, 1]],
119
+ [[0, -1, 1], [0.5000000000000001, -1.7320508075688772, -1], [1.0000000000000002, -0.8660254037844386, 1]],
118
120
  [[0, 0, -1], [0.8660254037844384, -1.0000000000000009, -1], [0.5000000000000001, -1.7320508075688772, -1]],
119
121
  [[0.5000000000000001, -1.7320508075688772, -1], [0.8660254037844384, -1.0000000000000009, -1], [1.0000000000000002, -0.8660254037844386, 1]],
120
122
  [[0, 0, 1], [1.0000000000000002, -0.8660254037844386, 1], [1.7320508075688767, -0.5000000000000004, 1]],
121
123
  [[1.0000000000000002, -0.8660254037844386, 1], [0.8660254037844384, -1.0000000000000009, -1], [1.7320508075688767, -0.5000000000000004, 1]],
122
- [[0, 0, -1], [1, -4.898587196589413e-16, -1], [0.8660254037844384, -1.0000000000000009, -1]],
123
- [[0.8660254037844384, -1.0000000000000009, -1], [1, -4.898587196589413e-16, -1], [1.7320508075688767, -0.5000000000000004, 1]],
124
- [[0, 0, 1], [1.7320508075688767, -0.5000000000000004, 1], [2, -2.4492935982947064e-16, 1]],
125
- [[1.7320508075688767, -0.5000000000000004, 1], [1, -4.898587196589413e-16, -1], [2, -2.4492935982947064e-16, 1]]
124
+ [[0, 0, -1], [1, 0, -1], [0.8660254037844384, -1.0000000000000009, -1]],
125
+ [[0.8660254037844384, -1.0000000000000009, -1], [1, 0, -1], [1.7320508075688767, -0.5000000000000004, 1]],
126
+ [[0, 0, 1], [1.7320508075688767, -0.5000000000000004, 1], [2, 0, 1]],
127
+ [[1.7320508075688767, -0.5000000000000004, 1], [1, 0, -1], [2, 0, 1]]
126
128
  ]
127
129
 
130
+ t.notThrows(() => geom3.validate(obs))
128
131
  t.is(pts.length, 48)
129
132
  t.true(comparePolygonsAsPoints(pts, exp))
130
133
 
@@ -132,6 +135,7 @@ test('cylinderElliptic (options)', (t) => {
132
135
  obs = cylinderElliptic({ startRadius: [1, 2], endRadius: [2, 1], startAngle: Math.PI / 2, endAngle: Math.PI * 2 * 0.75, segments: 12 })
133
136
  pts = geom3.toPoints(obs)
134
137
 
138
+ t.notThrows(() => geom3.validate(obs))
135
139
  t.is(pts.length, 28)
136
140
  // t.true(comparePolygonsAsPoints(pts, exp))
137
141
 
@@ -139,6 +143,7 @@ test('cylinderElliptic (options)', (t) => {
139
143
  obs = cylinderElliptic({ segments: 8 })
140
144
  pts = geom3.toPoints(obs)
141
145
 
146
+ t.notThrows(() => geom3.validate(obs))
142
147
  t.is(pts.length, 24)
143
148
 
144
149
  // test center
@@ -179,6 +184,23 @@ test('cylinderElliptic (options)', (t) => {
179
184
  [[-5, -5, -3.5], [-4.292893218813453, -5.707106781186548, -3.5], [-4, -5, -3.5]]
180
185
  ]
181
186
 
187
+ t.notThrows(() => geom3.validate(obs))
182
188
  t.is(pts.length, 24)
183
189
  t.true(comparePolygonsAsPoints(pts, exp))
184
190
  })
191
+
192
+ test('cylinderElliptic (cone)', (t) => {
193
+ const obs = cylinderElliptic({ endRadius: [0, 0] })
194
+ const pts = geom3.toPoints(obs)
195
+
196
+ t.notThrows(() => geom3.validate(obs))
197
+ t.is(pts.length, 64)
198
+ })
199
+
200
+ test('cylinderElliptic (squished)', (t) => {
201
+ const obs = cylinderElliptic({ startRadius: [1, 0], endRadius: [0, 1], segments: 4 })
202
+ const pts = geom3.toPoints(obs)
203
+
204
+ t.notThrows(() => geom3.validate(obs))
205
+ t.is(pts.length, 8)
206
+ })
@@ -4,6 +4,8 @@ const vec2 = require('../maths/vec2')
4
4
 
5
5
  const geom2 = require('../geometries/geom2')
6
6
 
7
+ const { sin, cos } = require('../utils/trigonometry')
8
+
7
9
  const { isGTE, isNumberArray } = require('./commonChecks')
8
10
 
9
11
  /**
@@ -62,7 +64,7 @@ const ellipse = (options) => {
62
64
  segments = (rotation < Math.PI * 2) ? segments + 1 : segments
63
65
  for (let i = 0; i < segments; i++) {
64
66
  const angle = (step * i) + startAngle
65
- const point = vec2.fromValues(radius[0] * Math.cos(angle), radius[1] * Math.sin(angle))
67
+ const point = vec2.fromValues(radius[0] * cos(angle), radius[1] * sin(angle))
66
68
  vec2.add(point, centerv, point)
67
69
  points.push(point)
68
70
  }
@@ -10,6 +10,7 @@ test('ellipse (defaults)', (t) => {
10
10
  const geometry = ellipse()
11
11
  const obs = geom2.toPoints(geometry)
12
12
 
13
+ t.notThrows(() => geom2.validate(geometry))
13
14
  t.deepEqual(obs.length, 32)
14
15
  })
15
16
 
@@ -52,6 +53,7 @@ test('ellipse (options)', (t) => {
52
53
  [3.9807852804032304, 4.804909677983871]
53
54
  ]
54
55
 
56
+ t.notThrows(() => geom2.validate(geometry))
55
57
  t.deepEqual(obs.length, 32)
56
58
  t.true(comparePoints(obs, exp))
57
59
 
@@ -63,20 +65,21 @@ test('ellipse (options)', (t) => {
63
65
  [2.77163859753386, 1.913417161825449],
64
66
  [2.121320343559643, 3.5355339059327373],
65
67
  [1.1480502970952695, 4.619397662556434],
66
- [1.8369701987210297e-16, 5],
68
+ [0, 5],
67
69
  [-1.1480502970952693, 4.619397662556434],
68
70
  [-2.1213203435596424, 3.5355339059327378],
69
71
  [-2.77163859753386, 1.9134171618254494],
70
- [-3, 6.123233995736766e-16],
72
+ [-3, 0],
71
73
  [-2.7716385975338604, -1.9134171618254483],
72
74
  [-2.121320343559643, -3.5355339059327373],
73
75
  [-1.148050297095271, -4.619397662556432],
74
- [-5.51091059616309e-16, -5],
76
+ [0, -5],
75
77
  [1.14805029709527, -4.619397662556433],
76
78
  [2.121320343559642, -3.5355339059327386],
77
79
  [2.7716385975338595, -1.913417161825452]
78
80
  ]
79
81
 
82
+ t.notThrows(() => geom2.validate(geometry))
80
83
  t.deepEqual(obs.length, 16)
81
84
  t.true(comparePoints(obs, exp))
82
85
 
@@ -84,22 +87,23 @@ test('ellipse (options)', (t) => {
84
87
  geometry = ellipse({ radius: [3, 5], startAngle: Math.PI / 2, segments: 16 })
85
88
  obs = geom2.toPoints(geometry)
86
89
  exp = [
87
- [1.8369701987210297e-16, 5],
90
+ [0, 5],
88
91
  [-1.1480502970952693, 4.619397662556434],
89
92
  [-2.1213203435596424, 3.5355339059327378],
90
93
  [-2.77163859753386, 1.9134171618254494],
91
- [-3, 6.123233995736766e-16],
94
+ [-3, 0],
92
95
  [-2.7716385975338604, -1.9134171618254483],
93
96
  [-2.121320343559643, -3.5355339059327373],
94
97
  [-1.148050297095271, -4.619397662556432],
95
- [-5.51091059616309e-16, -5],
98
+ [0, -5],
96
99
  [1.14805029709527, -4.619397662556433],
97
100
  [2.121320343559642, -3.5355339059327386],
98
101
  [2.7716385975338595, -1.913417161825452],
99
- [3, -1.2246467991473533e-15],
102
+ [3, 0],
100
103
  [0, 0]
101
104
  ]
102
105
 
106
+ t.notThrows(() => geom2.validate(geometry))
103
107
  t.deepEqual(obs.length, 14)
104
108
  t.true(comparePoints(obs, exp))
105
109
 
@@ -111,15 +115,17 @@ test('ellipse (options)', (t) => {
111
115
  [2.77163859753386, 1.913417161825449],
112
116
  [2.121320343559643, 3.5355339059327373],
113
117
  [1.1480502970952695, 4.619397662556434],
114
- [1.8369701987210297e-16, 5],
118
+ [0, 5],
115
119
  [0, 0]
116
120
  ]
117
121
 
122
+ t.notThrows(() => geom2.validate(geometry))
118
123
  t.deepEqual(obs.length, 6)
119
124
  t.true(comparePoints(obs, exp))
120
125
 
121
126
  // test segments
122
127
  geometry = ellipse({ segments: 72 })
123
128
  obs = geom2.toPoints(geometry)
129
+ t.notThrows(() => geom2.validate(geometry))
124
130
  t.deepEqual(obs.length, 72)
125
131
  })
@@ -3,6 +3,8 @@ const vec3 = require('../maths/vec3')
3
3
  const geom3 = require('../geometries/geom3')
4
4
  const poly3 = require('../geometries/poly3')
5
5
 
6
+ const { sin, cos } = require('../utils/trigonometry')
7
+
6
8
  const { isGTE, isNumberArray } = require('./commonChecks')
7
9
 
8
10
  /**
@@ -42,14 +44,14 @@ const ellipsoid = (options) => {
42
44
  const p1 = vec3.create()
43
45
  const p2 = vec3.create()
44
46
  for (let slice1 = 0; slice1 <= segments; slice1++) {
45
- const angle = Math.PI * 2.0 * slice1 / segments
46
- const cylinderpoint = vec3.add(vec3.create(), vec3.scale(p1, xvector, Math.cos(angle)), vec3.scale(p2, yvector, Math.sin(angle)))
47
+ const angle = 2 * Math.PI * slice1 / segments
48
+ const cylinderpoint = vec3.add(vec3.create(), vec3.scale(p1, xvector, cos(angle)), vec3.scale(p2, yvector, sin(angle)))
47
49
  if (slice1 > 0) {
48
50
  let prevcospitch, prevsinpitch
49
51
  for (let slice2 = 0; slice2 <= qsegments; slice2++) {
50
52
  const pitch = 0.5 * Math.PI * slice2 / qsegments
51
- const cospitch = Math.cos(pitch)
52
- const sinpitch = Math.sin(pitch)
53
+ const cospitch = cos(pitch)
54
+ const sinpitch = sin(pitch)
53
55
  if (slice2 > 0) {
54
56
  let points = []
55
57
  let point