Struct cogs_gamedev::grids::coords::Coord [−][src]
Expand description
Unsigned-int coordinates
Fields
x: usize
y: usize
Implementations
Get this as an index into an array representing a 2d array.
(AKA, y * width + x
.)
Get a list of this coordinate’s orthagonal neighbors.
They are given in clockwise order starting with the neighbor to the north,
as if each of Direction4::DIRECTIONS
had been added to them.
If a neighbor is out of bounds, it is skipped in the output.
There may be 2, 3, or 4 neighbors:
- 2 if this is at
(0, 0)
- 3 if this is on an edge (
x
ory
are 0) - 4 otherwise.
assert_eq!( Coord::new(5, 7).neighbors4(), &[ Coord::new(5, 6), Coord::new(6, 7), Coord::new(5, 8), Coord::new(4, 7), ] ); // May return fewer than 4 neighbors assert_eq!( Coord::new(0, 5).neighbors4(), &[ Coord::new(0, 4), Coord::new(1, 5), Coord::new(0, 6), // Skip (-1, 5) for being out of bounds ] );
Get a list of this coordinate’s orthagonal and diagonal neighbors.
They are given in clockwise order starting with the neighbor to the north,
as if each of Direction8::DIRECTIONS
had been added to them.
If a neighbor is out of bounds, it is skipped in the output.
There may be 3, 5, or 8 neighbors:
- 3 if this is at
(0, 0)
- 5 if this is on an edge (
x
ory
are 0) - 8 otherwise.
assert_eq!( Coord::new(5, 7).neighbors8(), [ Coord::new(5, 6), Coord::new(6, 6), Coord::new(6, 7), Coord::new(6, 8), Coord::new(5, 8), Coord::new(4, 8), Coord::new(4, 7), Coord::new(4, 6), ] ); // May return fewer than 8 neighbors assert_eq!( Coord::new(0, 5).neighbors8(), &[ Coord::new(0, 4), Coord::new(1, 4), Coord::new(1, 5), Coord::new(1, 6), Coord::new(0, 6), // Skip (-1, 6) for being out of bounds // Skip (-1, 5) // Skip (-1, 4) ] );
Trait Implementations
Performs the +=
operation. Read more
Performs the *=
operation. Read more
Try to convert an ICoord to a Coord. Will return Error if the ICoord has any negatives in it.
Auto Trait Implementations
impl RefUnwindSafe for Coord
impl UnwindSafe for Coord
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V