divide optimizations

This commit is contained in:
Will McGugan
2022-07-11 12:45:54 +01:00
parent d7d1b6b197
commit def1f5d6ab
8 changed files with 51 additions and 26 deletions

View File

@@ -569,8 +569,27 @@ class Region(NamedTuple):
)
return new_region
def grow(self, margin: tuple[int, int, int, int]) -> Region:
"""Grow a region by adding spacing.
Args:
margin (Spacing): Defines how many cells to grow the Region by at each edge.
Returns:
Region: New region.
"""
top, right, bottom, left = margin
x, y, width, height = self
return Region(
x=x - left,
y=y - top,
width=max(0, width + left + right),
height=max(0, height + top + bottom),
)
def shrink(self, margin: tuple[int, int, int, int]) -> Region:
"""Shrink a region by pushing each edge inwards.
"""Shrink a region by subtracting spacing.
Args:
margin (Spacing): Defines how many cells to shrink the Region by at each edge.