-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
38 lines (38 loc) · 1.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"use strict";
var makerjs = require("makerjs");
function outline(svgData, distance, opts) {
var defaultOptions = {
bezierAccuracy: 0.25,
joints: 0,
outside: true,
tagName: 'path'
};
var o = makerjs.extendObject(defaultOptions, opts);
var closed = true;
var input;
switch (o.tagName) {
case 'polyline':
closed = false;
//fall through
case 'polygon':
//use points.
//Need to mirror them on y axis because they are expected to be in MakerJs coordinate space
input = makerjs.model.mirror(new makerjs.models.ConnectTheDots(closed, svgData), false, true);
break;
default:
input = makerjs.importer.fromSVGPathData(svgData, { bezierAccuracy: o.bezierAccuracy });
break;
}
var result;
if (o.inside && o.outside) {
result = makerjs.model.expandPaths(input, distance, o.joints);
}
else {
result = makerjs.model.outline(input, distance, o.joints, o.inside);
}
makerjs.model.simplify(result);
return makerjs.exporter.toSVGPathData(result, false, [0, 0]);
}
exports.__esModule = true;
exports["default"] = outline;
module.exports = outline;