replace trace2count() with new offset() function

This commit is contained in:
Stewart Allen 2020-11-02 11:02:59 -05:00
commit afedbfb5f9
3 changed files with 11 additions and 65 deletions

View file

@ -18,7 +18,6 @@
newPoint = BASE.newPoint; newPoint = BASE.newPoint;
BASE.polygons = { BASE.polygons = {
trace2count : trace2count,
rayIntersect : rayIntersect, rayIntersect : rayIntersect,
alignWindings : alignWindings, alignWindings : alignWindings,
setWinding : setWinding, setWinding : setWinding,
@ -548,60 +547,7 @@
} }
} }
return polys; return opt.flat ? opt.outs : polys;
}
/**
* @param {Polygon} poly input
* @param {Polygon[]} traces output
* @param {number} offset distance to offset
* @param {number} count number of offsets
* @param {number} depth current depth (count) into offsets
* @param {Polygon[]} [last]
* @param {Polygon[]} [first]
*/
function trace2count(poly, traces, offset, count, depth, last, first) {
if (count === 0) {
if (last) last.append(poly);
return;
}
// offset polygon to outer traces array
let calcoff = depth === 0 && last ? offset / 2 : offset,
outer = poly.offset(calcoff, []),
inner = [],
j;
// outer offset failed
if (outer.length === 0) {
if (last) last.append(poly);
return;
}
// offset poly children to inner traces array
if (poly.inner) {
poly.inner.forEach(function(ic) {
ic.offset(-calcoff, inner);
});
}
let newouter = [], newinner = [];
subtract(outer, inner, newouter, newinner, poly.getZ());
if (newouter.length > 0) {
traces.appendAll(newouter);
if (depth === 0 && first) {
first.appendAll(newouter);
}
// recurse for multiple shells
if (count > 0) {
for (j=0; j<newouter.length; j++) {
trace2count(newouter[j], traces, offset, count - 1, depth + 1, last);
}
}
} else if (last) {
last.append(poly);
}
} }
/** /**

View file

@ -452,8 +452,7 @@
last = nulast; last = nulast;
} }
last.forEach(function(inner) { last.forEach(function(inner) {
// TODO replace with new offset() function POLY.offset([inner], -fillOffset, {outs: top.inner, flat: true, z: slice.z});
POLY.trace2count(inner, top.inner, fillOffset, 1, 0);
}); });
} }
}); });
@ -1008,14 +1007,15 @@
if (supports) supports.forEach(function (poly) { if (supports) supports.forEach(function (poly) {
// angle based on width/height ratio // angle based on width/height ratio
let angle = (poly.bounds.width() / poly.bounds.height() > 1) ? 90 : 0, let angle = (poly.bounds.width() / poly.bounds.height() > 1) ? 90 : 0;
// calculate fill density // calculate fill density
spacing = linewidth * (1 / density), let spacing = linewidth * (1 / density);
offsets = []; // inset support poly for fill lines 33% of nozzle width
// offset support poly for fill lines let inset = POLY.offset([poly], -linewidth/3, {flat: true, z: slice.z});
POLY.trace2count(poly, offsets, linewidth/4, 1, 0);
// do the fill // do the fill
if (offsets.length > 0) fillArea(offsets, angle, spacing, poly.fills = []); if (inset.length > 0) {
fillArea(inset, angle, spacing, poly.fills = []);
}
return true; return true;
}); });

View file

@ -669,7 +669,7 @@
// expand specified # of brims // expand specified # of brims
brims.forEach(function(brim) { brims.forEach(function(brim) {
POLY.trace2count(brim, polys, -nozzle, process.outputBrimCount, 0); POLY.offset([brim], nozzle, {outs: polys, flat: true, count: process.outputBrimCount});
}); });
// output brim points // output brim points