Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
953dcc9505
@ -62,7 +62,7 @@ class Coordinate:
|
|||||||
def getNeighbours(self, includeDiagonal: bool = True, minX: int = -inf, minY: int = -inf,
|
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]:
|
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 includeDiagonal: include diagonal neighbours
|
||||||
:param minX: ignore all neighbours that would have an X value below this
|
: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
|
:param maxZ: ignore all neighbours that would have an Z value above this
|
||||||
:return: list of Coordinate
|
:return: list of Coordinate
|
||||||
"""
|
"""
|
||||||
neighbourList = []
|
|
||||||
if self.z is None:
|
if self.z is None:
|
||||||
if includeDiagonal:
|
if includeDiagonal:
|
||||||
nb_list = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
|
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:
|
class Shape:
|
||||||
top_left: Coordinate
|
|
||||||
bottom_right: Coordinate
|
|
||||||
mode_3d: bool
|
|
||||||
|
|
||||||
def __init__(self, top_left: Coordinate, bottom_right: Coordinate):
|
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
|
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.bottom_right = bottom_right
|
||||||
self.mode_3d = top_left.z is not None and bottom_right.z is not None
|
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:
|
if not self.mode_3d:
|
||||||
return (self.bottom_right.x - self.top_left.x + 1) * (self.bottom_right.y - self.top_left.y + 1)
|
return (self.bottom_right.x - self.top_left.x + 1) * (self.bottom_right.y - self.top_left.y + 1)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -28,3 +28,11 @@ def triangular(n: int) -> int:
|
|||||||
0, 1, 3, 6, 10, 15, ...
|
0, 1, 3, 6, 10, 15, ...
|
||||||
"""
|
"""
|
||||||
return n * (n + 1) // 2
|
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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user