Struct cogs_gamedev::grids::coords::ICoord[][src]

pub struct ICoord {
    pub x: isize,
    pub y: isize,
}
Expand description

Signed-int coordinates

Fields

x: isizey: isize

Implementations

Create a new ICoord

Return the quadrant this coordinate is in.

  • 1: +X, +Y
  • 2: -X, +Y
  • 3: -X, -Y
  • 4: +X, -Y

Zeroes are treated as positive.

assert_eq!(ICoord::new(4, 5).quadrant(), 1);
assert_eq!(ICoord::new(-3, -2).quadrant(), 3);
// Zero is treated as positive
assert_eq!(ICoord::new(0, -8).quadrant(), 4);
assert_eq!(ICoord::new(0, 0).quadrant(), 1);

Try to convert this to a Coord. Returns None in case any part is negative.

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.


assert_eq!(
    ICoord::new(5, 7).neighbors4(),
    [
        ICoord::new(5, 6),
        ICoord::new(6, 7),
        ICoord::new(5, 8),
        ICoord::new(4, 7),
    ]
);

let origin = ICoord::new(-7, -12);
assert_eq!(
    origin.neighbors4()[..],
    Direction4::DIRECTIONS.iter().map(|dir| origin + *dir).collect::<Vec<_>>()[..],
);

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.


assert_eq!(
    ICoord::new(5, 7).neighbors8(),
    [
        ICoord::new(5, 6),
        ICoord::new(6, 6),
        ICoord::new(6, 7),
        ICoord::new(6, 8),
        ICoord::new(5, 8),
        ICoord::new(4, 8),
        ICoord::new(4, 7),
        ICoord::new(4, 6),
    ]
);

let origin = ICoord::new(-7, -12);
assert_eq!(
    origin.neighbors8()[..],
    Direction8::DIRECTIONS.iter().map(|dir| origin + *dir).collect::<Vec<_>>()[..],
);

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

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

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

Formats the value using the given formatter. Read more

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 * operation. Read more

Performs the *= operation. Read more

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

This method tests for !=.

Try to convert an ICoord to a Coord. Will return Error if the ICoord has any negatives in it.

The type returned in the event of a conversion error.

Performs the conversion.

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

Converts the given value to a String. 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.