Struct hex2d::Coordinate[][src]

pub struct Coordinate<I: Integer = i32> {
    pub x: I,
    pub y: I,
}
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

Iterator over each coordinate in straight line from self to dest

Iterator over each coordinate in straight line from self to dest

Skip points on the border of two tiles

Iterator over each coordinate in straight line from self to dest

On edge condition the pair contains different members, otherwise it’s the same.

Z coordinate

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

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

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

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

The resulting type after applying the - operator.

Performs the unary - operation. Read more

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

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. 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

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

Serialize this value into the given Serde serializer. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.