Struct sqrid::Gridbool

source ·
pub struct Gridbool<const WIDTH: u16, const HEIGHT: u16, const WORDS: usize>(/* private fields */);
Expand description

Space-optimized grid of booleans using bitmaps

Gridbool uses an array of u32 to implement a Qa-indexable grid of booleans, balancing space and performance.

At the moment we need to provide the number of u32 WORDS to use due to rust generic const limitations. We are able to check that the value is appropriate, though.

We can use the gridbool_create macro to use a Qa as a source of these values.

Implementations§

source§

impl<const W: u16, const H: u16, const WORDS: usize> Gridbool<W, H, WORDS>

source

pub const ALL_TRUE: Self = _

Const Gridbool filled with true values.

source

pub const ALL_FALSE: Self = _

Const Gridbool filled with false values.

source

pub const fn repeat(value: bool) -> Self

Create a Gridbool filled with the provided value.

source

pub fn set_t(&mut self, qaref: impl Borrow<Qa<W, H>>)

Set the provided Qa position to true.

source

pub fn set_f(&mut self, qaref: impl Borrow<Qa<W, H>>)

Set the provided Qa position to false.

source

pub fn set(&mut self, qaref: impl Borrow<Qa<W, H>>, value: bool)

Set the provided Qa position to value.

source

pub fn get(&self, qaref: impl Borrow<Qa<W, H>>) -> bool

Return the value at position Qa.

source

pub fn into_inner(self) -> [u32; WORDS]

Consume self and returns the inner bitmap.

source

pub fn as_inner(&self) -> &[u32; WORDS]

Return a reference to the inner bitmap; useful for testing.

source

pub fn as_inner_mut(&mut self) -> &mut [u32; WORDS]

Return a mut reference to the inner bitmap; useful for testing.

source

pub fn iter(&self) -> impl Iterator<Item = bool> + '_

Iterate over all true/false values in the Gridbool.

source

pub fn iter_qa(&self) -> impl Iterator<Item = (Qa<W, H>, bool)> + '_

Iterate over all coordinates and corresponding true/false values.

source

pub fn iter_t(&self) -> impl Iterator<Item = Qa<W, H>> + '_

Iterate over all true coordinates the Gridbool.

source

pub fn iter_f(&self) -> impl Iterator<Item = Qa<W, H>> + '_

Iterate over all false coordinates the Gridbool.

source

pub fn set_iter_t<AQA>(&mut self, qaiter: impl Iterator<Item = AQA>)
where AQA: Borrow<Qa<W, H>>,

Take a Qa iterator and set all corresponding values to true.

source

pub fn set_iter_f<AQA>(&mut self, qaiter: impl Iterator<Item = AQA>)
where AQA: Borrow<Qa<W, H>>,

Take a Qa iterator and set all corresponding values to false.

source

pub fn flip_h(&mut self)

Flip all elements horizontally.

source

pub fn flip_v(&mut self)

Flip all elements vertically.

source§

impl<const W: u16, const WORDS: usize> Gridbool<W, W, WORDS>

source

pub fn rotate_cw(&mut self)

Rotate all elements 90 degrees clockwise

source

pub fn rotate_cc(&mut self)

Rotate all elements 90 degrees counterclockwise

Trait Implementations§

source§

impl<const WIDTH: u16, const HEIGHT: u16, const WORDS: usize> Clone for Gridbool<WIDTH, HEIGHT, WORDS>

source§

fn clone(&self) -> Gridbool<WIDTH, HEIGHT, WORDS>

Returns a copy 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<const WIDTH: u16, const HEIGHT: u16, const WORDS: usize> Debug for Gridbool<WIDTH, HEIGHT, WORDS>

source§

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

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

impl<const W: u16, const H: u16, const WORDS: usize> Default for Gridbool<W, H, WORDS>

source§

fn default() -> Self

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

impl<const W: u16, const H: u16, const WORDS: usize> Display for Gridbool<W, H, WORDS>

source§

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

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

impl<AQA, const W: u16, const H: u16, const WORDS: usize> FromIterator<AQA> for Gridbool<W, H, WORDS>
where AQA: Borrow<Qa<W, H>>,

source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = AQA>,

Creates a value from an iterator. Read more
source§

impl<const W: u16, const H: u16, const WORDS: usize> FromIterator<bool> for Gridbool<W, H, WORDS>

source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = bool>,

Creates a value from an iterator. Read more
source§

impl<AQA, const W: u16, const H: u16, const WORDS: usize> Index<AQA> for Gridbool<W, H, WORDS>
where AQA: Borrow<Qa<W, H>>,

§

type Output = bool

The returned type after indexing.
source§

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

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

impl<const WIDTH: u16, const HEIGHT: u16, const WORDS: usize> PartialEq for Gridbool<WIDTH, HEIGHT, WORDS>

source§

fn eq(&self, other: &Gridbool<WIDTH, HEIGHT, WORDS>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const W: u16, const H: u16, const WORDS: usize, const SIZE: usize> SetQa<W, H, WORDS, SIZE> for Gridbool<W, H, WORDS>

source§

fn contains(&self, qa: &Qa<W, H>) -> bool

Check if the provided Qa is in the set
source§

fn insert(&mut self, qa: &Qa<W, H>)

Insert the provided Qa
source§

fn remove(&mut self, qa: &Qa<W, H>)

Remove the provided Qa
source§

fn set(&mut self, qa: &Qa<W, H>, add: bool)

Insert or remove the provided Qa
source§

impl<const WIDTH: u16, const HEIGHT: u16, const WORDS: usize> Copy for Gridbool<WIDTH, HEIGHT, WORDS>

source§

impl<const WIDTH: u16, const HEIGHT: u16, const WORDS: usize> Eq for Gridbool<WIDTH, HEIGHT, WORDS>

source§

impl<const WIDTH: u16, const HEIGHT: u16, const WORDS: usize> StructuralEq for Gridbool<WIDTH, HEIGHT, WORDS>

source§

impl<const WIDTH: u16, const HEIGHT: u16, const WORDS: usize> StructuralPartialEq for Gridbool<WIDTH, HEIGHT, WORDS>

Auto Trait Implementations§

§

impl<const WIDTH: u16, const HEIGHT: u16, const WORDS: usize> RefUnwindSafe for Gridbool<WIDTH, HEIGHT, WORDS>

§

impl<const WIDTH: u16, const HEIGHT: u16, const WORDS: usize> Send for Gridbool<WIDTH, HEIGHT, WORDS>

§

impl<const WIDTH: u16, const HEIGHT: u16, const WORDS: usize> Sync for Gridbool<WIDTH, HEIGHT, WORDS>

§

impl<const WIDTH: u16, const HEIGHT: u16, const WORDS: usize> Unpin for Gridbool<WIDTH, HEIGHT, WORDS>

§

impl<const WIDTH: u16, const HEIGHT: u16, const WORDS: usize> UnwindSafe for Gridbool<WIDTH, HEIGHT, WORDS>

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> 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,

§

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§

default 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>,

§

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>,

§

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.