pub struct Packer<T> { /* private fields */ }Expand description
A packer for items of type Item<T>.
Implementations§
Source§impl<T> Packer<T>
impl<T> Packer<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a packer with an initial capacity to prevent collection resizing.
Sourcepub fn with_items<I: IntoIterator<Item = Item<T>>>(items: I) -> Self
pub fn with_items<I: IntoIterator<Item = Item<T>>>(items: I) -> Self
Create a packer initialized with the collection of items.
Source§impl<T: Clone> Packer<T>
impl<T: Clone> Packer<T>
pub fn clear(&mut self) -> &mut Self
pub fn push(&mut self, item: Item<T>) -> &mut Self
pub fn extend<I: IntoIterator<Item = Item<T>>>(&mut self, items: I) -> &mut Self
Sourcepub fn pack(
&mut self,
into_rect: Rect,
) -> Result<Vec<PackedItem<T>>, Vec<PackedItem<T>>>
pub fn pack( &mut self, into_rect: Rect, ) -> Result<Vec<PackedItem<T>>, Vec<PackedItem<T>>>
Attempt to pack all the items into into_rect. The returned Vec<(Rect, T)>
will contain positions for all packed items on success, or just the items
the packer was able to successfully pack before failing.
This function uses some internal intermediary collections, which is why
it is mutable, so it cannot be called but it is valid to call it multiple times with different
into_rect values.
If you want to attempt to pack the same item list into several different
into_rect, it is valid to call this function multiple times on the same
Packer, and it will re-use its intermediary data structures.
Sourcepub fn pack_into_po2(&mut self, max_size: usize) -> Result<PackedItems<T>, ()>
pub fn pack_into_po2(&mut self, max_size: usize) -> Result<PackedItems<T>, ()>
Attempts to pack the supplied items into the smallest power of 2 container
it possibly can while not exceeding the provided max_size.
On success, returns the size of the container (a power of 2) and the packed items.