Implement caching when performing outline conversion
This commit is contained in:
parent
b16dfb91db
commit
e28ce0fd68
6 changed files with 82 additions and 14 deletions
|
@ -1,5 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
const crypto = require("crypto");
|
||||
|
||||
const TypoGeom = require("typo-geom");
|
||||
const Point = require("./point");
|
||||
const Transform = require("./transform");
|
||||
|
@ -51,6 +53,36 @@ exports.convertShapeToArcs = function convertShapeToArcs(shape) {
|
|||
return shape.map(convertContourToArcs);
|
||||
};
|
||||
|
||||
exports.hashShape = function (shape) {
|
||||
let s = "";
|
||||
for (const c of shape) {
|
||||
s += "[";
|
||||
for (const z of c) {
|
||||
s += `[${z.type};${Math.round(z.x * 0x10000)};${Math.round(z.y * 0x10000)}]`;
|
||||
}
|
||||
s += "]";
|
||||
}
|
||||
return crypto.createHash("sha256").update(s).digest();
|
||||
};
|
||||
|
||||
function contourToRep(contour) {
|
||||
let c = [];
|
||||
for (const z of contour) c.push({ type: z.type, x: z.x, y: z.y });
|
||||
return c;
|
||||
}
|
||||
exports.shapeToRep = function (shape) {
|
||||
return shape.map(contourToRep);
|
||||
};
|
||||
|
||||
function repToContour(contourRep) {
|
||||
let c = [];
|
||||
for (const z of contourRep) c.push(Point.fromXY(z.type, z.x, z.y));
|
||||
return c;
|
||||
}
|
||||
exports.repToShape = function (shapeRep) {
|
||||
return shapeRep.map(repToContour);
|
||||
};
|
||||
|
||||
function convertContourToArcs(contour) {
|
||||
if (!contour || !contour.length) return [];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue