PosT

Trait PosT 

Source
pub trait PosT:
    Debug
    + Default
    + Eq
    + PartialOrd
    + Copy {
    type Xtype: BoundedInt;
    type Ytype: BoundedInt;

    const WIDTH: usize;
    const HEIGHT: usize;
Show 37 methods // Required method fn new_(xy: (Self::Xtype, Self::Ytype)) -> Self; // Provided methods fn new<X, Y>(x: X, y: Y) -> Result<Self, Error> where X: BoundedInt, Y: BoundedInt, Self::Xtype: TryFrom<X>, Self::Ytype: TryFrom<Y>, Self: Sized { ... } fn into_tuple(self) -> (Self::Xtype, Self::Ytype) where Self: Sized { ... } fn tuple(&self) -> (Self::Xtype, Self::Ytype) { ... } fn x(&self) -> Self::Xtype { ... } fn y(&self) -> Self::Ytype { ... } fn inner_tuple( self, ) -> (<Self::Xtype as BoundedInt>::Inner, <Self::Ytype as BoundedInt>::Inner) { ... } fn tryfrom_pos<P>(pos: P) -> Result<Self, Error> where P: PosT, Self::Xtype: TryFrom<<P::Xtype as BoundedInt>::Inner>, Self::Ytype: TryFrom<<P::Ytype as BoundedInt>::Inner>, <P::Xtype as BoundedInt>::Inner: BoundedInt, <P::Ytype as BoundedInt>::Inner: BoundedInt, Self: Sized { ... } fn width() -> usize { ... } fn height() -> usize { ... } fn dimensions() -> usize { ... } fn first() -> Self where Self: Sized { ... } fn last() -> Self where Self: Sized { ... } fn is_corner(&self) -> bool { ... } fn is_side(&self) -> bool { ... } fn flip_h(&self) -> Self where Self: Sized { ... } fn flip_v(&self) -> Self where Self: Sized { ... } fn manhattan(&self, pos: &Self) -> usize { ... } fn inside(&self, pos1: &Self, pos2: &Self) -> bool { ... } fn to_usize(&self) -> usize { ... } fn tryfrom_usize(i: usize) -> Result<Self, Error> where Self: Sized { ... } fn next(&self) -> Option<Self> where Self: Sized { ... } fn next_y(&self) -> Option<Self> where Self: Sized { ... } fn prev(&self) -> Option<Self> where Self: Sized { ... } fn prev_y(&self) -> Option<Self> where Self: Sized { ... } fn iter_x() -> impl Iterator<Item = Self::Xtype> { ... } fn iter_y() -> impl Iterator<Item = Self::Ytype> { ... } fn iter_orientation<const XFIRST: bool>() -> PosTIter<XFIRST, Self> where Self: Sized { ... } fn iter() -> PosTIter<true, Self> where Self: Sized { ... } fn iter_horizontal() -> PosTIter<true, Self> where Self: Sized { ... } fn iter_vertical() -> PosTIter<false, Self> where Self: Sized { ... } fn iter_range(topleft: Self, botright: Self) -> PosTIterRange<Self> where Self: Sized + Copy { ... } fn iter_in_x(x: Self::Xtype) -> PosTIterInX<Self> where Self: Sized { ... } fn iter_in_y(y: Self::Ytype) -> PosTIterInY<Self> where Self: Sized { ... } fn tlbr_of(iter: impl Iterator<Item = Self>) -> Result<(Self, Self), Error> where Self: Sized { ... } fn rotate_cw(&self) -> Self where <<Self as PosT>::Ytype as BoundedInt>::Inner: Sub<Output = <<Self as PosT>::Ytype as BoundedInt>::Inner>, Self::Xtype: TryFrom<<<Self as PosT>::Ytype as BoundedInt>::Inner>, Self::Ytype: TryFrom<<<Self as PosT>::Xtype as BoundedInt>::Inner> { ... } fn rotate_cc(&self) -> Self where <<Self as PosT>::Xtype as BoundedInt>::Inner: Sub<Output = <<Self as PosT>::Xtype as BoundedInt>::Inner>, Self::Xtype: TryFrom<<<Self as PosT>::Ytype as BoundedInt>::Inner>, Self::Ytype: TryFrom<<<Self as PosT>::Xtype as BoundedInt>::Inner> { ... }
}
Expand description

Position trait

Required Associated Constants§

Source

const WIDTH: usize

Width

Source

const HEIGHT: usize

Height

Required Associated Types§

Source

type Xtype: BoundedInt

The type of the X coordinate

Source

type Ytype: BoundedInt

The type of the Y coordinate

Required Methods§

Source

fn new_(xy: (Self::Xtype, Self::Ytype)) -> Self

Internal new_ that creates the Pos type from the provided tuple.

Provided Methods§

Source

fn new<X, Y>(x: X, y: Y) -> Result<Self, Error>
where X: BoundedInt, Y: BoundedInt, Self::Xtype: TryFrom<X>, Self::Ytype: TryFrom<Y>, Self: Sized,

Create a new Pos with the given parameters

Source

