Skip to main content

MaxRectsBin

Struct MaxRectsBin 

Source
pub struct MaxRectsBin { /* private fields */ }
Expand description

A two-dimensional rectangle bin packer using the MAXRECTS data structure and different bin packing algorithms that use this structure.

It can be used to pack multiple rectangles of arbitrary size into a “bin” of rectangular shape with the goal to add as many rectangles as possible into the bin.

Implementations§

Source§

impl MaxRectsBin

Source

pub fn new(width: i32, height: i32) -> Self

Creates an empty bin of the given size.

Minimum width and height of a bin is 1.

Source

pub fn with_capacity(width: i32, height: i32, capacity: usize) -> Self

Creates an empty bin of the given size and reserves space for at least capacity number of mapped rectangle to improve performance.

Minimum width and height of a bin is 1.

Source

pub fn default_rule(&self) -> Heuristic

Returns the default Heuristic rule, which is used by the BinPacker trait’s insert and insert_list methods.

Source

pub fn set_default_rule(&mut self, rule: Heuristic)

Can be used to override the default Heuristic rule, which is used by the BinPacker trait’s insert and insert_list methods.

Source

pub fn insert(&mut self, dim: &Dimension, rule: Heuristic) -> Option<Rectangle>

Inserts a single Dimension object into the bin.

dim refers to the object to be packed into the bin.

rule specifies the rectangle placement rule to use for the packing operation.

Returns a copy of the packed Rectangle if the object was inserted successful, or None otherwise.

Source

pub fn insert_list( &mut self, nodes: &[Dimension], rule: Heuristic, ) -> (Vec<Rectangle>, Vec<Dimension>)

Attempts to insert the given list of Dimension objects into the bin.

nodes specifies the list of Dimension objects to insert. All successfully inserted objects will be removed from the list in the process.

rule specifies the rectangle placement rule to use for the packing operations.

Returns a list with all successfully inserted Rectangle objects.

This method performs slower than insert, but may result in more tightly packed bins for greater numbers of dimension objects.

Trait Implementations§

Source§

impl BinPacker for MaxRectsBin

Source§

fn width(&self) -> i32

Returns the width of the bin.
Source§

fn height(&self) -> i32

Returns the height of the bin.
Source§

fn clear_with(&mut self, capacity: usize)

Just as clear, this method removes all mapped rectangle from the bin, but also sets initial capacity of the internal rectangle lists to improve performance.
Source§

fn grow(&mut self, dw: u32, dh: u32)

Increases dimension of the bin by the specified values. Read more
Source§

fn shrink(&mut self, binary: bool)

Attempts to shrink the bin as much as possible. Read more
Source§

fn insert(&mut self, dim: &Dimension) -> Option<Rectangle>

Inserts a single Dimension object into the bin. Read more
Source§

fn insert_list( &mut self, nodes: &[Dimension], ) -> (Vec<Rectangle>, Vec<Dimension>)

Attempts to insert the given list of Dimension objects into the bin. Read more
Source§

fn occupancy(&self) -> f32

Computes the ratio of used surface area to the total bin area and returns it as a normalized value in the range [0.0, 1.0].
Source§

fn as_slice(&self) -> &[Rectangle]

Extracts a slice containing the entire list of mapped rectangles. Read more
Source§

fn is_empty(&self) -> bool

Returns true if the list of mapped rectangles contains no entries.
Source§

fn len(&self) -> usize

Returns the number of mapped rectangles in this Bin.
Source§

fn iter(&self) -> Iter<'_, Rectangle>

Returns an iterator over the list of mapped rectangles.
Source§

fn find_by_id(&self, id: isize) -> Option<Rectangle>

Returns the first mapped rectangle with the specified identifier, if available. Returns None otherwise.
Source§

fn visualize(&self) -> String

Returns a visual representation of the bin as ascii graphics String. Read more
Source§

fn clear(&mut self)

Removes all mapped rectangles from the bin.
Source§

impl Clone for MaxRectsBin

Source§

fn clone(&self) -> MaxRectsBin

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MaxRectsBin

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for MaxRectsBin

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Idx> Index<Idx> for MaxRectsBin
where Idx: SliceIndex<[Rectangle]>,

Source§

type Output = <Idx as SliceIndex<[Rectangle]>>::Output

The returned type after indexing.
Source§

fn index(&self, index: Idx) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl PartialEq for MaxRectsBin

Source§

fn eq(&self, other: &MaxRectsBin) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for MaxRectsBin

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.