Merge remote-tracking branch 'origin/master'

This commit is contained in:
Stefan Harmuth 2022-08-10 10:09:22 +02:00
commit 953dcc9505
2 changed files with 10 additions and 7 deletions

View File

@ -62,7 +62,7 @@ class Coordinate:
def getNeighbours(self, includeDiagonal: bool = True, minX: int = -inf, minY: int = -inf,
maxX: int = inf, maxY: int = inf, minZ: int = -inf, maxZ: int = inf) -> list[Coordinate]:
"""
Get a list of neighbouring coordinates
Get a list of neighbouring coordinates.
:param includeDiagonal: include diagonal neighbours
:param minX: ignore all neighbours that would have an X value below this
@ -73,7 +73,6 @@ class Coordinate:
:param maxZ: ignore all neighbours that would have an Z value above this
:return: list of Coordinate
"""
neighbourList = []
if self.z is None:
if includeDiagonal:
nb_list = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
@ -195,10 +194,6 @@ class Coordinate:
class Shape:
top_left: Coordinate
bottom_right: Coordinate
mode_3d: bool
def __init__(self, top_left: Coordinate, bottom_right: Coordinate):
"""
in 2D mode: top_left is the upper left corner and bottom_right the lower right
@ -211,7 +206,7 @@ class Shape:
self.bottom_right = bottom_right
self.mode_3d = top_left.z is not None and bottom_right.z is not None
def size(self):
def __len__(self):
if not self.mode_3d:
return (self.bottom_right.x - self.top_left.x + 1) * (self.bottom_right.y - self.top_left.y + 1)
else:

View File

@ -28,3 +28,11 @@ def triangular(n: int) -> int:
0, 1, 3, 6, 10, 15, ...
"""
return n * (n + 1) // 2
def pentagonal(n: int) -> int:
"""
A pentagonal number is a figurate number that extends the concept of triangular and square numbers to the pentagon
0, 1, 5, 12, 22, 35, ...
"""
return ((3 * n * n) - n) // 2