Bases: object
Define a rectangular area.
Many convenience handles and other properties are also defined - all of which may be assigned to which will result in altering the position and sometimes dimensions of the Rect:
- top – y pixel extent
- bottom – y pixel extent
- left – x pixel extent
- right – x pixel extent
- position – (x, y) of bottom-left corner pixel
- origin – (x, y) of bottom-left corner pixel
- center – (x, y) of center pixel
- topleft – (x, y) of top-left corner pixel
- topright – (x, y) of top-right corner pixel
- bottomleft – (x, y) of bottom-left corner pixel
- bottomright – (x, y) of bottom-right corner pixel
- midtop – (x, y) of middle of top side pixel
- midbottom – (x, y) of middle of bottom side pixel
- midleft – (x, y) of middle of left side pixel
- midright – (x, y) of middle of right side pixel
- size – (width, height) of rect
The Rect area includes the bottom and left borders but not the top and right borders.
Determine whether this rect is clipped by the other rect.
>>> r1 = Rect(0, 0, 10, 10)
>>> r2 = Rect(1, 1, 9, 9)
>>> r2.clippedBy(r1) # r2 fits inside r1
False
>>> r1.clippedBy(r2) # r1 is clipped by r2
True
>>> r2 = Rect(1, 1, 11, 11)
>>> r1.intersect(r2)
Rect(xy=1,1; wh=9,9)
>>> r1.clippedBy(r2)
True
>>> r2.intersect(r1)
Rect(xy=1,1; wh=9,9)
>>> r2.clippedBy(r1)
True
>>> r2 = Rect(11, 11, 1, 1)
>>> r1.clippedBy(r2)
True
Return boolean whether the point defined by x, y is inside the rect area.
Find the intersection of two Rects.
>>> r1 = Rect(0, 51, 200, 17)
>>> r2 = Rect(0, 64, 200, 55)
>>> r1.intersect(r2)
Rect(xy=0,64; wh=200,4)
>>> r1 = Rect(0, 64, 200, 55)
>>> r2 = Rect(0, 0, 200, 17)
>>> print r1.intersect(r2)
None
>>> r1 = Rect(10, 10, 10, 10)
>>> r2 = Rect(20, 20, 10, 10)
>>> print r1.intersect(r2)
None
>>> bool(Rect(0, 0, 1, 1))
True
>>> bool(Rect(0, 0, 1, 0))
False
>>> bool(Rect(0, 0, 0, 1))
False
>>> bool(Rect(0, 0, 0, 0))
False
Return boolean whether the “other” rect (an object with .x, .y, .width and .height attributes) overlaps this Rect in any way.