annotation cleanup
add grid.mul() and grid.div()
This commit is contained in:
parent
7b52ce4fba
commit
4ab6519321
@ -5,6 +5,7 @@ from typing import Any, List, Union
|
|||||||
|
|
||||||
OFF = False
|
OFF = False
|
||||||
ON = True
|
ON = True
|
||||||
|
Numeric = Union[int, float]
|
||||||
|
|
||||||
|
|
||||||
class GridTransformation(Enum):
|
class GridTransformation(Enum):
|
||||||
@ -58,19 +59,31 @@ class Grid:
|
|||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
def add(self, pos: Coordinate, value: Numeric = 1) -> Numeric:
|
||||||
|
return self.set(pos, self.get(pos) + value)
|
||||||
|
|
||||||
|
def sub(self, pos: Coordinate, value: Numeric = 1) -> Numeric:
|
||||||
|
return self.set(pos, self.get(pos) - value)
|
||||||
|
|
||||||
|
def mul(self, pos: Coordinate, value: Numeric = 1) -> Numeric:
|
||||||
|
return self.set(pos, self.get(pos) * value)
|
||||||
|
|
||||||
|
def div(self, pos: Coordinate, value: Numeric = 1) -> Numeric:
|
||||||
|
return self.set(pos, self.get(pos) / value)
|
||||||
|
|
||||||
def get(self, pos: Coordinate) -> Any:
|
def get(self, pos: Coordinate) -> Any:
|
||||||
if pos in self.__grid:
|
if pos in self.__grid:
|
||||||
return self.__grid[pos]
|
return self.__grid[pos]
|
||||||
else:
|
else:
|
||||||
return self.__default
|
return self.__default
|
||||||
|
|
||||||
def getOnCount(self):
|
def getOnCount(self) -> int:
|
||||||
return len(self.__grid)
|
return len(self.__grid)
|
||||||
|
|
||||||
def isSet(self, pos: Coordinate) -> bool:
|
def isSet(self, pos: Coordinate) -> bool:
|
||||||
return pos in self.__grid
|
return pos in self.__grid
|
||||||
|
|
||||||
def getCorners(self):
|
def getCorners(self) -> List[Coordinate]:
|
||||||
if not self.mode3D:
|
if not self.mode3D:
|
||||||
return [
|
return [
|
||||||
Coordinate(self.minX, self.minY),
|
Coordinate(self.minX, self.minY),
|
||||||
@ -100,16 +113,10 @@ class Grid:
|
|||||||
else:
|
else:
|
||||||
return self.minX <= pos.x <= self.maxX and self.minY <= pos.y <= self.maxY
|
return self.minX <= pos.x <= self.maxX and self.minY <= pos.y <= self.maxY
|
||||||
|
|
||||||
def add(self, pos: Coordinate, value: Union[float, int] = 1) -> Union[float, int]:
|
def getActiveCells(self) -> List[Coordinate]:
|
||||||
return self.set(pos, self.get(pos) + value)
|
|
||||||
|
|
||||||
def sub(self, pos: Coordinate, value: Union[float, int] = 1) -> Union[float, int]:
|
|
||||||
return self.set(pos, self.get(pos) - value)
|
|
||||||
|
|
||||||
def getActiveCells(self):
|
|
||||||
return list(self.__grid.keys())
|
return list(self.__grid.keys())
|
||||||
|
|
||||||
def getSum(self, includeNegative: bool = True):
|
def getSum(self, includeNegative: bool = True) -> Numeric:
|
||||||
grid_sum = 0
|
grid_sum = 0
|
||||||
for value in self.__grid.values():
|
for value in self.__grid.values():
|
||||||
if includeNegative or value > 0:
|
if includeNegative or value > 0:
|
||||||
@ -129,8 +136,7 @@ class Grid:
|
|||||||
else:
|
else:
|
||||||
return [x for x in neighbours if self.get(x) != self.__default]
|
return [x for x in neighbours if self.get(x) != self.__default]
|
||||||
|
|
||||||
def getNeighbourSum(self, pos: Coordinate, includeNegative: bool = True, includeDiagonal: bool = True) \
|
def getNeighbourSum(self, pos: Coordinate, includeNegative: bool = True, includeDiagonal: bool = True) -> Numeric:
|
||||||
-> Union[float, int]:
|
|
||||||
neighbour_sum = 0
|
neighbour_sum = 0
|
||||||
for neighbour in pos.getNeighbours(
|
for neighbour in pos.getNeighbours(
|
||||||
includeDiagonal=includeDiagonal,
|
includeDiagonal=includeDiagonal,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user