add array grouping and walk order. add new thin fill output method
This commit is contained in:
parent
1108940a54
commit
5e6c4b91aa
4 changed files with 81 additions and 2 deletions
|
|
@ -428,6 +428,39 @@
|
|||
return diff;
|
||||
}
|
||||
|
||||
// order array of elements using next closest element comparator
|
||||
// used for things like next-closest point walks (fdm thin fill)
|
||||
// in future, replace poly2poly and similar with this
|
||||
function orderClosest(array, fn, from) {
|
||||
if (!array.length) {
|
||||
return array;
|
||||
}
|
||||
let out = new Array(array.length);
|
||||
let outi = 0;
|
||||
let root = 0;
|
||||
if (!from) {
|
||||
from = array[root++];
|
||||
out[outi++] = from;
|
||||
}
|
||||
for (;;) {
|
||||
let best, best_i, best_dist = Infinity;
|
||||
for (let i=root; i<array.length; i++) {
|
||||
let el = array[i];
|
||||
if (!el) continue;
|
||||
let dist = fn(from, el);
|
||||
if (dist < best_dist) {
|
||||
best_dist = dist;
|
||||
best_i = i;
|
||||
best = el;
|
||||
}
|
||||
}
|
||||
if (!best) break;
|
||||
array[best_i] = undefined;
|
||||
from = out[outi++] = best;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** ******************************************************************
|
||||
* Connect to base
|
||||
******************************************************************* */
|
||||
|
|
@ -530,6 +563,7 @@
|
|||
intersect,
|
||||
determinant,
|
||||
numOrDefault,
|
||||
orderClosest,
|
||||
zInPlane,
|
||||
comma: (v) => {
|
||||
if (!v) return v;
|
||||
|
|
|
|||
Loading…
Reference in a new issue