Expand description
A 2-d bit-matrix.
Fields
width: usize
Width of the matrix.
height: usize
Height of the matrix.
Implementations
sourceimpl BitMatrix
impl BitMatrix
sourcepub fn with_dimensions(width: usize, height: usize) -> Self
pub fn with_dimensions(width: usize, height: usize) -> Self
Creates an empty BitMatrix with predefined dimensions.
sourcepub fn from_bits(
width: usize,
height: usize,
data: impl IntoIterator<Item = bool>
) -> Self
pub fn from_bits(
width: usize,
height: usize,
data: impl IntoIterator<Item = bool>
) -> Self
Builds a BitMatrix instance from another collection of bits.
If the data passed in contains more bits than will fit a matrix of the specified height and width, excess data is discarded. If not enough bits are passed in, 0s will be appended until the right size is reached.
sourcepub fn get(&self, x: usize, y: usize) -> Result<bool, BitMatrixError>
pub fn get(&self, x: usize, y: usize) -> Result<bool, BitMatrixError>
Returns the state of a bit at a specific coordinate.
sourcepub fn get_column(&self, x: usize) -> Result<Vec<bool>, BitMatrixError>
pub fn get_column(&self, x: usize) -> Result<Vec<bool>, BitMatrixError>
Returns the state of all the bits at a specific x-coordinate.
Bits are ordered by row, starting at y-coordinate 0.
sourcepub fn get_row(&self, y: usize) -> Result<Vec<bool>, BitMatrixError>
pub fn get_row(&self, y: usize) -> Result<Vec<bool>, BitMatrixError>
Returns the state of all the bits at a specific y-coordinate.
Bits are ordered by column, starting at x-coordinate 0.
sourcepub fn set(
&mut self,
x: usize,
y: usize,
state: bool
) -> Result<(), BitMatrixError>
pub fn set(
&mut self,
x: usize,
y: usize,
state: bool
) -> Result<(), BitMatrixError>
Changes the state of a bit at a specififc coordinate.
sourcepub fn resize_width(&mut self, len: usize)
pub fn resize_width(&mut self, len: usize)
Changes the width of the matrix.
If len is greater than matrix’s width, each row is extended with 0s. Otherwise, each row is concatenated.
sourcepub fn resize_height(&mut self, len: usize)
pub fn resize_height(&mut self, len: usize)
Changes the hieght of the matrix.
If len is greater than matrix’s height, it is extended with blank rows. Otherwise, the number of rows is suitably concatenated.
sourcepub fn to_bits(&self) -> Vec<bool>
pub fn to_bits(&self) -> Vec<bool>
Produces the contents of the matrix as a flat vec of bits.
Vec contains each row one after another.
sourcepub fn into_bits(self) -> Vec<bool>
pub fn into_bits(self) -> Vec<bool>
Consumes the BitMatrix to produce its contents as a flat vec of bits.
Vec contains each row one after another.
sourcepub fn to_columns(&self) -> Vec<Vec<bool>>
pub fn to_columns(&self) -> Vec<Vec<bool>>
Produces the contents of the matrix as a vec of its columns.
sourcepub fn into_columns(self) -> Vec<Vec<bool>>
pub fn into_columns(self) -> Vec<Vec<bool>>
Consumes the BitMatrix to produce its contents as a vec of its columns.
sourcepub fn to_rows(&self) -> Vec<Vec<bool>>
pub fn to_rows(&self) -> Vec<Vec<bool>>
Produces the contents of the matrix as a vec of its rows.
sourcepub fn into_rows(self) -> Vec<Vec<bool>>
pub fn into_rows(self) -> Vec<Vec<bool>>
Consumes the BitMatrix to produce its contents as a vec of its rows.
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Reduces the width and height such that there are no empty columns or rows on the edges.
Trait Implementations
impl Eq for BitMatrix
impl StructuralEq for BitMatrix
impl StructuralPartialEq for BitMatrix
Auto Trait Implementations
impl RefUnwindSafe for BitMatrix
impl Send for BitMatrix
impl Sync for BitMatrix
impl Unpin for BitMatrix
impl UnwindSafe for BitMatrix
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more