Skip to content

Commit

Permalink
fix: points_to_numpy_array now filters out outofbounds
Browse files Browse the repository at this point in the history
  • Loading branch information
eladyaniv01 committed Aug 13, 2020
1 parent 486f0f9 commit aedf9d2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
21 changes: 20 additions & 1 deletion MapAnalyzer/MapData.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,27 @@ def points_to_numpy_array(
"""
rows, cols = self.path_arr.shape
arr = np.zeros((rows, cols), dtype=np.uint8)
if isinstance(points, set):
points = list(points)

def in_bounds_x(x):
width = arr.shape[0] - 1
if 0 < x < width:
return x
return 0

def in_bounds_y(y):
height = arr.shape[1] - 1
if 0 < y < height:
return y
return 0

x_vec = np.vectorize(in_bounds_x)
y_vec = np.vectorize(in_bounds_y)
indices = self.points_to_indices(points)
arr[indices] = 1
x = x_vec(indices[0])
y = y_vec(indices[1])
arr[x, y] = 1
return arr

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion MapAnalyzer/Pather.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def pathfind(self, start: Tuple[int, int], goal: Tuple[int, int], grid: Optional
start = int(start[0]), int(start[1])
goal = int(goal[0]), int(goal[1])
else:
self.map_data.logger.error(PatherNoPointsException(start=start, goal=goal))
self.map_data.logger.warning(PatherNoPointsException(start=start, goal=goal))
return None
if grid is None:
grid = self.get_pyastar_grid()
Expand Down
10 changes: 5 additions & 5 deletions MapAnalyzer/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
19: "azure",
20: "azure"
}
LOG_FORMAT = "<w><bold>{time:YY:MM:DD:HH:mm:ss} |" \
" <level>{level: <8} </level>| <green>{name: ^15}</green> |" \
" {function: ^15} |" \
" {line: >4} |" \
" <level>{level.icon} {message}</level></bold></w>"
LOG_FORMAT = "<w><bold>{time:YY:MM:DD:HH:mm:ss}|" \
"<level>{level: <8}</level>|<green>{name: ^15}</green>|" \
"{function: ^15}|" \
"{line: >4}|" \
"<level>{level.icon}{message}</level></bold></w>"

0 comments on commit aedf9d2

Please sign in to comment.