Implement Rect.__contains__ on a Point
Returns True if the Rect contains the point.
This commit is contained in:
parent
b8e7e3d059
commit
6aefff838d
1 changed files with 9 additions and 0 deletions
|
@ -252,6 +252,15 @@ class Rect:
|
||||||
return Rect(Point(self.origin.x + left, self.origin.y + top),
|
return Rect(Point(self.origin.x + left, self.origin.y + top),
|
||||||
Size(self.size.width - right - left, self.size.height - top - bottom))
|
Size(self.size.width - right - left, self.size.height - top - bottom))
|
||||||
|
|
||||||
|
def __contains__(self, pt: Point) -> bool:
|
||||||
|
if pt.x < self.min_x or pt.x > self.max_x:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if pt.y < self.min_y or pt.y > self.max_y:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
yield tuple(self.origin)
|
yield tuple(self.origin)
|
||||||
yield tuple(self.size)
|
yield tuple(self.size)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue