pub struct Axial {
pub q: i32,
pub r: i32,
}Expand description
Axial coordinates use the same system as cube coordinates, but only store two of the coordinate values. This is possible since, for cube coordinate (x, y, z), the third value can always be calculated when the other two are known due to the constraint x + y + z == 0.
Fields§
§q: i32§r: i32Implementations§
Source§impl Axial
impl Axial
Sourcepub fn from_coords(q: i32, r: i32) -> Self
pub fn from_coords(q: i32, r: i32) -> Self
For two unsigned 32-bit integers x and y, the corresponding axial coordinate is (x, y).
§Examples
use chickenwire::coordinate::axial::Axial;
assert_eq!(Axial::from((1, 2)), Axial::from_coords(1, 2));Sourcepub fn dist(self, other: Self) -> i32
pub fn dist(self, other: Self) -> i32
Determines the distance between two axial coordinates.
§Examples
use chickenwire::coordinate::axial::Axial;
let origin = Axial::ORIGIN;
let coord_1 = Axial { q: 1, r: -3 };
let coord_2 = Axial { q: -8, r: 2 };
assert_eq!(origin.dist(coord_1), 3);
assert_eq!(coord_1.dist(origin), 3);
assert_eq!(coord_1.dist(coord_1), 0);
assert_eq!(coord_2.dist(coord_1), 9);Trait Implementations§
Source§impl Add for Axial
Adds two Axial coordinates in the same manner as vectors.
impl Add for Axial
Adds two Axial coordinates in the same manner as vectors.
§Examples
use chickenwire::coordinate::axial::Axial;
let coord_1 = Axial::from_coords(1, -3);
let coord_2 = Axial::from_coords(-5, 12);
assert_eq!(coord_1 + coord_2, Axial::from_coords(-4, 9));
assert_eq!(coord_2 + coord_1, Axial::from_coords(-4, 9));Source§impl Div<i32> for Axial
Divides an Axial coordinate by an i32 scalar, like a vector. Values
are truncated (i.e. rounded toward zero).
impl Div<i32> for Axial
Divides an Axial coordinate by an i32 scalar, like a vector. Values
are truncated (i.e. rounded toward zero).
Source§impl From<(i32, i32)> for Axial
Creates an Axial from an (i32, i32).
impl From<(i32, i32)> for Axial
Creates an Axial from an (i32, i32).
§Examples
use chickenwire::coordinate::axial::Axial;
assert_eq!(
Axial::from((1, 2)),
Axial { q: 1, r: 2 }
);Source§impl From<Axial> for Cube
For axial coordinate (q, r), cube coordinate (x, y, z) is calculated by
solving for y based upon the constraint x + y + z == 0, where x == q and
z == r.
impl From<Axial> for Cube
For axial coordinate (q, r), cube coordinate (x, y, z) is calculated by solving for y based upon the constraint x + y + z == 0, where x == q and z == r.
§Examples
use chickenwire::coordinate::axial::Axial;
use chickenwire::coordinate::cube::Cube;
let axial = Axial::from_coords(1, 2);
assert_eq!(Cube::from(Axial::ORIGIN), Cube::ORIGIN);
assert_eq!(Cube::from(axial), Cube::force_from_coords(1, -3, 2));Source§impl From<Axial> for MultiCoord
Creates a MultiCoord from an Axial.
impl From<Axial> for MultiCoord
Creates a MultiCoord from an Axial.
Source§impl From<Cube> for Axial
Creates an Axial from a Cube.
impl From<Cube> for Axial
Creates an Axial from a Cube.
§Examples
use chickenwire::coordinate::axial::Axial;
use chickenwire::coordinate::cube::Cube;
let cube = Cube::force_from_coords(1, 2, -3);
assert_eq!(
Axial::from(cube),
Axial { q: 1, r: -3 }
);
assert_eq!(
Axial::from(Cube::ORIGIN),
Axial::ORIGIN
);Source§impl From<MultiCoord> for Axial
Creates an Axial from a MultiCoord.
impl From<MultiCoord> for Axial
Creates an Axial from a MultiCoord.
Conversion from both axial and cube MultiCoords is supported.
§Panics
Panics when parsing a double or offset MultiCoord.
Source§fn from(coord: MultiCoord) -> Self
fn from(coord: MultiCoord) -> Self
Source§impl Mul<i32> for Axial
Multiplies an Axial coordinate by an i32 scalar, like a vector.
impl Mul<i32> for Axial
Multiplies an Axial coordinate by an i32 scalar, like a vector.
§Examples
use chickenwire::coordinate::axial::Axial;
let coord = Axial::from_coords(1, -3);
assert_eq!(-1 * coord, Axial::from_coords(-1, 3));
assert_eq!(0 * coord, Axial::ORIGIN);
assert_eq!(coord * 2, Axial::from_coords(2, -6));Source§impl Ord for Axial
impl Ord for Axial
Source§impl PartialOrd for Axial
impl PartialOrd for Axial
Source§impl Sub for Axial
Subtracts two Axial coordinates in the same manner as vectors.
impl Sub for Axial
Subtracts two Axial coordinates in the same manner as vectors.
§Examples
use chickenwire::coordinate::axial::Axial;
let coord_1 = Axial::from_coords(1, -3);
let coord_2 = Axial::from_coords(5, -12);
assert_eq!(coord_1 - coord_2, Axial::from_coords(-4, 9));
assert_eq!(coord_2 - coord_1, Axial::from_coords(4, -9));impl Copy for Axial
impl Eq for Axial
impl StructuralPartialEq for Axial
Auto Trait Implementations§
impl Freeze for Axial
impl RefUnwindSafe for Axial
impl Send for Axial
impl Sync for Axial
impl Unpin for Axial
impl UnwindSafe for Axial
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.