@jscad/svg-deserializer 3.0.1-alpha.0 → 3.0.3-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscad/svg-deserializer",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3-alpha.0",
|
|
4
4
|
"description": "SVG Deserializer for JSCAD",
|
|
5
5
|
"homepage": "https://openjscad.xyz/",
|
|
6
6
|
"repository": "https://github.com/jscad/OpenJSCAD.org",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@jscad/array-utils": "3.0.1-alpha.0",
|
|
41
|
-
"@jscad/io-utils": "3.0.
|
|
42
|
-
"@jscad/modeling": "3.0.
|
|
41
|
+
"@jscad/io-utils": "3.0.3-alpha.0",
|
|
42
|
+
"@jscad/modeling": "3.0.3-alpha.0",
|
|
43
43
|
"saxes": "6.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"rollup-plugin-banner": "^0.2.1",
|
|
53
53
|
"rollup-plugin-version-injector": "^1.3.3"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "b0a83db054ec02ccddd9e19e51f86bf30f72a69e"
|
|
56
56
|
}
|
package/src/shapesMapGeometry.js
CHANGED
|
@@ -133,15 +133,22 @@ export const shapesMapGeometry = (obj, objectify, params) => {
|
|
|
133
133
|
const listofpaths = expandPath(obj, svgUnitsPmm, svgUnitsX, svgUnitsY, svgUnitsV, svgGroups, segments, pathSelfClosed)
|
|
134
134
|
// order is important
|
|
135
135
|
const listofentries = Object.entries(listofpaths).sort((a, b) => a[0].localeCompare(b[0]))
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
136
|
+
if (target === 'geom2') {
|
|
137
|
+
// concatenate all sides to a single geom2
|
|
138
|
+
const outlines = []
|
|
139
|
+
listofentries.forEach((entry) => {
|
|
140
|
+
const path = entry[1]
|
|
141
|
+
// discard unclosed paths
|
|
142
|
+
if (path.isClosed) {
|
|
143
|
+
const points = path2.toPoints(path)
|
|
144
|
+
outlines.push(points)
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
if (outlines.length === 0) return []
|
|
148
|
+
return geom2.create(outlines)
|
|
149
|
+
} else {
|
|
150
|
+
return listofentries.map((entry) => entry[1])
|
|
151
|
+
}
|
|
145
152
|
}
|
|
146
153
|
}
|
|
147
154
|
|
|
@@ -153,6 +160,18 @@ const appendPoints = (points, geometry) => {
|
|
|
153
160
|
return path2.fromPoints({ }, points)
|
|
154
161
|
}
|
|
155
162
|
|
|
163
|
+
/*
|
|
164
|
+
* Expands the given SVG path object into a set of path segments.
|
|
165
|
+
* @param {object} obj - SVG path object to expand
|
|
166
|
+
* @param {number} svgUnitsPmm - SVG units per millimeter
|
|
167
|
+
* @param {number} svgUnitsX - X-axis SVG units
|
|
168
|
+
* @param {number} svgUnitsY - Y-axis SVG units
|
|
169
|
+
* @param {number} svgUnitsV - SVG units value
|
|
170
|
+
* @param {object} svgGroups - SVG groups object
|
|
171
|
+
* @param {number} segments - number of segments per 360 rotation
|
|
172
|
+
* @param {boolean} pathSelfClosed - Whether the path is self-closed
|
|
173
|
+
* @returns {object} a object containing the named paths
|
|
174
|
+
*/
|
|
156
175
|
const expandPath = (obj, svgUnitsPmm, svgUnitsX, svgUnitsY, svgUnitsV, svgGroups, segments, pathSelfClosed) => {
|
|
157
176
|
const paths = {}
|
|
158
177
|
const on = 'path'
|
|
@@ -326,9 +326,7 @@ test('deserialize : instantiate svg (path: with bezier) to objects', (t) => {
|
|
|
326
326
|
</svg>`
|
|
327
327
|
|
|
328
328
|
observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
329
|
-
t.is(observed.length,
|
|
330
|
-
shape = observed[0]
|
|
331
|
-
t.is(shape.points.length, 14) // open path
|
|
329
|
+
t.is(observed.length, 0) // open path
|
|
332
330
|
|
|
333
331
|
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
334
332
|
t.is(observed.length, 2)
|
|
@@ -344,9 +342,7 @@ test('deserialize : instantiate svg (path: with bezier) to objects', (t) => {
|
|
|
344
342
|
</svg>`
|
|
345
343
|
|
|
346
344
|
observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
347
|
-
t.is(observed.length,
|
|
348
|
-
shape = observed[0]
|
|
349
|
-
t.is(shape.points.length, 29) // open path
|
|
345
|
+
t.is(observed.length, 0) // open path
|
|
350
346
|
|
|
351
347
|
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
352
348
|
t.is(observed.length, 1)
|
|
@@ -420,13 +416,11 @@ test('deserialize : instantiate svg produced by inkscape to objects', (t) => {
|
|
|
420
416
|
`
|
|
421
417
|
|
|
422
418
|
let observed = deserialize({ filename: 'inkscape', output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
423
|
-
t.is(observed.length,
|
|
419
|
+
t.is(observed.length, 1)
|
|
424
420
|
let shape = observed[0]
|
|
425
|
-
t.is(shape.outlines.length,
|
|
421
|
+
t.is(shape.outlines.length, 2)
|
|
426
422
|
t.is(shape.outlines[0].length, 19)
|
|
427
|
-
shape
|
|
428
|
-
t.is(shape.outlines.length, 1)
|
|
429
|
-
t.is(shape.outlines[0].length, 20)
|
|
423
|
+
t.is(shape.outlines[1].length, 20)
|
|
430
424
|
|
|
431
425
|
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
432
426
|
t.is(observed.length, 2)
|
|
@@ -446,13 +440,11 @@ test('deserialize : instantiate shape with a hole to objects', (t) => {
|
|
|
446
440
|
`
|
|
447
441
|
|
|
448
442
|
let observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
449
|
-
t.is(observed.length,
|
|
443
|
+
t.is(observed.length, 1)
|
|
450
444
|
let shape = observed[0]
|
|
451
|
-
t.is(shape.outlines.length,
|
|
452
|
-
t.is(shape.outlines[0].length, 38)
|
|
453
|
-
shape = observed[1]
|
|
454
|
-
t.is(shape.outlines.length, 1)
|
|
445
|
+
t.is(shape.outlines.length, 2)
|
|
455
446
|
t.is(shape.outlines[0].length, 38)
|
|
447
|
+
t.is(shape.outlines[1].length, 38)
|
|
456
448
|
|
|
457
449
|
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
458
450
|
t.is(observed.length, 2)
|
|
@@ -472,9 +464,9 @@ test('deserialize : instantiate shape with a nested hole to objects', (t) => {
|
|
|
472
464
|
`
|
|
473
465
|
|
|
474
466
|
let observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
475
|
-
t.is(observed.length,
|
|
467
|
+
t.is(observed.length, 1)
|
|
476
468
|
let shape = observed[0]
|
|
477
|
-
t.is(shape.outlines.length,
|
|
469
|
+
t.is(shape.outlines.length, 4)
|
|
478
470
|
t.is(shape.outlines[0].length, 38)
|
|
479
471
|
|
|
480
472
|
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|