1.0.1 • Published 4 years ago

@eliasku/binpack v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

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:

  1. Best Area Fit
  2. Contact Point
  3. Bottom Left
  4. Best Long Side Fit
  5. Best Short Side Fit
1.0.1

4 years ago

1.0.0

4 years ago