From 47446f3f35c40b34f5f39a6495f71593afc5ee3e Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Thu, 22 Dec 2022 09:35:09 +0100 Subject: [PATCH] Grid.shift() - shift whole coordinate system --- tools/grid.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/grid.py b/tools/grid.py index d50d94b..4f9f708 100644 --- a/tools/grid.py +++ b/tools/grid.py @@ -287,6 +287,15 @@ class Grid: else: raise NotImplementedError(mode) + def shift(self, shift_x: int = None, shift_y: int = None): + self.minX, self.minY = self.minX + shift_x, self.minY + shift_y + self.maxX, self.maxY = self.maxX + shift_x, self.maxY + shift_y + coords = self.__grid + self.__grid = {} + for c, v in coords.items(): + nc = Coordinate(c.x + shift_x, c.y + shift_y) + self.set(nc, v) + def getPath_BFS(self, pos_from: Coordinate, pos_to: Coordinate, includeDiagonal: bool, walls: List[Any] = None, stop_at_first: Any = None) -> Union[None, List[Coordinate]]: queue = deque()