/// Returns iterator over [`Position`]s neighbor [`Position`]s. Filters out positions which
/// are outside given width and height bounds. Positions are returned in row-major order
/// starting from lower bound of the coordinates.
///
/// # Examples
/// ```
/// use mineraker::position::Position;
///
/// // Position which is against the lower horizontal bound.
/// let position = Position::new(1, 0);
/// let neighbors: Vec<Position> = position.neighbors(8, 8).collect();
///
/// assert_eq!(neighbors, [
///     Position::new(0, 0),
///     Position::new(2, 0),
///     Position::new(0, 1),
///     Position::new(1, 1),
///     Position::new(2, 1),
/// ]);
/// ```
Returns iterator over [`Position`]s neighbor [`Position`]s. Filters out positions which
are outside given width and height bounds. Positions are returned in row-major order
starting from lower bound of the coordinates.
Returns iterator over [ ` Position ` ] s neighbor [ ` Position ` ] s . Filters out positions which are outside given width and height bounds . Positions are returned in row - major order starting from lower bound of the coordinates .
pub fn neighbors(self, width: usize, height: usize) -> impl Iterator<Item = Self> {
        let (x, y) = (self.x, self.y);
        // Use wrapping_sub to wrap around to usize::MAX on zero values to always filter them out.
        [
            Position::new(x.wrapping_sub(1), y.wrapping_sub(1)),
            Position::new(x, y.wrapping_sub(1)),
            Position::new(x + 1, y.wrapping_sub(1)),
            Position::new(x.wrapping_sub(1), y),
            Position::new(x + 1, y),
            Position::new(x.wrapping_sub(1), y + 1),
            Position::new(x, y + 1),
            Position::new(x + 1, y + 1),
        ]
        .into_iter()
        .filter(move |pos| pos.x < width && pos.y < height)
    }
pub fn neighbors ( self , width : usize , height : usize ) -> impl Iterator < Item = Self > { let ( x , y ) = ( self . x , self . y ) ; // Use wrapping_sub to wrap around to usize::MAX on zero values to always filter them out. [ Position :: new ( x . wrapping_sub ( 1 ) , y . wrapping_sub ( 1 ) ) , Position :: new ( x , y . wrapping_sub ( 1 ) ) , Position :: new ( x + 1 , y . wrapping_sub ( 1 ) ) , Position :: new ( x . wrapping_sub ( 1 ) , y ) , Position :: new ( x + 1 , y ) , Position :: new ( x . wrapping_sub ( 1 ) , y + 1 ) , Position :: new ( x , y + 1 ) , Position :: new ( x + 1 , y + 1 ) , ] . into_iter ( ) . filter ( move | pos | pos . x < width && pos . y < height ) }
Returns iterator over [`Position`]s neighbor [`Position`]s. Filters out positions which
are outside given width and height bounds.
Returns iterator over [ ` Position ` ] s neighbor [ ` Position ` ] s . Filters out positions which are outside given width and height bounds .
self
width
usize
height
usize
examples
```
use mineraker::position::Position.

Position which is against the lower horizontal bound.
let position = Position::new(1, 0);
let neighbors: Vec = position.neighbors(8, 8).collect().


` ` ` use mineraker :: position :: Position . Position which is against the lower horizontal bound . let position = Position :: new ( 1 0 ) ; let neighbors : Vec = position . neighbors ( 8 8 ) . collect () .