/// Returns a point 1 unit away in the direction indicated. Grid origin is the most Southwest point
Returns a point 1 unit away in the direction indicated. Grid origin is the most Southwest point
Returns a point 1 unit away in the direction indicated . Grid origin is the most Southwest point
pub fn relative_point(
        &self,
        board: &GameBoard,
        direction: &GridDirection,
        length: i32,
    ) -> Option<Point> {
        let destination = match direction {
            GridDirection::North => Point {
                x: self.x,
                y: self.y + length,
            },
            GridDirection::NorthEast => Point {
                x: self.x + length,
                y: self.y + length,
            },
            GridDirection::East => Point {
                x: self.x + length,
                y: self.y,
            },
            GridDirection::SouthEast => Point {
                x: self.x + length,
                y: self.y - length,
            },
            GridDirection::South => Point {
                x: self.x,
                y: self.y - length,
            },
            GridDirection::SouthWest => Point {
                x: self.x - length,
                y: self.y - length,
            },
            GridDirection::West => Point {
                x: self.x - length,
                y: self.y,
            },
            GridDirection::NorthWest => Point {
                x: self.x - length,
                y: self.y + length,
            },
        };
        if !destination.is_on_board(board) {
            None
        } else {
            Some(destination)
        }
    }
pub fn relative_point ( & self , board : & GameBoard , direction : & GridDirection , length : i32 , ) -> Option < Point > { let destination = match direction { GridDirection :: North => Point { x : self . x , y : self . y + length , } , GridDirection :: NorthEast => Point { x : self . x + length , y : self . y + length , } , GridDirection :: East => Point { x : self . x + length , y : self . y , } , GridDirection :: SouthEast => Point { x : self . x + length , y : self . y - length , } , GridDirection :: South => Point { x : self . x , y : self . y - length , } , GridDirection :: SouthWest => Point { x : self . x - length , y : self . y - length , } , GridDirection :: West => Point { x : self . x - length , y : self . y , } , GridDirection :: NorthWest => Point { x : self . x - length , y : self . y + length , } , } ; if ! destination . is_on_board ( board ) { None } else { Some ( destination ) } }
Returns a point 1 unit away in the direction indicated.
Returns a point 1 unit away in the direction indicated .
&self
board
&GameBoard
direction
&GridDirection
length
i32