This commit is contained in:
parent
7959fe85cc
commit
b9485e4097
32 changed files with 4692 additions and 65 deletions
|
|
@ -350,7 +350,12 @@ interface Packed {
|
|||
}
|
||||
|
||||
/** Best-fit decreasing across all rooms, using one purchased board length. */
|
||||
function pack(source: SkirtingPiece[], stockLength: number, kerf: number): Packed {
|
||||
function pack(
|
||||
source: SkirtingPiece[],
|
||||
stockLength: number,
|
||||
kerf: number,
|
||||
exactTails = false,
|
||||
): Packed {
|
||||
const pieces = source.map((piece) => ({ ...piece }));
|
||||
let pending = [...pieces].sort(
|
||||
(a, b) => b.length - a.length || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0),
|
||||
|
|
@ -360,6 +365,25 @@ function pack(source: SkirtingPiece[], stockLength: number, kerf: number): Packe
|
|||
while (pending.length) {
|
||||
let available = stockLength;
|
||||
const assigned: SkirtingPiece[] = [];
|
||||
if (exactTails && pending.length > 2) {
|
||||
const head = pending[0];
|
||||
const tail = stockLength - consumedLength(head, stockLength, kerf);
|
||||
const options = pending.slice(1, 129).filter((piece) => fits(piece, tail));
|
||||
for (const second of options) {
|
||||
const remaining = tail - consumedLength(second, tail, kerf);
|
||||
const third = options.find(
|
||||
(piece) => piece !== second && Math.abs(piece.length - remaining) <= EPS,
|
||||
);
|
||||
if (!third) continue;
|
||||
pending = [
|
||||
head,
|
||||
second,
|
||||
third,
|
||||
...pending.filter((piece) => piece !== head && piece !== second && piece !== third),
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (const piece of pending) {
|
||||
if (!fits(piece, available)) continue;
|
||||
piece.blankLength = blankLength(piece, available);
|
||||
|
|
@ -525,6 +549,7 @@ export function planSkirting(
|
|||
piece.id = `${prefixes.get(piece.roomId)}${count}`;
|
||||
}
|
||||
candidates.push(pack(source, stockLength, settings.kerf));
|
||||
candidates.push(pack(source, stockLength, settings.kerf, true));
|
||||
};
|
||||
// Compare full-stock, balanced, and offcut-led wall joints.
|
||||
{
|
||||
|
|
@ -540,8 +565,8 @@ export function planSkirting(
|
|||
}
|
||||
candidates.sort(
|
||||
(a, b) =>
|
||||
(Math.abs(a.waste - b.waste) > EPS ? a.waste - b.waste : 0) ||
|
||||
a.cuts - b.cuts ||
|
||||
(Math.abs(a.waste - b.waste) > EPS ? a.waste - b.waste : 0) ||
|
||||
a.stocks.length - b.stocks.length ||
|
||||
a.pieces.length - b.pieces.length,
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue