pub struct ShelfAllocator { /* private fields */ }Expand description
Bin-packing shelf allocator for a texture atlas.
Allocates rectangular regions from a fixed-size atlas using the shelf (skyline) algorithm. Shelves are created lazily as needed.
Implementations§
Source§impl ShelfAllocator
impl ShelfAllocator
Sourcepub fn new(width: u32, height: u32) -> Self
pub fn new(width: u32, height: u32) -> Self
Create a new shelf allocator for an atlas of the given dimensions.
Sourcepub fn allocation_count(&self) -> u32
pub fn allocation_count(&self) -> u32
Number of live allocations.
Sourcepub fn allocate(&mut self, width: u32, height: u32) -> Option<AtlasRegion>
pub fn allocate(&mut self, width: u32, height: u32) -> Option<AtlasRegion>
Allocate a region of width x height pixels.
Returns None if the atlas is full.
Sourcepub fn deallocate(&mut self, region: &AtlasRegion)
pub fn deallocate(&mut self, region: &AtlasRegion)
Deallocate a previously allocated region.
The region is returned to its shelf for reuse.
Sourcepub fn shelf_count(&self) -> usize
pub fn shelf_count(&self) -> usize
Total number of shelves created.
Sourcepub fn utilisation_percent(&self) -> u32
pub fn utilisation_percent(&self) -> u32
Fraction of atlas height used, as a percentage (0-100).