1.0.2 • Published 4 years ago

guillotine-packer v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

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
PropertyDefaultDescription
binHeightundefinedrequired Height of the bin we will be packing the items into
binWidthundefinedrequired Width of the bin we will be packing the items into
itemsundefinedrequired 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
OptionDefaultDescription
kerfSize0The size of the blade kerf to account for when splitting rectanges
sortStrategyundefinedSortStrategy to use. Undefined will try all strategies and pick which performs the best.
splitStrategyundefinedSplitStrategy to use. Undefined will try all strategies and pick which performs the best.
selectionStrategyundefinedSelectionStrategy to use. Undefined will try all strategies and pick which performs the best.
allowRotationtrueWhether items may be rotated. If true, items will be rotated if doing so maximizes the offcut size.

:beers: