@jscad/modeling 2.9.0 → 2.9.3

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 (131) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +4 -4
  3. package/dist/jscad-modeling.min.js +437 -428
  4. package/package.json +3 -2
  5. package/src/colors/colorize.test.js +1 -1
  6. package/src/geometries/geom2/index.d.ts +1 -0
  7. package/src/geometries/geom2/index.js +2 -1
  8. package/src/geometries/geom2/toOutlines.js +66 -52
  9. package/src/geometries/geom2/validate.d.ts +3 -0
  10. package/src/geometries/geom2/validate.js +36 -0
  11. package/src/geometries/geom3/create.js +1 -1
  12. package/src/geometries/geom3/create.test.js +1 -1
  13. package/src/geometries/geom3/fromPoints.js +1 -1
  14. package/src/geometries/geom3/index.d.ts +1 -0
  15. package/src/geometries/geom3/index.js +2 -1
  16. package/src/geometries/geom3/isA.js +1 -1
  17. package/src/geometries/geom3/validate.d.ts +3 -0
  18. package/src/geometries/geom3/validate.js +62 -0
  19. package/src/geometries/path2/index.d.ts +1 -1
  20. package/src/geometries/path2/index.js +2 -2
  21. package/src/geometries/path2/validate.d.ts +3 -0
  22. package/src/geometries/path2/validate.js +41 -0
  23. package/src/geometries/poly2/arePointsInside.js +0 -35
  24. package/src/geometries/poly3/create.js +1 -1
  25. package/src/geometries/poly3/index.d.ts +1 -0
  26. package/src/geometries/poly3/index.js +2 -1
  27. package/src/geometries/poly3/measureArea.test.js +16 -16
  28. package/src/geometries/poly3/measureBoundingSphere.test.js +8 -8
  29. package/src/geometries/poly3/validate.d.ts +4 -0
  30. package/src/geometries/poly3/validate.js +64 -0
  31. package/src/maths/constants.d.ts +1 -0
  32. package/src/maths/constants.js +11 -0
  33. package/src/maths/utils/aboutEqualNormals.js +1 -5
  34. package/src/measurements/measureCenterOfMass.test.js +2 -2
  35. package/src/operations/booleans/intersect.test.js +8 -0
  36. package/src/operations/booleans/intersectGeom3.js +2 -1
  37. package/src/operations/booleans/scission.test.js +4 -4
  38. package/src/operations/booleans/subtract.test.js +8 -0
  39. package/src/operations/booleans/subtractGeom3.js +2 -1
  40. package/src/operations/booleans/to3DWalls.js +1 -1
  41. package/src/operations/booleans/trees/Node.js +10 -16
  42. package/src/operations/booleans/trees/PolygonTreeNode.js +13 -14
  43. package/src/operations/booleans/trees/Tree.js +1 -2
  44. package/src/operations/booleans/trees/splitPolygonByPlane.js +2 -3
  45. package/src/operations/booleans/union.test.js +27 -0
  46. package/src/operations/booleans/unionGeom3.js +2 -1
  47. package/src/operations/expansions/expand.test.js +30 -21
  48. package/src/operations/expansions/expandGeom3.test.js +14 -14
  49. package/src/operations/expansions/expandShell.js +5 -4
  50. package/src/operations/expansions/extrudePolygon.js +7 -7
  51. package/src/operations/expansions/offset.test.js +25 -0
  52. package/src/operations/extrusions/earcut/assignHoles.js +7 -3
  53. package/src/operations/extrusions/earcut/assignHoles.test.js +50 -4
  54. package/src/operations/extrusions/earcut/linkedList.js +1 -1
  55. package/src/operations/extrusions/extrudeFromSlices.test.js +16 -10
  56. package/src/operations/extrusions/extrudeLinear.test.js +15 -9
  57. package/src/operations/extrusions/extrudeRectangular.test.js +15 -8
  58. package/src/operations/extrusions/extrudeRotate.js +5 -1
  59. package/src/operations/extrusions/extrudeRotate.test.js +12 -0
  60. package/src/operations/extrusions/extrudeWalls.js +2 -2
  61. package/src/operations/extrusions/project.js +11 -14
  62. package/src/operations/extrusions/project.test.js +55 -55
  63. package/src/operations/hulls/hull.test.js +24 -1
  64. package/src/operations/hulls/hullChain.test.js +6 -4
  65. package/src/operations/hulls/hullGeom2.js +6 -18
  66. package/src/operations/hulls/hullGeom3.js +5 -18
  67. package/src/operations/hulls/hullPath2.js +4 -14
  68. package/src/operations/hulls/hullPath2.test.js +1 -1
  69. package/src/operations/hulls/hullPoints2.js +43 -92
  70. package/src/operations/hulls/toUniquePoints.js +34 -0
  71. package/src/operations/modifiers/generalize.js +2 -13
  72. package/src/operations/modifiers/generalize.test.js +5 -31
  73. package/src/operations/modifiers/insertTjunctions.js +1 -1
  74. package/src/operations/modifiers/insertTjunctions.test.js +21 -21
  75. package/src/operations/modifiers/mergePolygons.js +11 -14
  76. package/src/operations/{booleans → modifiers}/reTesselateCoplanarPolygons.js +1 -1
  77. package/src/operations/{booleans → modifiers}/reTesselateCoplanarPolygons.test.js +5 -5
  78. package/src/operations/{booleans → modifiers}/retessellate.js +2 -9
  79. package/src/operations/{booleans → modifiers}/retessellate.test.js +0 -0
  80. package/src/operations/modifiers/snapPolygons.test.js +12 -12
  81. package/src/operations/modifiers/triangulatePolygons.js +3 -3
  82. package/src/operations/transforms/align.test.js +12 -0
  83. package/src/operations/transforms/center.js +1 -1
  84. package/src/operations/transforms/center.test.js +12 -0
  85. package/src/operations/transforms/mirror.test.js +16 -0
  86. package/src/operations/transforms/rotate.test.js +10 -0
  87. package/src/operations/transforms/scale.test.js +15 -0
  88. package/src/operations/transforms/transform.test.js +5 -0
  89. package/src/operations/transforms/translate.test.js +16 -0
  90. package/src/primitives/arc.test.js +11 -0
  91. package/src/primitives/circle.test.js +15 -9
  92. package/src/primitives/cube.test.js +3 -0
  93. package/src/primitives/cuboid.js +1 -1
  94. package/src/primitives/cuboid.test.js +9 -24
  95. package/src/primitives/cylinder.test.js +7 -4
  96. package/src/primitives/cylinderElliptic.js +14 -7
  97. package/src/primitives/cylinderElliptic.test.js +72 -50
  98. package/src/primitives/ellipse.js +3 -1
  99. package/src/primitives/ellipse.test.js +14 -8
  100. package/src/primitives/ellipsoid.js +8 -6
  101. package/src/primitives/ellipsoid.test.js +84 -80
  102. package/src/primitives/geodesicSphere.test.js +3 -0
  103. package/src/primitives/line.test.js +1 -0
  104. package/src/primitives/polygon.test.js +15 -10
  105. package/src/primitives/polyhedron.js +1 -1
  106. package/src/primitives/polyhedron.test.js +14 -42
  107. package/src/primitives/rectangle.test.js +3 -0
  108. package/src/primitives/roundedCuboid.js +6 -6
  109. package/src/primitives/roundedCuboid.test.js +5 -0
  110. package/src/primitives/roundedCylinder.js +7 -5
  111. package/src/primitives/roundedCylinder.test.js +40 -36
  112. package/src/primitives/roundedRectangle.test.js +5 -0
  113. package/src/primitives/sphere.test.js +52 -73
  114. package/src/primitives/square.test.js +3 -0
  115. package/src/primitives/star.test.js +6 -0
  116. package/src/primitives/torus.test.js +8 -1
  117. package/src/primitives/triangle.js +1 -2
  118. package/src/primitives/triangle.test.js +7 -0
  119. package/src/utils/areAllShapesTheSameType.js +2 -2
  120. package/src/utils/areAllShapesTheSameType.test.js +17 -0
  121. package/src/utils/index.d.ts +1 -0
  122. package/src/utils/index.js +3 -1
  123. package/src/utils/trigonometry.d.ts +2 -0
  124. package/src/utils/trigonometry.js +34 -0
  125. package/src/utils/trigonometry.test.js +25 -0
  126. package/test/helpers/nearlyEqual.js +4 -1
  127. package/src/geometries/path2/eachPoint.d.ts +0 -9
  128. package/src/geometries/path2/eachPoint.js +0 -17
  129. package/src/geometries/path2/eachPoint.test.js +0 -11
  130. package/src/operations/modifiers/edges.js +0 -195
  131. package/src/operations/modifiers/repairTjunctions.js +0 -44
