guillotine-packer
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
]
})
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:
Modules
"guillotine-packer"
"guillotine-packer":
Packer
Parameters
__namedParameters: { binHeight: number ; binWidth: number ; items: Item [] }
binHeight: number
binWidth: number
items: Item []
allowRotation: boolean
kerfSize: number
Returns null | { bin: number ; height: number ; item: any ; width: number ; x: number ; y: number } [] []
"pack-strategy"
"pack-strategy":
PackStrategyOptions
Type declaration
allowRotation: boolean
binHeight: number
binWidth: number
items: Item []
kerfSize: number
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
Parameters
__namedParameters: { allowRotation: boolean ; binHeight: number ; binWidth: number ; items: Item [] ; kerfSize: number ; selectionStrategy: SelectionStrategy ; sortOrder: SortDirection ; sortStrategy: SortStrategy ; splitStrategy: SplitStrategy }
allowRotation: boolean
binHeight: number
binWidth: number
items: Item []
kerfSize: number
Returns { packedItems: { bin: number ; height: number ; item: any ; width: number ; x: number ; y: number } [] [] ; selectionStrategy: SelectionStrategy ; sortOrder: SortDirection ; sortStrategy: SortStrategy ; splitStrategy: SplitStrategy }
packedItems: { bin: number ; height: number ; item: any ; width: number ; x: number ; y: number } [] []
"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
Parameters
Returns SelectionImplementation
"sort-strategies"
"sort-strategies":
SortDirection
SortDirection:
SortStrategy
SortStrategy:
GetSortImplementation
Parameters
Returns Sorter
"split-strategies"
"split-strategies":
SplitStrategy
SplitStrategy:
LongAxisSplit
LongAxisSplit:
LongLeftoverAxisSplit
LongLeftoverAxisSplit:
ShortAxisSplit
ShortAxisSplit:
ShortLeftoverAxisSplit
ShortLeftoverAxisSplit:
GetSplitImplementation
GetSplitImplementation( strategy: SplitStrategy , kerfSize: number ) : Splitter
Parameters
Returns Splitter
"types"
"types":
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