pub struct Coordinate<T> {
pub x: T,
pub y: T,
}Expand description
A standard 2D Cartesian Coordinate
Fields§
§x: T§y: TImplementations§
Source§impl<T: Copy + 'static> Coordinate<T>
impl<T: Copy + 'static> Coordinate<T>
pub fn from<U: AsPrimitive<T>>(other: Coordinate<U>) -> Coordinate<T>
Source§impl<T: Integer + Copy> Coordinate<T>
impl<T: Integer + Copy> Coordinate<T>
Sourcepub fn neighbours(&self) -> Vec<Self>
pub fn neighbours(&self) -> Vec<Self>
All co-ordinates directly neighbouring the square on a grid, excluding diagonals
Sourcepub fn extended_neighbours(&self) -> Vec<Self>
pub fn extended_neighbours(&self) -> Vec<Self>
All co-ordinates directly neighbouring the square on a grid, including diagonals
Sourcepub fn hex_neighbours(&self) -> Vec<Self>
pub fn hex_neighbours(&self) -> Vec<Self>
Returns all co-ordinates directly neighbouring the square on an alternating hex grid:
1 2
3 X 4
5 6Sourcepub fn manhattan_distance(&self, other: &Self) -> T
pub fn manhattan_distance(&self, other: &Self) -> T
Taxicab / manhattan distance: difference between X coordinates plus difference between Y coordinates
Source§impl<T: Integer + Copy + CheckedSub + CheckedAdd + Unsigned> Coordinate<T>
impl<T: Integer + Copy + CheckedSub + CheckedAdd + Unsigned> Coordinate<T>
Sourcepub fn checked_neighbour(&self, direction: Direction) -> Option<Self>
pub fn checked_neighbour(&self, direction: Direction) -> Option<Self>
The neighbouring Coordinate in the supplied Direction, checked for under / overflow
Sourcepub fn checked_neighbours(
&self,
) -> impl Iterator<Item = Coordinate<T>> + use<'_, T>
pub fn checked_neighbours( &self, ) -> impl Iterator<Item = Coordinate<T>> + use<'_, T>
The neighbouring Coordinates in the four compass Directions, checked for under / overflow
Sourcepub fn checked_extended_neighbours(
&self,
) -> impl Iterator<Item = Coordinate<T>> + use<'_, T>
pub fn checked_extended_neighbours( &self, ) -> impl Iterator<Item = Coordinate<T>> + use<'_, T>
The neighbouring Coordinates in the eight Directions, checked for under / overflow
Trait Implementations§
Source§impl<T: Add<Output = T>> Add for Coordinate<T>
impl<T: Add<Output = T>> Add for Coordinate<T>
Source§impl<T: AddAssign> AddAssign for Coordinate<T>
impl<T: AddAssign> AddAssign for Coordinate<T>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+= operation. Read moreSource§impl<T: Unsigned + CheckedAdd<Output = T>> CheckedAdd for Coordinate<T>
impl<T: Unsigned + CheckedAdd<Output = T>> CheckedAdd for Coordinate<T>
Source§fn checked_add(&self, other: &Self) -> Option<Self>
fn checked_add(&self, other: &Self) -> Option<Self>
None is
returned.Source§impl<T: Unsigned + CheckedSub<Output = T>> CheckedSub for Coordinate<T>
impl<T: Unsigned + CheckedSub<Output = T>> CheckedSub for Coordinate<T>
Source§fn checked_sub(&self, other: &Self) -> Option<Self>
fn checked_sub(&self, other: &Self) -> Option<Self>
None is returned.Source§impl<T: Clone> Clone for Coordinate<T>
impl<T: Clone> Clone for Coordinate<T>
Source§fn clone(&self) -> Coordinate<T>
fn clone(&self) -> Coordinate<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for Coordinate<T>
impl<T: Debug> Debug for Coordinate<T>
Source§impl<T: Display> Display for Coordinate<T>
Renders Coordinate as (x,y)
impl<T: Display> Display for Coordinate<T>
Renders Coordinate as (x,y)
Source§impl<T: Hash> Hash for Coordinate<T>
impl<T: Hash> Hash for Coordinate<T>
Source§impl<T> Mul<T> for Coordinate<T>
impl<T> Mul<T> for Coordinate<T>
Source§type Output = Coordinate<T>
type Output = Coordinate<T>
* operator.Source§fn mul(self, n: T) -> Coordinate<T>
fn mul(self, n: T) -> Coordinate<T>
* operation. Read moreSource§impl<T: Eq + PartialEq + Ord + Copy> Ord for Coordinate<T>
Y values are treated as more significant than X values; this preserves the reading order used in a number of puzzles.
impl<T: Eq + PartialEq + Ord + Copy> Ord for Coordinate<T>
Y values are treated as more significant than X values; this preserves the reading order used in a number of puzzles.
Source§impl<T: PartialEq> PartialEq for Coordinate<T>
impl<T: PartialEq> PartialEq for Coordinate<T>
Source§impl<T> PartialOrd for Coordinate<T>
impl<T> PartialOrd for Coordinate<T>
Source§impl<T: Sub<Output = T>> Sub for Coordinate<T>
impl<T: Sub<Output = T>> Sub for Coordinate<T>
Source§impl<T: SubAssign> SubAssign for Coordinate<T>
impl<T: SubAssign> SubAssign for Coordinate<T>
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-= operation. Read moreimpl<T: Copy> Copy for Coordinate<T>
impl<T: Eq> Eq for Coordinate<T>
impl<T> StructuralPartialEq for Coordinate<T>
Auto Trait Implementations§
impl<T> Freeze for Coordinate<T>where
T: Freeze,
impl<T> RefUnwindSafe for Coordinate<T>where
T: RefUnwindSafe,
impl<T> Send for Coordinate<T>where
T: Send,
impl<T> Sync for Coordinate<T>where
T: Sync,
impl<T> Unpin for Coordinate<T>where
T: Unpin,
impl<T> UnwindSafe for Coordinate<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.