Struct hex_coordinates::CubeCoordinates
source · [−]pub struct CubeCoordinates {
pub q: Immutable<isize>,
pub r: Immutable<isize>,
pub s: Immutable<isize>,
}Expand description
_____
╱ r, s╲
╲__q__╱ _____
_____╱+1,-1╲_____
╱ 0,+1╲__0__╱-1, 0╲
╲_-1__╱ 0, 0╲_+1__╱
╱+1, 0╲__0__╱ 0,-1╲
╲_-1__╱+1,-1╲_+1__╱
╲__0__╱ +s -r
╲ ╱
-q ──╳── +q
╱ ╲
+r -sstd::ops::Div and std::ops::DivAssign are not implemented as the operation will not
always produce valid coordinates. It is only valid when all components q, r and s are
divisible by the given denominator. To highlight division here is done with a custom
CubeCoordinates::try_div
Fields
q: Immutable<isize>r: Immutable<isize>s: Immutable<isize>Implementations
sourceimpl CubeCoordinates
impl CubeCoordinates
sourcepub const fn neighbor(&self, direction: Direction) -> Self
pub const fn neighbor(&self, direction: Direction) -> Self
Returns the neighboring coordinates in a given direction.
sourcepub const fn manhattan_distance(&self, other: Self) -> usize
pub const fn manhattan_distance(&self, other: Self) -> usize
Returns the manhattan distance between 2 coordinates.
sourcepub fn coordinate_range(&self, range: usize) -> Vec<Self>
pub fn coordinate_range(&self, range: usize) -> Vec<Self>
Returns all coordinates steps steps from self where { -range <= steps <= range }.
Panics
When isize::try_from(range).is_err().
sourcepub const fn rotate(&self, center: Self, rotation: Rotation) -> Self
pub const fn rotate(&self, center: Self, rotation: Rotation) -> Self
Returns coordinates resulting from rotating self about center by Rotation.
sourcepub const fn try_div(&self, rhs: isize) -> Result<Self, InvalidCubeCoordinate>
pub const fn try_div(&self, rhs: isize) -> Result<Self, InvalidCubeCoordinate>
sourcepub const fn try_div_assign(
&mut self,
rhs: isize
) -> Result<(), InvalidCubeCoordinate>
pub const fn try_div_assign(
&mut self,
rhs: isize
) -> Result<(), InvalidCubeCoordinate>
Divides self by rhs and assigns result to self.
Errors
When the division produces an invalid coordinate.
Trait Implementations
sourceimpl Add<CubeCoordinates> for CubeCoordinates
impl Add<CubeCoordinates> for CubeCoordinates
type Output = CubeCoordinates
type Output = CubeCoordinates
The resulting type after applying the + operator.
sourceimpl AddAssign<CubeCoordinates> for CubeCoordinates
impl AddAssign<CubeCoordinates> for CubeCoordinates
sourceconst fn add_assign(&mut self, other: Self)
const fn add_assign(&mut self, other: Self)
Performs the += operation. Read more
sourceimpl Clone for CubeCoordinates
impl Clone for CubeCoordinates
sourcefn clone(&self) -> CubeCoordinates
fn clone(&self) -> CubeCoordinates
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for CubeCoordinates
impl Debug for CubeCoordinates
sourceimpl From<AxialCoordinates> for CubeCoordinates
impl From<AxialCoordinates> for CubeCoordinates
sourceconst fn from(_: AxialCoordinates) -> Self
const fn from(_: AxialCoordinates) -> Self
Converts to this type from the input type.
sourceimpl From<CubeCoordinates> for AxialCoordinates
impl From<CubeCoordinates> for AxialCoordinates
sourceconst fn from(_: CubeCoordinates) -> Self
const fn from(_: CubeCoordinates) -> Self
Converts to this type from the input type.
sourceimpl From<Direction> for CubeCoordinates
impl From<Direction> for CubeCoordinates
sourceimpl Mul<isize> for CubeCoordinates
impl Mul<isize> for CubeCoordinates
sourceimpl MulAssign<isize> for CubeCoordinates
impl MulAssign<isize> for CubeCoordinates
sourceconst fn mul_assign(&mut self, rhs: isize)
const fn mul_assign(&mut self, rhs: isize)
Performs the *= operation. Read more
sourceimpl PartialEq<CubeCoordinates> for CubeCoordinates
impl PartialEq<CubeCoordinates> for CubeCoordinates
sourcefn eq(&self, other: &CubeCoordinates) -> bool
fn eq(&self, other: &CubeCoordinates) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourcefn ne(&self, other: &CubeCoordinates) -> bool
fn ne(&self, other: &CubeCoordinates) -> bool
This method tests for !=.
sourceimpl Sub<CubeCoordinates> for CubeCoordinates
impl Sub<CubeCoordinates> for CubeCoordinates
type Output = CubeCoordinates
type Output = CubeCoordinates
The resulting type after applying the - operator.
sourceimpl SubAssign<CubeCoordinates> for CubeCoordinates
impl SubAssign<CubeCoordinates> for CubeCoordinates
sourceconst fn sub_assign(&mut self, other: Self)
const fn sub_assign(&mut self, other: Self)
Performs the -= operation. Read more
impl Copy for CubeCoordinates
impl Eq for CubeCoordinates
impl StructuralEq for CubeCoordinates
impl StructuralPartialEq for CubeCoordinates
Auto Trait Implementations
impl RefUnwindSafe for CubeCoordinates
impl Send for CubeCoordinates
impl Sync for CubeCoordinates
impl Unpin for CubeCoordinates
impl UnwindSafe for CubeCoordinates
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more