maxrects-packer / MaxRectsPacker
Class: MaxRectsPacker<T>
Defined in: maxrects-packer.ts:26
Type Parameters
T
T extends IRectangleInput = IRectangleInput
Constructors
Constructor
new MaxRectsPacker<
T>(width?,height?,padding?,options?):MaxRectsPacker<T>
Defined in: maxrects-packer.ts:54
Creates an instance of MaxRectsPacker.
Parameters
width?
number = EDGE_MAX_VALUE
width of the output atlas (default is 4096)
height?
number = EDGE_MAX_VALUE
height of the output atlas (default is 4096)
padding?
number = 0
padding between glyphs/images (omitted or undefined defaults to 0); rejects NaN and infinities, while other JavaScript values retain their coercion behaviour
options?
IOption = {}
(Optional) packing options
Returns
MaxRectsPacker<T>
Properties
bins
bins:
Bin<T>[]
Defined in: maxrects-packer.ts:30
The Bin array added to the packer
height
height:
number=EDGE_MAX_VALUE
Defined in: maxrects-packer.ts:56
height of the output atlas (default is 4096)
options
options:
IOption
Defined in: maxrects-packer.ts:35
Options for MaxRect Packer, see IOption for the full list and defaults.
padding
padding:
number=0
Defined in: maxrects-packer.ts:57
padding between glyphs/images (omitted or undefined defaults to 0); rejects NaN and infinities, while other JavaScript values retain their coercion behaviour
width
width:
number=EDGE_MAX_VALUE
Defined in: maxrects-packer.ts:55
width of the output atlas (default is 4096)
Accessors
currentBinIndex
Get Signature
get currentBinIndex():
number
Defined in: maxrects-packer.ts:412
Return current functioning bin index, perior to this wont accept any new elements
Returns
number
dirty
Get Signature
get dirty():
boolean
Defined in: maxrects-packer.ts:419
Returns dirty status of all child bins
Returns
boolean
rects
Get Signature
get rects():
T[]
Defined in: maxrects-packer.ts:426
Return all rectangles in this packer
Returns
T[]
Methods
add()
Call Signature
add(
width,height,data):T
Defined in: maxrects-packer.ts:84
Add a bin/rectangle object with data to packer
Parameters
width
number
width of the input bin/rectangle
height
number
height of the input bin/rectangle
data
any
custom data object; with tag: true and exclusiveTag: true the packer reads data.tag to label a bin it has to open, so only an object can carry a tag. undefined is treated as untagged data rather than rejected: the rect is offered to the existing bins first, and a bin opened for it stays untagged — what the single-argument form does for a rect that carries no data Supplied data is preserved as-is, including null; omitting it at runtime retains the default {}.
Returns
T
Call Signature
add(
rect):T
Defined in: maxrects-packer.ts:94
Add a bin/rectangle object extends IRectangle to packer
With tag: true, a new bin is labelled only in exclusive mode. Non-exclusive bins may hold several tags: read each rect's data.tag or tag, rather than expecting an automatic bin.tag. Explicit or loaded bin labels are preserved.
Parameters
rect
T
the rect object add to the packer bin
Returns
T
addArray()
addArray(
input):void
Defined in: maxrects-packer.ts:175
Add an Array of bins/rectangles to the packer.
Javascript: Any object has property: { width, height, ... } is accepted.
Typescript: object shall extends MaxrectsPacker.IRectangle.
note: object has hash property will have more stable packing result
Non-exclusive tag groups can share a bin, so newly opened bins have no automatic tag label.
The input array keeps its order; sorting uses a copy while placement still mutates its rects.
Parameters
input
readonly T[]
Array of bin/rectangles, including readonly arrays
Returns
void
load()
load(
bins):void
Defined in: maxrects-packer.ts:318
Load bins to the packer: each one replaces the bin at its index, and existing bins past the loaded array are kept. A saved bin too large for this packer is restored as an OversizedElementBin placeholder at its index, keeping its options, tag, maxWidth/maxHeight and free space. Falsy labels remain metadata but act as untagged in exclusive placement comparisons.
Parameters
bins
IBin[]
MaxRectsBin objects
Returns
void
next()
next():
number
Defined in: maxrects-packer.ts:304
Stop adding new elements to the current bin.
note: After calling next() all elements will no longer added to previous bins.
Returns
number
The index the next bin will take
repack()
repack(
quick?):void
Defined in: maxrects-packer.ts:279
Repack all elements inside bins. A full repack rebuilds library-owned bins and does not migrate their tag, data or custom fields. Keep durable business data on the rects, which are reused.
Parameters
quick?
boolean = true
quick repack only dirty bins (default is true)
Returns
void
reset()
reset():
void
Defined in: maxrects-packer.ts:268
Reset entire packer to initial states, keep settings
Returns
void
save()
save():
IBin[]
Defined in: maxrects-packer.ts:361
Output current free space, with empty rect arrays and shallow copies of each bin's options. Rect payloads and arbitrary bin data are outside this snapshot.
Returns
IBin[]