Fix width and height calculations
This commit is contained in:
@@ -76,22 +76,25 @@ class Tetromino(NamedTuple):
|
||||
@property
|
||||
@lru_cache(maxsize=16)
|
||||
def bounding_box_width(self):
|
||||
def ctz(arr: list):
|
||||
for i, c in enumerate(reversed(arr)):
|
||||
if c:
|
||||
return i
|
||||
return len(arr)
|
||||
|
||||
return max(map(lambda r: len(r) - ctz(r), self.shape))
|
||||
start = self.width
|
||||
end = 0
|
||||
for row in self.shape:
|
||||
for x, cell in enumerate(row):
|
||||
if cell:
|
||||
end = max(end, x + 1)
|
||||
start = min(start, x)
|
||||
return end - start
|
||||
|
||||
@property
|
||||
@lru_cache(maxsize=16)
|
||||
def bounding_box_height(self):
|
||||
for y, row in reversed(list(enumerate(self.shape))):
|
||||
for x, cell in enumerate(row):
|
||||
if cell:
|
||||
return y + 1
|
||||
return 0
|
||||
start = self.height
|
||||
end = 0
|
||||
for y, row in enumerate(self.shape):
|
||||
if any(row):
|
||||
end = max(end, y + 1)
|
||||
start = min(start, y)
|
||||
return end - start
|
||||
|
||||
def rotated(self, times: int):
|
||||
"""Return self rotated TIMES times to the right."""
|
||||
|
||||
Reference in New Issue
Block a user