[][src]Struct thud::Coord

pub struct Coord { /* fields omitted */ }

Checked container for a coordinate to address into a Board

Methods

impl Coord[src]

pub fn valid(x: usize, y: usize) -> bool[src]

Check whether the given (x, y) pair is a valid coordinate pair

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 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)?;
let destination1 = Coord::zero_based(10, 10)?;
let destination2 = Coord::zero_based(12, 7)?;

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 Coords.

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.