Struct hex2d::Coordinate [] [src]

pub struct Coordinate<I: Integer = i32> {
    pub x: I,
    pub y: I,
}

Coordinate on 2d hexagonal grid

Fields

x coordinate

y coordinate

Methods

impl<I: Integer> Coordinate<I>
[src]

[src]

Create new Coord from x and y

[src]

Old name for nearest

[src]

Round x, y float to nearest hex coordinates

[src]

Old name for nearest_lossy

[src]

Round x, y float to nearest hex coordinates

Return None, if exactly on the border of two hex coordinates

[src]

Old name for nearest_with_offset

[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.

[src]

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.

[src]

Old name for to_pixel

[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.

[src]

Convert to integer pixel coordinates using spacing, where the parameters mean the width and height multiplications

[src]

Scale coordinate by a factor s

[src]

Array with all the neighbors of a coordinate

[src]

Rotate self around a point (0, 0, 0) using angle of rotation a

[src]

Rotate self around a center using angle of rotation a

[src]

Execute f for each coordinate in straight line from self to dest

[src]

Execute f for each coordinate in straight line from self to dest

Skip points on the border of two tiles

[src]

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.

[src]

Construct a straight line to a dest

[src]

Construct a straight line to a dest

Skip points on the border of two tiles

[src]

Construct a straight line to a dest

[src]

Z coordinate

[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));
}

[src]

Directions that lead from center to a given point.

Returns an array of one or two dirs.

[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));
}

[src]

Directions from self to coord

[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

[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

[src]

Distance between two Coordinates

[src]

All coordinates in radius r

[src]

Execute f for all coordinates in radius r

[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 &center.neighbors() {
    for &ring_c in &c.ring(5, Spin::CCW(XY)) {
        assert_eq!(c.distance(ring_c), 5);
    }
}

[src]

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]

[src]

Returns a copy of the value. Read more

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]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl<I: Hash + Integer> Hash for Coordinate<I>
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<I: Debug + Integer> Debug for Coordinate<I>
[src]

[src]

Formats the value using the given formatter.

impl<I: Ord + Integer> Ord for Coordinate<I>
[src]

[src]

This method returns an Ordering between self and other. Read more

1.22.0
[src]

Compares and returns the maximum of two values. Read more

1.22.0
[src]

Compares and returns the minimum of two values. Read more

impl<I: PartialOrd + Integer> PartialOrd for Coordinate<I>
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[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]

[src]

Deserialize a value using a Decoder.

impl<I: Integer> ToCoordinate<I> for Coordinate<I>
[src]

[src]

Convert to Coordinate part of this data

impl<I: Integer, T: ToCoordinate<I>> Add<T> for Coordinate<I>
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl<I: Integer, T: ToCoordinate<I>> Sub<T> for Coordinate<I>
[src]

The resulting type after applying the - operator.

[src]

Performs the - operation.

impl<I: Integer> Neg for Coordinate<I>
[src]

The resulting type after applying the - operator.

[src]

Performs the unary - operation.