[−][src]Struct chickenwire::coordinate::double::Double
Double
coordinates are similar to offset coordinates. However, instead
of alternating rows and columns, the horizontal or vertical step size of
the adjacent hexes are doubled. This is useful for a variety of
operations.
For a Sharp
grid, the column value increases by a factor of two with
each column. For a Flat
grid, the row value increases by a factor of two
with each row. In both cases, the sum of a valid coordinate's row and
column values must be even, i.e. for interlaced coordinate (col, row),
(col + row) % 2 == 0.
Double
s are opaque, to enforce constraints.
Methods
impl Double
[src]
pub const ORIGIN: Double
[src]
Double
coordinate origin of (0, 0).
pub fn from_coords(col: i32, row: i32) -> CoordResult<Double>
[src]
Attempts to create a Double
from two i32
values. If these values
obey the Double
constraint, (row + col) % 2 == 0, then returns that
Double
in an Ok
. Otherwise, returns an Err
.
Examples
use chickenwire::coordinate::double::Double; let double_1 = Double::from_coords(1, 3); let double_2 = Double::from_coords(0, 1); assert!(double_1.is_ok()); assert_eq!(double_1.unwrap().col(), 1); assert_eq!(double_1.unwrap().row(), 3); assert!(double_2.is_err());
pub fn force_from_coords(col: i32, row: i32) -> Double
[src]
Creates a Double
from two i32
values.
Panics
Panics if the given i32
values fail to obey the constraint
(row + col) % 2 == 0.
Examples
use chickenwire::coordinate::double::Double; let double_1 = Double::force_from_coords(1, 3); assert_eq!(double_1.col(), 1); assert_eq!(double_1.row(), 3);
pub fn from_tuple((col, row): (i32, i32)) -> CoordResult<Double>
[src]
Attempts to create a Double
from a tuple of two i32
values. If
these values obey the Double
constraint, (row + col) % 2 == 0, then
returns that Double
in an Ok
. Otherwise, returns an Err
.
Examples
use chickenwire::coordinate::double::Double; let double_1 = Double::from_tuple((1, 3)); let double_2 = Double::from_tuple((0, 1)); assert!(double_1.is_ok()); assert_eq!(double_1.unwrap().col(), 1); assert_eq!(double_1.unwrap().row(), 3); assert!(double_2.is_err());
pub fn col(&self) -> i32
[src]
Return the column value of a Double
.
pub fn row(&self) -> i32
[src]
Return the row value of a Double
.
pub fn flat_to_cube(self) -> Cube
[src]
Convert a Double
to a Cube
, assuming the grid has a Tilt::Flat
.
pub fn sharp_to_cube(self) -> Cube
[src]
Convert a Double
to a Cube
, assuming the grid has a Tilt::Sharp
.
pub fn flat_neighbors(self) -> Vec<Self>
[src]
Calculates the Double
coordinates of the hexes surrounding the
calling instance, in the context of a HexGrid
whose hexes have the
Tilt::Flat
orientation.
pub fn sharp_neighbors(self) -> Vec<Self>
[src]
Calculates the Double
coordinates of the hexes surrounding the
calling instance, in the context of a HexGrid
whose hexes have the
Tilt::Sharp
orientation.
pub fn flat_dist(self, other: Self) -> i32
[src]
Calculates the distance between two Double
coordinates in the
context of a HexGrid
whose hexes have the Tilt::Flat
orientation.
Examples
use chickenwire::coordinate::Double; let coord_1 = Double::force_from_coords(1, 1); let coord_2 = Double::force_from_coords(2, 2); let coord_3 = Double::force_from_coords(4, 2); // Determines the distance between any two hexes assert_eq!(Double::ORIGIN.flat_dist(coord_1), 1); assert_eq!(coord_1.flat_dist(coord_2), 1); assert_eq!(coord_1.flat_dist(coord_3), 3); // The distance between two identical coordinates is always zero assert_eq!(coord_1.flat_dist(coord_1), 0); assert_eq!(coord_1.sharp_dist(coord_1), 0); // Ordering doesn't matter assert_eq!( coord_1.flat_dist(coord_2), coord_2.flat_dist(coord_1) ); // Distance may or may not depend upon hex orientation assert_eq!( coord_1.flat_dist(coord_2), coord_1.sharp_dist(coord_2) ); assert_ne!( coord_1.flat_dist(coord_3), coord_1.sharp_dist(coord_3) );
pub fn sharp_dist(self, other: Self) -> i32
[src]
Calculates the distance between two Double
coordinates in the
context of a HexGrid
whose hexes have the Tilt::Sharp
orientation.
Examples
use chickenwire::coordinate::double::Double; let coord_1 = Double::force_from_coords(1, 1); let coord_2 = Double::force_from_coords(2, 2); let coord_3 = Double::force_from_coords(4, 2); // Determines the distance between any two hexes assert_eq!(Double::ORIGIN.sharp_dist(coord_1), 1); assert_eq!(coord_1.sharp_dist(coord_2), 1); assert_eq!(coord_1.sharp_dist(coord_3), 2); // The distance between two identical coordinates is always zero assert_eq!(coord_1.sharp_dist(coord_1), 0); assert_eq!(coord_1.flat_dist(coord_1), 0); // Ordering doesn't matter assert_eq!( coord_1.sharp_dist(coord_2), coord_2.sharp_dist(coord_1) ); // Distance may or may not depend upon hex orientation assert_eq!( coord_1.sharp_dist(coord_2), coord_1.flat_dist(coord_2) ); assert_ne!( coord_1.sharp_dist(coord_3), coord_1.flat_dist(coord_3) );
Trait Implementations
impl From<(i32, i32)> for Double
[src]
Creates a Double
from an (i32, i32)
.
Panics
Panics when the sum of the tuple elements is odd, since this violates the
constraints of the Double
coordinate system.
Examples
use chickenwire::coordinate::double::Double; let double = Double::from((0, 2)); assert_eq!(double.col(), 0); assert_eq!(double.row(), 2);
impl From<MultiCoord> for Double
[src]
Creates a Double
from a MultiCoord
.
Panics
Panics when the MultiCoord
encodes an Axial
, Cube
, or Offset
.
fn from(coord: MultiCoord) -> Self
[src]
impl From<Double> for CoordSys
[src]
Creates a CoordSys::Double
from a Double
.
impl From<Double> for MultiCoord
[src]
Creates a MultiCoord
from a Double
.
impl Ord for Double
[src]
fn cmp(&self, other: &Double) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
clamp
)Restrict a value to a certain interval. Read more
impl PartialOrd<Double> for Double
[src]
fn partial_cmp(&self, other: &Double) -> Option<Ordering>
[src]
fn lt(&self, other: &Double) -> bool
[src]
fn le(&self, other: &Double) -> bool
[src]
fn gt(&self, other: &Double) -> bool
[src]
fn ge(&self, other: &Double) -> bool
[src]
impl PartialEq<Double> for Double
[src]
impl Default for Double
[src]
impl Clone for Double
[src]
fn clone(&self) -> Double
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Eq for Double
[src]
impl Copy for Double
[src]
impl Debug for Double
[src]
impl Add<Double> for Double
[src]
Adds two Double
coordinates in the same manner as vectors.
Examples
use chickenwire::coordinate::double::Double; assert_eq!( Double::force_from_coords(-2, 2) + Double::force_from_coords(3, 5), Double::force_from_coords(1, 7) );
type Output = Self
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self
[src]
impl Sub<Double> for Double
[src]
Subtracts two Double
coordinates in the same manner as vectors.
Examples
use chickenwire::coordinate::double::Double; assert_eq!( Double::force_from_coords(3, 1) - Double::force_from_coords(6, 2), Double::force_from_coords(-3, -1) );
type Output = Self
The resulting type after applying the -
operator.
fn sub(self, other: Self) -> Self
[src]
impl Mul<i32> for Double
[src]
Multiplies a Double
coordinate by an i32
scalar, like a vector.
Examples
use chickenwire::coordinate::double::Double; assert_eq!( Double::force_from_coords(1, 3) * 5, Double::force_from_coords(5, 15) ); assert_eq!( 0 * Double::force_from_coords(100, 2), Double::ORIGIN ); assert_eq!( Double::force_from_coords(1, 3) * (-1), Double::force_from_coords(-1, -3) );
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, n: i32) -> Self
[src]
impl Mul<Double> for i32
[src]
type Output = Double
The resulting type after applying the *
operator.
fn mul(self, coord: Double) -> Double
[src]
impl Hash for Double
[src]
Auto Trait Implementations
impl Unpin for Double
impl Send for Double
impl Sync for Double
impl UnwindSafe for Double
impl RefUnwindSafe for Double
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<N> NodeTrait for N where
N: Copy + Ord + Hash,
[src]
N: Copy + Ord + Hash,
impl<M> Measure for M where
M: Debug + PartialOrd<M> + Add<M, Output = M> + Default + Clone,
[src]
M: Debug + PartialOrd<M> + Add<M, Output = M> + Default + Clone,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,