A class for manipulating rectangles.
Note that the x, y coordinates and the width and height stored inside a Rect object may be negative and that Rect functions do not perform any check against negative values.
__init__ | Default constructor. |
CenterIn | Returns the rectangle having the same size as this one but centered relatively to the given rectangle r. |
CentreIn | Returns the rectangle having the same size as this one but centered relatively to the given rectangle r. |
Contains | Returns True if the given point is inside the rectangle (or on its boundary) and False otherwise. |
Deflate | Decrease the rectangle size. |
Get | Return the rectangle’s properties as a tuple. |
GetBottom | Gets the bottom point of the rectangle. |
GetBottomLeft | Gets the position of the bottom left corner. |
GetBottomRight | Gets the position of the bottom right corner. |
GetHeight | Gets the height member. |
GetLeft | Gets the left point of the rectangle (the same as GetX ). |
GetPosition | Gets the position. |
GetRight | Gets the right point of the rectangle. |
GetSize | Gets the size. |
GetTop | Gets the top point of the rectangle (the same as GetY ). |
GetTopLeft | Gets the position of the top left corner of the rectangle, same as GetPosition . |
GetTopRight | Gets the position of the top right corner. |
GetWidth | Gets the width member. |
GetX | Gets the x member. |
GetY | Gets the y member. |
Inflate | Increases the size of the rectangle. |
Intersect | Modifies this rectangle to contain the overlapping portion of this rectangle and the one passed in as parameter. |
Intersects | Returns True if this rectangle has a non-empty intersection with the rectangle rect and False otherwise. |
IsEmpty | Returns True if this rectangle has a width or height less than or equal to 0 and False otherwise. |
Offset | Moves the rectangle by the specified offset. |
SetBottom | Set the bottome edge of th rectangle. |
SetBottomLeft | Set the bottom-left point of the rectangle. |
SetBottomRight | Set the bottom-right point of the rectangle. |
SetHeight | Sets the height. |
SetLeft | Set the left side of the rectangle. |
SetRight | Set the right side of the rectangle. |
SetSize | Sets the size. |
SetTop | Set the top edge of the rectangle. |
SetTopLeft | Set the top-left point of the rectangle. |
SetTopRight | Set the top-right point of the rectangle. |
SetWidth | Sets the width. |
SetX | Sets the x position. |
SetY | Sets the y position. |
Union | Modifies the rectangle to contain the bounding box of this rectangle and the one passed in as parameter. |
__getitem__ | |
__len__ | |
__nonzero__ | |
__reduce__ | |
__repr__ | |
__setitem__ | |
__str__ | |
__imul__ | Returns the intersection of two rectangles (which may be empty). |
__iadd__ | Like Union , but doesn’t treat empty rectangles specially. |
Bottom | See GetBottom and SetBottom |
BottomLeft | See GetBottomLeft and SetBottomLeft |
BottomRight | See GetBottomRight and SetBottomRight |
Height | See GetHeight and SetHeight |
Left | See GetLeft and SetLeft |
Position | See GetPosition |
Right | See GetRight and SetRight |
Size | See GetSize and SetSize |
Top | See GetTop and SetTop |
TopLeft | See GetTopLeft and SetTopLeft |
TopRight | See GetTopRight and SetTopRight |
Width | See GetWidth and SetWidth |
X | See GetX and SetX |
Y | See GetY and SetY |
bottom | See GetBottom and SetBottom |
bottomLeft | See GetBottomLeft and SetBottomLeft |
bottomRight | See GetBottomRight and SetBottomRight |
left | See GetLeft and SetLeft |
right | See GetRight and SetRight |
top | See GetTop and SetTop |
topLeft | See GetTopLeft and SetTopLeft |
topRight | See GetTopRight and SetTopRight |
A class for manipulating rectangles.
Possible constructors:
Rect()
Rect(x, y, width, height)
Rect(pos, size)
Rect(size)
Rect(topLeft, bottomRight)
Overloaded Implementations:
__init__ (self)
Default constructor.
Initializes to zero the internal x, y, width and height members.
__init__ (self, x, y, width, height)
Creates a Rect object from x, y, width and height values.
Parameters: |
|
---|
__init__ (self, pos, size)
Creates a Rect object from position pos and size values.
Parameters: |
---|
__init__ (self, size)
Creates a Rect object from size values at the origin.
Parameters: | size (Size) – |
---|
__init__ (self, topLeft, bottomRight)
Creates a Rect object from top-left and bottom-right points.
Parameters: |
---|
Returns the rectangle having the same size as this one but centered relatively to the given rectangle r.
By default, rectangle is centred in both directions but if dir includes only VERTICAL or only HORIZONTAL , then it is only centered in this direction while the other component of its position remains unchanged.
Parameters: |
|
---|---|
Return type: |
Returns the rectangle having the same size as this one but centered relatively to the given rectangle r.
By default, rectangle is centred in both directions but if dir includes only VERTICAL or only HORIZONTAL , then it is only centered in this direction while the other component of its position remains unchanged.
Parameters: |
|
---|---|
Return type: |
Overloaded Implementations:
Contains (self, x, y)
Returns True if the given point is inside the rectangle (or on its boundary) and False otherwise.
Parameters: |
|
---|---|
Return type: | bool |
Contains (self, pt)
Returns True if the given point is inside the rectangle (or on its boundary) and False otherwise.
Parameters: | pt (Point) – |
---|---|
Return type: | bool |
Contains (self, rect)
Returns True if the given rectangle is completely inside this rectangle (or touches its boundary) and False otherwise.
Parameters: | rect (Rect) – |
---|---|
Return type: | bool |
Decrease the rectangle size.
This method is the opposite from Inflate : Deflate(a, b) is equivalent to Inflate(-a, -b). Please refer to Inflate for full description.
Overloaded Implementations:
Deflate (self, dx, dy)
Parameters: |
|
---|---|
Return type: |
Deflate (self, diff)
Parameters: | diff (Size) – |
---|---|
Return type: | Rect |
Deflate (self, diff)
Parameters: | diff (int) – |
---|---|
Return type: | Rect |
Return the rectangle’s properties as a tuple.
Return type: | tuple |
---|---|
Returns: | ( x, y, width, height ) |
Gets the bottom point of the rectangle.
Return type: | int |
---|
Gets the height member.
Return type: | int |
---|
Gets the right point of the rectangle.
Return type: | int |
---|
Gets the position of the top left corner of the rectangle, same as GetPosition .
Return type: | Point |
---|
Gets the width member.
Return type: | int |
---|
Gets the x member.
Return type: | int |
---|
Gets the y member.
Return type: | int |
---|
Increases the size of the rectangle.
The left border is moved farther left and the right border is moved farther right by dx. The upper border is moved farther up and the bottom border is moved farther down by dy. (Note that the width and height of the rectangle thus change by 2dx and 2dy, respectively.) If one or both of dx and dy are negative, the opposite happens: the rectangle size decreases in the respective direction.
Inflating and deflating behaves “naturally”. Defined more precisely, that means:
See also
Overloaded Implementations:
Inflate (self, dx, dy)
Parameters: |
|
---|---|
Return type: |
Inflate (self, diff)
Parameters: | diff (Size) – |
---|---|
Return type: | Rect |
Inflate (self, diff)
Parameters: | diff (int) – |
---|---|
Return type: | Rect |
Modifies this rectangle to contain the overlapping portion of this rectangle and the one passed in as parameter.
Returns: | This rectangle, modified. |
---|
Returns True if this rectangle has a non-empty intersection with the rectangle rect and False otherwise.
Parameters: | rect (Rect) – |
---|---|
Return type: | bool |
Returns True if this rectangle has a width or height less than or equal to 0 and False otherwise.
Return type: | bool |
---|
Moves the rectangle by the specified offset.
If dx is positive, the rectangle is moved to the right, if dy is positive, it is moved to the bottom, otherwise it is moved to the left or top respectively.
Overloaded Implementations:
Offset (self, dx, dy)
Parameters: |
|
---|
Offset (self, pt)
Parameters: | pt (Point) – |
---|
Set the bottome edge of th rectangle.
Parameters: | bottom (int) – |
---|
Sets the height.
Parameters: | height (int) – |
---|
Set the left side of the rectangle.
Parameters: | left (int) – |
---|
Set the right side of the rectangle.
Parameters: | right (int) – |
---|
Set the top edge of the rectangle.
Parameters: | top (int) – |
---|
Sets the width.
Parameters: | width (int) – |
---|
Sets the x position.
Parameters: | x (int) – |
---|
Sets the y position.
Parameters: | y (int) – |
---|
Modifies the rectangle to contain the bounding box of this rectangle and the one passed in as parameter.
Returns the intersection of two rectangles (which may be empty).
Parameters: | r (Rect) – |
---|
See GetBottomLeft and SetBottomLeft
See GetBottomRight and SetBottomRight
See GetPosition
See GetTopLeft and SetTopLeft
See GetTopRight and SetTopRight
See GetBottomLeft and SetBottomLeft
See GetBottomRight and SetBottomRight
See GetTopLeft and SetTopLeft
See GetTopRight and SetTopRight