@eliasku/binpack
v1.0.1
Published
This library based on awesome [RectangleBinPack](https://github.com/juj/RectangleBinPack) work and paper.
Downloads
4
Readme
Bin Packing
This library based on awesome RectangleBinPack work and paper.
You pass your Rectangles for input. You got packed pages with placed Rectangles.
Install
npm i @eliasku/binpack
or
yarn add @eliasku/binpack
Example
import { pack } from '@eliasku/binpack';
// define input rects
const rects = [
{ w: 10, h: 10 },
{ w: 20, h: 20, padding: 1 },
{ w: 30, h: 40, padding: 8, data: 'MyUserData' },
];
const result = pack(rects, {
maxWidth: 2048,
maxHeight: 2048,
method: 0, // by default
rotate: true, // allow rotation, true by default
});
for (const page of result.pages) {
console.log(page.rects);
}
Algorithm
Simple MaxRects
with heuristics:
- Best Area Fit
- Contact Point
- Bottom Left
- Best Long Side Fit
- Best Short Side Fit