11import numpy as np
22import matplotlib .pyplot as plt
33from enum import Enum
4+ from typing import Tuple , TypeAlias
45
6+ Numpy2DArray : TypeAlias = np .ndarray [Tuple [int , int ], np .dtype [np .int_ ]]
7+ Numpy1DArray : TypeAlias = np .ndarray [np .dtype [np .int_ ]]
58
69class Position :
710 x : int
@@ -11,7 +14,7 @@ def __init__(self, x: int, y: int):
1114 self .x = x
1215 self .y = y
1316
14- def as_ndarray (self ) -> np . ndarray [ int , int ] :
17+ def as_ndarray (self ) -> Numpy1DArray :
1518 return np .array ([self .x , self .y ])
1619
1720 def __add__ (self , other ):
@@ -46,8 +49,8 @@ class ObstacleArrangement(Enum):
4649
4750class Grid :
4851 # Set in constructor
49- grid_size = None
50- grid = None
52+ grid_size : Numpy1DArray
53+ grid : Numpy2DArray
5154 obstacle_paths : list [list [Position ]] = []
5255 # Obstacles will never occupy these points. Useful to avoid impossible scenarios
5356 obstacle_avoid_points = []
@@ -60,7 +63,7 @@ class Grid:
6063
6164 def __init__ (
6265 self ,
63- grid_size : np . ndarray [ int , int ] ,
66+ grid_size : Numpy1DArray ,
6467 num_obstacles : int = 40 ,
6568 obstacle_avoid_points : list [Position ] = [],
6669 obstacle_arrangement : ObstacleArrangement = ObstacleArrangement .RANDOM ,
@@ -180,7 +183,7 @@ def obstacle_arrangement_1(self, obs_count: int) -> list[list[Position]]:
180183 Check if the given position is valid at time t
181184
182185 input:
183- position (np.ndarray[int, int] ): (x, y) position
186+ position (Position ): (x, y) position
184187 t (int): time step
185188
186189 output:
@@ -218,7 +221,7 @@ def inside_grid_bounds(self, position: Position) -> bool:
218221 Sample a random position that is within the grid's boundaries
219222
220223 output:
221- np.ndarray[int, int] : (x, y) position
224+ Position : (x, y) position
222225 """
223226 def sample_random_position (self ) -> Position :
224227 return Position (
0 commit comments