Add a couple geometry methods
- Vector.from_point to convert a point to a vector - Rect.width and Rect.height convenience properties
This commit is contained in:
parent
b0b75f7e76
commit
ec28f984da
1 changed files with 15 additions and 0 deletions
|
@ -71,6 +71,11 @@ class Vector:
|
|||
dx: int = 0
|
||||
dy: int = 0
|
||||
|
||||
@classmethod
|
||||
def from_point(cls, point: Point) -> 'Vector':
|
||||
'''Create a Vector from a Point'''
|
||||
return Vector(point.x, point.y)
|
||||
|
||||
def __iter__(self):
|
||||
yield self.dx
|
||||
yield self.dy
|
||||
|
@ -164,6 +169,16 @@ class Rect:
|
|||
'''Maximum y-value that is still within the bounds of this rectangle.'''
|
||||
return self.origin.y + self.size.height - 1
|
||||
|
||||
@property
|
||||
def width(self) -> int:
|
||||
'''The width of the rectangle. A convenience property for accessing `self.size.width`.'''
|
||||
return self.size.width
|
||||
|
||||
@property
|
||||
def height(self) -> int:
|
||||
'''The height of the rectangle. A convenience property for accessing `self.size.height`.'''
|
||||
return self.size.height
|
||||
|
||||
@property
|
||||
def midpoint(self) -> Point:
|
||||
'''A Point in the middle of the Rect'''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue