DoubleSharp
bin-packing
Optimizationcrates.ionpm
bin-packing
bin-packing turns a list of required parts and available material into layouts you can inspect in an application. It covers linear cutting stock, rectangular sheet packing, and boxes placed inside three-dimensional bins. The Rust crate has native Node.js and WebAssembly packages, so the same kinds of problems can run in a backend or a browser tool. Model dimensions, quantities, permitted rotations, and relevant stock constraints before solving. The result describes assignments and waste. For fabrication workflows, separate cut-planning APIs can turn completed one-dimensional or two-dimensional layouts into ordered operations.
From a parts list to a usable layout
Build the problem around the material and process that the application needs to represent.
Describe stock and demand
Choose the one-, two-, or three-dimensional model. Add stock sizes and required part quantities, using one consistent unit for dimensions and cutting allowances.
Encode physical constraints
Set kerf and trim where supported, inventory limits, and rotation permissions. For sheet jobs requiring straight through-cuts, select the guillotine constraint before solving.
Solve and inspect the result
Start with the auto strategy. Read placements, unused material, and unplaced demand before presenting a plan. Review inventory requirements when stock availability is capped.
Plan the cutting operations
For a completed cutting-stock or sheet layout, choose a supported cut-planning preset. A table-saw or panel-saw plan needs a guillotine-compatible sheet layout.
Try a small cutting-stock problem
Install @0xdoublesharp/bin-packing-wasm with your package manager, then use this in an application with a supported bundler. The example asks for two 45-unit parts from 100-unit bars, allowing one unit of kerf between cuts. The function returns a solution object rather than a rendered diagram.
import { solve1d } from '@0xdoublesharp/bin-packing-wasm';
const solution = solve1d(
{
stock: [{ name: 'bar', length: 100, kerf: 1 }],
demands: [{ name: 'rail', length: 45, quantity: 2 }],
},
{ algorithm: 'auto' },
);
console.log(solution.stock_count, solution.total_waste);Packing and cutting answer different questions
A sheet layout tells you where rectangles fit. A cut plan describes how to separate them with a particular tool. Keeping both results matters when a compact layout cannot be produced by the intended saw. The planning APIs report ordered operations and their modeled costs.
For example, plan2dCuts accepts a finished sheet solution and a machine preset. Table-saw and panel-saw presets reject layouts that cannot be separated by guillotine cuts. Set guillotine_required when creating that layout.
Read the result before promising an optimum
The library includes heuristics and restricted exact backends. Auto compares candidate solutions; selecting it does not promise a proven optimum. Inspect the exactness and lower-bound information provided by the selected solver.
Choose the package entry point for your runtime. The WebAssembly bundler entry loads without an explicit initialization call, while raw browser ES modules use the web entry and await init(). The Node.js WebAssembly entry loads synchronously. The native Node.js package is a separate installation.
Explore the other libraries
Browse the DoubleSharp catalog for developer tools and libraries for other application workflows.