new fill technique

This commit is contained in:
Stewart Allen 2018-02-11 16:18:46 -05:00
commit e19f64c1a2
2 changed files with 60 additions and 19 deletions

View file

@ -621,6 +621,7 @@ var gs_base_polygons = exports;
// store origin as start/affinity point for fill // store origin as start/affinity point for fill
rayint.origin = newPoint(start.x, start.y, start.z); rayint.origin = newPoint(start.x, start.y, start.z);
rayint.mindex = Infinity;
for (i = 0; i < steps; i++) { for (i = 0; i < steps; i++) {
var p1 = newPoint(start.x - raySlope.dx * 1000, start.y - raySlope.dy * 1000, zpos, NOKEY), var p1 = newPoint(start.x - raySlope.dx * 1000, start.y - raySlope.dy * 1000, zpos, NOKEY),
@ -628,7 +629,7 @@ var gs_base_polygons = exports;
// store origin line for distance tests in print // store origin line for distance tests in print
if (i == 0) rayint.oline = [p1,p2]; if (i == 0) rayint.oline = [p1,p2];
lines.push([p1,p2]); lines.push([p1,p2]);
start.x += stepX; start.x += stepX;
start.y += stepY; start.y += stepY;
@ -637,6 +638,8 @@ var gs_base_polygons = exports;
clip.AddPaths(lines, ptyp.ptSubject, false); clip.AddPaths(lines, ptyp.ptSubject, false);
clip.AddPaths(toClipper(polys), ptyp.ptClip, true); clip.AddPaths(toClipper(polys), ptyp.ptClip, true);
lines = [];
if (clip.Execute(ctyp.ctIntersection, ctre, cfil.pftNonZero, cfil.pftEvenOdd)) { if (clip.Execute(ctyp.ctIntersection, ctre, cfil.pftNonZero, cfil.pftEvenOdd)) {
ctre.m_AllPolys.forEach(function(poly) { ctre.m_AllPolys.forEach(function(poly) {
if (minlen || maxlen) { if (minlen || maxlen) {
@ -644,12 +647,28 @@ var gs_base_polygons = exports;
if (minlen && plen < minlen) return; if (minlen && plen < minlen) return;
if (maxlen && plen > maxlen) return; if (maxlen && plen > maxlen) return;
} }
poly.m_polygon.forEach(function(point) { var p1 = newPoint(null,null,zpos,null,poly.m_polygon[0]);
rayint.push(newPoint(null,null,zpos,null,point)); var p2 = newPoint(null,null,zpos,null,poly.m_polygon[1]);
}); var od = Math.round(rayint.origin.distToLine(p1,p2) / spacing);
rayint.mindex = Math.min(rayint.mindex, od);
lines.push([p1, p2, od]);
// poly.m_polygon.forEach(function(point) {
// rayint.push(newPoint(null,null,zpos,null,point));
// });
}); });
} }
lines.sort(function(a,b) {
return a[2] - b[2];
})
lines.forEach(function(line, index) {
line[0].index = line[2];
line[1].index = line[2];
rayint.push(line[0]);
rayint.push(line[1]);
})
return rayint; return rayint;
} }

View file

@ -569,8 +569,12 @@ var gs_kiri_print = exports;
function outputFills(lines, bounds) { function outputFills(lines, bounds) {
var mindist, p1, p2, dist, point, find, list, len, lastout, origin, lastDist2Origin, var mindist, p1, p2, dist, point, find, list, len, lastout, origin, lastDist2Origin,
skip = false, skip = false,
pass = 0; pass = 0,
marked = 0,
lastIndex = null,
nextIndex = lines.mindex;
var time = new Date().getTime();
var scans = 0, sorts = 0;
while (lines) { while (lines) {
list = []; list = [];
mindist = Infinity; mindist = Infinity;
@ -578,11 +582,23 @@ var gs_kiri_print = exports;
// order all points by distance to last point // order all points by distance to last point
for (i=0; i<lines.length; i++) { for (i=0; i<lines.length; i++) {
point = lines[i]; point = lines[i];
if (lastIndex && point.index < lastIndex) continue;
if (nextIndex > lines.mindex && point.index > nextIndex) break;
if (point.del) continue; if (point.del) continue;
dist = origin.distTo2D(point); dist = origin.distTo2D(point);
list.push({i:i, p:point, d:dist}); list.push({i:i, p:point, d:origin.distTo2D(point)});
scans++;
}
// restart near origin if some still unmarked
if (list.length === 0 && marked < lines.length) {
lastIndex = null;
nextIndex = lines.mindex;
continue;
} }
if (list.length > 0) { if (list.length > 0) {
// scans += list.length;
sorts++;
console.log({sorting:list.length, ni:nextIndex, ll:lines.lenght});
list.sort(function(a,b) { return a.d - b.d }); list.sort(function(a,b) { return a.d - b.d });
find = list[0]; find = list[0];
@ -598,23 +614,28 @@ var gs_kiri_print = exports;
dist = startPoint.distTo2D(p1); dist = startPoint.distTo2D(p1);
// find next closest to fill origin on seek // find next closest to fill origin on seek
if (antiBacklash) { // if (antiBacklash) {
var dist2Origin = p1.distToLine(lines.oline[0], lines.oline[1]); // var dist2Origin = p1.distToLine(lines.oline[0], lines.oline[1]);
if (!skip) { // if (!skip) {
if (lastDist2Origin && dist2Origin < lastDist2Origin) { // if (lastDist2Origin && dist2Origin < lastDist2Origin) {
lastDist2Origin = null; // lastDist2Origin = null;
skip = true; // skip = true;
continue; // continue;
} // }
} // }
lastDist2Origin = dist2Origin; // lastDist2Origin = dist2Origin;
} // }
skip = false; // skip = false;
// mark as used (temporary) // mark as used (temporary)
p1.del = true; p1.del = true;
p2.del = true; p2.del = true;
len = p1.distTo2D(p2); len = p1.distTo2D(p2);
marked += 2;
// scan up to next index on next pass
lastIndex = p1.index;
nextIndex = p1.index + 1;
// if dist to new segment is less than thinWall // if dist to new segment is less than thinWall
// and segment length is less than thinWall then // and segment length is less than thinWall then
@ -654,6 +675,7 @@ var gs_kiri_print = exports;
} }
// clear delete marks so we can re-print later // clear delete marks so we can re-print later
if (lines) lines.forEach(function(p) { p.del = false }); if (lines) lines.forEach(function(p) { p.del = false });
console.log({ftime: new Date().getTime() - time, scans:scans, sorts:sorts});
} }
/** /**