fix: Rect.contains() 支持双参数(x,y)和四参数(l,t,r,b)重载

This commit is contained in:
shuiyu1123 committed 2026-06-24 14:27:17 +00:00
1 parent a51854455b
commit 4645015004
1 file changed
+11 -8
+11 -8
View File
@@ -258,14 +258,17 @@ class Rect(Stub):
self.right -= dx
self.bottom -= dy
def contains(self, x: int, y: int) -> bool:
return self.left < self.right and self.top < self.bottom \
and x >= self.left and x < self.right and y >= self.top and y < self.bottom
def contains(self, left: int, top: int, right: int, bottom: int) -> bool:
return self.left < self.right and self.top < self.bottom \
and self.left <= left and self.top <= top \
and self.right >= right and self.bottom >= bottom
def contains(self, *args) -> bool:
if len(args) == 2:
x, y = args
return (self.left < self.right and self.top < self.bottom
and x >= self.left and x < self.right and y >= self.top and y < self.bottom)
elif len(args) == 4:
left, top, right, bottom = args
return (self.left < self.right and self.top < self.bottom
and self.left <= left and self.top <= top
and self.right >= right and self.bottom >= bottom)
return False
def intersect(self, left: int, top: int, right: int, bottom: int) -> bool:
nL = max(self.left, left)