Skip to content

Latest commit

 

History

History
92 lines (74 loc) · 3.75 KB

README.md

File metadata and controls

92 lines (74 loc) · 3.75 KB

guillotine-packer

styled with prettier Travis Coverage Status semantic-release

What is this?

This is a bin packing implementation based off of this fantastic paper. Originally developed as part of Part Placer for the woodworking community, however it can be used for all sorts of bin packing applications! Guillotine based algorithms translate well for many real-world material use cases, as they nicely balance outputs that can easily performed on machinery with efficient material use.

Getting Started

Install

npm install guillotine-packer

Usage

import { packer } from 'guillotine-packer'

  const result = packer({
    binHeight: 30,
    binWidth: 30,
    items: [
      {
        name: 'test2',
        width: 20,
        height: 20
      } as Item,
      {
        name: 'test',
        width: 20,
        height: 20
      } as Item
    ]
  })

  /* OUTPUT:

  Array [
  Array [
    Object {
      "bin": 1,
      "height": 20,
      "item": Object {
        "name": "test2",
      },
      "width": 20,
      "x": 0,
      "y": 0,
    },
    Object {
      "bin": 1,
      "height": 20,
      "item": Object {
        "name": "test",
      },
      "width": 20,
      "x": 20,
      "y": 0,
    },
  ],
]

  */

Parameters

Inputs
Property Default Description
binHeight undefined required Height of the bin we will be packing the items into
binWidth undefined required Width of the bin we will be packing the items into
items undefined required Array of items. Each item should have a width and height property. Additional properties will be included in the item property of the results
Options
Option Default Description
kerfSize 0 The size of the blade kerf to account for when splitting rectanges
sortStrategy undefined SortStrategy to use. Undefined will try all strategies and pick which performs the best.
splitStrategy undefined SplitStrategy to use. Undefined will try all strategies and pick which performs the best.
selectionStrategy undefined SelectionStrategy to use. Undefined will try all strategies and pick which performs the best.
allowRotation true Whether items may be rotated. If true, items will be rotated if doing so maximizes the offcut size.

🍻