fn into_tuple(self) -> (Self::Xtype, Self::Ytype)
where Self: Sized,

Return the corresponding tuple

Defining this can lead to less copies.

Source

fn tuple(&self) -> (Self::Xtype, Self::Ytype)

Return the corresponding tuple

You can either define both PosT::x and PosT::y, or PosT::tuple.

Source

fn x(&self) -> Self::Xtype

Get the X component

You can either define both PosT::x and PosT::y, or PosT::tuple.

Source

fn y(&self) -> Self::Ytype

Get the Y component

You can either define both PosT::x and PosT::y, or PosT::tuple.

Source

fn inner_tuple( self, ) -> (<Self::Xtype as BoundedInt>::Inner, <Self::Ytype as BoundedInt>::Inner)

Return the corresponding inner tuple

Source

fn tryfrom_pos<P>(pos: P) -> Result<Self, Error>
where P: PosT, Self::Xtype: TryFrom<<P::Xtype as BoundedInt>::Inner>, Self::Ytype: TryFrom<<P::Ytype as BoundedInt>::Inner>, <P::Xtype as BoundedInt>::Inner: BoundedInt, <P::Ytype as BoundedInt>::Inner: BoundedInt, Self: Sized,

Create a position from another position

Source

fn width() -> usize

Return the width (x) supported by the position type

Source

fn height() -> usize

Return the height (y) supported by the position type

Source

fn dimensions() -> usize

Return the total dimension supported by the position type

Source

fn first() -> Self
where Self: Sized,

First coordinate, top left, origin

Source

fn last() -> Self
where Self: Sized,

Last coordinate, bottom right

Source

fn is_corner(&self) -> bool

Return true if self is a corner of the grid.

Source

fn is_side(&self) -> bool

Return true if self is on the side of the grid.

Source

fn flip_h(&self) -> Self
where Self: Sized,

Flip the coordinate vertically

Source

fn flip_v(&self) -> Self
where Self: Sized,

Flip the coordinate horizontally

Source

fn manhattan(&self, pos: &Self) -> usize

Return the manhattan distance

Source

fn inside(&self, pos1: &Self, pos2: &Self) -> bool

Check that the position is inside the provided limits

Source

fn to_usize(&self) -> usize

Return a usize index corresponding to the position.

Source

fn tryfrom_usize(i: usize) -> Result<Self, Error>
where Self: Sized,

Create a new position from the provided usize, if possible; return an error otherwise.

Source

fn next(&self) -> Option<Self>
where Self: Sized,

Return the next position horizontally (English read sequence), or None if self is the last one.

Source

fn next_y(&self) -> Option<Self>
where Self: Sized,

Return the next position vertically, or None if self is the last one.

Source

fn prev(&self) -> Option<Self>
where Self: Sized,

Return the previous position horizontally (English read sequence), or None if self is the first one.

Source

fn prev_y(&self) -> Option<Self>
where Self: Sized,

Return the previous position vertically, or None if self is the first one.

Source

fn iter_x() -> impl Iterator<Item = Self::Xtype>

Returns an iterator over valid X values

Source

fn iter_y() -> impl Iterator<Item = Self::Ytype>

Returns an iterator over valid Y values

Source

fn iter_orientation<const XFIRST: bool>() -> PosTIter<XFIRST, Self>
where Self: Sized,

Return an iterator that returns all positions within the grid dimensions in the given orientation - true for horizontally, false for vertically.

Source

fn iter() -> PosTIter<true, Self>
where Self: Sized,

Return an iterator that returns all positions within the grid dimensions.

Source

fn iter_horizontal() -> PosTIter<true, Self>
where Self: Sized,

Return an iterator that returns all positions within the grid dimensions horizontally.

Source

fn iter_vertical() -> PosTIter<false, Self>
where Self: Sized,

Return an iterator that returns all positions within the grid dimensions vertically.

Source

fn iter_range(topleft: Self, botright: Self) -> PosTIterRange<Self>
where Self: Sized + Copy,

Return an iterator that returns all positions within the grid coordinates.

Source

fn iter_in_x(x: Self::Xtype) -> PosTIterInX<Self>
where Self: Sized,

Return an iterator that returns all positions in a column.

Source

fn iter_in_y(y: Self::Ytype) -> PosTIterInY<Self>
where Self: Sized,

Return an iterator that returns all positions in a line.

Source

fn tlbr_of(iter: impl Iterator<Item = Self>) -> Result<(Self, Self), Error>
where Self: Sized,

Calculate a top-left and a bottom-right Pos’s that contains all iterated points.

Source

fn rotate_cw(&self) -> Self
where <<Self as PosT>::Ytype as BoundedInt>::Inner: Sub<Output = <<Self as PosT>::Ytype as BoundedInt>::Inner>, Self::Xtype: TryFrom<<<Self as PosT>::Ytype as BoundedInt>::Inner>, Self::Ytype: TryFrom<<<Self as PosT>::Xtype as BoundedInt>::Inner>,

Rotate the square grid coordinate 90 degrees clockwise

Source

