add custom debur for rendering

This commit is contained in:
Stewart Allen 2020-11-11 17:13:54 -05:00
commit e5956bd4c9
2 changed files with 29 additions and 2 deletions

View file

@ -230,10 +230,33 @@
return Math.abs(diff); return Math.abs(diff);
} }
PRO.debur = function(dist) {
if (this.len < 2) {
return null;
}
const pa = this.points,
pln = pa.length,
open = this.open,
newp = newPolygon(),
min = dist || BASE.config.precision_merge;
let lo;
newp.push(lo = pa[0]);
for (let i=1; i<pln; i++) {
if (lo.distTo2D(pa[i]) >= min) {
newp.push(lo = pa[i]);
}
}
newp.open = open;
newp.parent = this.parent;
if (newp.length < 2) {
return null;
}
return newp;
};
PRO.miter = function(debug) { PRO.miter = function(debug) {
if (this.length < 3) return this; if (this.length < 3) return this;
// todo - to eliminate path sharps in renders
const slo = [], pa = this.points, pln = pa.length, open = this.open; const slo = [], pa = this.points, pln = pa.length, open = this.open;
let last; let last;
for (let i=1; i<pln; i++) { for (let i=1; i<pln; i++) {

View file

@ -164,7 +164,11 @@
polys.forEach(poly => { polys.forEach(poly => {
const contour = []; const contour = [];
poly = poly.clean().miter(); poly = poly.debur();
if (!poly) return;
poly = poly.miter();
// cleaning converts open to closed which is problematic
// poly = poly.clean().miter();
// if (poly.debug) { // if (poly.debug) {
// const save = this.current; // const save = this.current;
// this.setLayer('debug.acute', 0xff0000).addPoly(poly, {thin:true}); // this.setLayer('debug.acute', 0xff0000).addPoly(poly, {thin:true});