more efficient output ordering when using depth first

This commit is contained in:
Stewart Allen 2020-02-06 22:06:13 -05:00
commit ff15e6185c
2 changed files with 11 additions and 10 deletions

View file

@ -853,19 +853,19 @@ var gs_kiri_print = exports;
* to be more like outputOrderClosest() and have the option to account for * to be more like outputOrderClosest() and have the option to account for
* depth in determining distance * depth in determining distance
*/ */
function poly2polyEmit(array, startPoint, emitter) { function poly2polyEmit(array, startPoint, emitter, mark) {
var mindist, dist, found, count = 0; var mindist, dist, found, count = 0, marker = mark || 'delete';
for (;;) { for (;;) {
found = null; found = null;
mindist = Infinity; mindist = Infinity;
array.forEach(function(poly) { array.forEach(function(poly) {
if (poly.delete) return; if (poly[marker]) return;
if (poly.isOpen()) { if (poly.isOpen()) {
const d2f = startPoint.distTo2D(poly.first()); const d2f = startPoint.distTo2D(poly.first());
const d2l = startPoint.distTo2D(poly.first()); const d2l = startPoint.distTo2D(poly.first());
if (d2f > mindist && d2l > mindist) return; if (d2f > mindist && d2l > mindist) return;
if (d2l < mindist && d2l < d2f) { if (d2l < mindist && d2l < d2f) {
poly.reverse(); // poly.reverse();
found = {poly:poly, index:0, point:poly.first()}; found = {poly:poly, index:0, point:poly.first()};
} else if (d2f < mindist) { } else if (d2f < mindist) {
found = {poly:poly, index:0, point:poly.first()}; found = {poly:poly, index:0, point:poly.first()};
@ -881,7 +881,7 @@ var gs_kiri_print = exports;
}); });
}); });
if (found) { if (found) {
found.poly.delete = true; found.poly[marker] = true;
startPoint = emitter(found.poly, found.index, ++count, startPoint) || found.point; startPoint = emitter(found.poly, found.index, ++count, startPoint) || found.point;
} else { } else {
break; break;
@ -889,7 +889,7 @@ var gs_kiri_print = exports;
} }
// undo delete marks // undo delete marks
array.forEach(function(poly) { poly.delete = false }); array.forEach(function(poly) { poly[marker] = false });
return startPoint; return startPoint;
} }
@ -974,9 +974,10 @@ var gs_kiri_print = exports;
poolPoly.mark = true; poolPoly.mark = true;
const polys = poolPoly.pool.slice().append(poolPoly); const polys = poolPoly.pool.slice().append(poolPoly);
startPoint = poly2polyEmit(polys, startPoint, emitter); startPoint = poly2polyEmit(polys, startPoint, emitter);
poolPoly.poolsDown.forEach(function(downPool) { // poolPoly.poolsDown.forEach(function(downPool) {
emitPool(downPool); // emitPool(downPool);
}); // });
poly2polyEmit(poolPoly.poolsDown, startPoint, emitPool, "del_pdown");
}; };
// from the top layer, iterate and descend through all connected pools // from the top layer, iterate and descend through all connected pools

View file

@ -1,7 +1,7 @@
var exports = { var exports = {
COPYRIGHT:"Copyright (C) 2014-2019 Stewart Allen <sa@grid.space> - All Rights Reserved", COPYRIGHT:"Copyright (C) 2014-2019 Stewart Allen <sa@grid.space> - All Rights Reserved",
LICENSE:"See the license.md file included with the source distribution", LICENSE:"See the license.md file included with the source distribution",
VERSION:"1.5.2" VERSION:"1.5.3"
}; };
if (!module) var module = {}; if (!module) var module = {};
module.exports = exports; module.exports = exports;