Skip to content

Commit

Permalink
new names and defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jul 30, 2021
1 parent 3edcfda commit 2967fc0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/textual/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def clamp(value: T, minimum: T, maximum: T) -> T:
Returns:
T: New value that is not less than the minimum or greater than the maximum.
"""
if minimum > maximum:
maximum, minimum = minimum, maximum
if value < minimum:
return minimum
elif value > maximum:
Expand All @@ -28,8 +30,8 @@ def clamp(value: T, minimum: T, maximum: T) -> T:
class Offset(NamedTuple):
"""A point defined by x and y coordinates."""

x: int
y: int
x: int = 0
y: int = 0

@property
def is_origin(self) -> bool:
Expand Down Expand Up @@ -76,7 +78,7 @@ def __bool__(self) -> bool:

@property
def area(self) -> int:
"""Get the area of the dimensions.
"""Get the area of the size.
Returns:
int: Area in cells.
Expand All @@ -90,7 +92,7 @@ def region(self) -> Region:
return Region(0, 0, width, height)

def contains(self, x: int, y: int) -> bool:
"""Check if a point is in the region.
"""Check if a point is in the size.
Args:
x (int): X coordinate (column)
Expand All @@ -103,7 +105,7 @@ def contains(self, x: int, y: int) -> bool:
return width > x >= 0 and height > y >= 0

def contains_point(self, point: tuple[int, int]) -> bool:
"""Check if a point is in the region.
"""Check if a point is in the size.
Args:
point (tuple[int, int]): A tuple of x and y coordinates.
Expand All @@ -127,7 +129,7 @@ def __contains__(self, other: Any) -> bool:


class Region(NamedTuple):
"""Defines a rectangular region of the screen."""
"""Defines a rectangular region."""

x: int
y: int
Expand Down Expand Up @@ -176,7 +178,7 @@ def y_extents(self) -> tuple[int, int]:
return (self.y, self.y + self.height)

@property
def x_end(self) -> int:
def x_max(self) -> int:
return self.x + self.width

@property
Expand Down Expand Up @@ -210,7 +212,7 @@ def corners(self) -> tuple[int, int, int, int]:

@property
def x_range(self) -> range:
return range(self.x, self.x_end)
return range(self.x, self.x_max)

@property
def y_range(self) -> range:
Expand Down
2 changes: 1 addition & 1 deletion src/textual/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def render(
# first_cut = clamp(render_region.x, clip_x, clip_x2)
# last_cut = clamp(render_region.x + render_region.width, clip_x, clip_x2)
first_cut = render_region.x
last_cut = render_region.x_end
last_cut = render_region.x_max
final_cuts = [cut for cut in cuts[y] if (last_cut >= cut >= first_cut)]
# final_cuts = cuts[y]

Expand Down

0 comments on commit 2967fc0

Please sign in to comment.