ShelfPacker
Shelf packing: rows (“shelves”) of the height of their first item, filled left to right. Freed rectangles go to a free list and are reused by items that fit them without wasting more than half. Pure: tested in Node.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ShelfPacker(
width,height,padding?):ShelfPacker
A page of width × height pixels, with padding pixels kept around each item.
Parameters
Section titled “Parameters”number
The page’s width, pixels.
height
Section titled “height”number
The page’s height, pixels.
padding?
Section titled “padding?”number
Pixels kept free around each item (no bleeding when sampled).
Returns
Section titled “Returns”ShelfPacker
Properties
Section titled “Properties”
readonlywidth:number
The page’s width, pixels.
height
Section titled “height”
readonlyheight:number
The page’s height, pixels.
padding
Section titled “padding”
readonlypadding:number
Pixels kept free around each item (no bleeding when sampled).
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get fill():
number
Share of the page’s height used by shelves.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”alloc()
Section titled “alloc()”alloc(
w,h):Placed|null
A place for a w × h item (padding added around it), or null if the page is full.
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”Placed | null
release()
Section titled “release()”release(
r):void
Gives a rectangle from alloc back.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
reset()
Section titled “reset()”reset():
void
Empties the page.
Returns
Section titled “Returns”void