pub struct ICoord {
pub x: isize,
pub y: isize,
}
Expand description
Signed-int coordinates
Fields§
§x: isize
§y: isize
Implementations§
Source§impl ICoord
impl ICoord
Sourcepub fn quadrant(self) -> usize
pub fn quadrant(self) -> usize
Return the quadrant this coordinate is in.
- 1: +X, +Y
- 2: -X, +Y
- 3: -X, -Y
- 4: +X, -Y
Zeroes are treated as positive.
assert_eq!(ICoord::new(4, 5).quadrant(), 1);
assert_eq!(ICoord::new(-3, -2).quadrant(), 3);
// Zero is treated as positive
assert_eq!(ICoord::new(0, -8).quadrant(), 4);
assert_eq!(ICoord::new(0, 0).quadrant(), 1);
Sourcepub fn to_coord(self) -> Option<Coord>
pub fn to_coord(self) -> Option<Coord>
Try to convert this to a Coord.
Returns None
in case any part is negative.
Sourcepub fn neighbors4(self) -> [ICoord; 4]
pub fn neighbors4(self) -> [ICoord; 4]
Get a list of this coordinate’s orthagonal neighbors.
They are given in clockwise order starting with the neighbor to the north,
as if each of Direction4::DIRECTIONS
had been added to them.
assert_eq!(
ICoord::new(5, 7).neighbors4(),
[
ICoord::new(5, 6),
ICoord::new(6, 7),
ICoord::new(5, 8),
ICoord::new(4, 7),
]
);
let origin = ICoord::new(-7, -12);
assert_eq!(
origin.neighbors4()[..],
Direction4::DIRECTIONS.iter().map(|dir| origin + *dir).collect::<Vec<_>>()[..],
);
Sourcepub fn neighbors8(self) -> [ICoord; 8]
pub fn neighbors8(self) -> [ICoord; 8]
Get a list of this coordinate’s orthagonal and diagonal neighbors.
They are given in clockwise order starting with the neighbor to the north,
as if each of Direction8::DIRECTIONS
had been added to them.
assert_eq!(
ICoord::new(5, 7).neighbors8(),
[
ICoord::new(5, 6),
ICoord::new(6, 6),
ICoord::new(6, 7),
ICoord::new(6, 8),
ICoord::new(5, 8),
ICoord::new(4, 8),
ICoord::new(4, 7),
ICoord::new(4, 6),
]
);
let origin = ICoord::new(-7, -12);
assert_eq!(
origin.neighbors8()[..],
Direction8::DIRECTIONS.iter().map(|dir| origin + *dir).collect::<Vec<_>>()[..],
);
Trait Implementations§
Source§impl Add<Direction4> for ICoord
impl Add<Direction4> for ICoord
Source§impl Add<Direction8> for ICoord
impl Add<Direction8> for ICoord
Source§impl AddAssign<Direction4> for ICoord
impl AddAssign<Direction4> for ICoord
Source§fn add_assign(&mut self, rhs: Direction4)
fn add_assign(&mut self, rhs: Direction4)
Performs the
+=
operation. Read moreSource§impl AddAssign<Direction8> for ICoord
impl AddAssign<Direction8> for ICoord
Source§fn add_assign(&mut self, rhs: Direction8)
fn add_assign(&mut self, rhs: Direction8)
Performs the
+=
operation. Read moreSource§impl AddAssign for ICoord
impl AddAssign for ICoord
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+=
operation. Read moreSource§impl MulAssign<isize> for ICoord
impl MulAssign<isize> for ICoord
Source§fn mul_assign(&mut self, rhs: isize)
fn mul_assign(&mut self, rhs: isize)
Performs the
*=
operation. Read moreSource§impl SubAssign for ICoord
impl SubAssign for ICoord
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-=
operation. Read moreSource§impl TryFrom<ICoord> for Coord
Try to convert an ICoord to a Coord.
Will return Error if the ICoord has any negatives in it.
impl TryFrom<ICoord> for Coord
Try to convert an ICoord to a Coord. Will return Error if the ICoord has any negatives in it.
impl Copy for ICoord
impl Eq for ICoord
impl StructuralPartialEq for ICoord
Auto Trait Implementations§
impl Freeze for ICoord
impl RefUnwindSafe for ICoord
impl Send for ICoord
impl Sync for ICoord
impl Unpin for ICoord
impl UnwindSafe for ICoord
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CallHasher for T
impl<T> CallHasher for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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