This commit is contained in:
Andras Schmelczer 2026-09-11 16:58:56 +01:00
commit 9689bfcc18
23 changed files with 1815 additions and 955 deletions

View file

@ -54,25 +54,18 @@ export function readyOffcutInstructions(piece: FlooringPiece): string {
return `Use offcut; no new cut. Required factory short ends: ${ends}.`;
}
/** Batch identical cuts without losing any placement codes or changing factory-edge orientation. */
export function groupFlooringCuts(plan: FlooringPlan): FlooringPiece[][] {
const groups = new Map<string, FlooringPiece[]>();
const precise = (value: number) => Math.round(value * 1000);
for (const piece of flooringCuts(plan)) {
const key = JSON.stringify([
piece.roomId,
precise(piece.length),
precise(piece.width),
piece.shaped,
piece.cut,
piece.factoryLeft,
piece.factoryRight,
piece.ripEdge,
piece.shaped ? piece.template.map((point) => [precise(point.x), precise(point.y)]) : null,
]);
const group = groups.get(key);
/** Keep every cut from a purchased board together, in allocation order across rooms. */
function groupByStock<T extends { stockId: string }>(pieces: T[], stocks: { id: string }[]): T[][] {
const groups = new Map<string, T[]>(stocks.map((stock) => [stock.id, []]));
for (const piece of pieces) {
const group = groups.get(piece.stockId);
if (group) group.push(piece);
else groups.set(key, [piece]);
else groups.set(piece.stockId, [piece]);
}
return [...groups.values()];
return [...groups.values()].filter((group) => group.length > 0);
}
export const groupFlooringCuts = (plan: FlooringPlan) =>
groupByStock(flooringCuts(plan), plan.stocks);
export const groupSkirtingCuts = (plan: SkirtingPlan) =>
groupByStock(skirtingCuts(plan), plan.stocks);