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
|
||||
ON = True
|
||||
Numeric = Union[int, float]
|
||||
|
||||
|
||||
class GridTransformation(Enum):
|
||||
@ -58,19 +59,31 @@ class Grid:
|
||||
|
||||
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:
|
||||
if pos in self.__grid:
|
||||
return self.__grid[pos]
|
||||
else:
|
||||
return self.__default
|
||||
|
||||
def getOnCount(self):
|
||||
def getOnCount(self) -> int:
|
||||
return len(self.__grid)
|
||||
|
||||
def isSet(self, pos: Coordinate) -> bool:
|
||||
return pos in self.__grid
|
||||
|
||||
def getCorners(self):
|
||||
def getCorners(self) -> List[Coordinate]:
|
||||
if not self.mode3D:
|
||||
return [
|
||||
Coordinate(self.minX, self.minY),
|
||||
@ -100,16 +113,10 @@ class Grid:
|
||||
else:
|
||||
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]:
|
||||
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):
|
||||
def getActiveCells(self) -> List[Coordinate]:
|
||||
return list(self.__grid.keys())
|
||||
|
||||
def getSum(self, includeNegative: bool = True):
|
||||
def getSum(self, includeNegative: bool = True) -> Numeric:
|
||||
grid_sum = 0
|
||||
for value in self.__grid.values():
|
||||
if includeNegative or value > 0:
|
||||
@ -129,8 +136,7 @@ class Grid:
|
||||
else:
|
||||
return [x for x in neighbours if self.get(x) != self.__default]
|
||||
|
||||
def getNeighbourSum(self, pos: Coordinate, includeNegative: bool = True, includeDiagonal: bool = True) \
|
||||
-> Union[float, int]:
|
||||
def getNeighbourSum(self, pos: Coordinate, includeNegative: bool = True, includeDiagonal: bool = True) -> Numeric:
|
||||
neighbour_sum = 0
|
||||
for neighbour in pos.getNeighbours(
|
||||
includeDiagonal=includeDiagonal,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user