Represents a rectangle with integer coordinates.
x
andy
members specify the coordinates of the rectangle top-left corner andwidth
andheight
specify its width and height respectively. The usual C++ semi-open interval convention is used: pointp
lies inside the rectangle if and only if both conditions below are satisfied:x <= p.x < (rect.x + rect.width) y <= p.y < (rect.y + rect.height)
In other words, the rectangle left and right boundaries are at x
and x+width-1
and its top and bottom boundaries are at y
and y+height-1
respectively.
Note that the x and y coordinates may be negative, but width and height are always strictly positive for non-empty rectangles.
See also
Default constructor. |
|
Returns the rectangle having the same size as this one but centered relatively to the given rectangle r. |
|
Returns the rectangle having the same size as this one but centered relatively to the given rectangle r. |
|
Returns |
|
Decrease the rectangle size. |
|
Return the rectangle’s properties as a tuple. |
|
Gets the bottom point of the rectangle. |
|
Gets the position of the bottom left corner. |
|
Gets the position of the bottom right corner. |
|
Gets the height member. |
|
Returns an immutable representation of the |
|
Gets the left point of the rectangle (the same as |
|
Gets the position. |
|
Gets the right point of the rectangle. |
|
Gets the size. |
|
Gets the top point of the rectangle (the same as |
|
Gets the position of the top left corner of the rectangle, same as |
|
Gets the position of the top right corner. |
|
Gets the width member. |
|
Gets the x member. |
|
Gets the y member. |
|
Increases the size of the rectangle. |
|
Modifies this rectangle to contain the overlapping portion of this rectangle and the one passed in as parameter. |
|
Returns |
|
Returns |
|
Moves the rectangle by the specified offset. |
|
Set the bottom edge of the rectangle. |
|
Set the bottom-left point of the rectangle. |
|
Set the bottom-right point of the rectangle. |
|
Sets the height. |
|
Set the left side of the rectangle. |
|
Sets the position. |
|
Set the right side of the rectangle. |
|
Sets the size. |
|
Set the top edge of the rectangle. |
|
Set the top-left point of the rectangle. |
|
Set the top-right point of the rectangle. |
|
Sets the width. |
|
Sets the x position. |
|
Sets the y position. |
|
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). |
|
Like |
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
A public C++ attribute of type |
|
A public C++ attribute of type |
|
A public C++ attribute of type |
|
A public C++ attribute of type |
wx.
Rect
(object)¶Possible constructors:
Rect()
Rect(x, y, width, height)
Rect(pos, size)
Rect(size)
Rect(topLeft, bottomRight)
Represents a rectangle with integer coordinates.
__init__
(self, *args, **kw)¶__init__ (self)
Default constructor.
Initializes to zero the internal x, y, width and height members.
__init__ (self, x, y, width, height)
Creates a wx.Rect object from x, y, width and height values.
x (int) –
y (int) –
width (int) –
height (int) –
__init__ (self, pos, size)
Creates a wx.Rect object from position pos and size values.
__init__ (self, size)
Creates a wx.Rect object from size values at the origin.
size (wx.Size) –
__init__ (self, topLeft, bottomRight)
Creates a wx.Rect object from top-left and bottom-right points.
The width of the rectangle will be bottomRight.x-topLeft.x+1
and the height will be bottomRight.y-topLeft.y+1
.
CenterIn
(self, r, dir=BOTH)¶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.
CentreIn
(self, r, dir=BOTH)¶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.
Contains
(self, *args, **kw)¶Contains (self, x, y)
Returns True
if the given point is inside the rectangle (or on its boundary) and False
otherwise.
x (int) –
y (int) –
bool
Contains (self, pt)
Returns True
if the given point is inside the rectangle (or on its boundary) and False
otherwise.
pt (wx.Point) –
bool
Contains (self, rect)
Returns True
if the given rectangle is completely inside this rectangle (or touches its boundary) and False
otherwise.
rect (wx.Rect) –
bool
Deflate
(self, *args, **kw)¶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.
Deflate (self, dx, dy)
dx (int) –
dy (int) –
Deflate (self, diff)
Deflate (self, diff)
diff (int) –
Get
(self)¶Return the rectangle’s properties as a tuple.
tuple
( x, y, width, height )
GetBottom
(self)¶Gets the bottom point of the rectangle.
int
GetHeight
(self)¶Gets the height member.
int
GetIM
(self)¶Returns an immutable representation of the wx.Rect
object, based on namedtuple
.
This new object is hashable and can be used as a dictionary key,
be added to sets, etc. It can be converted back into a real wx.Rect
with a simple statement like this: obj = wx.Rect(imObj)
.
GetRight
(self)¶Gets the right point of the rectangle.
int
GetTopLeft
(self)¶Gets the position of the top left corner of the rectangle, same as GetPosition
.
GetWidth
(self)¶Gets the width member.
int
GetX
(self)¶Gets the x member.
int
GetY
(self)¶Gets the y member.
int
Inflate
(self, *args, **kw)¶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:
“Real” inflates (that is, dx and/or dy = 0) are not constrained. Thus inflating a rectangle can cause its upper left corner to move into the negative numbers. (2.5.4 and older forced the top left coordinate to not fall below (0, 0), which implied a forced move of the rectangle.)
Deflates are clamped to not reduce the width or height of the rectangle below zero. In such cases, the top-left corner is nonetheless handled properly. For example, a rectangle at (10, 10) with size (20, 40) that is inflated by (-15, -15) will become located at (20, 25) at size (0, 10). Finally, observe that the width and height are treated independently. In the above example, the width is reduced by 20, whereas the height is reduced by the full 30 (rather than also stopping at 20, when the width reached zero).
Intersect
(self, rect)¶Modifies this rectangle to contain the overlapping portion of this rectangle and the one passed in as parameter.
Intersects
(self, rect)¶Returns True
if this rectangle has a non-empty intersection with the rectangle rect and False
otherwise.
rect (wx.Rect) –
bool
IsEmpty
(self)¶Returns True
if this rectangle has a width or height less than or equal to 0 and False
otherwise.
bool
Offset
(self, *args, **kw)¶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.
Offset (self, dx, dy)
dx (int) –
dy (int) –
Offset (self, pt)
pt (wx.Point) –
SetBottom
(self, bottom)¶Set the bottom edge of the rectangle.
Notice that this doesn’t affect GetTop
return value but changes the rectangle height to set its bottom side to the given position.
bottom (int) –
SetHeight
(self, height)¶Sets the height.
height (int) –
SetLeft
(self, left)¶Set the left side of the rectangle.
Notice that because the rectangle stores its left side and width, calling SetLeft
changes the right side position too – but does preserve the width.
left (int) –
SetRight
(self, right)¶Set the right side of the rectangle.
Notice that this doesn’t affect GetLeft
return value but changes the rectangle width to set its right side to the given position.
right (int) –
SetTop
(self, top)¶Set the top edge of the rectangle.
Notice that because the rectangle stores its top side and height, calling SetTop
changes the bottom side position too – but does preserve the height.
top (int) –
SetWidth
(self, width)¶Sets the width.
width (int) –
SetX
(self, x)¶Sets the x position.
x (int) –
SetY
(self, y)¶Sets the y position.
y (int) –
Union
(self, rect)¶Modifies the rectangle to contain the bounding box of this rectangle and the one passed in as parameter.
__bool__
(self)¶__eq__
(self, other)¶bool
__getitem__
(self, idx)¶__len__
(self)¶__ne__
(self, other)¶bool
__nonzero__
(self)¶__reduce__
(self)¶__repr__
(self)¶__setitem__
(self, idx, val)¶__str__
(self)¶__imul__
(self)¶Returns the intersection of two rectangles (which may be empty).
r (wx.Rect) –
__iadd__
(self)¶Like Union
, but doesn’t treat empty rectangles specially.
r (wx.Rect) –
BottomLeft
¶See GetBottomLeft
and SetBottomLeft
BottomRight
¶See GetBottomRight
and SetBottomRight
Position
¶See GetPosition
and SetPosition
TopLeft
¶See GetTopLeft
and SetTopLeft
TopRight
¶See GetTopRight
and SetTopRight
bottomLeft
¶See GetBottomLeft
and SetBottomLeft
bottomRight
¶See GetBottomRight
and SetBottomRight
height
¶A public C++ attribute of type int
. Height member.
topLeft
¶See GetTopLeft
and SetTopLeft
topRight
¶See GetTopRight
and SetTopRight
width
¶A public C++ attribute of type int
. Width member.
x
¶A public C++ attribute of type int
. x coordinate of the top-left corner of the rectangle.
y
¶A public C++ attribute of type int
. y coordinate of the top-left corner of the rectangle.