Boxpack—Bin packing algorithm!
Bin packing algorithm!
Example
var bin = ; var boxes = bin; documentinnerHTML = boxes;
Data structures
{width: {Number}, height: {Number}}
{Rect} Defines rectangles that we want to pack in a bin.
{x: {Number}, y: {Number}, width: {Number}, height: {Number}}
{Box} Defines where a rectangle was packed in a bin.
Bin methods
var bin = boxpack({Object} options)
Creates a new bin for packing rects into.
var result = bin.pack({width: 50, height: 100})
result
will return false
if there was no room left to pack the Rect
.
Otherwise it will return Box
Weighting algorithms
boxpack.algo.dist
Sorts boxes based on their distance from (0, 0)
boxpack.algo.top
Sorts boxes based on their distance from the X-axis
boxpack.algo.left
Sorts boxes based on their distance from the Y-axis
Helper functions
boxpack.rectFit({Rect}, {Box}) -> {Boolean}
boxpack.boxFit({Box}, {Box}) -> {Boolean}
boxpack.intersect({Box}, {Box}) -> {Boolean}
boxpack.divideX({Box}, {Number}) -> {Array {Box}}
boxpack.divideY({Box}, {Number}) -> {Array {Box}}
boxpack.subtract({Box}, {Box}) -> {Array {Box}}
License
MIT