A carpenter has a list of 60 rectangles and a stack of 2800 × 2070 mm boards. "How many boards do I buy?" sounds like textbook bin packing, until you add the constraints of a real saw. The board optimiser of SyntaxFlow is a plain JavaScript file with no DOM and no dependencies. Here is what is in it and why.
The constraint that defines the problem: guillotine cuts
A beam saw or a sliding table saw cannot cut a hole in the middle of a board. Every cut runs from one edge of the piece on the saw to the opposite edge. A layout that respects this is called guillotine . A pinwheel arrangement (four rectangles around a central one) can be denser on paper and cannot be cut with a saw at all.
So the optimiser produces only layouts a saw can cut. There is a separate mode for CNC routers, which cut round each part; more on it at the end.
Kerf and trim, with one trick
The blade removes material: the kerf, typically 3 to 4 mm. Factory edges are rough, so the sheet loses a trim strip on its edges.…