maxrects-packer / MaxRectsBin
Class: MaxRectsBin<T>
Defined in: maxrects-bin.ts:21
Extends
Bin<T>
Type Parameters
T
T extends IRectangleInput = IRectangleInput
Constructors
Constructor
new MaxRectsBin<
T>(maxWidth?,maxHeight?,padding?,options?):MaxRectsBin<T>
Defined in: maxrects-bin.ts:65
Creates an instance of MaxRectsBin.
Parameters
maxWidth?
number = EDGE_MAX_VALUE
width of the bin (default is 4096)
maxHeight?
number = EDGE_MAX_VALUE
height of the bin (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
MaxRectsBin<T>
Overrides
Properties
_dirty
protected_dirty:number=0
Defined in: abstract-bin.ts:31
Inherited from
data?
optionaldata?:any
Defined in: abstract-bin.ts:28
Inherited from
freeRects
freeRects:
Rectangle[] =[]
Defined in: maxrects-bin.ts:24
Overrides
height
height:
number
Defined in: maxrects-bin.ts:23
Overrides
maxHeight
maxHeight:
number=EDGE_MAX_VALUE
Defined in: maxrects-bin.ts:67
height of the bin (default is 4096)
Inherited from
maxWidth
maxWidth:
number=EDGE_MAX_VALUE
Defined in: maxrects-bin.ts:66
width of the bin (default is 4096)
Inherited from
options
options:
IOption
Defined in: maxrects-bin.ts:46
Overrides
padding
padding:
number=0
Defined in: maxrects-bin.ts:68
padding between glyphs/images (omitted or undefined defaults to 0); rejects NaN and infinities, while other JavaScript values retain their coercion behaviour
rects
rects:
T[] =[]
Defined in: maxrects-bin.ts:31
The rects this bin holds, in the order they were placed. This is the packing output rather than an input: the bin keeps its own record of which placements turned their rect beside it, and a consumer that reshapes this array — a splice(), a sort(), an assignment — leaves records that no longer line up, which clone() ignores rather than applying to the wrong rect.
Overrides
tag?
optionaltag?:string
Defined in: abstract-bin.ts:29
Inherited from
width
width:
number
Defined in: maxrects-bin.ts:22
Overrides
Accessors
dirty
Get Signature
get dirty():
boolean
Defined in: abstract-bin.ts:32
Returns
boolean
Inherited from
Methods
add()
Call Signature
add(
rect):T|undefined
Defined in: maxrects-bin.ts:95
Parameters
rect
T
Returns
T | undefined
Overrides
Call Signature
add(
width,height,data):T|undefined
Defined in: maxrects-bin.ts:102
Construct and place a rect with the supplied payload, including null.
Parameters
width
number
width of the rect
height
number
height of the rect
data
any
payload retained as-is; omitting it at runtime keeps the default {}
Returns
T | undefined
Overrides
clone()
clone():
MaxRectsBin<T>
Defined in: maxrects-bin.ts:208
Copy this bin. The copy packs copies of the same rects, so neither bin can reach the other's state: mutating a rect one of them holds, or adding to one bin, leaves the other alone. The rect copies are shallow (Rectangle.Clone), so a payload stored in rect.data is still shared, and a rect class that cannot be copied that way reports it from Rectangle.Clone().
The copy reproduces the source's placements under the bin's current options. The replay is handed each rect in the orientation the source was handed it, which is what makes that work: a rect this bin turned is stored as the footprint it occupies, and the bin records which placements turned theirs, because the state alone cannot say whether the bin turned a rect or the caller handed it over already rotated. When that orientation is no longer one the bin takes — options.allowRotation turned off after the placement, say — the rect falls back to the orientation it is stored in rather than failing the copy.
It throws when the replay cannot place a rect this bin holds in either orientation, which a rect resized after it was placed into something the bin can no longer hold brings about. Reporting it beats handing back a bin that quietly holds fewer rects than the original.
Returns
MaxRectsBin<T>
a bin holding copies of the same rects, with the same options, tag and data — the copies are re-packed under the current options, so the size it grows to and the placements it lands on can differ from the source's when a rect was edited after it was placed, or when the options changed since
Overrides
repack()
repack():
T[] |undefined
Defined in: maxrects-bin.ts:125
Returns
T[] | undefined
Overrides
reset()
reset(
deepReset?,resetOption?):void
Defined in: maxrects-bin.ts:153
Parameters
deepReset?
boolean = false
resetOption?
boolean = false
Returns
void
Overrides
setDirty()
setDirty(
value?):void
Defined in: abstract-bin.ts:38
Set bin dirty status
Parameters
value?
boolean = true
Returns
void