Skip to content

Commit

Permalink
fix extra space option
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Apr 25, 2024
1 parent a941856 commit 184726c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions npm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function placeAllParts(
stock: Stock[],
packer: Packer<PartToCut>,
): { layouts: PotentialBoardLayout[]; leftovers: PartToCut[] } {
const extraSpace = new Distance(config.extraSpace).m;
const unplacedParts = new Set(
[...parts].sort(
// Sort by material, thickness, and area to ensure parts of the same
Expand Down Expand Up @@ -138,11 +139,18 @@ function placeAllParts(
continue;
}

const boardRect = new Rectangle(board, 0, 0, board.width, board.length);
const layout: PotentialBoardLayout = {
placements: [],
stock: board,
};
const boardRect = new Rectangle(
board,
0,
0,
board.width - extraSpace,
board.length - extraSpace,
);
console.log({ boardRect, board, extraSpace });

// Fill the bin
const partsToPlace = unplacedPartsArray
Expand Down Expand Up @@ -183,6 +191,8 @@ function minimizeLayoutStock(
stock: Stock[],
packer: Packer<PartToCut>,
): PotentialBoardLayout {
const extraSpace = new Distance(config.extraSpace).m;

// Get alternative stock, smaller areas first.
const altStock = stock
.filter((stock) =>
Expand All @@ -195,8 +205,8 @@ function minimizeLayoutStock(
smallerStock,
0,
0,
smallerStock.width,
smallerStock.length,
smallerStock.width - extraSpace,
smallerStock.length - extraSpace,
);
const rects = [...originalLayout.placements];
const res = packer.pack(bin, rects, getPackerOptions(config));
Expand Down

0 comments on commit 184726c

Please sign in to comment.