turn function loops into for-let-of
This commit is contained in:
parent
4d830c3b12
commit
10969c5be3
2 changed files with 52 additions and 49 deletions
|
|
@ -78,11 +78,11 @@
|
|||
polys = tops || [],
|
||||
min = numOrDefault(minarea, 0.1);
|
||||
|
||||
tnode.m_Childs.forEach(function(child) {
|
||||
for (let child of tnode.m_Childs) {
|
||||
poly = fromClipperNode(child, z);
|
||||
// throw out all tiny polygons
|
||||
if (!poly.open && poly.area() < min) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
if (parent) {
|
||||
parent.addInner(poly);
|
||||
|
|
@ -92,7 +92,7 @@
|
|||
if (child.m_Childs) {
|
||||
fromClipperTree(child, z, polys, parent ? null : poly, minarea);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return polys;
|
||||
};
|
||||
|
|
@ -100,10 +100,10 @@
|
|||
function fromClipperTreeUnion(tnode, z, minarea, tops, parent) {
|
||||
let polys = tops || [], poly;
|
||||
|
||||
tnode.m_Childs.forEach(function(child) {
|
||||
for (let child of tnode.m_Childs) {
|
||||
poly = fromClipperNode(child, z);
|
||||
if (!poly.open && minarea && poly.area() < minarea) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
if (parent) {
|
||||
parent.addInner(poly);
|
||||
|
|
@ -113,7 +113,7 @@
|
|||
if (child.m_Childs) {
|
||||
fromClipperTreeUnion(child, z, minarea, polys, parent ? null : poly);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return polys;
|
||||
};
|
||||
|
|
@ -122,16 +122,17 @@
|
|||
let clib = self.ClipperLib,
|
||||
clip = clib.Clipper;
|
||||
|
||||
if (tree.m_Childs) tree.m_Childs.forEach(function(child) {
|
||||
if (tree.m_Childs)
|
||||
for (let child of tree.m_Childs) {
|
||||
child.m_polygon = clip.CleanPolygon(child.m_polygon, CONF.clipperClean);
|
||||
cleanClipperTree(child.m_Childs);
|
||||
});
|
||||
}
|
||||
|
||||
return tree;
|
||||
};
|
||||
|
||||
function filter(array, output, fn) {
|
||||
array.forEach(function(poly) {
|
||||
for (let poly of array) {
|
||||
poly = fn(poly);
|
||||
if (poly) {
|
||||
if (Array.isArray(poly)) {
|
||||
|
|
@ -140,7 +141,7 @@
|
|||
output.push(poly);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
|
@ -479,11 +480,11 @@
|
|||
|
||||
// cause inner / outer polys to be reversed from each other
|
||||
alignWindings(polys);
|
||||
polys.forEach(function(poly) {
|
||||
for (let poly of polys) {
|
||||
if (poly.inner) {
|
||||
setWinding(poly.inner, !poly.isClockwise());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let orig = polys,
|
||||
count = numOrDefault(opts.count, 1),
|
||||
|
|
@ -501,13 +502,13 @@
|
|||
zed = opts.z || 0;
|
||||
|
||||
// setup offset
|
||||
polys.forEach(function(poly) {
|
||||
for (let poly of polys) {
|
||||
// convert to clipper format
|
||||
poly = poly.toClipper();
|
||||
if (clean) poly = ClipperLib.Clipper.CleanPolygons(poly, CONF.clipperClean);
|
||||
if (simple) poly = ClipperLib.Clipper.SimplifyPolygons(poly, fill);
|
||||
coff.AddPaths(poly, join, type);
|
||||
});
|
||||
}
|
||||
// perform offset
|
||||
coff.Execute(ctre, offs * CONF.clipper);
|
||||
// convert back from clipper output format
|
||||
|
|
@ -619,7 +620,9 @@
|
|||
);
|
||||
|
||||
// compute union of top boundaries
|
||||
while (i < polys.length) bounds.merge(polys[i++].bounds);
|
||||
while (i < polys.length) {
|
||||
bounds.merge(polys[i++].bounds);
|
||||
}
|
||||
|
||||
// ray stepping is an axis from the line perpendicular to the ray
|
||||
let rayint = output || [],
|
||||
|
|
@ -664,7 +667,7 @@
|
|||
lines = [];
|
||||
|
||||
if (clip.Execute(ctyp.ctIntersection, ctre, cfil.pftNonZero, cfil.pftEvenOdd)) {
|
||||
ctre.m_AllPolys.forEach(function(poly) {
|
||||
for (let poly of ctre.m_AllPolys) {
|
||||
if (minlen || maxlen) {
|
||||
let plen = clib.JS.PerimeterOfPath(poly.m_polygon, false, 1);
|
||||
if (minlen && plen < minlen) return;
|
||||
|
|
@ -674,20 +677,20 @@
|
|||
let p2 = BASE.pointFromClipper(poly.m_polygon[1], zpos);
|
||||
let od = rayint.origin.distToLineNew(p1,p2) / spacing;
|
||||
lines.push([p1, p2, od]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
lines.sort(function(a,b) {
|
||||
return a[2] - b[2];
|
||||
})
|
||||
|
||||
lines.forEach(function(line) {
|
||||
for (let line of lines) {
|
||||
let dist = Math.round(line[2]);
|
||||
line[0].index = dist;
|
||||
line[1].index = dist;
|
||||
rayint.push(line[0]);
|
||||
rayint.push(line[1]);
|
||||
})
|
||||
}
|
||||
|
||||
return rayint;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -867,11 +867,11 @@
|
|||
target.newline();
|
||||
|
||||
// prepare top infill structure
|
||||
tops.forEach(function(top) {
|
||||
for (let top of tops) {
|
||||
top.fill_sparse = top.fill_sparse || [];
|
||||
polys.appendAll(top.fill_off);
|
||||
polys.appendAll(top.solids);
|
||||
});
|
||||
}
|
||||
|
||||
// update fill fingerprint for this slice
|
||||
slice._fill_finger = POLY.fingerprint(polys);
|
||||
|
|
@ -904,20 +904,20 @@
|
|||
|
||||
// solid fill areas
|
||||
if (solids.length) {
|
||||
tops.forEach(top => {
|
||||
for (let top of tops) {
|
||||
if (!top.fill_off) return;
|
||||
let masks = top.fill_off.slice();
|
||||
if (top.solids) {
|
||||
masks = POLY.subtract(masks, top.solids, [], null, slice.z);
|
||||
}
|
||||
let angl = process.sliceFillAngle * ((slice.index % 2) + 1);
|
||||
solids.forEach(solid => {
|
||||
for (let solid of solids) {
|
||||
let inter = [],
|
||||
fillable = [];
|
||||
masks.forEach(mask => {
|
||||
for (let mask of masks) {
|
||||
let p = solid.mask(mask);
|
||||
if (p && p.length) inter.appendAll(p);
|
||||
});
|
||||
}
|
||||
// offset fill area to accommodate trace
|
||||
if (inter.length) {
|
||||
POLY.expand(inter, -options.lineWidth/2, slice.z, fillable);
|
||||
|
|
@ -925,18 +925,18 @@
|
|||
// fill intersected areas
|
||||
if (inter.length) {
|
||||
slice.isSparseFill = true;
|
||||
inter.forEach(p => {
|
||||
for (let p of inter) {
|
||||
p.forEachSegment((p1, p2) => {
|
||||
top.fill_lines.push(p1, p2);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
if (fillable.length) {
|
||||
let lines = POLY.fillArea(fillable, angl, options.lineWidth);
|
||||
top.fill_lines.appendAll(lines);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if only solids were added and no lines to clip
|
||||
|
|
@ -954,15 +954,15 @@
|
|||
clip.AddPaths(POLY.toClipper(polys), ptyp.ptClip, true);
|
||||
|
||||
if (clip.Execute(ctyp.ctIntersection, ctre, cfil.pftNonZero, cfil.pftEvenOdd)) {
|
||||
ctre.m_AllPolys.forEach(function(node) {
|
||||
for (let node of ctre.m_AllPolys) {
|
||||
poly = POLY.fromClipperNode(node, slice.z);
|
||||
tops.forEach(function(top) {
|
||||
for (let top of tops) {
|
||||
// use only polygons inside this top
|
||||
if (poly.isInside(top.poly)) {
|
||||
top.fill_sparse.push(poly);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -1044,15 +1044,15 @@
|
|||
inner = isSLA ? slice.topPolys() : slice.topFillOff();
|
||||
|
||||
// trim each solid to the inner bounds
|
||||
unioned.forEach(function(p) {
|
||||
for (let p of unioned) {
|
||||
p.setZ(slice.z);
|
||||
inner.forEach(function(i) {
|
||||
for (let i of inner) {
|
||||
let masks = p.mask(i);
|
||||
if (masks && masks.length > 0) {
|
||||
trims.appendAll(masks);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// clear old solids and make array for new
|
||||
tops.forEach(top => { top.solids = [] });
|
||||
|
|
@ -1061,20 +1061,20 @@
|
|||
slice.solids = solids = trims;
|
||||
|
||||
// parent each solid polygon inside the smallest bounding top
|
||||
solids.forEach(function(solid) {
|
||||
tops.forEach(function(top) {
|
||||
for (let solid of solids) {
|
||||
for (let top of tops) {
|
||||
if (top.poly.overlaps(solid)) {
|
||||
if (!solid.parent || solid.parent.area() > top.poly.area()) {
|
||||
if (solid.areaDeep() < minarea) {
|
||||
// console.log({i:slice.index,cull_solid:solid,area:solid.areaDeep()});
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
solid.parent = top.poly;
|
||||
top.solids.push(solid);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// for SLA to bypass line infill
|
||||
if (isSLA) {
|
||||
|
|
@ -1082,16 +1082,16 @@
|
|||
}
|
||||
|
||||
// create empty filled line array for each top
|
||||
tops.forEach(function(top) {
|
||||
for (let top of tops) {
|
||||
// synth belt anchor tops don't want fill
|
||||
if (!top.fill_lines) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
const tofill = [];
|
||||
const angfill = [];
|
||||
const newfill = top.fill_lines = [];
|
||||
// determine fill orientation from top
|
||||
solids.forEach(function(solid) {
|
||||
for (let solid of solids) {
|
||||
if (solid.parent === top.poly) {
|
||||
if (solid.fillang) {
|
||||
angfill.push(solid);
|
||||
|
|
@ -1099,20 +1099,20 @@
|
|||
tofill.push(solid);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (tofill.length > 0) {
|
||||
doFillArea(fillQ, tofill, angle, spacing, newfill);
|
||||
top.fill_lines_norm = {angle:angle,spacing:spacing};
|
||||
}
|
||||
if (angfill.length > 0) {
|
||||
top.fill_lines_ang = {spacing:spacing,list:[],poly:[]};
|
||||
angfill.forEach(function(af) {
|
||||
for (let af of angfill) {
|
||||
doFillArea(fillQ, [af], af.fillang.angle + 45, spacing, newfill);
|
||||
top.fill_lines_ang.list.push(af.fillang.angle + 45);
|
||||
top.fill_lines_ang.poly.push(af.clone());
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue