order shells with inner priority for better finish, consistency
This commit is contained in:
parent
a0405e51d4
commit
cddb2d1747
1 changed files with 16 additions and 10 deletions
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue