Struct BitMatrix

Source
pub struct BitMatrix {
    pub width: usize,
    pub height: usize,
    /* private fields */
}
Expand description

A 2-d bit-matrix.

Fields§

§width: usize

Width of the matrix.

§height: usize

Height of the matrix.

Implementations§

Source§

impl BitMatrix

Source

pub fn new() -> Self

Creates an empty BitMatrix with zero width or height.

Source

pub fn with_dimensions(width: usize, height: usize) -> Self

Creates an empty BitMatrix with predefined dimensions.

Source

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.

Source

pub fn get(&self, x: usize, y: usize) -> Result<bool, BitMatrixError>

Returns the state of a bit at a specific coordinate.

Source

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.

Source

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.

Source

pub fn set( &mut self, x: usize, y: usize, state: bool, ) -> Result<(), BitMatrixError>

Changes the state of a bit at a specififc coordinate.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn to_columns(&self) -> Vec<Vec<bool>>

Produces the contents of the matrix as a vec of its columns.

Source

pub fn into_columns(self) -> Vec<Vec<bool>>

Consumes the BitMatrix to produce its contents as a vec of its columns.

Source

pub fn to_rows(&self) -> Vec<Vec<bool>>

Produces the contents of the matrix as a vec of its rows.

Source

pub fn into_rows(self) -> Vec<Vec<bool>>

Consumes the BitMatrix to produce its contents as a vec of its rows.

Source

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§

Source§

impl Clone for BitMatrix

Source§

fn clone(&self) -> BitMatrix

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for BitMatrix

Source§

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

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

impl Default for BitMatrix

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Hash for BitMatrix

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for BitMatrix

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Eq for BitMatrix

Source§

impl StructuralPartialEq for BitMatrix

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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, 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.