[−][src]Struct thud::Coord
Checked container for a coordinate to address into a Board
Methods
impl Coord
[src]
pub fn zero_based(x: usize, y: usize) -> Result<Self, ThudError>
[src]
Make a new Coord
using 0-based axes values.
The squares are addressed as if the board were a 15x15 square with the bottom-left square being (0, 0); confusingly, this is out of bounds. See the official Thud rules for the shape of the board.
Will return Err(ThudError::InvalidPosition)
if the coordinates supplied are out of bounds
of the board.
pub fn one_based(x: usize, y: usize) -> Result<Self, ThudError>
[src]
pub fn value(&self) -> (usize, usize)
[src]
Get the values inside the coordinate, zero-based.
Since Coord
is bound-checked on creation, the values returned here are guaranteed to be
valid coordinates on the board.
pub fn max(&self) -> usize
[src]
Return the larger of the two coordinates.
Useful for use with .diff()
to get the orthogonal/diagonal distance between two squares:
use thud::Coord; let source = Coord::zero_based(7,7).unwrap(); let destination1 = Coord::zero_based(10, 10).unwrap(); let destination2 = Coord::zero_based(12, 7).unwrap(); assert_eq!(source.diff(destination1).max(), 3); assert_eq!(source.diff(destination2).max(), 5);
pub fn diff(self, rhs: Self) -> Self
[src]
Return the absolute difference between two Coord
s.
Example:
use thud::Coord; let source = Coord::zero_based(7,7).unwrap(); let destination1 = Coord::zero_based(10, 10).unwrap(); let destination2 = Coord::zero_based(12, 7).unwrap(); assert_eq!(source.diff(destination1), (3, 3).into()); assert_eq!(source.diff(destination2), (5, 0).into());
Trait Implementations
impl Clone for Coord
[src]
impl Copy for Coord
[src]
impl Debug for Coord
[src]
impl From<(usize, usize)> for Coord
[src]
impl PartialEq<Coord> for Coord
[src]
impl StructuralPartialEq for Coord
[src]
Auto Trait Implementations
impl RefUnwindSafe for Coord
impl Send for Coord
impl Sync for Coord
impl Unpin for Coord
impl UnwindSafe for Coord
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,