[][src]Struct hex_game::coord::Coord

pub struct Coord {
    pub x: u8,
    pub y: u8,
}

A coordinate on a Hex board, such that (x, y) = (0, 0) is the top left and (1, 0) is the hex immediately to the right of that hex. Cannot support boards larger than 128x128 for performance reasons.

Fields

x: u8

The x-axis, starting from the left column at 0.

y: u8

The y-axis, starting from the top row at 0.

Methods

impl Coord
[src]

pub fn new(x: u8, y: u8) -> Option<Coord>
[src]

Creates a new Coord, returning None if either x or y exceed 25.

pub fn neighbors(self) -> Vec<Coord>
[src]

Returns an iterator representing each of this hex's neighbors, clockwise from the top left. If this hex is on the first row or column, will return fewer than six coordinates.

pub fn is_neighbor(self, other: Coord) -> bool
[src]

Returns true if the two hexes neighbor each other or equal each other, and false otherwise.

pub fn abs_sub(int1: u8, int2: u8) -> u8
[src]

Gets the absolute difference between two unsigned u8s, in a way that avoids overflow.

pub fn distance(self, other: Coord) -> u8
[src]

Gets the distance between two coordinates, defined as the number of steps in the grid needed to connect them. A distance of 0 means equality, and a distance of 1 means the two are neighboring.

Trait Implementations

impl Eq for Coord
[src]

impl Copy for Coord
[src]

impl Default for Coord
[src]

impl PartialEq<Coord> for Coord
[src]

impl Clone for Coord
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Coord
[src]

impl Display for Coord
[src]

impl Hash for Coord
[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Add<Coord> for Coord
[src]

type Output = Coord

The resulting type after applying the + operator.

fn add(self, rhs: Coord) -> Self::Output
[src]

Adds componentwise, but does not check the addition.

impl FromStr for Coord
[src]

type Err = ParseCoordError

The associated error which can be returned from parsing.

Auto Trait Implementations

impl Send for Coord

impl Sync for Coord

Blanket Implementations

impl<T> From for T
[src]

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

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

type Owned = T

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<Q, K> Equivalent for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]