pub struct Coordinate { /* private fields */ }Expand description
A hex coordinate using a cubic coordinate scheme.
See http://www.redblobgames.com/grids/hexagons/#coordinates for more detail.
All three coordinates must sum to zero.
Implementations§
Source§impl Coordinate
impl Coordinate
Sourcepub fn new() -> Result<Self, &'static str>
pub fn new() -> Result<Self, &'static str>
Create a new Coordinate at 0, 0, 0.
This returns a Result to match at, but always succeeds.
Sourcepub fn at(x: i64, y: i64, z: i64) -> Result<Self, &'static str>
pub fn at(x: i64, y: i64, z: i64) -> Result<Self, &'static str>
Create a new Coordinate at the specified location, if that location is valid.
Sourcepub fn neighbors(&self) -> Vec<Coordinate>
pub fn neighbors(&self) -> Vec<Coordinate>
Get the six neighbors of a given Coordinate.
Sourcepub fn neighbor(&self, direction: usize) -> Result<Coordinate, &'static str>
pub fn neighbor(&self, direction: usize) -> Result<Coordinate, &'static str>
Get the neighbor in direction. Valid directions are in [0, 5].
Sourcepub fn distance_to(&self, other: Coordinate) -> i64
pub fn distance_to(&self, other: Coordinate) -> i64
Get the distance between two coordinates, in grid tiles.
Trait Implementations§
Source§impl Add for Coordinate
impl Add for Coordinate
Source§type Output = Coordinate
type Output = Coordinate
The resulting type after applying the
+ operator.Source§fn add(self, other: Coordinate) -> Coordinate
fn add(self, other: Coordinate) -> Coordinate
Performs the
+ operation. Read moreSource§impl Clone for Coordinate
impl Clone for Coordinate
Source§fn clone(&self) -> Coordinate
fn clone(&self) -> Coordinate
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Coordinate
impl Debug for Coordinate
Source§impl PartialEq for Coordinate
impl PartialEq for Coordinate
Source§impl PartialOrd for Coordinate
impl PartialOrd for Coordinate
Source§impl Sub for Coordinate
impl Sub for Coordinate
Source§type Output = Coordinate
type Output = Coordinate
The resulting type after applying the
- operator.Source§fn sub(self, other: Coordinate) -> Coordinate
fn sub(self, other: Coordinate) -> Coordinate
Performs the
- operation. Read moreimpl Copy for Coordinate
impl StructuralPartialEq for Coordinate
Auto Trait Implementations§
impl Freeze for Coordinate
impl RefUnwindSafe for Coordinate
impl Send for Coordinate
impl Sync for Coordinate
impl Unpin for Coordinate
impl UnwindSafe for Coordinate
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
Mutably borrows from an owned value. Read more