pub struct Coords {
pub row: CoordValue,
pub column: CoordValue,
}
Expand description
Coordinates of a single cell of the board.
hexgame
uses a zero-based (row, column)-format analogous to matrix-indices.
The following diagram shows on the left the format used by Coords
and on the right
the “c4” format similar to Chess that is commonly used in the literature.
Note that the order of row-index and column-index is swapped between both formats:
The marked cell has coordinates (1, 3) and d2, respectively.
0 1 2 3 4 a b c d e
0\. . . . .\0 1\. . . . .\1
1\. . . ● .\1 2\. . . ● .\2
2\. . . . .\2 3\. . . . .\3
3\. . . . .\3 4\. . . . .\4
4\. . . . .\4 5\. . . . .\5
0 1 2 3 4 a b c d e
The from_str
and to_string
methods can be used to convert between the formats.
use std::str::FromStr;
let coords = Coords::new(7, 0);
// Note the different order!
assert_eq!(coords.to_string(), "a8");
let other_coords = Coords::from_str("a8").unwrap();
assert_eq!(coords, other_coords);
Fields
row: CoordValue
Zero-based row index, counted from top to bottom.
column: CoordValue
Zero-based column index, counted from left to right.
Implementations
sourceimpl Coords
impl Coords
sourcepub fn new(row: CoordValue, column: CoordValue) -> Self
pub fn new(row: CoordValue, column: CoordValue) -> Self
Create a new Coords instance. Watch out: Order of parameters is different from the commonly used “c4” format.
sourcepub fn is_on_board_with_size(&self, size: CoordValue) -> bool
pub fn is_on_board_with_size(&self, size: CoordValue) -> bool
Return whether this coordinate exist on a board of the given size.
Trait Implementations
sourceimpl From<Coords> for CoordsOrEdge
impl From<Coords> for CoordsOrEdge
sourcefn from(coords: Coords) -> CoordsOrEdge
fn from(coords: Coords) -> CoordsOrEdge
Performs the conversion.
impl Copy for Coords
impl Eq for Coords
impl StructuralEq for Coords
impl StructuralPartialEq for Coords
Auto Trait Implementations
impl RefUnwindSafe for Coords
impl Send for Coords
impl Sync for Coords
impl Unpin for Coords
impl UnwindSafe for Coords
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more