Struct ICoord

Source
pub struct ICoord {
    pub x: isize,
    pub y: isize,
}
Expand description

Signed-int coordinates

Fields§

§x: isize§y: isize

Implementations§

Source§

impl ICoord

Source

pub fn new(x: isize, y: isize) -> Self

Create a new ICoord

Source

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);
Source

pub fn to_coord(self) -> Option<Coord>

Try to convert this to a Coord. Returns None in case any part is negative.

Source

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<_>>()[..],
);
Source

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

Source§

type Output = ICoord

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction4) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Direction8> for ICoord

Source§

type Output = ICoord

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction8) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<ICoord> for IRect

Source§

type Output = IRect

The resulting type after applying the + operator.
Source§

fn add(self, rhs: ICoord) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for ICoord

Source§

type Output = ICoord

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign<Direction4> for ICoord

Source§

fn add_assign(&mut self, rhs: Direction4)

Performs the += operation. Read more
Source§

impl AddAssign<Direction8> for ICoord

Source§

fn add_assign(&mut self, rhs: Direction8)

Performs the += operation. Read more
Source§

impl AddAssign for ICoord

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for ICoord

Source§

fn clone(&self) -> ICoord

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 ICoord

Source§

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

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

impl Display for ICoord

Source§

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

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

impl From<Coord> for ICoord

Source§

fn from(value: Coord) -> Self

Converts to this type from the input type.
Source§

impl Hash for ICoord

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 Mul<isize> for ICoord

Source§

type Output = ICoord

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: isize) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign<isize> for ICoord

Source§

fn mul_assign(&mut self, rhs: isize)

Performs the *= operation. Read more
Source§

impl PartialEq for ICoord

Source§

fn eq(&self, other: &ICoord) -> 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 Sub for ICoord

Source§

type Output = ICoord

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign for ICoord

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl TryFrom<ICoord> for Coord

Try to convert an ICoord to a Coord. Will return Error if the ICoord has any negatives in it.

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(value: ICoord) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for ICoord

Source§

impl Eq for ICoord

Source§

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> 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> CallHasher for T
where T: Hash + ?Sized,

Source§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64
where H: Hash + ?Sized, B: BuildHasher,

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> ToString for T
where T: Display + ?Sized,

Source§

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

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V