Struct hex2d::Coordinate
[−]
[src]
pub struct Coordinate<I: Integer = i32> { pub x: I, pub y: I, }
Coordinate on 2d hexagonal grid
Fields
x: I
x
coordinate
y: I
y
coordinate
Methods
impl<I: Integer> Coordinate<I>
[src]
fn new(x: I, y: I) -> Coordinate<I>
[src]
Create new Coord from x
and y
fn from_round(x: f32, y: f32) -> Coordinate<I>
[src]
Old name for nearest
fn nearest(x: f32, y: f32) -> Coordinate<I>
[src]
Round x, y float to nearest hex coordinates
fn from_round_lossy(x: f32, y: f32) -> Option<Coordinate<I>>
[src]
Old name for nearest_lossy
fn nearest_lossy(x: f32, y: f32) -> Option<Coordinate<I>>
[src]
Round x, y float to nearest hex coordinates
Return None, if exactly on the border of two hex coordinates
fn from_pixel_integer(
spacing: IntegerSpacing<I>,
v: (I, I)
) -> (Coordinate<I>, (I, I))
[src]
spacing: IntegerSpacing<I>,
v: (I, I)
) -> (Coordinate<I>, (I, I))
Old name for nearest_with_offset
fn from_pixel(x: f32, y: f32, spacing: Spacing) -> Coordinate<I>
[src]
Find the hex containing a pixel. The origin of the pixel coordinates is the center of the hex at (0,0) in hex coordinates.
fn nearest_with_offset(
spacing: IntegerSpacing<I>,
v: (I, I)
) -> (Coordinate<I>, (I, I))
[src]
spacing: IntegerSpacing<I>,
v: (I, I)
) -> (Coordinate<I>, (I, I))
Convert integer pixel coordinates v
using spacing
to nearest coordinate that has both
integer pixel coordinates lower or equal to v
. Also return offset (in integer pixels)
from that coordinate.
Useful for ASCII visualization.
fn to_pixel_float(&self, spacing: Spacing) -> (f32, f32)
[src]
Old name for to_pixel
fn to_pixel(&self, spacing: Spacing) -> (f32, f32)
[src]
Convert to pixel coordinates using spacing
, where the
parameter means the edge length of a hexagon.
This function is meant for graphical user interfaces where resolution is big enough that floating point calculation make sense.
fn to_pixel_integer(&self, spacing: IntegerSpacing<I>) -> (I, I)
[src]
Convert to integer pixel coordinates using spacing
, where the
parameters mean the width and height multiplications
fn scale(&self, s: I) -> Coordinate<I>
[src]
Scale coordinate by a factor s
fn neighbors(&self) -> [Coordinate<I>; 6]
[src]
Array with all the neighbors of a coordinate
fn rotate_around_zero(&self, a: Angle) -> Coordinate<I>
[src]
Rotate self around a point (0, 0, 0)
using angle of rotation a
fn rotate_around(&self, center: Coordinate<I>, a: Angle) -> Coordinate<I>
[src]
Rotate self
around a center
using angle of rotation a
fn for_each_in_line_to<F>(&self, dest: Coordinate<I>, f: F) where
F: FnMut(Coordinate<I>),
&'a I: Add<&'a I, Output = I>,
[src]
F: FnMut(Coordinate<I>),
&'a I: Add<&'a I, Output = I>,
Execute f
for each coordinate in straight line from self
to dest
fn for_each_in_line_to_lossy<F>(&self, dest: Coordinate<I>, f: F) where
F: FnMut(Coordinate<I>),
&'a I: Add<&'a I, Output = I>,
[src]
F: FnMut(Coordinate<I>),
&'a I: Add<&'a I, Output = I>,
Execute f
for each coordinate in straight line from self
to dest
Skip points on the border of two tiles
fn for_each_in_line_to_with_edge_detection<F>(&self, dest: Coordinate<I>, f: F) where
F: FnMut((Coordinate<I>, Coordinate<I>)),
&'a I: Add<&'a I, Output = I>,
[src]
F: FnMut((Coordinate<I>, Coordinate<I>)),
&'a I: Add<&'a I, Output = I>,
Execute f
for pairs of coordinates in straight line from self
to dest
On edge condition the pair contains different members, otherwise it's the same.
fn line_to(&self, dest: Coordinate<I>) -> Vec<Coordinate<I>> where
&'a I: Add<&'a I, Output = I>,
[src]
&'a I: Add<&'a I, Output = I>,
Construct a straight line to a dest
fn line_to_lossy(&self, dest: Coordinate<I>) -> Vec<Coordinate<I>> where
&'a I: Add<&'a I, Output = I>,
[src]
&'a I: Add<&'a I, Output = I>,
Construct a straight line to a dest
Skip points on the border of two tiles
fn line_to_with_edge_detection(
&self,
dest: Coordinate<I>
) -> Vec<(Coordinate<I>, Coordinate<I>)> where
&'a I: Add<&'a I, Output = I>,
[src]
&self,
dest: Coordinate<I>
) -> Vec<(Coordinate<I>, Coordinate<I>)> where
&'a I: Add<&'a I, Output = I>,
Construct a straight line to a dest
fn z(&self) -> I
[src]
Z coordinate
fn direction_from_center_cw(&self) -> Option<Direction>
[src]
Direction from center (0, 0)
to coordinate
In case of diagonals (edge of two major directions), prefers direction that is clockwise from the diagonal
Returns: None if is center
use hex2d::{Direction, Coordinate}; use hex2d::{Left, Right}; let center = Coordinate::new(0, 0); assert_eq!(center.direction_from_center_cw(), None); for &d in Direction::all() { assert_eq!((center + d).direction_from_center_cw(), Some(d)); assert_eq!((center + d + (d + Left)).direction_from_center_cw(), Some(d)); assert_eq!((center + d + (d + Right)).direction_from_center_cw(), Some(d + Right)); }
fn directions_from_center(&self) -> Vec<Direction>
[src]
Directions that lead from center to a given point.
Returns an array of one or two dirs.
fn direction_from_center_ccw(&self) -> Option<Direction>
[src]
Direction from center (0, 0)
to coordinate
In case of diagonals (edge of two major directions), prefers direction that is counter-clockwise from the diagonal.
Returns: None if is center
use hex2d::{Direction, Coordinate}; use hex2d::{Left, Right}; let center = Coordinate::new(0, 0); assert_eq!(center.direction_from_center_ccw(), None); for &d in Direction::all() { assert_eq!((center + d).direction_from_center_ccw(), Some(d)); assert_eq!((center + d + (d + Left)).direction_from_center_ccw(), Some(d + Left)); assert_eq!((center + d + (d + Right)).direction_from_center_ccw(), Some(d)); }
fn directions_to(&self, coord: Coordinate<I>) -> Vec<Direction>
[src]
Directions from self to coord
fn direction_to_cw(&self, coor: Coordinate<I>) -> Option<Direction>
[src]
Direction from self to coord
In case of diagonals (edge of two major directions), prefers direction that is clockwise from the diagonal.
Returns: None if is center
fn direction_to_ccw(&self, coor: Coordinate<I>) -> Option<Direction>
[src]
Direction from self to coor
In case of diagonals (edge of two major directions), prefers direction that is counter-clockwise from the diagonal.
Returns: None if is center
fn distance(&self, c: Coordinate<I>) -> I
[src]
Distance between two Coordinates
fn range(&self, r: I) -> Vec<Coordinate<I>> where
&'a I: Add<&'a I, Output = I>,
[src]
&'a I: Add<&'a I, Output = I>,
All coordinates in radius r
fn for_each_in_range<F>(&self, r: I, f: F) where
F: FnMut(Coordinate<I>),
&'a I: Add<&'a I, Output = I>,
[src]
F: FnMut(Coordinate<I>),
&'a I: Add<&'a I, Output = I>,
Execute f
for all coordinates in radius r
fn ring(&self, r: i32, s: Spin) -> Vec<Coordinate<I>>
[src]
A ring of radius r
, starting in a corner in a given Direction
Example: Elements in order for Ring of radius 2, Direction ZX, CCW
8
9 7
10 . 6
. .
11 x 5
. .
0 . 4
1 3
2
use hex2d::{Coordinate, Spin, XY}; let center = Coordinate::new(5, -1); for &c in ¢er.neighbors() { for &ring_c in &c.ring(5, Spin::CCW(XY)) { assert_eq!(c.distance(ring_c), 5); } }
fn for_each_in_ring<F>(&self, r: i32, s: Spin, f: F) where
F: FnMut(Coordinate<I>),
[src]
F: FnMut(Coordinate<I>),
Call f
for each coordinate in a ring
See ring
for a ring description.
Trait Implementations
impl<I: Copy + Integer> Copy for Coordinate<I>
[src]
impl<I: Clone + Integer> Clone for Coordinate<I>
[src]
fn clone(&self) -> Coordinate<I>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<I: Eq + Integer> Eq for Coordinate<I>
[src]
impl<I: PartialEq + Integer> PartialEq for Coordinate<I>
[src]
fn eq(&self, __arg_0: &Coordinate<I>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Coordinate<I>) -> bool
[src]
This method tests for !=
.
impl<I: Hash + Integer> Hash for Coordinate<I>
[src]
fn hash<__HI: Hasher>(&self, __arg_0: &mut __HI)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<I: Debug + Integer> Debug for Coordinate<I>
[src]
impl<I: Ord + Integer> Ord for Coordinate<I>
[src]
fn cmp(&self, __arg_0: &Coordinate<I>) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.22.0[src]
Compares and returns the minimum of two values. Read more
impl<I: PartialOrd + Integer> PartialOrd for Coordinate<I>
[src]
fn partial_cmp(&self, __arg_0: &Coordinate<I>) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Coordinate<I>) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Coordinate<I>) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Coordinate<I>) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Coordinate<I>) -> bool
[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<I: Decodable + Integer> Decodable for Coordinate<I>
[src]
fn decode<__DI: Decoder>(
__arg_0: &mut __DI
) -> Result<Coordinate<I>, __DI::Error>
[src]
__arg_0: &mut __DI
) -> Result<Coordinate<I>, __DI::Error>
Deserialize a value using a Decoder
.
impl<I: Integer> ToCoordinate<I> for Coordinate<I>
[src]
fn to_coordinate(&self) -> Coordinate<I>
[src]
Convert to Coordinate
part of this data
impl<I: Integer, T: ToCoordinate<I>> Add<T> for Coordinate<I>
[src]
type Output = Coordinate<I>
The resulting type after applying the +
operator.
fn add(self, c: T) -> Coordinate<I>
[src]
Performs the +
operation.
impl<I: Integer, T: ToCoordinate<I>> Sub<T> for Coordinate<I>
[src]
type Output = Coordinate<I>
The resulting type after applying the -
operator.
fn sub(self, c: T) -> Coordinate<I>
[src]
Performs the -
operation.
impl<I: Integer> Neg for Coordinate<I>
[src]
type Output = Coordinate<I>
The resulting type after applying the -
operator.
fn neg(self) -> Coordinate<I>
[src]
Performs the unary -
operation.