pub struct Qa<const WIDTH: u16, const HEIGHT: u16> { /* private fields */ }Expand description
Square grid absolute coordinate
This generic type receives the dimensions of the square grid as const generic parameters, and prevents the cration of instances outside the grid.
Recommended usage is through a type alias; for instance, to create a 4x4 grid coordinate type:
type Qa = sqrid::Qa<4, 4>;We can only generate Qa instances that are valid - i.e. inside
the grid. Some of the ways to create instances:
- Using one of the const associated items:
Qa::FIRSTandQa::LAST;Qa::TOP_LEFT, etc.;Qa::CENTER. - Using
Qa::newwith X and Y coordinates and handling theResult; can also be used in const contexts.let qa = Qa::new(3, 3)?; - Using
try_fromwith a(u16, u16)tuple or a tuple reference. It’s equivalent toQa::new:use std::convert::{TryFrom, TryInto}; let qa1 = Qa::try_from((3, 3))?; let qa2 : Qa = (3_u16, 3_u16).try_into()?; - Using
Qa::new_unwrap, be be aware that it panics if the coordinates are not valid. This is convenient in const contexts, asunwrapis not a const fn method.const qa : Qa = Qa::new_unwrap(3, 3); - Using
Qa::new_staticto create an instance at compile time, which is also when the validity of the coordinates is checked.The following, for instance, doesn’t compile:const QA : Qa = Qa::new_static::<3, 3>();ⓘconst QA : Qa = Qa::new_static::<3, 30>();
Implementations§
source§impl<const W: u16, const H: u16> Qa<W, H>
impl<const W: u16, const H: u16> Qa<W, H>
sourcepub const FIRST: Qa<W, H> = _
pub const FIRST: Qa<W, H> = _
Coordinates of the first element of the grid: (0, 0).
Also known as origin.
sourcepub const BOTTOM_LEFT: Qa<W, H> = _
pub const BOTTOM_LEFT: Qa<W, H> = _
Coordinates of the bottom-left coordinate.
sourcepub const BOTTOM_RIGHT: Qa<W, H> = _
pub const BOTTOM_RIGHT: Qa<W, H> = _
Coordinates of the bottom-right coordinate.
sourcepub const fn new(x: u16, y: u16) -> Result<Self, Error>
pub const fn new(x: u16, y: u16) -> Result<Self, Error>
Create a new Qa instance; returns error if a coordinate is
out-of-bounds.
sourcepub const fn new_unwrap(x: u16, y: u16) -> Self
pub const fn new_unwrap(x: u16, y: u16) -> Self
Create a new Qa instance, supports being called in const
context; panics if a coordinate is out-of-bounds.
sourcepub const fn new_static<const X: u16, const Y: u16>() -> Self
pub const fn new_static<const X: u16, const Y: u16>() -> Self
Create a new Qa instance at compile time.
Checks arguments at compile time - for instance, the following doesn’t compile:
const QA : sqrid::Qa<5,5> = sqrid::Qa::<5,5>::new_static::<9,9>();
sourcepub fn tryfrom_tuple(xyref: impl Borrow<(u16, u16)>) -> Result<Qa<W, H>, Error>
pub fn tryfrom_tuple(xyref: impl Borrow<(u16, u16)>) -> Result<Qa<W, H>, Error>
Create a new Qa from the provided (u16, u16), if
possible; return an error otherwise.
sourcepub fn tryfrom_qa<const W2: u16, const H2: u16>(
qa2: Qa<W2, H2>
) -> Result<Qa<W, H>, Error>
pub fn tryfrom_qa<const W2: u16, const H2: u16>( qa2: Qa<W2, H2> ) -> Result<Qa<W, H>, Error>
Create a new Qa from the provided Qa with different
dimensions, if possible; return an error otherwise.
sourcepub fn tryfrom_usize(iref: impl Borrow<usize>) -> Result<Qa<W, H>, Error>
pub fn tryfrom_usize(iref: impl Borrow<usize>) -> Result<Qa<W, H>, Error>
Create a new Qa from the provided usize, if possible;
return an error otherwise.
sourcepub fn tlbr_of(
iter: impl Iterator<Item = Qa<W, H>>
) -> Result<(Qa<W, H>, Qa<W, H>), Error>
pub fn tlbr_of( iter: impl Iterator<Item = Qa<W, H>> ) -> Result<(Qa<W, H>, Qa<W, H>), Error>
Calculate a top-left and a bottom-right Qa’s that contains all iterated points.
sourcepub fn next(self) -> Option<Self>
pub fn next(self) -> Option<Self>
Return the next Qa in sequence (English read sequence), or
None if self is the last one.
sourcepub fn iter() -> QaIter<W, H> ⓘ
pub fn iter() -> QaIter<W, H> ⓘ
Return an iterator that returns all Qa’s within the grid
dimensions.
sourcepub fn iter_horizontal() -> QaIter<W, H> ⓘ
pub fn iter_horizontal() -> QaIter<W, H> ⓘ
Return an iterator that returns all Qa’s within the grid
dimensions horizontally.
sourcepub fn iter_vertical() -> QaIter<W, H> ⓘ
pub fn iter_vertical() -> QaIter<W, H> ⓘ
Return an iterator that returns all Qa’s within the grid
dimensions vertically.
sourcepub fn iter_range(topleft: Self, botright: Self) -> QaIterRange<W, H> ⓘ
pub fn iter_range(topleft: Self, botright: Self) -> QaIterRange<W, H> ⓘ
Return an iterator that returns all Qa’s within the grid
coordinates.
sourcepub fn iter_in_x(x: u16) -> Option<QaIterInX<W, H>>
pub fn iter_in_x(x: u16) -> Option<QaIterInX<W, H>>
Return an iterator that returns all Qa’s in a column.
sourcepub fn iter_in_y(y: u16) -> Option<QaIterInY<W, H>>
pub fn iter_in_y(y: u16) -> Option<QaIterInY<W, H>>
Return an iterator that returns all Qa’s in a line.
Trait Implementations§
source§impl<const WIDTH: u16, const HEIGHT: u16> Ord for Qa<WIDTH, HEIGHT>
impl<const WIDTH: u16, const HEIGHT: u16> Ord for Qa<WIDTH, HEIGHT>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<const WIDTH: u16, const HEIGHT: u16> PartialEq for Qa<WIDTH, HEIGHT>
impl<const WIDTH: u16, const HEIGHT: u16> PartialEq for Qa<WIDTH, HEIGHT>
source§impl<const WIDTH: u16, const HEIGHT: u16> PartialOrd for Qa<WIDTH, HEIGHT>
impl<const WIDTH: u16, const HEIGHT: u16> PartialOrd for Qa<WIDTH, HEIGHT>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more