MATSvg = {
const parser = new DOMParser();
const doc = parser.parseFromString(SvgOut, "application/xml");
const pathd = doc.querySelector(".polygon").getAttribute("d");
const paths = matsutil.getPathsFromStr(pathd);
console.log(paths);
const mats = matsutil.findMats(paths, 3);
const sats = mats.map((mat) => matsutil.toScaleAxis(mat, 1.5));
const satsFinal = drawMats(sats);
function drawMats(inputmats) {
const satsFinal = [];
const mls = [];
function createLS(x0, y0, x1, y1) {
mls.push([
[x0 - UpperLeft[0] * -1, y0 - UpperLeft[1] * -1],
[x1 - UpperLeft[0] * -1, y1 - UpperLeft[1] * -1]
]);
}
function getLinePathStr(ps) {
let [[x0, y0], [x1, y1]] = ps;
createLS(x0, y0, x1, y1);
return `M ${x0} ${y0} L ${x1} ${y1}`;
}
function getQuadBezierPathStr(ps) {
let [[x0, y0], [x1, y1], [x2, y2]] = ps;
createLS(x0, y0, x2, y2);
return `M ${x0} ${y0} Q ${x1} ${y1} ${x2} ${y2}`;
}
function getCubicBezierPathStr(ps) {
let [[x0, y0], [x1, y1], [x2, y2], [x3, y3]] = ps;
createLS(x0, y0, x3, y3);
return `M ${x0} ${y0} L ${x3} ${y3}`;
}
inputmats.forEach(f);
function f(mat) {
let cpNode = mat.cpNode;
if (!cpNode) return;
let fs = [
getLinePathStr,
getLinePathStr,
getLinePathStr,
getQuadBezierPathStr,
getCubicBezierPathStr
];
matsutil.traverseEdges(cpNode, function (cpNodeO) {
if (matsutil.isTerminating(cpNodeO)) return;
let bezier = matsutil.getCurveToNext(cpNodeO);
if (!bezier) return;
satsFinal.push(
`<path d="${fs[bezier.length](bezier)}" fill="none" stroke="${
["red", "red", "blue", "green", "red"][bezier.length]
}" stroke-width="0.2%"/>`
);
});
}
return [satsFinal, mls];
}
return [
`<svg viewBox="${doc
.querySelector("svg")
.getAttribute(
"viewBox"
)}" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2"><g>${satsFinal[0].join(
""
)}</g></svg>`,
satsFinal[1]
];
}