@jscad/modeling 3.0.2-alpha.0 → 3.0.4-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/jscad-modeling.es.js +2 -7
- package/dist/jscad-modeling.min.js +2 -7
- package/package.json +6 -7
- package/rollup.config.js +8 -4
- package/src/colors/colorize.test.js +1 -1
- package/src/curves/bezier/arcLengthToT.js +1 -1
- package/src/curves/bezier/create.js +1 -1
- package/src/curves/bezier/index.js +7 -7
- package/src/curves/bezier/length.js +1 -1
- package/src/curves/bezier/lengths.js +2 -1
- package/src/curves/bezier/tangentAt.js +1 -1
- package/src/curves/bezier/valueAt.js +1 -1
- package/src/curves/index.js +3 -3
- package/src/geometries/geom2/applyTransforms.js +3 -1
- package/src/geometries/geom2/clone.js +5 -1
- package/src/geometries/geom2/create.js +4 -14
- package/src/geometries/geom2/fromSides.js +4 -2
- package/src/geometries/geom2/index.d.ts +0 -2
- package/src/geometries/geom2/index.js +21 -7
- package/src/geometries/geom2/isA.js +5 -1
- package/src/geometries/geom2/reverse.js +4 -2
- package/src/geometries/geom2/toOutlines.js +2 -1
- package/src/geometries/geom2/toPoints.js +5 -2
- package/src/geometries/geom2/toSides.js +4 -3
- package/src/geometries/geom2/toString.js +3 -2
- package/src/geometries/geom2/transform.js +4 -2
- package/src/geometries/geom2/validate.js +6 -2
- package/src/geometries/geom3/applyTransforms.test.js +2 -2
- package/src/geometries/geom3/clone.js +5 -1
- package/src/geometries/geom3/clone.test.js +2 -2
- package/src/geometries/geom3/create.js +6 -28
- package/src/geometries/geom3/{fromPoints.d.ts → fromVertices.d.ts} +1 -1
- package/src/geometries/geom3/{fromPoints.js → fromVertices.js} +15 -2
- package/src/geometries/geom3/{fromPoints.test.js → fromVertices.test.js} +6 -6
- package/src/geometries/geom3/{fromPointsConvex.d.ts → fromVerticesConvex.d.ts} +1 -1
- package/src/geometries/geom3/fromVerticesConvex.js +25 -0
- package/src/geometries/geom3/{fromPointsConvex.test.js → fromVerticesConvex.test.js} +3 -3
- package/src/geometries/geom3/index.d.ts +4 -5
- package/src/geometries/geom3/index.js +29 -9
- package/src/geometries/geom3/invert.js +5 -1
- package/src/geometries/geom3/invert.test.js +2 -2
- package/src/geometries/geom3/isA.js +5 -1
- package/src/geometries/geom3/isA.test.js +2 -2
- package/src/geometries/geom3/isConvex.d.ts +3 -0
- package/src/geometries/geom3/isConvex.js +65 -0
- package/src/geometries/geom3/isConvex.test.js +44 -0
- package/src/geometries/geom3/toPolygons.js +4 -2
- package/src/geometries/geom3/toString.js +3 -2
- package/src/geometries/geom3/toString.test.js +2 -2
- package/src/geometries/geom3/{toPoints.d.ts → toVertices.d.ts} +1 -1
- package/src/geometries/geom3/toVertices.js +20 -0
- package/src/geometries/geom3/{toPoints.test.js → toVertices.test.js} +4 -4
- package/src/geometries/geom3/transform.js +5 -2
- package/src/geometries/geom3/transform.test.js +2 -2
- package/src/geometries/geom3/validate.js +6 -2
- package/src/geometries/geom3/validate.test.js +4 -4
- package/src/geometries/index.d.ts +1 -0
- package/src/geometries/index.js +10 -7
- package/src/geometries/path2/appendArc.js +7 -5
- package/src/geometries/path2/appendArc.test.js +11 -15
- package/src/geometries/path2/appendBezier.js +6 -4
- package/src/geometries/path2/appendPoints.js +4 -2
- package/src/geometries/path2/applyTransforms.js +3 -0
- package/src/geometries/path2/clone.js +5 -1
- package/src/geometries/path2/close.js +5 -1
- package/src/geometries/path2/concat.js +3 -2
- package/src/geometries/path2/create.js +5 -25
- package/src/geometries/path2/equals.js +12 -7
- package/src/geometries/path2/fromPoints.js +5 -3
- package/src/geometries/path2/index.d.ts +0 -2
- package/src/geometries/path2/index.js +21 -6
- package/src/geometries/path2/isA.js +5 -1
- package/src/geometries/path2/reverse.js +4 -2
- package/src/geometries/path2/toPoints.js +5 -3
- package/src/geometries/path2/toString.js +3 -2
- package/src/geometries/path2/transform.js +4 -2
- package/src/geometries/path2/validate.js +5 -1
- package/src/geometries/path3/applyTransforms.js +22 -0
- package/src/geometries/path3/applyTransforms.test.js +28 -0
- package/src/geometries/path3/close.d.ts +3 -0
- package/src/geometries/path3/close.js +33 -0
- package/src/geometries/path3/close.test.js +43 -0
- package/src/geometries/path3/concat.d.ts +3 -0
- package/src/geometries/path3/concat.js +35 -0
- package/src/geometries/path3/concat.test.js +35 -0
- package/src/geometries/path3/create.d.ts +4 -0
- package/src/geometries/path3/create.js +14 -0
- package/src/geometries/path3/create.test.js +8 -0
- package/src/geometries/path3/equals.d.ts +3 -0
- package/src/geometries/path3/equals.js +50 -0
- package/src/geometries/path3/equals.test.js +38 -0
- package/src/geometries/path3/fromVertices.d.ts +8 -0
- package/src/geometries/path3/fromVertices.js +44 -0
- package/src/geometries/path3/fromVertices.test.js +33 -0
- package/src/geometries/path3/index.d.ts +13 -0
- package/src/geometries/path3/index.js +37 -0
- package/src/geometries/path3/isA.d.ts +3 -0
- package/src/geometries/path3/isA.js +22 -0
- package/src/geometries/path3/isA.test.js +19 -0
- package/src/geometries/path3/reverse.d.ts +3 -0
- package/src/geometries/path3/reverse.js +18 -0
- package/src/geometries/path3/reverse.test.js +9 -0
- package/src/geometries/path3/toString.d.ts +3 -0
- package/src/geometries/path3/toString.js +23 -0
- package/src/geometries/path3/toVertices.d.ts +4 -0
- package/src/geometries/path3/toVertices.js +15 -0
- package/src/geometries/path3/toVertices.test.js +13 -0
- package/src/geometries/path3/transform.d.ts +4 -0
- package/src/geometries/path3/transform.js +20 -0
- package/src/geometries/path3/transform.test.js +50 -0
- package/src/geometries/path3/type.d.ts +10 -0
- package/src/geometries/path3/validate.d.ts +1 -0
- package/src/geometries/path3/validate.js +44 -0
- package/src/geometries/poly2/arePointsInside.js +4 -1
- package/src/geometries/poly2/clone.js +4 -1
- package/src/geometries/poly2/create.js +3 -15
- package/src/geometries/poly2/index.js +16 -4
- package/src/geometries/poly2/isA.js +5 -1
- package/src/geometries/poly2/isConvex.js +5 -1
- package/src/geometries/poly2/isSimple.js +5 -1
- package/src/geometries/poly2/measureArea.js +4 -1
- package/src/geometries/poly2/measureBoundingBox.js +6 -1
- package/src/geometries/poly2/reverse.js +4 -1
- package/src/geometries/poly2/toPoints.js +6 -1
- package/src/geometries/poly2/toString.js +5 -1
- package/src/geometries/poly2/transform.js +5 -1
- package/src/geometries/poly2/validate.js +6 -2
- package/src/geometries/poly3/clone.js +4 -1
- package/src/geometries/poly3/create.js +4 -17
- package/src/geometries/poly3/fromVerticesAndPlane.js +3 -1
- package/src/geometries/poly3/index.js +19 -4
- package/src/geometries/poly3/invert.js +4 -1
- package/src/geometries/poly3/isA.js +5 -1
- package/src/geometries/poly3/isConvex.js +5 -1
- package/src/geometries/poly3/measureArea.js +5 -1
- package/src/geometries/poly3/measureBoundingBox.js +4 -1
- package/src/geometries/poly3/measureBoundingSphere.js +4 -3
- package/src/geometries/poly3/measureSignedVolume.js +6 -1
- package/src/geometries/poly3/plane.js +6 -0
- package/src/geometries/poly3/toString.js +5 -1
- package/src/geometries/poly3/toVertices.js +6 -1
- package/src/geometries/poly3/transform.js +5 -1
- package/src/geometries/poly3/validate.js +6 -2
- package/src/geometries/slice/calculatePlane.js +3 -3
- package/src/geometries/slice/clone.js +4 -1
- package/src/geometries/slice/create.js +5 -10
- package/src/geometries/slice/equals.js +5 -1
- package/src/geometries/slice/fromGeom2.js +1 -1
- package/src/geometries/slice/fromVertices.js +3 -3
- package/src/geometries/slice/index.js +19 -4
- package/src/geometries/slice/isA.js +5 -1
- package/src/geometries/slice/reverse.js +5 -2
- package/src/geometries/slice/toEdges.js +5 -3
- package/src/geometries/slice/toPolygons.js +5 -1
- package/src/geometries/slice/toString.js +5 -1
- package/src/geometries/slice/toVertices.js +5 -3
- package/src/geometries/slice/transform.js +4 -3
- package/src/geometries/slice/validate.js +3 -2
- package/src/index.d.ts +1 -0
- package/src/index.js +4 -0
- package/src/maths/constants.js +11 -7
- package/src/maths/index.js +2 -1
- package/src/maths/mat4/isOnlyTransformScale.js +1 -1
- package/src/operations/booleans/index.js +2 -0
- package/src/operations/booleans/intersect.js +0 -1
- package/src/operations/booleans/intersectGeom3.test.js +4 -4
- package/src/operations/booleans/scission.js +0 -1
- package/src/operations/booleans/subtractGeom3.test.js +4 -4
- package/src/operations/booleans/trees/splitLineSegmentByPlane.js +1 -4
- package/src/operations/booleans/trees/splitPolygonByPlane.test.js +138 -0
- package/src/operations/booleans/unionGeom3.test.js +40 -5
- package/src/operations/extrusions/extrudeFromSlices.js +15 -5
- package/src/operations/extrusions/extrudeFromSlices.test.js +6 -6
- package/src/operations/extrusions/extrudeLinear.test.js +8 -8
- package/src/operations/extrusions/extrudeRotate.js +2 -1
- package/src/operations/extrusions/extrudeRotate.test.js +46 -12
- package/src/operations/extrusions/extrudeWalls.test.js +60 -0
- package/src/operations/hulls/hull.test.js +5 -5
- package/src/operations/hulls/hullChain.test.js +5 -5
- package/src/operations/hulls/toUniquePoints.js +2 -2
- package/src/operations/minkowski/index.d.ts +1 -0
- package/src/operations/minkowski/index.js +15 -0
- package/src/operations/minkowski/minkowskiSum.d.ts +4 -0
- package/src/operations/minkowski/minkowskiSum.js +223 -0
- package/src/operations/minkowski/minkowskiSum.test.js +199 -0
- package/src/operations/modifiers/generalize.test.js +6 -6
- package/src/operations/modifiers/insertTjunctions.test.js +2 -2
- package/src/operations/modifiers/reTesselateCoplanarPolygons.js +10 -3
- package/src/operations/modifiers/reTesselateCoplanarPolygons.test.js +36 -1
- package/src/operations/modifiers/retessellate.js +4 -2
- package/src/operations/modifiers/retessellate.test.js +10 -10
- package/src/operations/modifiers/snap.test.js +28 -19
- package/src/operations/offsets/offsetGeom3.test.js +9 -11
- package/src/operations/transforms/center.test.js +7 -7
- package/src/operations/transforms/mirror.test.js +7 -7
- package/src/operations/transforms/rotate.test.js +7 -7
- package/src/operations/transforms/scale.test.js +7 -7
- package/src/operations/transforms/transform.test.js +2 -2
- package/src/operations/transforms/translate.test.js +7 -7
- package/src/primitives/arc.js +2 -2
- package/src/primitives/arc.test.js +104 -113
- package/src/primitives/cube.test.js +4 -4
- package/src/primitives/cuboid.test.js +4 -4
- package/src/primitives/cylinder.test.js +5 -5
- package/src/primitives/cylinderElliptic.test.js +9 -9
- package/src/primitives/ellipsoid.test.js +5 -5
- package/src/primitives/geodesicSphere.test.js +4 -4
- package/src/primitives/polyhedron.test.js +2 -2
- package/src/primitives/roundedCuboid.test.js +7 -7
- package/src/primitives/roundedCylinder.test.js +9 -9
- package/src/primitives/sphere.test.js +5 -5
- package/src/primitives/torus.test.js +4 -4
- package/src/utils/flatten.js +1 -1
- package/src/utils/flatten.test.js +94 -0
- package/src/geometries/geom2/fromCompactBinary.d.ts +0 -3
- package/src/geometries/geom2/fromCompactBinary.js +0 -40
- package/src/geometries/geom2/fromToCompactBinary.test.js +0 -100
- package/src/geometries/geom2/toCompactBinary.d.ts +0 -3
- package/src/geometries/geom2/toCompactBinary.js +0 -56
- package/src/geometries/geom3/fromCompactBinary.d.ts +0 -3
- package/src/geometries/geom3/fromCompactBinary.js +0 -42
- package/src/geometries/geom3/fromPointsConvex.js +0 -25
- package/src/geometries/geom3/fromToCompactBinary.test.js +0 -139
- package/src/geometries/geom3/toCompactBinary.d.ts +0 -3
- package/src/geometries/geom3/toCompactBinary.js +0 -66
- package/src/geometries/geom3/toPoints.js +0 -15
- package/src/geometries/path2/fromCompactBinary.d.ts +0 -3
- package/src/geometries/path2/fromCompactBinary.js +0 -31
- package/src/geometries/path2/fromToCompactBinary.test.js +0 -114
- package/src/geometries/path2/toCompactBinary.d.ts +0 -3
- package/src/geometries/path2/toCompactBinary.js +0 -50
|
@@ -10,7 +10,7 @@ import { comparePolygonsAsPoints } from '../../test/helpers/index.js'
|
|
|
10
10
|
|
|
11
11
|
test('cylinder (defaults)', (t) => {
|
|
12
12
|
const obs = cylinder()
|
|
13
|
-
const pts = geom3.
|
|
13
|
+
const pts = geom3.toVertices(obs)
|
|
14
14
|
|
|
15
15
|
t.notThrows(() => geom3.validate(obs))
|
|
16
16
|
t.is(measureArea(obs), 18.789084266699856)
|
|
@@ -20,7 +20,7 @@ test('cylinder (defaults)', (t) => {
|
|
|
20
20
|
|
|
21
21
|
test('cylinder (zero height)', (t) => {
|
|
22
22
|
const obs = cylinder({ height: 0 })
|
|
23
|
-
const pts = geom3.
|
|
23
|
+
const pts = geom3.toVertices(obs)
|
|
24
24
|
t.notThrows(() => geom3.validate(obs))
|
|
25
25
|
t.is(measureArea(obs), 0)
|
|
26
26
|
t.is(measureVolume(obs), 0)
|
|
@@ -29,7 +29,7 @@ test('cylinder (zero height)', (t) => {
|
|
|
29
29
|
|
|
30
30
|
test('cylinder (zero radius)', (t) => {
|
|
31
31
|
const obs = cylinder({ radius: 0 })
|
|
32
|
-
const pts = geom3.
|
|
32
|
+
const pts = geom3.toVertices(obs)
|
|
33
33
|
t.notThrows(() => geom3.validate(obs))
|
|
34
34
|
t.is(measureArea(obs), 0)
|
|
35
35
|
t.is(measureVolume(obs), 0)
|
|
@@ -38,7 +38,7 @@ test('cylinder (zero radius)', (t) => {
|
|
|
38
38
|
|
|
39
39
|
test('cylinder (options)', (t) => {
|
|
40
40
|
let obs = cylinder({ height: 10, radius: 4, segments: 5 })
|
|
41
|
-
let pts = geom3.
|
|
41
|
+
let pts = geom3.toVertices(obs)
|
|
42
42
|
let exp = [
|
|
43
43
|
[[0, 0, -5], [1.2360679774997898, 3.804226065180614, -5], [4, 0, -5]],
|
|
44
44
|
[[1.2360679774997898, 3.804226065180614, -5], [1.2360679774997898, 3.804226065180614, 5],
|
|
@@ -70,7 +70,7 @@ test('cylinder (options)', (t) => {
|
|
|
70
70
|
|
|
71
71
|
// test center
|
|
72
72
|
obs = cylinder({ center: [-5, -5, -5], segments: 5 })
|
|
73
|
-
pts = geom3.
|
|
73
|
+
pts = geom3.toVertices(obs)
|
|
74
74
|
exp = [
|
|
75
75
|
[[-5, -5, -6], [-4.6909830056250525, -4.048943483704846, -6], [-4, -5, -6]],
|
|
76
76
|
[[-4.6909830056250525, -4.048943483704846, -6], [-4.6909830056250525, -4.048943483704846, -4],
|
|
@@ -12,7 +12,7 @@ import { comparePolygonsAsPoints } from '../../test/helpers/index.js'
|
|
|
12
12
|
|
|
13
13
|
test('cylinderElliptic (defaults)', (t) => {
|
|
14
14
|
const obs = cylinderElliptic()
|
|
15
|
-
const pts = geom3.
|
|
15
|
+
const pts = geom3.toVertices(obs)
|
|
16
16
|
|
|
17
17
|
t.notThrows(() => geom3.validate(obs))
|
|
18
18
|
t.is(measureArea(obs), 18.789084266699856)
|
|
@@ -23,7 +23,7 @@ test('cylinderElliptic (defaults)', (t) => {
|
|
|
23
23
|
test('cylinderElliptic (options)', (t) => {
|
|
24
24
|
// test height
|
|
25
25
|
let obs = cylinderElliptic({ height: 10, segments: 12 })
|
|
26
|
-
let pts = geom3.
|
|
26
|
+
let pts = geom3.toVertices(obs)
|
|
27
27
|
let exp = [
|
|
28
28
|
[[0, 0, -5], [0.8660254037844387, 0.49999999999999994, -5], [1, 0, -5]],
|
|
29
29
|
[[0.8660254037844387, 0.49999999999999994, -5], [0.8660254037844387, 0.49999999999999994, 5],
|
|
@@ -83,7 +83,7 @@ test('cylinderElliptic (options)', (t) => {
|
|
|
83
83
|
|
|
84
84
|
// test startRadius and endRadius
|
|
85
85
|
obs = cylinderElliptic({ startRadius: [1, 2], endRadius: [2, 1], segments: 12 })
|
|
86
|
-
pts = geom3.
|
|
86
|
+
pts = geom3.toVertices(obs)
|
|
87
87
|
exp = [
|
|
88
88
|
[[0, 0, -1], [0.8660254037844387, 0.9999999999999999, -1], [1, 0, -1]],
|
|
89
89
|
[[1, 0, -1], [0.8660254037844387, 0.9999999999999999, -1], [2, 0, 1]],
|
|
@@ -143,7 +143,7 @@ test('cylinderElliptic (options)', (t) => {
|
|
|
143
143
|
|
|
144
144
|
// test startAngle and endAngle
|
|
145
145
|
obs = cylinderElliptic({ startRadius: [1, 2], endRadius: [2, 1], startAngle: TAU / 4, endAngle: TAU * 0.75, segments: 12 })
|
|
146
|
-
pts = geom3.
|
|
146
|
+
pts = geom3.toVertices(obs)
|
|
147
147
|
|
|
148
148
|
t.notThrows(() => geom3.validate(obs))
|
|
149
149
|
t.is(measureArea(obs), 22.17105015072561)
|
|
@@ -152,7 +152,7 @@ test('cylinderElliptic (options)', (t) => {
|
|
|
152
152
|
|
|
153
153
|
// test startAngle and endAngle
|
|
154
154
|
obs = cylinderElliptic({ startAngle: 1, endAngle: 1 + TAU })
|
|
155
|
-
pts = geom3.
|
|
155
|
+
pts = geom3.toVertices(obs)
|
|
156
156
|
|
|
157
157
|
t.notThrows(() => geom3.validate(obs))
|
|
158
158
|
t.is(measureArea(obs), 18.78908426669986)
|
|
@@ -161,7 +161,7 @@ test('cylinderElliptic (options)', (t) => {
|
|
|
161
161
|
|
|
162
162
|
// test segments
|
|
163
163
|
obs = cylinderElliptic({ segments: 8 })
|
|
164
|
-
pts = geom3.
|
|
164
|
+
pts = geom3.toVertices(obs)
|
|
165
165
|
|
|
166
166
|
t.notThrows(() => geom3.validate(obs))
|
|
167
167
|
t.is(measureArea(obs), 17.902724085175244)
|
|
@@ -170,7 +170,7 @@ test('cylinderElliptic (options)', (t) => {
|
|
|
170
170
|
|
|
171
171
|
// test center
|
|
172
172
|
obs = cylinderElliptic({ center: [-5, -5, -5], height: 3, segments: 8 })
|
|
173
|
-
pts = geom3.
|
|
173
|
+
pts = geom3.toVertices(obs)
|
|
174
174
|
exp = [
|
|
175
175
|
[[-5, -5, -6.5], [-4.292893218813452, -4.292893218813452, -6.5], [-4, -5, -6.5]],
|
|
176
176
|
[[-4.292893218813452, -4.292893218813452, -6.5], [-4.292893218813452, -4.292893218813452, -3.5],
|
|
@@ -215,7 +215,7 @@ test('cylinderElliptic (options)', (t) => {
|
|
|
215
215
|
|
|
216
216
|
test('cylinderElliptic (cone)', (t) => {
|
|
217
217
|
const obs = cylinderElliptic({ endRadius: [0, 0] })
|
|
218
|
-
const pts = geom3.
|
|
218
|
+
const pts = geom3.toVertices(obs)
|
|
219
219
|
|
|
220
220
|
t.notThrows(() => geom3.validate(obs))
|
|
221
221
|
t.is(measureArea(obs), 10.128239395900382)
|
|
@@ -225,7 +225,7 @@ test('cylinderElliptic (cone)', (t) => {
|
|
|
225
225
|
|
|
226
226
|
test('cylinderElliptic (squished)', (t) => {
|
|
227
227
|
const obs = cylinderElliptic({ startRadius: [1, 0], endRadius: [0, 1], segments: 4 })
|
|
228
|
-
const pts = geom3.
|
|
228
|
+
const pts = geom3.toVertices(obs)
|
|
229
229
|
|
|
230
230
|
t.notThrows(() => geom3.validate(obs))
|
|
231
231
|
t.is(measureArea(obs), 8.47213595499958)
|
|
@@ -10,7 +10,7 @@ import { comparePolygonsAsPoints } from '../../test/helpers/index.js'
|
|
|
10
10
|
|
|
11
11
|
test('ellipsoid (defaults)', (t) => {
|
|
12
12
|
const obs = ellipsoid()
|
|
13
|
-
const pts = geom3.
|
|
13
|
+
const pts = geom3.toVertices(obs)
|
|
14
14
|
|
|
15
15
|
t.notThrows(() => geom3.validate(obs))
|
|
16
16
|
t.is(measureArea(obs), 12.465694088650583)
|
|
@@ -21,7 +21,7 @@ test('ellipsoid (defaults)', (t) => {
|
|
|
21
21
|
test('ellipsoid (options)', (t) => {
|
|
22
22
|
// test radius
|
|
23
23
|
let obs = ellipsoid({ radius: [3, 5, 7], segments: 12 })
|
|
24
|
-
let pts = geom3.
|
|
24
|
+
let pts = geom3.toVertices(obs)
|
|
25
25
|
let exp = [
|
|
26
26
|
[[3, 0, 0], [2.598076211353316, -2.4999999999999996, 0],
|
|
27
27
|
[2.25, -2.1650635094610964, -3.4999999999999996], [2.598076211353316, 0, -3.4999999999999996]],
|
|
@@ -152,14 +152,14 @@ test('ellipsoid (options)', (t) => {
|
|
|
152
152
|
|
|
153
153
|
// test segments
|
|
154
154
|
obs = ellipsoid({ segments: 8 })
|
|
155
|
-
pts = geom3.
|
|
155
|
+
pts = geom3.toVertices(obs)
|
|
156
156
|
t.notThrows(() => geom3.validate(obs))
|
|
157
157
|
t.is(measureArea(obs), 11.013439076647456)
|
|
158
158
|
t.is(measureVolume(obs), 3.2189514164974597)
|
|
159
159
|
t.is(pts.length, 32)
|
|
160
160
|
|
|
161
161
|
obs = ellipsoid({ center: [-3, 5, 7], segments: 8 })
|
|
162
|
-
pts = geom3.
|
|
162
|
+
pts = geom3.toVertices(obs)
|
|
163
163
|
exp = [
|
|
164
164
|
[[-2, 5, 7], [-2.2928932188134525, 4.292893218813452, 7],
|
|
165
165
|
[-2.5, 4.5, 6.292893218813452], [-2.2928932188134525, 5, 6.292893218813452]],
|
|
@@ -220,7 +220,7 @@ test('ellipsoid (options)', (t) => {
|
|
|
220
220
|
|
|
221
221
|
test('ellipsoid (zero radius)', (t) => {
|
|
222
222
|
const obs = ellipsoid({ radius: [1, 1, 0] })
|
|
223
|
-
const pts = geom3.
|
|
223
|
+
const pts = geom3.toVertices(obs)
|
|
224
224
|
t.notThrows(() => geom3.validate(obs))
|
|
225
225
|
t.is(measureArea(obs), 0)
|
|
226
226
|
t.is(measureVolume(obs), 0)
|
|
@@ -10,7 +10,7 @@ import { comparePolygonsAsPoints } from '../../test/helpers/index.js'
|
|
|
10
10
|
|
|
11
11
|
test('geodesicSphere (defaults)', (t) => {
|
|
12
12
|
const obs = geodesicSphere()
|
|
13
|
-
const pts = geom3.
|
|
13
|
+
const pts = geom3.toVertices(obs)
|
|
14
14
|
t.notThrows(() => geom3.validate(obs))
|
|
15
15
|
t.is(pts.length, 20)
|
|
16
16
|
})
|
|
@@ -18,7 +18,7 @@ test('geodesicSphere (defaults)', (t) => {
|
|
|
18
18
|
test('geodesicSphere (options)', (t) => {
|
|
19
19
|
// test radius
|
|
20
20
|
let obs = geodesicSphere({ radius: 5 })
|
|
21
|
-
let pts = geom3.
|
|
21
|
+
let pts = geom3.toVertices(obs)
|
|
22
22
|
const exp = [
|
|
23
23
|
[[4.253254557317035, 0, 2.628654726407001], [2.628654726407001, -4.253254557317035, 0], [4.253254557317035, 0, -2.628654726407001]],
|
|
24
24
|
[[4.253254557317035, 0, -2.628654726407001], [2.628654726407001, 4.253254557317035, 0], [4.253254557317035, 0, 2.628654726407001]],
|
|
@@ -50,7 +50,7 @@ test('geodesicSphere (options)', (t) => {
|
|
|
50
50
|
|
|
51
51
|
// test frequency
|
|
52
52
|
obs = geodesicSphere({ radius: 5, frequency: 18 })
|
|
53
|
-
pts = geom3.
|
|
53
|
+
pts = geom3.toVertices(obs)
|
|
54
54
|
|
|
55
55
|
t.notThrows.skip(() => geom3.validate(obs))
|
|
56
56
|
t.is(measureArea(obs), 303.76605423529395)
|
|
@@ -60,7 +60,7 @@ test('geodesicSphere (options)', (t) => {
|
|
|
60
60
|
|
|
61
61
|
test('geodesicSphere (zero radius)', (t) => {
|
|
62
62
|
const obs = geodesicSphere({ radius: 0 })
|
|
63
|
-
const pts = geom3.
|
|
63
|
+
const pts = geom3.toVertices(obs)
|
|
64
64
|
t.notThrows(() => geom3.validate(obs))
|
|
65
65
|
t.is(measureArea(obs), 0)
|
|
66
66
|
t.is(measureVolume(obs), 0)
|
|
@@ -14,7 +14,7 @@ test('polyhedron (points and faces)', (t) => {
|
|
|
14
14
|
let faces = [[0, 1, 2, 3], [5, 6, 7, 4], [0, 5, 4, 1], [3, 2, 7, 6], [0, 3, 6, 5], [1, 4, 7, 2]]
|
|
15
15
|
const colors = [[0, 0, 0, 1], [1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1], [0.5, 0.5, 0.5, 1], [1, 1, 1, 1]]
|
|
16
16
|
let obs = polyhedron({ points, faces, colors })
|
|
17
|
-
let pts = geom3.
|
|
17
|
+
let pts = geom3.toVertices(obs)
|
|
18
18
|
let exp = [
|
|
19
19
|
[[-1, -1, -1], [-1, -1, 1], [-1, 1, 1], [-1, 1, -1]],
|
|
20
20
|
[[1, -1, -1], [1, 1, -1], [1, 1, 1], [1, -1, 1]],
|
|
@@ -33,7 +33,7 @@ test('polyhedron (points and faces)', (t) => {
|
|
|
33
33
|
points = [[10, 10, 0], [10, -10, 0], [-10, -10, 0], [-10, 10, 0], [0, 0, 10]]
|
|
34
34
|
faces = [[0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4], [1, 0, 3], [2, 1, 3]]
|
|
35
35
|
obs = polyhedron({ points: points, faces: faces, orientation: 'inward' })
|
|
36
|
-
pts = geom3.
|
|
36
|
+
pts = geom3.toVertices(obs)
|
|
37
37
|
exp = [
|
|
38
38
|
[[0, 0, 10], [10, -10, 0], [10, 10, 0]],
|
|
39
39
|
[[0, 0, 10], [-10, -10, 0], [10, -10, 0]],
|
|
@@ -10,7 +10,7 @@ import { comparePolygonsAsPoints } from '../../test/helpers/index.js'
|
|
|
10
10
|
|
|
11
11
|
test('roundedCuboid (defaults)', (t) => {
|
|
12
12
|
const obs = roundedCuboid()
|
|
13
|
-
const pts = geom3.
|
|
13
|
+
const pts = geom3.toVertices(obs)
|
|
14
14
|
|
|
15
15
|
t.notThrows(() => geom3.validate(obs))
|
|
16
16
|
t.is(measureArea(obs), 21.87859958298585)
|
|
@@ -20,7 +20,7 @@ test('roundedCuboid (defaults)', (t) => {
|
|
|
20
20
|
|
|
21
21
|
test('roundedCuboid (zero size)', (t) => {
|
|
22
22
|
const obs = roundedCuboid({ size: [1, 1, 0] })
|
|
23
|
-
const pts = geom3.
|
|
23
|
+
const pts = geom3.toVertices(obs)
|
|
24
24
|
t.notThrows(() => geom3.validate(obs))
|
|
25
25
|
t.is(measureArea(obs), 0)
|
|
26
26
|
t.is(measureVolume(obs), 0)
|
|
@@ -29,7 +29,7 @@ test('roundedCuboid (zero size)', (t) => {
|
|
|
29
29
|
|
|
30
30
|
test('roundedCuboid (zero radius)', (t) => {
|
|
31
31
|
const obs = roundedCuboid({ roundRadius: 0 })
|
|
32
|
-
const pts = geom3.
|
|
32
|
+
const pts = geom3.toVertices(obs)
|
|
33
33
|
t.notThrows(() => geom3.validate(obs))
|
|
34
34
|
t.is(measureArea(obs), 24)
|
|
35
35
|
t.is(measureVolume(obs), 7.999999999999999)
|
|
@@ -39,7 +39,7 @@ test('roundedCuboid (zero radius)', (t) => {
|
|
|
39
39
|
test('roundedCuboid (options)', (t) => {
|
|
40
40
|
// test segments
|
|
41
41
|
let obs = roundedCuboid({ segments: 8 })
|
|
42
|
-
let pts = geom3.
|
|
42
|
+
let pts = geom3.toVertices(obs)
|
|
43
43
|
let exp = []
|
|
44
44
|
|
|
45
45
|
t.notThrows(() => geom3.validate(obs))
|
|
@@ -49,7 +49,7 @@ test('roundedCuboid (options)', (t) => {
|
|
|
49
49
|
|
|
50
50
|
// test center
|
|
51
51
|
obs = roundedCuboid({ center: [4, 5, 6], segments: 8 })
|
|
52
|
-
pts = geom3.
|
|
52
|
+
pts = geom3.toVertices(obs)
|
|
53
53
|
exp = [
|
|
54
54
|
]
|
|
55
55
|
|
|
@@ -60,7 +60,7 @@ test('roundedCuboid (options)', (t) => {
|
|
|
60
60
|
|
|
61
61
|
// test size
|
|
62
62
|
obs = roundedCuboid({ size: [8, 10, 12], segments: 8 })
|
|
63
|
-
pts = geom3.
|
|
63
|
+
pts = geom3.toVertices(obs)
|
|
64
64
|
exp = [
|
|
65
65
|
[[4, 4.8, -5.8], [3.9414213562373095, 4.941421356237309, -5.8],
|
|
66
66
|
[3.9414213562373095, 4.941421356237309, 5.8], [4, 4.8, 5.8]],
|
|
@@ -163,7 +163,7 @@ test('roundedCuboid (options)', (t) => {
|
|
|
163
163
|
|
|
164
164
|
// test roundRadius
|
|
165
165
|
obs = roundedCuboid({ size: [8, 10, 12], roundRadius: 2, segments: 8 })
|
|
166
|
-
pts = geom3.
|
|
166
|
+
pts = geom3.toVertices(obs)
|
|
167
167
|
exp = [
|
|
168
168
|
[[4, 3, -4], [3.414213562373095, 4.414213562373095, -4],
|
|
169
169
|
[3.414213562373095, 4.414213562373095, 4], [4, 3, 4]],
|
|
@@ -10,7 +10,7 @@ import { comparePolygonsAsPoints } from '../../test/helpers/index.js'
|
|
|
10
10
|
|
|
11
11
|
test('roundedCylinder (defaults)', (t) => {
|
|
12
12
|
const obs = roundedCylinder()
|
|
13
|
-
const pts = geom3.
|
|
13
|
+
const pts = geom3.toVertices(obs)
|
|
14
14
|
|
|
15
15
|
t.notThrows(() => geom3.validate(obs))
|
|
16
16
|
t.is(measureArea(obs), 16.844951865908268)
|
|
@@ -20,7 +20,7 @@ test('roundedCylinder (defaults)', (t) => {
|
|
|
20
20
|
|
|
21
21
|
test('roundedCylinder (zero height)', (t) => {
|
|
22
22
|
const obs = roundedCylinder({ height: 0 })
|
|
23
|
-
const pts = geom3.
|
|
23
|
+
const pts = geom3.toVertices(obs)
|
|
24
24
|
t.notThrows(() => geom3.validate(obs))
|
|
25
25
|
t.is(measureArea(obs), 0)
|
|
26
26
|
t.is(measureVolume(obs), 0)
|
|
@@ -29,7 +29,7 @@ test('roundedCylinder (zero height)', (t) => {
|
|
|
29
29
|
|
|
30
30
|
test('roundedCylinder (zero radius)', (t) => {
|
|
31
31
|
const obs = roundedCylinder({ radius: 0, roundRadius: 0 })
|
|
32
|
-
const pts = geom3.
|
|
32
|
+
const pts = geom3.toVertices(obs)
|
|
33
33
|
t.notThrows(() => geom3.validate(obs))
|
|
34
34
|
t.is(measureArea(obs), 0)
|
|
35
35
|
t.is(measureVolume(obs), 0)
|
|
@@ -38,7 +38,7 @@ test('roundedCylinder (zero radius)', (t) => {
|
|
|
38
38
|
|
|
39
39
|
test('roundedCylinder (zero roundRadius)', (t) => {
|
|
40
40
|
const obs = roundedCylinder({ roundRadius: 0 })
|
|
41
|
-
const pts = geom3.
|
|
41
|
+
const pts = geom3.toVertices(obs)
|
|
42
42
|
t.notThrows(() => geom3.validate(obs))
|
|
43
43
|
t.is(measureArea(obs), 18.789084266699856)
|
|
44
44
|
t.is(measureVolume(obs), 6.2428903045161)
|
|
@@ -48,7 +48,7 @@ test('roundedCylinder (zero roundRadius)', (t) => {
|
|
|
48
48
|
test('roundedCylinder (options)', (t) => {
|
|
49
49
|
// test segments
|
|
50
50
|
let obs = roundedCylinder({ segments: 5 })
|
|
51
|
-
let pts = geom3.
|
|
51
|
+
let pts = geom3.toVertices(obs)
|
|
52
52
|
let exp = [
|
|
53
53
|
]
|
|
54
54
|
|
|
@@ -59,7 +59,7 @@ test('roundedCylinder (options)', (t) => {
|
|
|
59
59
|
|
|
60
60
|
// test center
|
|
61
61
|
obs = roundedCylinder({ segments: 5, center: [-5, -5, -5] })
|
|
62
|
-
pts = geom3.
|
|
62
|
+
pts = geom3.toVertices(obs)
|
|
63
63
|
exp = [
|
|
64
64
|
[[-4.048943483704846, -4.6909830056250525, -5.8], [-5, -4, -5.8],
|
|
65
65
|
[-5, -4, -4.2], [-4.048943483704846, -4.6909830056250525, -4.2]],
|
|
@@ -91,7 +91,7 @@ test('roundedCylinder (options)', (t) => {
|
|
|
91
91
|
|
|
92
92
|
// test height
|
|
93
93
|
obs = roundedCylinder({ segments: 5, height: 20 })
|
|
94
|
-
pts = geom3.
|
|
94
|
+
pts = geom3.toVertices(obs)
|
|
95
95
|
exp = [
|
|
96
96
|
[[0.9510565162951535, 0.30901699437494745, -9.8], [0, 1, -9.8],
|
|
97
97
|
[0, 1, 9.8], [0.9510565162951535, 0.30901699437494745, 9.8]],
|
|
@@ -123,7 +123,7 @@ test('roundedCylinder (options)', (t) => {
|
|
|
123
123
|
|
|
124
124
|
// test radius
|
|
125
125
|
obs = roundedCylinder({ segments: 5, radius: 10 })
|
|
126
|
-
pts = geom3.
|
|
126
|
+
pts = geom3.toVertices(obs)
|
|
127
127
|
exp = [
|
|
128
128
|
[[9.510565162951535, 3.0901699437494745, -0.8], [0, 10, -0.8],
|
|
129
129
|
[0, 10, 0.8], [9.510565162951535, 3.0901699437494745, 0.8]],
|
|
@@ -154,7 +154,7 @@ test('roundedCylinder (options)', (t) => {
|
|
|
154
154
|
|
|
155
155
|
// test round radius
|
|
156
156
|
obs = roundedCylinder({ segments: 5, height: 20, radius: 5, roundRadius: 2 })
|
|
157
|
-
pts = geom3.
|
|
157
|
+
pts = geom3.toVertices(obs)
|
|
158
158
|
exp = [
|
|
159
159
|
[[4.755282581475767, 1.5450849718747373, -8], [0, 5, -8],
|
|
160
160
|
[0, 5, 8], [4.755282581475767, 1.5450849718747373, 8]],
|
|
@@ -10,7 +10,7 @@ import { comparePolygonsAsPoints } from '../../test/helpers/index.js'
|
|
|
10
10
|
|
|
11
11
|
test('sphere (defaults)', (t) => {
|
|
12
12
|
const obs = sphere()
|
|
13
|
-
const pts = geom3.
|
|
13
|
+
const pts = geom3.toVertices(obs)
|
|
14
14
|
|
|
15
15
|
t.notThrows(() => geom3.validate(obs))
|
|
16
16
|
t.is(measureArea(obs), 12.465694088650583)
|
|
@@ -21,7 +21,7 @@ test('sphere (defaults)', (t) => {
|
|
|
21
21
|
test('sphere (options)', (t) => {
|
|
22
22
|
// test radius
|
|
23
23
|
let obs = sphere({ radius: 5, segments: 12 })
|
|
24
|
-
let pts = geom3.
|
|
24
|
+
let pts = geom3.toVertices(obs)
|
|
25
25
|
let exp = []
|
|
26
26
|
t.notThrows(() => geom3.validate(obs))
|
|
27
27
|
t.is(measureArea(obs), 296.5322084069296)
|
|
@@ -31,7 +31,7 @@ test('sphere (options)', (t) => {
|
|
|
31
31
|
|
|
32
32
|
// test segments
|
|
33
33
|
obs = sphere({ segments: 8 })
|
|
34
|
-
pts = geom3.
|
|
34
|
+
pts = geom3.toVertices(obs)
|
|
35
35
|
exp = [
|
|
36
36
|
[[1, 0, 0], [0.7071067811865476, -0.7071067811865475, 0],
|
|
37
37
|
[0.5000000000000001, -0.5, -0.7071067811865475], [0.7071067811865476, 0, -0.7071067811865475]],
|
|
@@ -116,7 +116,7 @@ test('sphere (options)', (t) => {
|
|
|
116
116
|
|
|
117
117
|
// test center
|
|
118
118
|
obs = sphere({ center: [-3, 5, 7], segments: 8 })
|
|
119
|
-
pts = geom3.
|
|
119
|
+
pts = geom3.toVertices(obs)
|
|
120
120
|
exp = [
|
|
121
121
|
[[-2, 5, 7], [-2.2928932188134525, 4.292893218813452, 7],
|
|
122
122
|
[-2.5, 4.5, 6.292893218813452], [-2.2928932188134525, 5, 6.292893218813452]],
|
|
@@ -176,7 +176,7 @@ test('sphere (options)', (t) => {
|
|
|
176
176
|
|
|
177
177
|
test('sphere (zero radius)', (t) => {
|
|
178
178
|
const obs = sphere({ radius: 0 })
|
|
179
|
-
const pts = geom3.
|
|
179
|
+
const pts = geom3.toVertices(obs)
|
|
180
180
|
t.notThrows(() => geom3.validate(obs))
|
|
181
181
|
t.is(measureArea(obs), 0)
|
|
182
182
|
t.is(measureVolume(obs), 0)
|
|
@@ -12,7 +12,7 @@ import { comparePoints } from '../../test/helpers/index.js'
|
|
|
12
12
|
|
|
13
13
|
test('torus (defaults)', (t) => {
|
|
14
14
|
const obs = torus()
|
|
15
|
-
const pts = geom3.
|
|
15
|
+
const pts = geom3.toVertices(obs)
|
|
16
16
|
|
|
17
17
|
t.notThrows(() => geom3.validate(obs))
|
|
18
18
|
t.is(measureArea(obs), 157.0282327749074)
|
|
@@ -26,7 +26,7 @@ test('torus (defaults)', (t) => {
|
|
|
26
26
|
|
|
27
27
|
test('torus (simple options)', (t) => {
|
|
28
28
|
const obs = torus({ innerRadius: 0.5, innerSegments: 4, outerRadius: 5, outerSegments: 8 })
|
|
29
|
-
const pts = geom3.
|
|
29
|
+
const pts = geom3.toVertices(obs)
|
|
30
30
|
t.notThrows(() => geom3.validate(obs))
|
|
31
31
|
t.is(measureArea(obs), 83.36086132479792)
|
|
32
32
|
t.is(measureVolume(obs), 14.14213562373095)
|
|
@@ -39,7 +39,7 @@ test('torus (simple options)', (t) => {
|
|
|
39
39
|
|
|
40
40
|
test('torus (complex options)', (t) => {
|
|
41
41
|
const obs = torus({ innerRadius: 1, outerRadius: 5, innerSegments: 32, outerSegments: 72, startAngle: TAU / 4, outerRotation: TAU / 4 })
|
|
42
|
-
const pts = geom3.
|
|
42
|
+
const pts = geom3.toVertices(obs)
|
|
43
43
|
t.notThrows(() => geom3.validate(obs))
|
|
44
44
|
t.is(measureArea(obs), 55.472610544494)
|
|
45
45
|
t.is(measureVolume(obs), 24.484668362201525)
|
|
@@ -52,7 +52,7 @@ test('torus (complex options)', (t) => {
|
|
|
52
52
|
|
|
53
53
|
test('torus (startAngle)', (t) => {
|
|
54
54
|
const obs = torus({ startAngle: 1, endAngle: 1 + TAU })
|
|
55
|
-
const pts = geom3.
|
|
55
|
+
const pts = geom3.toVertices(obs)
|
|
56
56
|
t.notThrows(() => geom3.validate(obs))
|
|
57
57
|
t.is(measureArea(obs), 157.0282327749074)
|
|
58
58
|
t.is(measureVolume(obs), 77.94735870844195)
|
package/src/utils/flatten.js
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import test from 'ava'
|
|
2
|
+
|
|
3
|
+
import { flatten } from './index.js'
|
|
4
|
+
|
|
5
|
+
test('flatten: test an empty array returns empty.', (t) => {
|
|
6
|
+
t.deepEqual(flatten([]), [])
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
test('flatten: test a flat array is unchanged.', (t) => {
|
|
10
|
+
t.deepEqual(flatten([1, 2, 3]), [1, 2, 3])
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('flatten: test single level nesting is flattened.', (t) => {
|
|
14
|
+
t.deepEqual(flatten([1, [2, 3], 4]), [1, 2, 3, 4])
|
|
15
|
+
t.deepEqual(flatten([[1, 2], [3, 4]]), [1, 2, 3, 4])
|
|
16
|
+
t.deepEqual(flatten([[1], [2], [3]]), [1, 2, 3])
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('flatten: test deep nesting is flattened.', (t) => {
|
|
20
|
+
t.deepEqual(flatten([1, [2, [3, [4]]]]), [1, 2, 3, 4])
|
|
21
|
+
t.deepEqual(flatten([[[[1]]]]), [1])
|
|
22
|
+
t.deepEqual(flatten([1, [2, [3, [4, [5]]]]]), [1, 2, 3, 4, 5])
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test('flatten: test mixed nesting depths are flattened.', (t) => {
|
|
26
|
+
t.deepEqual(flatten([1, [2, 3], [[4, 5]], [[[6]]]]), [1, 2, 3, 4, 5, 6])
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('flatten: test empty nested arrays are removed.', (t) => {
|
|
30
|
+
t.deepEqual(flatten([[]]), [])
|
|
31
|
+
t.deepEqual(flatten([[], []]), [])
|
|
32
|
+
t.deepEqual(flatten([1, [], 2]), [1, 2])
|
|
33
|
+
t.deepEqual(flatten([[], [1], []]), [1])
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('flatten: test single element arrays are flattened.', (t) => {
|
|
37
|
+
t.deepEqual(flatten([1]), [1])
|
|
38
|
+
t.deepEqual(flatten([[1]]), [1])
|
|
39
|
+
t.deepEqual(flatten([[[1]]]), [1])
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('flatten: test element order is preserved.', (t) => {
|
|
43
|
+
t.deepEqual(flatten([1, [2, 3], 4, [5, 6]]), [1, 2, 3, 4, 5, 6])
|
|
44
|
+
t.deepEqual(flatten([[1, 2], 3, [4, [5, 6]]]), [1, 2, 3, 4, 5, 6])
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('flatten: test object references are preserved.', (t) => {
|
|
48
|
+
const obj1 = { id: 1 }
|
|
49
|
+
const obj2 = { id: 2 }
|
|
50
|
+
const obj3 = { id: 3 }
|
|
51
|
+
const result = flatten([obj1, [obj2, obj3]])
|
|
52
|
+
t.is(result[0], obj1)
|
|
53
|
+
t.is(result[1], obj2)
|
|
54
|
+
t.is(result[2], obj3)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('flatten: test various types are preserved.', (t) => {
|
|
58
|
+
const obj = { a: 1 }
|
|
59
|
+
const fn = () => {}
|
|
60
|
+
t.deepEqual(flatten([1, 'string', null, undefined, true]), [1, 'string', null, undefined, true])
|
|
61
|
+
|
|
62
|
+
const result = flatten([obj, [fn]])
|
|
63
|
+
t.is(result[0], obj)
|
|
64
|
+
t.is(result[1], fn)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('flatten: test large flat array is unchanged.', (t) => {
|
|
68
|
+
const large = []
|
|
69
|
+
for (let i = 0; i < 1000; i++) {
|
|
70
|
+
large.push(i)
|
|
71
|
+
}
|
|
72
|
+
const result = flatten(large)
|
|
73
|
+
t.is(result.length, 1000)
|
|
74
|
+
t.is(result[0], 0)
|
|
75
|
+
t.is(result[999], 999)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test('flatten: test large nested array is flattened.', (t) => {
|
|
79
|
+
const nested = []
|
|
80
|
+
for (let i = 0; i < 100; i++) {
|
|
81
|
+
nested.push([i * 10, i * 10 + 1, i * 10 + 2])
|
|
82
|
+
}
|
|
83
|
+
const result = flatten(nested)
|
|
84
|
+
t.is(result.length, 300)
|
|
85
|
+
t.is(result[0], 0)
|
|
86
|
+
t.is(result[3], 10)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('flatten: test input array is not modified.', (t) => {
|
|
90
|
+
const input = [1, [2, 3], 4]
|
|
91
|
+
const inputCopy = JSON.stringify(input)
|
|
92
|
+
flatten(input)
|
|
93
|
+
t.is(JSON.stringify(input), inputCopy)
|
|
94
|
+
})
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import * as mat4 from '../../maths/mat4/index.js'
|
|
2
|
-
import * as vec2 from '../../maths/vec2/index.js'
|
|
3
|
-
|
|
4
|
-
import { create } from './create.js'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Create a new 2D geometry from the given compact binary data.
|
|
8
|
-
* @param {Array} data - compact binary data
|
|
9
|
-
* @returns {Geom2} a new geometry
|
|
10
|
-
* @alias module:modeling/geometries/geom2.fromCompactBinary
|
|
11
|
-
*/
|
|
12
|
-
export const fromCompactBinary = (data) => {
|
|
13
|
-
if (data[0] !== 0) throw new Error('invalid compact binary data')
|
|
14
|
-
|
|
15
|
-
const created = create()
|
|
16
|
-
|
|
17
|
-
created.transforms = mat4.clone(data.slice(1, 17))
|
|
18
|
-
|
|
19
|
-
for (let i = 21; i < data.length;) {
|
|
20
|
-
const length = data[i++] // number of points for this polygon
|
|
21
|
-
if (length < 0 || i + length * 2 > data.length) {
|
|
22
|
-
throw new Error('invalid compact binary data')
|
|
23
|
-
}
|
|
24
|
-
const outline = []
|
|
25
|
-
for (let j = 0; j < length; j++) {
|
|
26
|
-
const x = data[i + j * 2]
|
|
27
|
-
const y = data[i + j * 2 + 1]
|
|
28
|
-
outline.push(vec2.fromValues(x, y))
|
|
29
|
-
}
|
|
30
|
-
created.outlines.push(outline)
|
|
31
|
-
i += length * 2
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// transfer known properties, i.e. color
|
|
35
|
-
if (data[17] >= 0) {
|
|
36
|
-
created.color = [data[17], data[18], data[19], data[20]]
|
|
37
|
-
}
|
|
38
|
-
// TODO: how about custom properties or fields ?
|
|
39
|
-
return created
|
|
40
|
-
}
|