Struct hex2d::Coordinate [−][src]
Expand description
Coordinate on 2d hexagonal grid
Fields
x: I
x
coordinate
y: I
y
coordinate
Implementations
Create new Coord from x
and y
Round x, y float to nearest hex coordinates
Round x, y float to nearest hex coordinates
Return None, if exactly on the border of two hex coordinates
Find the hex containing a pixel. The origin of the pixel coordinates is the center of the hex at (0,0) in hex coordinates.
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.
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.
Convert to integer pixel coordinates using spacing
, where the
parameters mean the width and height multiplications
Scale coordinate by a factor s
Array with all the neighbors of a coordinate
Rotate self around a point (0, 0, 0)
using angle of rotation a
Rotate self
around a center
using angle of rotation a
pub fn line_to_iter(&self, dest: Coordinate<I>) -> LineTo<I>ⓘNotable traits for LineTo<I>impl<I: Integer + Signed + Copy + NumCast + FromPrimitive + ToPrimitive + CheckedAdd + AddAssign> Iterator for LineTo<I> type Item = Coordinate<I>;
pub fn line_to_iter(&self, dest: Coordinate<I>) -> LineTo<I>ⓘNotable traits for LineTo<I>impl<I: Integer + Signed + Copy + NumCast + FromPrimitive + ToPrimitive + CheckedAdd + AddAssign> Iterator for LineTo<I> type Item = Coordinate<I>;
impl<I: Integer + Signed + Copy + NumCast + FromPrimitive + ToPrimitive + CheckedAdd + AddAssign> Iterator for LineTo<I> type Item = Coordinate<I>;
Iterator over each coordinate in straight line from self
to dest
pub fn line_to_lossy_iter(&self, dest: Coordinate<I>) -> LineToLossy<I>ⓘNotable traits for LineToLossy<I>impl<I: Integer + Signed + Copy + NumCast + FromPrimitive + ToPrimitive + CheckedAdd + AddAssign> Iterator for LineToLossy<I> type Item = Coordinate<I>;
pub fn line_to_lossy_iter(&self, dest: Coordinate<I>) -> LineToLossy<I>ⓘNotable traits for LineToLossy<I>impl<I: Integer + Signed + Copy + NumCast + FromPrimitive + ToPrimitive + CheckedAdd + AddAssign> Iterator for LineToLossy<I> type Item = Coordinate<I>;
impl<I: Integer + Signed + Copy + NumCast + FromPrimitive + ToPrimitive + CheckedAdd + AddAssign> Iterator for LineToLossy<I> type Item = Coordinate<I>;
Iterator over each coordinate in straight line from self
to dest
Skip points on the border of two tiles
pub fn line_to_with_edge_detection_iter(
&self,
dest: Coordinate<I>
) -> LineToWithEdgeDetection<I>ⓘNotable traits for LineToWithEdgeDetection<I>impl<I: Integer + Signed + Copy + NumCast + FromPrimitive + ToPrimitive + CheckedAdd + AddAssign> Iterator for LineToWithEdgeDetection<I> type Item = (Coordinate<I>, Coordinate<I>);
pub fn line_to_with_edge_detection_iter(
&self,
dest: Coordinate<I>
) -> LineToWithEdgeDetection<I>ⓘNotable traits for LineToWithEdgeDetection<I>impl<I: Integer + Signed + Copy + NumCast + FromPrimitive + ToPrimitive + CheckedAdd + AddAssign> Iterator for LineToWithEdgeDetection<I> type Item = (Coordinate<I>, Coordinate<I>);
impl<I: Integer + Signed + Copy + NumCast + FromPrimitive + ToPrimitive + CheckedAdd + AddAssign> Iterator for LineToWithEdgeDetection<I> type Item = (Coordinate<I>, Coordinate<I>);
Iterator over each coordinate in straight line from self
to dest
On edge condition the pair contains different members, otherwise it’s the same.
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)); }
Directions that lead from center to a given point.
Returns an array of one or two directions.
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)); }
Directions from self to coord
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
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
Distance between two Coordinates
pub fn range_iter(&self, r: I) -> Range<I>ⓘNotable traits for Range<I>impl<I: Integer + Signed + Copy + NumCast + FromPrimitive + CheckedAdd + AddAssign> Iterator for Range<I> type Item = Coordinate<I>;
pub fn range_iter(&self, r: I) -> Range<I>ⓘNotable traits for Range<I>impl<I: Integer + Signed + Copy + NumCast + FromPrimitive + CheckedAdd + AddAssign> Iterator for Range<I> type Item = Coordinate<I>;
impl<I: Integer + Signed + Copy + NumCast + FromPrimitive + CheckedAdd + AddAssign> Iterator for Range<I> type Item = Coordinate<I>;
An iterator over all coordinates in radius r
Iterator over each coordinate in a ring
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_iter(5, Spin::CCW(XY)) { assert_eq!(c.distance(ring_c), 5); } }
Trait Implementations
type Output = Coordinate<I>
type Output = Coordinate<I>
The resulting type after applying the +
operator.
Performs the +
operation. Read more
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
type Output = Coordinate<I>
type Output = Coordinate<I>
The resulting type after applying the -
operator.
Performs the unary -
operation. Read more
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
type Output = Coordinate<I>
type Output = Coordinate<I>
The resulting type after applying the -
operator.
Performs the -
operation. Read more
Auto Trait Implementations
impl<I> RefUnwindSafe for Coordinate<I> where
I: RefUnwindSafe,
impl<I> Send for Coordinate<I> where
I: Send,
impl<I> Sync for Coordinate<I> where
I: Sync,
impl<I> Unpin for Coordinate<I> where
I: Unpin,
impl<I> UnwindSafe for Coordinate<I> where
I: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more