Published
Edited
Sep 4, 2019
1 fork
Importers
Insert cell
Insert cell
expandPath = (pathString, expandBy = 2, bevel = 0, origin = [0, 0]) => {
const makerModel = makerjs.importer.fromSVGPathData(pathString);
makerjs.model.originate(makerModel);
makerjs.model.simplify(makerModel);
// IDK why we need + 0.00001 here
const expanded = makerjs.model.expandPaths(makerModel, expandBy, bevel);
makerjs.model.simplify(expanded);
const svg = html`${makerjs.exporter.toSVG(expanded, { origin })}`;
return svg.querySelector("path").getAttribute("d");
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
exampleOutput = expandPath(examplePathInput, 2 + 0.00001, 0, [3, 3])
Insert cell
Insert cell
Insert cell
Insert cell
exampleOutputBug = expandPath(examplePathInput, 2, 0, [3, 3])
Insert cell
html`<svg width="216" height="216">
<path fill="none" stroke="rgba(0,0,0,1)" stroke-width="1" d="${exampleOutputBug}"></path>
</svg>`
Insert cell
makerjs = require("https://bundle.run/makerjs@0.17.0")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more