@@ -10,6 +10,7 @@ test('roundedCylinder (defaults)', (t) => {
10
10
  const obs = roundedCylinder()
11
11
  const pts = geom3.toPoints(obs)
12
12
 
13
+ t.notThrows(() => geom3.validate(obs))
13
14
  t.is(pts.length, 544)
14
15
  })
15
16
 
@@ -20,6 +21,7 @@ test('roundedCylinder (options)', (t) => {
20
21
  let exp = [
21
22
  ]
22
23
 
24
+ t.notThrows(() => geom3.validate(obs))
23
25
  t.is(pts.length, 15)
24
26
 
25
27
  // test center
@@ -48,6 +50,7 @@ test('roundedCylinder (options)', (t) => {
48
50
  [[-5, -5, -4], [-5, -4, -4.2], [-5.951056516295154, -4.6909830056250525, -4.2]]
49
51
  ]
50
52
 
53
+ t.notThrows(() => geom3.validate(obs))
51
54
  t.is(pts.length, 15)
52
55
  t.true(comparePolygonsAsPoints(pts, exp))
53
56
 
@@ -57,26 +60,27 @@ test('roundedCylinder (options)', (t) => {
57
60
  exp = [
58
61
  [[0.9510565162951535, 0.30901699437494745, -9.8], [0, 1, -9.8],
59
62
  [0, 1, 9.8], [0.9510565162951535, 0.30901699437494745, 9.8]],
60
- [[0, 1, -9.8], [0.9510565162951535, 0.30901699437494745, -9.8], [0, 6.123233995736766e-17, -10]],
61
- [[0, 6.123233995736766e-17, 10], [0.9510565162951535, 0.30901699437494745, 9.8], [0, 1, 9.8]],
63
+ [[0, 1, -9.8], [0.9510565162951535, 0.30901699437494745, -9.8], [0, 0, -10]],
64
+ [[0, 0, 10], [0.9510565162951535, 0.30901699437494745, 9.8], [0, 1, 9.8]],
62
65
  [[0.5877852522924732, -0.8090169943749473, -9.8], [0.9510565162951535, 0.30901699437494745, -9.8],
63
66
  [0.9510565162951535, 0.30901699437494745, 9.8], [0.5877852522924732, -0.8090169943749473, 9.8]],
64
- [[0.9510565162951535, 0.30901699437494745, -9.8], [0.5877852522924732, -0.8090169943749473, -9.8], [5.823541592445462e-17, 1.8921833652170753e-17, -10]],
65
- [[5.823541592445462e-17, 1.8921833652170753e-17, 10], [0.5877852522924732, -0.8090169943749473, 9.8], [0.9510565162951535, 0.30901699437494745, 9.8]],
67
+ [[0.9510565162951535, 0.30901699437494745, -9.8], [0.5877852522924732, -0.8090169943749473, -9.8], [0, 0, -10]],
68
+ [[0, 0, 10], [0.5877852522924732, -0.8090169943749473, 9.8], [0.9510565162951535, 0.30901699437494745, 9.8]],
66
69
  [[-0.587785252292473, -0.8090169943749475, -9.8], [0.5877852522924732, -0.8090169943749473, -9.8],
67
70
  [0.5877852522924732, -0.8090169943749473, 9.8], [-0.587785252292473, -0.8090169943749475, 9.8]],
68
- [[0.5877852522924732, -0.8090169943749473, -9.8], [-0.587785252292473, -0.8090169943749475, -9.8], [3.599146639029984e-17, -4.9538003630854574e-17, -10]],
69
- [[3.599146639029984e-17, -4.9538003630854574e-17, 10], [-0.587785252292473, -0.8090169943749475, 9.8], [0.5877852522924732, -0.8090169943749473, 9.8]],
71
+ [[0.5877852522924732, -0.8090169943749473, -9.8], [-0.587785252292473, -0.8090169943749475, -9.8], [0, 0, -10]],
72
+ [[0, 0, 10], [-0.587785252292473, -0.8090169943749475, 9.8], [0.5877852522924732, -0.8090169943749473, 9.8]],
70
73
  [[-0.9510565162951536, 0.30901699437494723, -9.8], [-0.587785252292473, -0.8090169943749475, -9.8],
71
74
  [-0.587785252292473, -0.8090169943749475, 9.8], [-0.9510565162951536, 0.30901699437494723, 9.8]],
72
- [[-0.587785252292473, -0.8090169943749475, -9.8], [-0.9510565162951536, 0.30901699437494723, -9.8], [-3.5991466390299825e-17, -4.953800363085458e-17, -10]],
73
- [[-3.5991466390299825e-17, -4.953800363085458e-17, 10], [-0.9510565162951536, 0.30901699437494723, 9.8], [-0.587785252292473, -0.8090169943749475, 9.8]],
74
- [[-2.4492935982947064e-16, 1, -9.8], [-0.9510565162951536, 0.30901699437494723, -9.8],
75
- [-0.9510565162951536, 0.30901699437494723, 9.8], [-2.4492935982947064e-16, 1, 9.8]],
76
- [[-0.9510565162951536, 0.30901699437494723, -9.8], [-2.4492935982947064e-16, 1, -9.8], [-5.823541592445463e-17, 1.8921833652170737e-17, -10]],
77
- [[-5.823541592445463e-17, 1.8921833652170737e-17, 10], [-2.4492935982947064e-16, 1, 9.8], [-0.9510565162951536, 0.30901699437494723, 9.8]]
75
+ [[-0.587785252292473, -0.8090169943749475, -9.8], [-0.9510565162951536, 0.30901699437494723, -9.8], [0, 0, -10]],
76
+ [[0, 0, 10], [-0.9510565162951536, 0.30901699437494723, 9.8], [-0.587785252292473, -0.8090169943749475, 9.8]],
77
+ [[0, 1, -9.8], [-0.9510565162951536, 0.30901699437494723, -9.8],
78
+ [-0.9510565162951536, 0.30901699437494723, 9.8], [0, 1, 9.8]],
79
+ [[-0.9510565162951536, 0.30901699437494723, -9.8], [0, 1, -9.8], [0, 0, -10]],
80
+ [[0, 0, 10], [0, 1, 9.8], [-0.9510565162951536, 0.30901699437494723, 9.8]]
78
81
  ]
79
82
 
83
+ t.notThrows(() => geom3.validate(obs))
80
84
  t.is(pts.length, 15)
81
85
  t.true(comparePolygonsAsPoints(pts, exp))
82
86
 
@@ -86,26 +90,26 @@ test('roundedCylinder (options)', (t) => {
86
90
  exp = [
87
91
  [[9.510565162951535, 3.0901699437494745, -0.8], [0, 10, -0.8],
88
92
  [0, 10, 0.8], [9.510565162951535, 3.0901699437494745, 0.8]],
89
- [[0, 10, -0.8], [9.510565162951535, 3.0901699437494745, -0.8], [0, 6.123233995736766e-16, -1]],
90
- [[0, 6.123233995736766e-16, 1], [9.510565162951535, 3.0901699437494745, 0.8], [0, 10, 0.8]],
93
+ [[0, 10, -0.8], [9.510565162951535, 3.0901699437494745, -0.8], [0, 0, -1]],
94
+ [[0, 0, 1], [9.510565162951535, 3.0901699437494745, 0.8], [0, 10, 0.8]],
91
95
  [[5.877852522924733, -8.090169943749473, -0.8], [9.510565162951535, 3.0901699437494745, -0.8],
92
96
  [9.510565162951535, 3.0901699437494745, 0.8], [5.877852522924733, -8.090169943749473, 0.8]],
93
- [[9.510565162951535, 3.0901699437494745, -0.8], [5.877852522924733, -8.090169943749473, -0.8], [5.823541592445461e-16, 1.8921833652170753e-16, -1]],
94
- [[5.823541592445461e-16, 1.8921833652170753e-16, 1], [5.877852522924733, -8.090169943749473, 0.8], [9.510565162951535, 3.0901699437494745, 0.8]],
97
+ [[9.510565162951535, 3.0901699437494745, -0.8], [5.877852522924733, -8.090169943749473, -0.8], [0, 0, -1]],
98
+ [[0, 0, 1], [5.877852522924733, -8.090169943749473, 0.8], [9.510565162951535, 3.0901699437494745, 0.8]],
95
99
  [[-5.87785252292473, -8.090169943749475, -0.8], [5.877852522924733, -8.090169943749473, -0.8],
96
100
  [5.877852522924733, -8.090169943749473, 0.8], [-5.87785252292473, -8.090169943749475, 0.8]],
97
- [[5.877852522924733, -8.090169943749473, -0.8], [-5.87785252292473, -8.090169943749475, -0.8], [3.599146639029984e-16, -4.953800363085457e-16, -1]],
98
- [[3.599146639029984e-16, -4.953800363085457e-16, 1], [-5.87785252292473, -8.090169943749475, 0.8], [5.877852522924733, -8.090169943749473, 0.8]],
101
+ [[5.877852522924733, -8.090169943749473, -0.8], [-5.87785252292473, -8.090169943749475, -0.8], [0, 0, -1]],
102
+ [[0, 0, 1], [-5.87785252292473, -8.090169943749475, 0.8], [5.877852522924733, -8.090169943749473, 0.8]],
99
103
  [[-9.510565162951536, 3.0901699437494723, -0.8], [-5.87785252292473, -8.090169943749475, -0.8],
100
104
  [-5.87785252292473, -8.090169943749475, 0.8], [-9.510565162951536, 3.0901699437494723, 0.8]],
101
- [[-5.87785252292473, -8.090169943749475, -0.8], [-9.510565162951536, 3.0901699437494723, -0.8], [-3.5991466390299825e-16, -4.953800363085459e-16, -1]],
102
- [[-3.5991466390299825e-16, -4.953800363085459e-16, 1], [-9.510565162951536, 3.0901699437494723, 0.8], [-5.87785252292473, -8.090169943749475, 0.8]],
103
- [[-2.4492935982947065e-15, 10, -0.8], [-9.510565162951536, 3.0901699437494723, -0.8],
104
- [-9.510565162951536, 3.0901699437494723, 0.8], [-2.4492935982947065e-15, 10, 0.8]],
105
- [[-9.510565162951536, 3.0901699437494723, -0.8], [-2.4492935982947065e-15, 10, -0.8], [-5.823541592445462e-16, 1.8921833652170739e-16, -1]],
106
- [[-5.823541592445462e-16, 1.8921833652170739e-16, 1], [-2.4492935982947065e-15, 10, 0.8], [-9.510565162951536, 3.0901699437494723, 0.8]]
105
+ [[-5.87785252292473, -8.090169943749475, -0.8], [-9.510565162951536, 3.0901699437494723, -0.8], [0, 0, -1]],
106
+ [[0, 0, 1], [-9.510565162951536, 3.0901699437494723, 0.8], [-5.87785252292473, -8.090169943749475, 0.8]],
107
+ [[0, 10, -0.8], [-9.510565162951536, 3.0901699437494723, -0.8], [-9.510565162951536, 3.0901699437494723, 0.8], [0, 10, 0.8]],
108
+ [[-9.510565162951536, 3.0901699437494723, -0.8], [0, 10, -0.8], [0, 0, -1]],
109
+ [[0, 0, 1], [0, 10, 0.8], [-9.510565162951536, 3.0901699437494723, 0.8]]
107
110
  ]
108
111
 
112
+ t.notThrows(() => geom3.validate(obs))
109
113
  t.is(pts.length, 15)
110
114
  t.true(comparePolygonsAsPoints(pts, exp))
111
115
 
@@ -115,26 +119,26 @@ test('roundedCylinder (options)', (t) => {
115
119
  exp = [
116
120
  [[4.755282581475767, 1.5450849718747373, -8], [0, 5, -8],
117
121
  [0, 5, 8], [4.755282581475767, 1.5450849718747373, 8]],
118
- [[0, 5, -8], [4.755282581475767, 1.5450849718747373, -8], [0, 3.061616997868383e-16, -10]],
119
- [[0, 3.061616997868383e-16, 10], [4.755282581475767, 1.5450849718747373, 8], [0, 5, 8]],
122
+ [[0, 5, -8], [4.755282581475767, 1.5450849718747373, -8], [0, 0, -10]],
123
+ [[0, 0, 10], [4.755282581475767, 1.5450849718747373, 8], [0, 5, 8]],
120
124
  [[2.9389262614623664, -4.045084971874736, -8], [4.755282581475767, 1.5450849718747373, -8],
121
125
  [4.755282581475767, 1.5450849718747373, 8], [2.9389262614623664, -4.045084971874736, 8]],
122
- [[4.755282581475767, 1.5450849718747373, -8], [2.9389262614623664, -4.045084971874736, -8], [2.9117707962227305e-16, 9.460916826085377e-17, -10]],
123
- [[2.9117707962227305e-16, 9.460916826085377e-17, 10], [2.9389262614623664, -4.045084971874736, 8], [4.755282581475767, 1.5450849718747373, 8]],
126
+ [[4.755282581475767, 1.5450849718747373, -8], [2.9389262614623664, -4.045084971874736, -8], [0, 0, -10]],
127
+ [[0, 0, 10], [2.9389262614623664, -4.045084971874736, 8], [4.755282581475767, 1.5450849718747373, 8]],
124
128
  [[-2.938926261462365, -4.045084971874737, -8], [2.9389262614623664, -4.045084971874736, -8],
125
129
  [2.9389262614623664, -4.045084971874736, 8], [-2.938926261462365, -4.045084971874737, 8]],
126
- [[2.9389262614623664, -4.045084971874736, -8], [-2.938926261462365, -4.045084971874737, -8], [1.799573319514992e-16, -2.4769001815427284e-16, -10]],
127
- [[1.799573319514992e-16, -2.4769001815427284e-16, 10], [-2.938926261462365, -4.045084971874737, 8], [2.9389262614623664, -4.045084971874736, 8]],
130
+ [[2.9389262614623664, -4.045084971874736, -8], [-2.938926261462365, -4.045084971874737, -8], [0, 0, -10]],
131
+ [[0, 0, 10], [-2.938926261462365, -4.045084971874737, 8], [2.9389262614623664, -4.045084971874736, 8]],
128
132
  [[-4.755282581475768, 1.5450849718747361, -8], [-2.938926261462365, -4.045084971874737, -8],
129
133
  [-2.938926261462365, -4.045084971874737, 8], [-4.755282581475768, 1.5450849718747361, 8]],
130
- [[-2.938926261462365, -4.045084971874737, -8], [-4.755282581475768, 1.5450849718747361, -8], [-1.7995733195149913e-16, -2.4769001815427294e-16, -10]],
131
- [[-1.7995733195149913e-16, -2.4769001815427294e-16, 10], [-4.755282581475768, 1.5450849718747361, 8], [-2.938926261462365, -4.045084971874737, 8]],
132
- [[-1.2246467991473533e-15, 5, -8], [-4.755282581475768, 1.5450849718747361, -8],
133
- [-4.755282581475768, 1.5450849718747361, 8], [-1.2246467991473533e-15, 5, 8]],
134
- [[-4.755282581475768, 1.5450849718747361, -8], [-1.2246467991473533e-15, 5, -8], [-2.911770796222731e-16, 9.460916826085369e-17, -10]],
135
- [[-2.911770796222731e-16, 9.460916826085369e-17, 10], [-1.2246467991473533e-15, 5, 8], [-4.755282581475768, 1.5450849718747361, 8]]
134
+ [[-2.938926261462365, -4.045084971874737, -8], [-4.755282581475768, 1.5450849718747361, -8], [0, 0, -10]],
135
+ [[0, 0, 10], [-4.755282581475768, 1.5450849718747361, 8], [-2.938926261462365, -4.045084971874737, 8]],
136
+ [[0, 5, -8], [-4.755282581475768, 1.5450849718747361, -8], [-4.755282581475768, 1.5450849718747361, 8], [0, 5, 8]],
137
+ [[-4.755282581475768, 1.5450849718747361, -8], [0, 5, -8], [0, 0, -10]],
138
+ [[0, 0, 10], [0, 5, 8], [-4.755282581475768, 1.5450849718747361, 8]]
136
139
  ]
137
140
 
141
+ t.notThrows(() => geom3.validate(obs))
138
142
  t.is(pts.length, 15)
139
143
  t.true(comparePolygonsAsPoints(pts, exp))
140
144
  })
@@ -10,6 +10,7 @@ test('roundedRectangle (defaults)', (t) => {
10
10
  const geometry = roundedRectangle()
11
11
  const obs = geom2.toPoints(geometry)
12
12
 
13
+ t.notThrows(() => geom2.validate(geometry))
13
14
  t.deepEqual(obs.length, 36)
14
15
  })
15
16
 
@@ -39,6 +40,7 @@ test('roundedRectangle (options)', (t) => {
39
40
  [4.984775906502257, 4.123463313526982],
40
41
  [5, 4.2]
41
42
  ]
43
+ t.notThrows(() => geom2.validate(geometry))
42
44
  t.deepEqual(obs.length, 20)
43
45
  t.true(comparePoints(obs, exp))
44
46
 
@@ -67,6 +69,7 @@ test('roundedRectangle (options)', (t) => {
67
69
  [4.984775906502257, -2.8765366864730177],
68
70
  [5, -2.8]
69
71
  ]
72
+ t.notThrows(() => geom2.validate(geometry))
70
73
  t.deepEqual(obs.length, 20)
71
74
  t.true(comparePoints(obs, exp))
72
75
 
@@ -95,11 +98,13 @@ test('roundedRectangle (options)', (t) => {
95
98
  [4.847759065022574, -1.7653668647301801],
96
99
  [5, -1.0000000000000004]
97
100
  ]
101
+ t.notThrows(() => geom2.validate(geometry))
98
102
  t.deepEqual(obs.length, 20)
99
103
  t.true(comparePoints(obs, exp))
100
104
 
101
105
  // test segments
102
106
  geometry = roundedRectangle({ size: [10, 6], roundRadius: 2, segments: 64 })
103
107
  obs = geom2.toPoints(geometry)
108
+ t.notThrows(() => geom2.validate(geometry))
104
109
  t.deepEqual(obs.length, 68)
105
110
  })
@@ -10,6 +10,7 @@ test('sphere (defaults)', (t) => {
10
10
  const obs = sphere()
11
11
  const pts = geom3.toPoints(obs)
12
12
 
13
+ t.notThrows(() => geom3.validate(obs))
13
14
  t.is(pts.length, 512)
14
15
  })
15
16
 
@@ -18,6 +19,7 @@ test('sphere (options)', (t) => {
18
19
  let obs = sphere({ radius: 5, segments: 12 })
19
20
  let pts = geom3.toPoints(obs)
20
21
  let exp = []
22
+ t.notThrows(() => geom3.validate(obs))
21
23
  t.is(pts.length, 72)
22
24
  // t.true(comparePolygonsAsPoints(pts, exp))
23
25
 
@@ -29,102 +31,78 @@ test('sphere (options)', (t) => {
29
31
  [0.5000000000000001, -0.5, -0.7071067811865475], [0.7071067811865476, 0, -0.7071067811865475]],
30
32
  [[0.7071067811865476, 0, 0.7071067811865475], [0.5000000000000001, -0.5, 0.7071067811865475],
31
33
  [0.7071067811865476, -0.7071067811865475, 0], [1, 0, 0]],
32
- [[0.7071067811865476, 0, -0.7071067811865475], [0.5000000000000001, -0.5, -0.7071067811865475], [6.123233995736766e-17, 0, -1]],
33
- [[6.123233995736766e-17, 0, 1], [0.5000000000000001, -0.5, 0.7071067811865475], [0.7071067811865476, 0, 0.7071067811865475]],
34
- [[0.7071067811865476, -0.7071067811865475, 0], [6.123233995736766e-17, -1, 0],
35
- [4.329780281177467e-17, -0.7071067811865476, -0.7071067811865475], [0.5000000000000001, -0.5, -0.7071067811865475]],
36
- [[0.5000000000000001, -0.5, 0.7071067811865475], [4.329780281177467e-17, -0.7071067811865476, 0.7071067811865475],
37
- [6.123233995736766e-17, -1, 0], [0.7071067811865476, -0.7071067811865475, 0]],
38
- [[0.5000000000000001, -0.5, -0.7071067811865475], [4.329780281177467e-17, -0.7071067811865476, -0.7071067811865475],
39
- [4.329780281177467e-17, -4.329780281177466e-17, -1]],
40
- [[4.329780281177467e-17, -4.329780281177466e-17, 1],
41
- [4.329780281177467e-17, -0.7071067811865476, 0.7071067811865475],
34
+ [[0.7071067811865476, 0, -0.7071067811865475], [0.5000000000000001, -0.5, -0.7071067811865475], [0, 0, -1]],
35
+ [[0, 0, 1], [0.5000000000000001, -0.5, 0.7071067811865475], [0.7071067811865476, 0, 0.7071067811865475]],
36
+ [[0.7071067811865476, -0.7071067811865475, 0], [0, -1, 0],
37
+ [0, -0.7071067811865476, -0.7071067811865475], [0.5000000000000001, -0.5, -0.7071067811865475]],
38
+ [[0.5000000000000001, -0.5, 0.7071067811865475], [0, -0.7071067811865476, 0.7071067811865475],
39
+ [0, -1, 0], [0.7071067811865476, -0.7071067811865475, 0]],
40
+ [[0.5000000000000001, -0.5, -0.7071067811865475],
41
+ [0, -0.7071067811865476, -0.7071067811865475], [0, 0, -1]],
42
+ [[0, 0, 1], [0, -0.7071067811865476, 0.7071067811865475],
42
43
  [0.5000000000000001, -0.5, 0.7071067811865475]],
43
- [[6.123233995736766e-17, -1, 0],
44
- [-0.7071067811865475, -0.7071067811865476, 0],
44
+ [[0, -1, 0], [-0.7071067811865475, -0.7071067811865476, 0],
45
45
  [-0.5, -0.5000000000000001, -0.7071067811865475],
46
- [4.329780281177467e-17, -0.7071067811865476, -0.7071067811865475]],
47
- [[4.329780281177467e-17, -0.7071067811865476, 0.7071067811865475],
46
+ [0, -0.7071067811865476, -0.7071067811865475]],
47
+ [[0, -0.7071067811865476, 0.7071067811865475],
48
48
  [-0.5, -0.5000000000000001, 0.7071067811865475],
49
- [-0.7071067811865475, -0.7071067811865476, 0],
50
- [6.123233995736766e-17, -1, 0]],
51
- [[4.329780281177467e-17, -0.7071067811865476, -0.7071067811865475],
52
- [-0.5, -0.5000000000000001, -0.7071067811865475],
53
- [3.749399456654644e-33, -6.123233995736766e-17, -1]],
54
- [[3.749399456654644e-33, -6.123233995736766e-17, 1],
55
- [-0.5, -0.5000000000000001, 0.7071067811865475],
56
- [4.329780281177467e-17, -0.7071067811865476, 0.7071067811865475]],
57
- [[-0.7071067811865475, -0.7071067811865476, 0],
58
- [-1, -1.2246467991473532e-16, 0],
59
- [-0.7071067811865476, -8.659560562354934e-17, -0.7071067811865475],
49
+ [-0.7071067811865475, -0.7071067811865476, 0], [0, -1, 0]],
50
+ [[0, -0.7071067811865476, -0.7071067811865475],
51
+ [-0.5, -0.5000000000000001, -0.7071067811865475], [0, 0, -1]],
52
+ [[0, 0, 1], [-0.5, -0.5000000000000001, 0.7071067811865475],
53
+ [0, -0.7071067811865476, 0.7071067811865475]],
54
+ [[-0.7071067811865475, -0.7071067811865476, 0], [-1, 0, 0],
55
+ [-0.7071067811865476, 0, -0.7071067811865475],
60
56
  [-0.5, -0.5000000000000001, -0.7071067811865475]],
61
57
  [[-0.5, -0.5000000000000001, 0.7071067811865475],
62
- [-0.7071067811865476, -8.659560562354934e-17, 0.7071067811865475],
63
- [-1, -1.2246467991473532e-16, 0],
58
+ [-0.7071067811865476, 0, 0.7071067811865475], [-1, 0, 0],
64
59
  [-0.7071067811865475, -0.7071067811865476, 0]],
65
60
  [[-0.5, -0.5000000000000001, -0.7071067811865475],
66
- [-0.7071067811865476, -8.659560562354934e-17, -0.7071067811865475],
67
- [-4.329780281177466e-17, -4.329780281177467e-17, -1]],
68
- [[-4.329780281177466e-17, -4.329780281177467e-17, 1],
69
- [-0.7071067811865476, -8.659560562354934e-17, 0.7071067811865475],
61
+ [-0.7071067811865476, 0, -0.7071067811865475], [0, 0, -1]],
62
+ [[0, 0, 1], [-0.7071067811865476, 0, 0.7071067811865475],
70
63
  [-0.5, -0.5000000000000001, 0.7071067811865475]],
71
- [[-1, -1.2246467991473532e-16, 0],
72
- [-0.7071067811865477, 0.7071067811865475, 0],
73
- [-0.5000000000000001, 0.5, -0.7071067811865475],
74
- [-0.7071067811865476, -8.659560562354934e-17, -0.7071067811865475]],
75
- [[-0.7071067811865476, -8.659560562354934e-17, 0.7071067811865475],
76
- [-0.5000000000000001, 0.5, 0.7071067811865475],
77
- [-0.7071067811865477, 0.7071067811865475, 0],
78
- [-1, -1.2246467991473532e-16, 0]],
79
- [[-0.7071067811865476, -8.659560562354934e-17, -0.7071067811865475],
64
+ [[-1, 0, 0], [-0.7071067811865477, 0.7071067811865475, 0],
80
65
  [-0.5000000000000001, 0.5, -0.7071067811865475],
81
- [-6.123233995736766e-17, -7.498798913309288e-33, -1]],
82
- [[-6.123233995736766e-17, -7.498798913309288e-33, 1],
66
+ [-0.7071067811865476, 0, -0.7071067811865475]],
67
+ [[-0.7071067811865476, 0, 0.7071067811865475],
83
68
  [-0.5000000000000001, 0.5, 0.7071067811865475],
84
- [-0.7071067811865476, -8.659560562354934e-17, 0.7071067811865475]],
85
- [[-0.7071067811865477, 0.7071067811865475, 0],
86
- [-1.8369701987210297e-16, 1, 0],
87
- [-1.29893408435324e-16, 0.7071067811865476, -0.7071067811865475],
69
+ [-0.7071067811865477, 0.7071067811865475, 0], [-1, 0, 0]],
70
+ [[-0.7071067811865476, 0, -0.7071067811865475],
71
+ [-0.5000000000000001, 0.5, -0.7071067811865475], [0, 0, -1]],
72
+ [[0, 0, 1], [-0.5000000000000001, 0.5, 0.7071067811865475],
73
+ [-0.7071067811865476, 0, 0.7071067811865475]],
74
+ [[-0.7071067811865477, 0.7071067811865475, 0], [0, 1, 0],
75
+ [0, 0.7071067811865476, -0.7071067811865475],
88
76
  [-0.5000000000000001, 0.5, -0.7071067811865475]],
89
77
  [[-0.5000000000000001, 0.5, 0.7071067811865475],
90
- [-1.29893408435324e-16, 0.7071067811865476, 0.7071067811865475],
91
- [-1.8369701987210297e-16, 1, 0],
78
+ [0, 0.7071067811865476, 0.7071067811865475], [0, 1, 0],
92
79
  [-0.7071067811865477, 0.7071067811865475, 0]],
93
80
  [[-0.5000000000000001, 0.5, -0.7071067811865475],
94
- [-1.29893408435324e-16, 0.7071067811865476, -0.7071067811865475],
95
- [-4.3297802811774677e-17, 4.329780281177466e-17, -1]],
96
- [[-4.3297802811774677e-17, 4.329780281177466e-17, 1],
97
- [-1.29893408435324e-16, 0.7071067811865476, 0.7071067811865475],
81
+ [0, 0.7071067811865476, -0.7071067811865475], [0, 0, -1]],
82
+ [[0, 0, 1], [0, 0.7071067811865476, 0.7071067811865475],
98
83
  [-0.5000000000000001, 0.5, 0.7071067811865475]],
99
- [[-1.8369701987210297e-16, 1, 0],
100
- [0.7071067811865474, 0.7071067811865477, 0],
101
- [0.4999999999999999, 0.5000000000000001, -0.7071067811865475],
102
- [-1.29893408435324e-16, 0.7071067811865476, -0.7071067811865475]],
103
- [[-1.29893408435324e-16, 0.7071067811865476, 0.7071067811865475],
104
- [0.4999999999999999, 0.5000000000000001, 0.7071067811865475],
105
- [0.7071067811865474, 0.7071067811865477, 0],
106
- [-1.8369701987210297e-16, 1, 0]],
107
- [[-1.29893408435324e-16, 0.7071067811865476, -0.7071067811865475],
84
+ [[0, 1, 0], [0.7071067811865474, 0.7071067811865477, 0],
108
85
  [0.4999999999999999, 0.5000000000000001, -0.7071067811865475],
109
- [-1.1248198369963932e-32, 6.123233995736766e-17, -1]],
110
- [[-1.1248198369963932e-32, 6.123233995736766e-17, 1],
86
+ [0, 0.7071067811865476, -0.7071067811865475]],
87
+ [[0, 0.7071067811865476, 0.7071067811865475],
111
88
  [0.4999999999999999, 0.5000000000000001, 0.7071067811865475],
112
- [-1.29893408435324e-16, 0.7071067811865476, 0.7071067811865475]],
113
- [[0.7071067811865474, 0.7071067811865477, 0],
114
- [1, 2.4492935982947064e-16, 0],
115
- [0.7071067811865476, 1.7319121124709868e-16, -0.7071067811865475],
89
+ [0.7071067811865474, 0.7071067811865477, 0], [0, 1, 0]],
90
+ [[0, 0.7071067811865476, -0.7071067811865475],
91
+ [0.4999999999999999, 0.5000000000000001, -0.7071067811865475], [0, 0, -1]],
92
+ [[0, 0, 1], [0.4999999999999999, 0.5000000000000001, 0.7071067811865475],
93
+ [0, 0.7071067811865476, 0.7071067811865475]],
94
+ [[0.7071067811865474, 0.7071067811865477, 0], [1, 0, 0],
95
+ [0.7071067811865476, 0, -0.7071067811865475],
116
96
  [0.4999999999999999, 0.5000000000000001, -0.7071067811865475]],
117
97
  [[0.4999999999999999, 0.5000000000000001, 0.7071067811865475],
118
- [0.7071067811865476, 1.7319121124709868e-16, 0.7071067811865475],
119
- [1, 2.4492935982947064e-16, 0],
98
+ [0.7071067811865476, 0, 0.7071067811865475], [1, 0, 0],
120
99
  [0.7071067811865474, 0.7071067811865477, 0]],
121
100
  [[0.4999999999999999, 0.5000000000000001, -0.7071067811865475],
122
- [0.7071067811865476, 1.7319121124709868e-16, -0.7071067811865475],
123
- [4.329780281177465e-17, 4.3297802811774677e-17, -1]],
124
- [[4.329780281177465e-17, 4.3297802811774677e-17, 1],
125
- [0.7071067811865476, 1.7319121124709868e-16, 0.7071067811865475],
101
+ [0.7071067811865476, 0, -0.7071067811865475], [0, 0, -1]],
102
+ [[0, 0, 1], [0.7071067811865476, 0, 0.7071067811865475],
126
103
  [0.4999999999999999, 0.5000000000000001, 0.7071067811865475]]
127
104
  ]
105
+ t.notThrows(() => geom3.validate(obs))
128
106
  t.is(pts.length, 32)
129
107
  t.true(comparePolygonsAsPoints(pts, exp))
130
108
 
@@ -181,6 +159,7 @@ test('sphere (options)', (t) => {
181
159
  [[-2.5, 5.5, 6.292893218813452], [-2.2928932188134525, 5, 6.292893218813452], [-3, 5, 6]],
182
160
  [[-3, 5, 8], [-2.2928932188134525, 5, 7.707106781186548], [-2.5, 5.5, 7.707106781186548]]
183
161
  ]
162
+ t.notThrows(() => geom3.validate(obs))
184
163
  t.is(pts.length, 32)
185
164
  t.true(comparePolygonsAsPoints(pts, exp))
186
165
  })
@@ -9,6 +9,7 @@ const comparePoints = require('../../test/helpers/comparePoints')
9
9
  test('square (defaults)', (t) => {
10
10
  const geometry = square()
11
11
  const obs = geom2.toPoints(geometry)
12
+ t.notThrows(() => geom2.validate(geometry))
12
13
  t.deepEqual(obs.length, 4)
13
14
  })
14
15
 
@@ -23,6 +24,7 @@ test('square (options)', (t) => {
23
24
  [3, 10]
24
25
  ]
25
26
 
27
+ t.notThrows(() => geom2.validate(obs))
26
28
  t.is(pts.length, 4)
27
29
  t.true(comparePoints(pts, exp))
28
30
 
@@ -36,6 +38,7 @@ test('square (options)', (t) => {
36
38
  [-3.5, 3.5]
37
39
  ]
38
40
 
41
+ t.notThrows(() => geom2.validate(obs))
39
42
  t.is(pts.length, 4)
40
43
  t.true(comparePoints(pts, exp))
41
44
  })
@@ -22,6 +22,7 @@ test('star (defaults)', (t) => {
22
22
  [0.3090169943749474, -0.22451398828979277]
23
23
  ]
24
24
 
25
+ t.notThrows(() => geom2.validate(geometry))
25
26
  t.deepEqual(pts.length, 10)
26
27
  t.true(comparePoints(pts, exp))
27
28
  })
@@ -43,6 +44,7 @@ test('star (options)', (t) => {
43
44
  [6.545084971874736, 3.8774300585510364]
44
45
  ]
45
46
 
47
+ t.notThrows(() => geom2.validate(geometry))
46
48
  t.deepEqual(pts.length, 10)
47
49
  t.true(comparePoints(pts, exp))
48
50
 
@@ -68,6 +70,7 @@ test('star (options)', (t) => {
68
70
  [3.535533905932737, -1.464466094067265]
69
71
  ]
70
72
 
73
+ t.notThrows(() => geom2.validate(geometry))
71
74
  t.deepEqual(pts.length, 16)
72
75
  t.true(comparePoints(pts, exp))
73
76
 
@@ -93,6 +96,7 @@ test('star (options)', (t) => {
93
96
  [2.4999999999999996, -1.0355339059327393]
94
97
  ]
95
98
 
99
+ t.notThrows(() => geom2.validate(geometry))
96
100
  t.deepEqual(pts.length, 16)
97
101
  t.true(comparePoints(pts, exp))
98
102
 
@@ -118,6 +122,7 @@ test('star (options)', (t) => {
118
122
  [0.9238795325112865, -0.3826834323650904]
119
123
  ]
120
124
 
125
+ t.notThrows(() => geom2.validate(geometry))
121
126
  t.deepEqual(pts.length, 16)
122
127
  t.true(comparePoints(pts, exp))
123
128
 
@@ -137,6 +142,7 @@ test('star (options)', (t) => {
137
142
  [0.2987632431673025, -1.8863168790768006]
138
143
  ]
139
144
 
145
+ t.notThrows(() => geom2.validate(geometry))
140
146
  t.deepEqual(pts.length, 10)
141
147
  t.true(comparePoints(pts, exp))
142
148
  })
@@ -10,30 +10,36 @@ test('torus (defaults)', (t) => {
10
10
  const obs = torus()
11
11
  const pts = geom3.toPoints(obs)
12
12
 
13
+ t.notThrows(() => geom3.validate(obs))
13
14
  t.is(pts.length, 2048) // 32 * 32 * 2 (polys/segment) = 2048
14
15
 
15
16
  const bounds = measureBoundingBox(obs)
16
17
  const expectedBounds = [[-5, -5, -1], [5, 5, 1]]
18
+ t.notThrows(() => geom3.validate(obs))
17
19
  t.true(comparePoints(bounds, expectedBounds), 'Bounding box was not as expected: ' + JSON.stringify(bounds))
18
20
  })
19
21
 
20
- test('torus (Simple options)', (t) => {
22
+ test('torus (simple options)', (t) => {
21
23
  const obs = torus({ innerRadius: 0.5, innerSegments: 4, outerRadius: 5, outerSegments: 8 })
22
24
  const pts = geom3.toPoints(obs)
25
+ t.notThrows(() => geom3.validate(obs))
23
26
  t.is(pts.length, 64) // 4 * 8 * 2 (polys/segment) = 64
24
27
 
25
28
  const bounds = measureBoundingBox(obs)
26
29
  const expectedBounds = [[-5.5, -5.5, -0.5], [5.5, 5.5, 0.5]]
30
+ t.notThrows(() => geom3.validate(obs))
27
31
  t.true(comparePoints(bounds, expectedBounds), 'Bounding box was not as expected: ' + JSON.stringify(bounds))
28
32
  })
29
33
 
30
34
  test('torus (complex options)', (t) => {
31
35
  const obs = torus({ innerRadius: 1, outerRadius: 5, innerSegments: 32, outerSegments: 72, startAngle: Math.PI / 2, outerRotation: Math.PI / 2 })
32
36
  const pts = geom3.toPoints(obs)
37
+ t.notThrows(() => geom3.validate(obs))
33
38
  t.is(pts.length, 1212)
34
39
 
35
40
  const bounds = measureBoundingBox(obs)
36
41
  const expectedBounds = [[-6, 0, -1], [0, 6, 1]]
42
+ t.notThrows(() => geom3.validate(obs))
37
43
  t.true(comparePoints(bounds, expectedBounds), 'Bounding box was not as expected: ' + JSON.stringify(bounds))
38
44
  })
39
45
 
@@ -42,5 +48,6 @@ test('torus (square by square)', (t) => {
42
48
 
43
49
  const bounds = measureBoundingBox(obs)
44
50
  const expectedBounds = [[-5, -5, -1], [5, 5, 1]]
51
+ t.notThrows(() => geom3.validate(obs))
45
52
  t.true(comparePoints(bounds, expectedBounds), 'Bounding box was not as expected: ' + JSON.stringify(bounds))
46
53
  })
@@ -1,11 +1,10 @@
1
+ const { NEPS } = require('../maths/constants')
1
2
  const vec2 = require('../maths/vec2')
2
3
 
3
4
  const geom2 = require('../geometries/geom2')
4
5
 
5
6
  const { isNumberArray } = require('./commonChecks')
6
7
 
7
- const NEPS = 1e-13
8
-
9
8
  // returns angle C
10
9
  const solveAngleFromSSS = (a, b, c) => Math.acos(((a * a) + (b * b) - (c * c)) / (2 * a * b))
11
10
 
@@ -16,6 +16,7 @@ test('triangle (defaults)', (t) => {
16
16
  [0.5000000000000002, 0.8660254037844387]
17
17
  ]
18
18
 
19
+ t.notThrows(() => geom2.validate(geometry))
19
20
  t.deepEqual(obs.length, 3)
20
21
  t.true(comparePoints(obs, exp))
21
22
  })
@@ -30,6 +31,7 @@ test('triangle (options)', (t) => {
30
31
  [1.5, 5.809475019311125]
31
32
  ]
32
33
 
34
+ t.notThrows(() => geom2.validate(geometry))
33
35
  t.deepEqual(obs.length, 3)
34
36
  t.true(comparePoints(obs, exp))
35
37
 
@@ -42,6 +44,7 @@ test('triangle (options)', (t) => {
42
44
  [0, 1.0000000000000002]
43
45
  ]
44
46
 
47
+ t.notThrows(() => geom2.validate(geometry))
45
48
  t.deepEqual(obs.length, 3)
46
49
  t.true(comparePoints(obs, exp))
47
50
 
@@ -54,6 +57,7 @@ test('triangle (options)', (t) => {
54
57
  [2.1348320069064197, 4.015035054457325]
55
58
  ]
56
59
 
60
+ t.notThrows(() => geom2.validate(geometry))
57
61
  t.deepEqual(obs.length, 3)
58
62
  t.true(comparePoints(obs, exp))
59
63
 
@@ -66,6 +70,7 @@ test('triangle (options)', (t) => {
66
70
  [1.295667368233083, 5.196637976713814]
67
71
  ]
68
72
 
73
+ t.notThrows(() => geom2.validate(geometry))
69
74
  t.deepEqual(obs.length, 3)
70
75
  t.true(comparePoints(obs, exp))
71
76
 
@@ -78,6 +83,7 @@ test('triangle (options)', (t) => {
78
83
  [0.4075867970664495, 5.282967061559405]
79
84
  ]
80
85
 
86
+ t.notThrows(() => geom2.validate(geometry))
81
87
  t.deepEqual(obs.length, 3)
82
88
  t.true(comparePoints(obs, exp))
83
89
 
@@ -90,6 +96,7 @@ test('triangle (options)', (t) => {
90
96
  [8.494946725906148, 12.990574573070846]
91
97
  ]
92
98
 
99
+ t.notThrows(() => geom2.validate(geometry))
93
100
  t.deepEqual(obs.length, 3)
94
101
  t.true(comparePoints(obs, exp))
95
102
  })
@@ -10,7 +10,7 @@ const path2 = require('../geometries/path2')
10
10
  */
11
11
  const areAllShapesTheSameType = (shapes) => {
12
12
  let previousType
13
- shapes.forEach((shape) => {
13
+ for (const shape of shapes) {
14
14
  let currentType = 0
15
15
  if (geom2.isA(shape)) currentType = 1
16
16
  if (geom3.isA(shape)) currentType = 2
@@ -18,7 +18,7 @@ const areAllShapesTheSameType = (shapes) => {
18
18
 
19
19
  if (previousType && currentType !== previousType) return false
20
20
  previousType = currentType
21
- })
21
+ }
22
22
  return true
23
23
  }
24
24
 
@@ -0,0 +1,17 @@
1
+ const test = require('ava')
2
+
3
+ const { cube, square } = require('../primitives')
4
+
5
+ const { areAllShapesTheSameType } = require('./index')
6
+
7
+ test('utils: areAllShapesTheSameType() should return correct values', (t) => {
8
+ const geometry2 = square()
9
+ const geometry3 = cube()
10
+
11
+ t.true(areAllShapesTheSameType([]))
12
+ t.true(areAllShapesTheSameType([geometry2]))
13
+ t.true(areAllShapesTheSameType([geometry3]))
14
+ t.true(areAllShapesTheSameType([geometry2, geometry2]))
15
+ t.true(areAllShapesTheSameType([geometry3, geometry3]))
16
+ t.false(areAllShapesTheSameType([geometry2, geometry3]))
17
+ })
@@ -5,5 +5,6 @@ export { default as fnNumberSort } from './fnNumberSort'
5
5
  export { default as insertSorted } from './insertSorted'
6
6
  export { default as radiusToSegments } from './radiusToSegments'
7
7
  export { default as radToDeg } from './radToDeg'
8
+ export * from './trigonometry'
8
9
 
9
10
  export as namespace utils
@@ -6,10 +6,12 @@
6
6
  */
7
7
  module.exports = {
8
8
  areAllShapesTheSameType: require('./areAllShapesTheSameType'),
9
+ cos: require('./trigonometry').cos,
9
10
  degToRad: require('./degToRad'),
10
11
  flatten: require('./flatten'),
11
12
  fnNumberSort: require('./fnNumberSort'),
12
13
  insertSorted: require('./insertSorted'),
13
14
  radiusToSegments: require('./radiusToSegments'),
14
- radToDeg: require('./radToDeg')
15
+ radToDeg: require('./radToDeg'),
16
+ sin: require('./trigonometry').sin
15
17
  }
@@ -0,0 +1,2 @@
1
+ export function cos(radians: number): number
2
+ export function sin(radians: number): number
@@ -0,0 +1,34 @@
1
+ const { NEPS } = require('../maths/constants')
2
+
3
+ /*
4
+ * Returns zero if n is within epsilon of zero, otherwise return n
5
+ */
6
+ const rezero = (n) => Math.abs(n) < NEPS ? 0 : n
7
+
8
+ /**
9
+ * Return Math.sin but accurate for 90 degree rotations.
10
+ * Fixes rounding errors when sin should be 0.
11
+ *
12
+ * @param {Number} radians - angle in radians
13
+ * @returns {Number} sine of the given angle
14
+ * @alias module:modeling/utils.sin
15
+ * @example
16
+ * sin(Math.PI) == 0
17
+ * sin(2 * Math.PI) == 0
18
+ */
19
+ const sin = (radians) => rezero(Math.sin(radians))
20
+
21
+ /**
22
+ * Return Math.cos but accurate for 90 degree rotations.
23
+ * Fixes rounding errors when cos should be 0.
24
+ *
25
+ * @param {Number} radians - angle in radians
26
+ * @returns {Number} cosine of the given angle
27
+ * @alias module:modeling/utils.cos
28
+ * @example
29
+ * cos(0.5 * Math.PI) == 0
30
+ * cos(1.5 * Math.PI) == 0
31
+ */
32
+ const cos = (radians) => rezero(Math.cos(radians))
33
+
34
+ module.exports = { sin, cos }