Skip to main content

OffsetPosition

Trait OffsetPosition 

Source
pub trait OffsetPosition:
    Eq
    + Hash
    + Clone
    + Add<Self::Offset, Output = Self, Output = Self>
    + Add<Self::Diagonal> {
    type Offset: Neg<Output = Self::Offset> + Clone;
    type Diagonal: Neg<Output = Self::Diagonal> + Clone;

    // Required methods
    fn all_offsets() -> impl Iterator<Item = Self::Offset>;
    fn all_diagonals() -> impl Iterator<Item = Self::Diagonal>;
}
Expand description

Position types for tiles that provides abstract access to all of the position’s adjacent positions.

Required Associated Types§

Source

type Offset: Neg<Output = Self::Offset> + Clone

An offset from a position to one of its adjacent positions. Since OffsetPosition implements Add<Offset, Ouput=Self>, an offset can be added to a position to get the adjacent position.

Source

type Diagonal: Neg<Output = Self::Diagonal> + Clone

A diagonal offset from a position to one of the positions that are nearby but not adjacent. Since OffsetPosition implements Add<Diagonal, Ouput=Self>, a diagonal can be added to a position to get the diagonal position.

Required Methods§

Source

fn all_offsets() -> impl Iterator<Item = Self::Offset>

An iterator over all offsets, giving access to all adjacent positions from any position by using position arithmetic: position + offset == adjacent position.

Source

fn all_diagonals() -> impl Iterator<Item = Self::Diagonal>

An iterator over all diagonals, giving access to nearby non-adjacent positions by using position arithmetic: position + diagonal == nearby position.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§