order shells with inner priority for better finish, consistency

This commit is contained in:
Stewart Allen 2017-12-14 23:05:27 -05:00
commit cddb2d1747

View file

@ -660,26 +660,32 @@ var gs_kiri_print = exports;
*/ */
function outputOrderClosest(array, fn, fnp) { function outputOrderClosest(array, fn, fnp) {
if (array.length === 1) { if (array.length === 1) {
return fn(fnp ? fnp(array[0]) : array[0]); return fn(array[0]);
} }
array = array.slice(); array = array.slice();
var closest, find, next, poly; var closest, find, next, order, poly, lastDepth = 0;
for (;;) { for (;;) {
order = [];
closest = null; closest = null;
for (i=0; i<array.length; i++) { for (i=0; i<array.length; i++) {
next = array[i]; next = array[i];
if (!next) continue; if (!next) continue;
poly = fnp ? fnp(next) : next; poly = fnp ? fnp(next) : next;
find = poly.findClosestPointTo(startPoint); find = poly.findClosestPointTo(startPoint);
if (!closest || find.distance < closest.distance) { order.push({
closest = find; i: i,
closest.i = i; n: next,
closest.next = next; d: find.distance - (poly.depth * thinWall),
} });
} }
if (!closest) return; if (order.length === 0) {
array[closest.i] = null; return;
fn(closest.next); }
order.sort(function(a,b) {
return a.d - b.d;
});
array[order[0].i] = null;
fn(order[0].n);
} }
} }