fn rotate_cc(&self) -> Self
where <<Self as PosT>::Xtype as BoundedInt>::Inner: Sub<Output = <<Self as PosT>::Xtype as BoundedInt>::Inner>, Self::Xtype: TryFrom<<<Self as PosT>::Ytype as BoundedInt>::Inner>, Self::Ytype: TryFrom<<<Self as PosT>::Xtype as BoundedInt>::Inner>,

Rotate the square grid coordinate 90 degrees counter-clockwise

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl PosT for (i8, i8)

Source§

const WIDTH: usize = 255usize

Source§

const HEIGHT: usize = 255usize

Source§

type Xtype = i8

Source§

type Ytype = i8

Source§

fn new_(xy: (i8, i8)) -> Self

Source§

fn into_tuple(self) -> (Self::Xtype, Self::Ytype)

Source§

fn tuple(&self) -> (Self::Xtype, Self::Ytype)

Source§

fn x(&self) -> Self::Xtype

Source§

fn y(&self) -> Self::Ytype

Source§

impl PosT for (i16, i16)

Source§

const WIDTH: usize = 65_535usize

Source§

const HEIGHT: usize = 65_535usize

Source§

type Xtype = i16

Source§

type Ytype = i16

Source§

fn new_(xy: (i16, i16)) -> Self

Source§

fn into_tuple(self) -> (Self::Xtype, Self::Ytype)

Source§

fn tuple(&self) -> (Self::Xtype, Self::Ytype)

Source§

fn x(&self) -> Self::Xtype

Source§

fn y(&self) -> Self::Ytype

Source§

impl PosT for (i32, i32)

Source§

const WIDTH: usize = 4_294_967_295usize

Source§

const HEIGHT: usize = 4_294_967_295usize

Source§

type Xtype = i32

Source§

type Ytype = i32

Source§

fn new_(xy: (i32, i32)) -> Self

Source§

fn into_tuple(self) -> (Self::Xtype, Self::Ytype)

Source§

fn tuple(&self) -> (Self::Xtype, Self::Ytype)

Source§

fn x(&self) -> Self::Xtype

Source§

fn y(&self) -> Self::Ytype

Source§

impl PosT for (u8, u8)

Source§

const WIDTH: usize = 255usize

Source§

const HEIGHT: usize = 255usize

Source§

type Xtype = u8

Source§

type Ytype = u8

Source§

fn new_(xy: (u8, u8)) -> Self

Source§

fn into_tuple(self) -> (Self::Xtype, Self::Ytype)

Source§

fn tuple(&self) -> (Self::Xtype, Self::Ytype)

Source§

fn x(&self) -> Self::Xtype

Source§

fn y(&self) -> Self::Ytype

Source§

impl PosT for (u16, u16)

Source§

const WIDTH: usize = 65_535usize

Source§

const HEIGHT: usize = 65_535usize

Source§

type Xtype = u16

Source§

type Ytype = u16

Source§

fn new_(xy: (u16, u16)) -> Self

Source§

fn into_tuple(self) -> (Self::Xtype, Self::Ytype)

Source§

fn tuple(&self) -> (Self::Xtype, Self::Ytype)

Source§

fn x(&self) -> Self::Xtype

Source§

fn y(&self) -> Self::Ytype

Source§

impl PosT for (u32, u32)

Source§

const WIDTH: usize = 4_294_967_295usize

Source§

const HEIGHT: usize = 4_294_967_295usize

Source§

type Xtype = u32

Source§

type Ytype = u32

Source§

fn new_(xy: (u32, u32)) -> Self

Source§

fn into_tuple(self) -> (Self::Xtype, Self::Ytype)

Source§

fn tuple(&self) -> (Self::Xtype, Self::Ytype)

Source§

fn x(&self) -> Self::Xtype

Source§

fn y(&self) -> Self::Ytype

Source§

impl PosT for (u64, u64)

Source§

const WIDTH: usize = 18_446_744_073_709_551_615usize

Source§

const HEIGHT: usize = 18_446_744_073_709_551_615usize

Source§

type Xtype = u64

Source§

type Ytype = u64

Source§

fn new_(xy: (u64, u64)) -> Self

Source§

fn into_tuple(self) -> (Self::Xtype, Self::Ytype)

Source§

fn tuple(&self) -> (Self::Xtype, Self::Ytype)

Source§

fn x(&self) -> Self::Xtype

Source§

fn y(&self) -> Self::Ytype

Source§

impl PosT for (u128, u128)

Source§

const WIDTH: usize = 18_446_744_073_709_551_615usize

Source§

const HEIGHT: usize = 18_446_744_073_709_551_615usize

Source§

type Xtype = u128

Source§

type Ytype = u128

Source§

fn new_(xy: (u128, u128)) -> Self

Source§

fn into_tuple(self) -> (Self::Xtype, Self::Ytype)

Source§

fn tuple(&self) -> (Self::Xtype, Self::Ytype)

Source§

fn x(&self) -> Self::Xtype

Source§

fn y(&self) -> Self::Ytype

Implementors§

Source§

impl<const XMAX: u16, const YMAX: u16> PosT for Pos<XMAX, YMAX>