Options
All
  • Public
  • Public/Protected
  • All
Menu

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.

:beers:

Index

Modules

"guillotine-packer"

"guillotine-packer":

Packer

"pack-strategy"

"pack-strategy":

PackStrategyOptions

PackStrategyOptions: { allowRotation: boolean; binHeight: number; binWidth: number; items: Item[]; kerfSize: number; selectionStrategy: SelectionStrategy; sortOrder: SortDirection; sortStrategy: SortStrategy; splitStrategy: SplitStrategy }

Type declaration

PackedItem

PackedItem: { bin: number; height: number; item: any; width: number; x: number; y: number }

Type declaration

  • bin: number
  • height: number
  • item: any
  • width: number
  • x: number
  • y: number

PackStrategy

"selection-strategies"

"selection-strategies":

SelectionStrategy

SelectionStrategy:

BEST_AREA_FIT

BEST_AREA_FIT:

BEST_LONG_SIDE_FIT

BEST_LONG_SIDE_FIT:

BEST_SHORT_SIDE_FIT

BEST_SHORT_SIDE_FIT:

GetSelectionImplementation

"sort-strategies"

"sort-strategies":

SortDirection

SortDirection:

ASC

ASC:

DESC

DESC:

SortStrategy

SortStrategy:

Area

Area:

Differences

Differences:

LongSide

LongSide:

Perimeter

Perimeter:

Ratio

Ratio:

ShortSide

ShortSide:

GetSortImplementation

"split-strategies"

"split-strategies":

SplitStrategy

SplitStrategy:

LongAxisSplit

LongAxisSplit:

LongLeftoverAxisSplit

LongLeftoverAxisSplit:

ShortAxisSplit

ShortAxisSplit:

ShortLeftoverAxisSplit

ShortLeftoverAxisSplit:

GetSplitImplementation

  • GetSplitImplementation(strategy: SplitStrategy, kerfSize: number): Splitter

"types"

"types":

Item

Item:

height

height: number

width

width: number

Rectangle

Rectangle: { bin: number; height: number; id: string; splitFrom?: undefined | string; width: number; x: number; y: number }

Type declaration

  • bin: number
  • height: number
  • id: string
  • Optional splitFrom?: undefined | string
  • width: number
  • x: number
  • y: number

"util"

"util":

Const cartesian

  • cartesian(a: any[], b?: any[], ...c: any): any[]
  • Parameters

    • a: any[]
    • Optional b: any[]
    • Rest ...c: any

    Returns any[]

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc