Skip to content

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.

new ShelfPacker(width, height, padding?): ShelfPacker

A page of width × height pixels, with padding pixels kept around each item.

number

The page’s width, pixels.

number

The page’s height, pixels.

number

Pixels kept free around each item (no bleeding when sampled).

ShelfPacker

readonly width: number

The page’s width, pixels.


readonly height: number

The page’s height, pixels.


readonly padding: number

Pixels kept free around each item (no bleeding when sampled).

get fill(): number

Share of the page’s height used by shelves.

number

alloc(w, h): Placed | null

A place for a w × h item (padding added around it), or null if the page is full.

number

number

Placed | null


release(r): void

Gives a rectangle from alloc back.

Rect

void


reset(): void

Empties the page.

void