@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.
- package/CHANGELOG.md +42 -0
- package/README.md +4 -4
- package/dist/jscad-modeling.min.js +437 -428
- package/package.json +3 -2
- package/src/colors/colorize.test.js +1 -1
- package/src/geometries/geom2/index.d.ts +1 -0
- package/src/geometries/geom2/index.js +2 -1
- package/src/geometries/geom2/toOutlines.js +66 -52
- package/src/geometries/geom2/validate.d.ts +3 -0
- package/src/geometries/geom2/validate.js +36 -0
- package/src/geometries/geom3/create.js +1 -1
- package/src/geometries/geom3/create.test.js +1 -1
- package/src/geometries/geom3/fromPoints.js +1 -1
- package/src/geometries/geom3/index.d.ts +1 -0
- package/src/geometries/geom3/index.js +2 -1
- package/src/geometries/geom3/isA.js +1 -1
- package/src/geometries/geom3/validate.d.ts +3 -0
- package/src/geometries/geom3/validate.js +62 -0
- package/src/geometries/path2/index.d.ts +1 -1
- package/src/geometries/path2/index.js +2 -2
- package/src/geometries/path2/validate.d.ts +3 -0
- package/src/geometries/path2/validate.js +41 -0
- package/src/geometries/poly2/arePointsInside.js +0 -35
- package/src/geometries/poly3/create.js +1 -1
- package/src/geometries/poly3/index.d.ts +1 -0
- package/src/geometries/poly3/index.js +2 -1
- package/src/geometries/poly3/measureArea.test.js +16 -16
- package/src/geometries/poly3/measureBoundingSphere.test.js +8 -8
- package/src/geometries/poly3/validate.d.ts +4 -0
- package/src/geometries/poly3/validate.js +64 -0
- package/src/maths/constants.d.ts +1 -0
- package/src/maths/constants.js +11 -0
- package/src/maths/utils/aboutEqualNormals.js +1 -5
- package/src/measurements/measureCenterOfMass.test.js +2 -2
- package/src/operations/booleans/intersect.test.js +8 -0
- package/src/operations/booleans/intersectGeom3.js +2 -1
- package/src/operations/booleans/scission.test.js +4 -4
- package/src/operations/booleans/subtract.test.js +8 -0
- package/src/operations/booleans/subtractGeom3.js +2 -1
- package/src/operations/booleans/to3DWalls.js +1 -1
- package/src/operations/booleans/trees/Node.js +10 -16
- package/src/operations/booleans/trees/PolygonTreeNode.js +13 -14
- package/src/operations/booleans/trees/Tree.js +1 -2
- package/src/operations/booleans/trees/splitPolygonByPlane.js +2 -3
- package/src/operations/booleans/union.test.js +27 -0
- package/src/operations/booleans/unionGeom3.js +2 -1
- package/src/operations/expansions/expand.test.js +30 -21
- package/src/operations/expansions/expandGeom3.test.js +14 -14
- package/src/operations/expansions/expandShell.js +5 -4
- package/src/operations/expansions/extrudePolygon.js +7 -7
- package/src/operations/expansions/offset.test.js +25 -0
- package/src/operations/extrusions/earcut/assignHoles.js +7 -3
- package/src/operations/extrusions/earcut/assignHoles.test.js +50 -4
- package/src/operations/extrusions/earcut/linkedList.js +1 -1
- package/src/operations/extrusions/extrudeFromSlices.test.js +16 -10
- package/src/operations/extrusions/extrudeLinear.test.js +15 -9
- package/src/operations/extrusions/extrudeRectangular.test.js +15 -8
- package/src/operations/extrusions/extrudeRotate.js +5 -1
- package/src/operations/extrusions/extrudeRotate.test.js +12 -0
- package/src/operations/extrusions/extrudeWalls.js +2 -2
- package/src/operations/extrusions/project.js +11 -14
- package/src/operations/extrusions/project.test.js +55 -55
- package/src/operations/hulls/hull.test.js +24 -1
- package/src/operations/hulls/hullChain.test.js +6 -4
- package/src/operations/hulls/hullGeom2.js +6 -18
- package/src/operations/hulls/hullGeom3.js +5 -18
- package/src/operations/hulls/hullPath2.js +4 -14
- package/src/operations/hulls/hullPath2.test.js +1 -1
- package/src/operations/hulls/hullPoints2.js +43 -92
- package/src/operations/hulls/toUniquePoints.js +34 -0
- package/src/operations/modifiers/generalize.js +2 -13
- package/src/operations/modifiers/generalize.test.js +5 -31
- package/src/operations/modifiers/insertTjunctions.js +1 -1
- package/src/operations/modifiers/insertTjunctions.test.js +21 -21
- package/src/operations/modifiers/mergePolygons.js +11 -14
- package/src/operations/{booleans → modifiers}/reTesselateCoplanarPolygons.js +1 -1
- package/src/operations/{booleans → modifiers}/reTesselateCoplanarPolygons.test.js +5 -5
- package/src/operations/{booleans → modifiers}/retessellate.js +2 -9
- package/src/operations/{booleans → modifiers}/retessellate.test.js +0 -0
- package/src/operations/modifiers/snapPolygons.test.js +12 -12
- package/src/operations/modifiers/triangulatePolygons.js +3 -3
- package/src/operations/transforms/align.test.js +12 -0
- package/src/operations/transforms/center.js +1 -1
- package/src/operations/transforms/center.test.js +12 -0
- package/src/operations/transforms/mirror.test.js +16 -0
- package/src/operations/transforms/rotate.test.js +10 -0
- package/src/operations/transforms/scale.test.js +15 -0
- package/src/operations/transforms/transform.test.js +5 -0
- package/src/operations/transforms/translate.test.js +16 -0
- package/src/primitives/arc.test.js +11 -0
- package/src/primitives/circle.test.js +15 -9
- package/src/primitives/cube.test.js +3 -0
- package/src/primitives/cuboid.js +1 -1
- package/src/primitives/cuboid.test.js +9 -24
- package/src/primitives/cylinder.test.js +7 -4
- package/src/primitives/cylinderElliptic.js +14 -7
- package/src/primitives/cylinderElliptic.test.js +72 -50
- package/src/primitives/ellipse.js +3 -1
- package/src/primitives/ellipse.test.js +14 -8
- package/src/primitives/ellipsoid.js +8 -6
- package/src/primitives/ellipsoid.test.js +84 -80
- package/src/primitives/geodesicSphere.test.js +3 -0
- package/src/primitives/line.test.js +1 -0
- package/src/primitives/polygon.test.js +15 -10
- package/src/primitives/polyhedron.js +1 -1
- package/src/primitives/polyhedron.test.js +14 -42
- package/src/primitives/rectangle.test.js +3 -0
- package/src/primitives/roundedCuboid.js +6 -6
- package/src/primitives/roundedCuboid.test.js +5 -0
- package/src/primitives/roundedCylinder.js +7 -5
- package/src/primitives/roundedCylinder.test.js +40 -36
- package/src/primitives/roundedRectangle.test.js +5 -0
- package/src/primitives/sphere.test.js +52 -73
- package/src/primitives/square.test.js +3 -0
- package/src/primitives/star.test.js +6 -0
- package/src/primitives/torus.test.js +8 -1
- package/src/primitives/triangle.js +1 -2
- package/src/primitives/triangle.test.js +7 -0
- package/src/utils/areAllShapesTheSameType.js +2 -2
- package/src/utils/areAllShapesTheSameType.test.js +17 -0
- package/src/utils/index.d.ts +1 -0
- package/src/utils/index.js +3 -1
- package/src/utils/trigonometry.d.ts +2 -0
- package/src/utils/trigonometry.js +34 -0
- package/src/utils/trigonometry.test.js +25 -0
- package/test/helpers/nearlyEqual.js +4 -1
- package/src/geometries/path2/eachPoint.d.ts +0 -9
- package/src/geometries/path2/eachPoint.js +0 -17
- package/src/geometries/path2/eachPoint.test.js +0 -11
- package/src/operations/modifiers/edges.js +0 -195
- 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,
|
|
61
|
-
[[0,
|
|
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], [
|
|
65
|
-
[[
|
|
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], [
|
|
69
|
-
[[
|
|
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], [
|
|
73
|
-
[[
|
|
74
|
-
[[
|
|
75
|
-
[-0.9510565162951536, 0.30901699437494723, 9.8], [
|
|
76
|
-
[[-0.9510565162951536, 0.30901699437494723, -9.8], [
|
|
77
|
-
[[
|
|
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,
|
|
90
|
-
[[0,
|
|
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], [
|
|
94
|
-
[[
|
|
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], [
|
|
98
|
-
[[
|
|
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], [
|
|
102
|
-
[[
|
|
103
|
-
[[-
|
|
104
|
-
|
|
105
|
-
[[
|
|
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,
|
|
119
|
-
[[0,
|
|
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], [
|
|
123
|
-
[[
|
|
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], [
|
|
127
|
-
[[
|
|
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], [
|
|
131
|
-
[[
|
|
132
|
-
[[
|
|
133
|
-
|
|
134
|
-
[[
|
|
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], [
|
|
33
|
-
[[
|
|
34
|
-
[[0.7071067811865476, -0.7071067811865475, 0], [
|
|
35
|
-
[
|
|
36
|
-
[[0.5000000000000001, -0.5, 0.7071067811865475], [
|
|
37
|
-
[
|
|
38
|
-
[[0.5000000000000001, -0.5, -0.7071067811865475],
|
|
39
|
-
[
|
|
40
|
-
[[
|
|
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
|
-
[[
|
|
44
|
-
[-0.7071067811865475, -0.7071067811865476, 0],
|
|
44
|
+
[[0, -1, 0], [-0.7071067811865475, -0.7071067811865476, 0],
|
|
45
45
|
[-0.5, -0.5000000000000001, -0.7071067811865475],
|
|
46
|
-
[
|
|
47
|
-
[[
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
[
|
|
54
|
-
[[
|
|
55
|
-
[-0.
|
|
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,
|
|
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,
|
|
67
|
-
|
|
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, -
|
|
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
|
-
[-
|
|
82
|
-
[[-
|
|
66
|
+
[-0.7071067811865476, 0, -0.7071067811865475]],
|
|
67
|
+
[[-0.7071067811865476, 0, 0.7071067811865475],
|
|
83
68
|
[-0.5000000000000001, 0.5, 0.7071067811865475],
|
|
84
|
-
[-0.
|
|
85
|
-
[[-0.
|
|
86
|
-
[-
|
|
87
|
-
|
|
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
|
-
[
|
|
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
|
-
[
|
|
95
|
-
|
|
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
|
-
[[
|
|
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
|
-
[
|
|
110
|
-
[[
|
|
86
|
+
[0, 0.7071067811865476, -0.7071067811865475]],
|
|
87
|
+
[[0, 0.7071067811865476, 0.7071067811865475],
|
|
111
88
|
[0.4999999999999999, 0.5000000000000001, 0.7071067811865475],
|
|
112
|
-
[
|
|
113
|
-
[[0
|
|
114
|
-
[
|
|
115
|
-
|
|
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,
|
|
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,
|
|
123
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
+
})
|
package/src/utils/index.d.ts
CHANGED
|
@@ -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
|
package/src/utils/index.js
CHANGED
|
@@ -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,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 }
|