.. include:: headings.inc .. _Rect: ========================================================================================================================================== |phoenix_title| **Rect** ========================================================================================================================================== A class for manipulating rectangles. Note that the x, y coordinates and the width and height stored inside a :ref:`Rect` object may be negative and that :ref:`Rect` functions do not perform any check against negative values. .. seealso:: :ref:`Point`, :ref:`Size` | |class_hierarchy| Inheritance Diagram ===================================== Inheritance diagram for class **Rect** .. raw:: html

Inheritance diagram of Rect

| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~Rect.__init__` Default constructor. :meth:`~Rect.CenterIn` Returns the rectangle having the same size as this one but centered relatively to the given rectangle `r`. :meth:`~Rect.CentreIn` Returns the rectangle having the same size as this one but centered relatively to the given rectangle `r`. :meth:`~Rect.Contains` Returns ``True`` if the given point is inside the rectangle (or on its boundary) and ``False`` otherwise. :meth:`~Rect.Deflate` Decrease the rectangle size. :meth:`~Rect.Get` Return the rectangle's properties as a tuple. :meth:`~Rect.GetBottom` Gets the bottom point of the rectangle. :meth:`~Rect.GetBottomLeft` Gets the position of the bottom left corner. :meth:`~Rect.GetBottomRight` Gets the position of the bottom right corner. :meth:`~Rect.GetHeight` Gets the height member. :meth:`~Rect.GetLeft` Gets the left point of the rectangle (the same as :meth:`GetX` ). :meth:`~Rect.GetPosition` Gets the position. :meth:`~Rect.GetRight` Gets the right point of the rectangle. :meth:`~Rect.GetSize` Gets the size. :meth:`~Rect.GetTop` Gets the top point of the rectangle (the same as :meth:`GetY` ). :meth:`~Rect.GetTopLeft` Gets the position of the top left corner of the rectangle, same as :meth:`GetPosition` . :meth:`~Rect.GetTopRight` Gets the position of the top right corner. :meth:`~Rect.GetWidth` Gets the width member. :meth:`~Rect.GetX` Gets the x member. :meth:`~Rect.GetY` Gets the y member. :meth:`~Rect.Inflate` Increases the size of the rectangle. :meth:`~Rect.Intersect` Modifies this rectangle to contain the overlapping portion of this rectangle and the one passed in as parameter. :meth:`~Rect.Intersects` Returns ``True`` if this rectangle has a non-empty intersection with the rectangle `rect` and ``False`` otherwise. :meth:`~Rect.IsEmpty` Returns ``True`` if this rectangle has a width or height less than or equal to 0 and ``False`` otherwise. :meth:`~Rect.Offset` Moves the rectangle by the specified offset. :meth:`~Rect.SetBottom` Set the bottome edge of th rectangle. :meth:`~Rect.SetBottomLeft` Set the bottom-left point of the rectangle. :meth:`~Rect.SetBottomRight` Set the bottom-right point of the rectangle. :meth:`~Rect.SetHeight` Sets the height. :meth:`~Rect.SetLeft` Set the left side of the rectangle. :meth:`~Rect.SetRight` Set the right side of the rectangle. :meth:`~Rect.SetSize` Sets the size. :meth:`~Rect.SetTop` Set the top edge of the rectangle. :meth:`~Rect.SetTopLeft` Set the top-left point of the rectangle. :meth:`~Rect.SetTopRight` Set the top-right point of the rectangle. :meth:`~Rect.SetWidth` Sets the width. :meth:`~Rect.SetX` Sets the x position. :meth:`~Rect.SetY` Sets the y position. :meth:`~Rect.Union` Modifies the rectangle to contain the bounding box of this rectangle and the one passed in as parameter. :meth:`~Rect.__getitem__` :meth:`~Rect.__len__` :meth:`~Rect.__nonzero__` :meth:`~Rect.__reduce__` :meth:`~Rect.__repr__` :meth:`~Rect.__setitem__` :meth:`~Rect.__str__` :meth:`~Rect.__imul__` Returns the intersection of two rectangles (which may be empty). :meth:`~Rect.__iadd__` Like :meth:`Union` , but doesn't treat empty rectangles specially. ================================================================================ ================================================================================ | |property_summary| Properties Summary ===================================== ================================================================================ ================================================================================ :attr:`~Rect.Bottom` See :meth:`~Rect.GetBottom` and :meth:`~Rect.SetBottom` :attr:`~Rect.BottomLeft` See :meth:`~Rect.GetBottomLeft` and :meth:`~Rect.SetBottomLeft` :attr:`~Rect.BottomRight` See :meth:`~Rect.GetBottomRight` and :meth:`~Rect.SetBottomRight` :attr:`~Rect.Height` See :meth:`~Rect.GetHeight` and :meth:`~Rect.SetHeight` :attr:`~Rect.Left` See :meth:`~Rect.GetLeft` and :meth:`~Rect.SetLeft` :attr:`~Rect.Position` See :meth:`~Rect.GetPosition` :attr:`~Rect.Right` See :meth:`~Rect.GetRight` and :meth:`~Rect.SetRight` :attr:`~Rect.Size` See :meth:`~Rect.GetSize` and :meth:`~Rect.SetSize` :attr:`~Rect.Top` See :meth:`~Rect.GetTop` and :meth:`~Rect.SetTop` :attr:`~Rect.TopLeft` See :meth:`~Rect.GetTopLeft` and :meth:`~Rect.SetTopLeft` :attr:`~Rect.TopRight` See :meth:`~Rect.GetTopRight` and :meth:`~Rect.SetTopRight` :attr:`~Rect.Width` See :meth:`~Rect.GetWidth` and :meth:`~Rect.SetWidth` :attr:`~Rect.X` See :meth:`~Rect.GetX` and :meth:`~Rect.SetX` :attr:`~Rect.Y` See :meth:`~Rect.GetY` and :meth:`~Rect.SetY` :attr:`~Rect.bottom` See :meth:`~Rect.GetBottom` and :meth:`~Rect.SetBottom` :attr:`~Rect.bottomLeft` See :meth:`~Rect.GetBottomLeft` and :meth:`~Rect.SetBottomLeft` :attr:`~Rect.bottomRight` See :meth:`~Rect.GetBottomRight` and :meth:`~Rect.SetBottomRight` :attr:`~Rect.left` See :meth:`~Rect.GetLeft` and :meth:`~Rect.SetLeft` :attr:`~Rect.right` See :meth:`~Rect.GetRight` and :meth:`~Rect.SetRight` :attr:`~Rect.top` See :meth:`~Rect.GetTop` and :meth:`~Rect.SetTop` :attr:`~Rect.topLeft` See :meth:`~Rect.GetTopLeft` and :meth:`~Rect.SetTopLeft` :attr:`~Rect.topRight` See :meth:`~Rect.GetTopRight` and :meth:`~Rect.SetTopRight` ================================================================================ ================================================================================ | |api| Class API =============== .. class:: Rect(object) A class for manipulating rectangles. **Possible constructors**:: Rect() Rect(x, y, width, height) Rect(pos, size) Rect(size) Rect(topLeft, bottomRight) .. method:: __init__(self, *args, **kw) |overload| **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 :ref:`Rect` object from `x`, `y`, `width` and `height` values. :param `x`: :type `x`: int :param `y`: :type `y`: int :param `width`: :type `width`: int :param `height`: :type `height`: int **~~~** **__init__** `(self, pos, size)` Creates a :ref:`Rect` object from position `pos` and `size` values. :param `pos`: :type `pos`: Point :param `size`: :type `size`: Size **~~~** **__init__** `(self, size)` Creates a :ref:`Rect` object from `size` values at the origin. :param `size`: :type `size`: Size **~~~** **__init__** `(self, topLeft, bottomRight)` Creates a :ref:`Rect` object from top-left and bottom-right points. :param `topLeft`: :type `topLeft`: Point :param `bottomRight`: :type `bottomRight`: Point **~~~** .. method:: 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. :param `r`: :type `r`: Rect :param `dir`: :type `dir`: int :rtype: :ref:`Rect` .. method:: 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. :param `r`: :type `r`: Rect :param `dir`: :type `dir`: int :rtype: :ref:`Rect` .. method:: Contains(self, *args, **kw) |overload| **Overloaded Implementations**: **~~~** **Contains** `(self, x, y)` Returns ``True`` if the given point is inside the rectangle (or on its boundary) and ``False`` otherwise. :param `x`: :type `x`: int :param `y`: :type `y`: int :rtype: `bool` **~~~** **Contains** `(self, pt)` Returns ``True`` if the given point is inside the rectangle (or on its boundary) and ``False`` otherwise. :param `pt`: :type `pt`: Point :rtype: `bool` **~~~** **Contains** `(self, rect)` Returns ``True`` if the given rectangle is completely inside this rectangle (or touches its boundary) and ``False`` otherwise. :param `rect`: :type `rect`: Rect :rtype: `bool` **~~~** .. method:: Deflate(self, *args, **kw) Decrease the rectangle size. This method is the opposite from :meth:`Inflate` : Deflate(a, b) is equivalent to Inflate(-a, -b). Please refer to :meth:`Inflate` for full description. |overload| **Overloaded Implementations**: **~~~** **Deflate** `(self, dx, dy)` :param `dx`: :type `dx`: int :param `dy`: :type `dy`: int :rtype: :ref:`Rect` **~~~** **Deflate** `(self, diff)` :param `diff`: :type `diff`: Size :rtype: :ref:`Rect` **~~~** **Deflate** `(self, diff)` :param `diff`: :type `diff`: int :rtype: :ref:`Rect` **~~~** .. method:: Get(self) Return the rectangle's properties as a tuple. :rtype: `tuple` :returns: ( `x`, `y`, `width`, `height` ) .. method:: GetBottom(self) Gets the bottom point of the rectangle. :rtype: `int` .. method:: GetBottomLeft(self) Gets the position of the bottom left corner. :rtype: :ref:`Point` .. method:: GetBottomRight(self) Gets the position of the bottom right corner. :rtype: :ref:`Point` .. method:: GetHeight(self) Gets the height member. :rtype: `int` .. method:: GetLeft(self) Gets the left point of the rectangle (the same as :meth:`GetX` ). :rtype: `int` .. method:: GetPosition(self) Gets the position. :rtype: :ref:`Point` .. method:: GetRight(self) Gets the right point of the rectangle. :rtype: `int` .. method:: GetSize(self) Gets the size. :rtype: :ref:`Size` .. seealso:: :meth:`SetSize` .. method:: GetTop(self) Gets the top point of the rectangle (the same as :meth:`GetY` ). :rtype: `int` .. method:: GetTopLeft(self) Gets the position of the top left corner of the rectangle, same as :meth:`GetPosition` . :rtype: :ref:`Point` .. method:: GetTopRight(self) Gets the position of the top right corner. :rtype: :ref:`Point` .. method:: GetWidth(self) Gets the width member. :rtype: `int` .. method:: GetX(self) Gets the x member. :rtype: `int` .. method:: GetY(self) Gets the y member. :rtype: `int` .. method:: 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). .. seealso:: :meth:`Deflate` |overload| **Overloaded Implementations**: **~~~** **Inflate** `(self, dx, dy)` :param `dx`: :type `dx`: int :param `dy`: :type `dy`: int :rtype: :ref:`Rect` **~~~** **Inflate** `(self, diff)` :param `diff`: :type `diff`: Size :rtype: :ref:`Rect` **~~~** **Inflate** `(self, diff)` :param `diff`: :type `diff`: int :rtype: :ref:`Rect` **~~~** .. method:: Intersect(self, *args, **kw) Modifies this rectangle to contain the overlapping portion of this rectangle and the one passed in as parameter. :returns: This rectangle, modified. .. method:: Intersects(self, rect) Returns ``True`` if this rectangle has a non-empty intersection with the rectangle `rect` and ``False`` otherwise. :param `rect`: :type `rect`: Rect :rtype: `bool` .. method:: IsEmpty(self) Returns ``True`` if this rectangle has a width or height less than or equal to 0 and ``False`` otherwise. :rtype: `bool` .. method:: 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. |overload| **Overloaded Implementations**: **~~~** **Offset** `(self, dx, dy)` :param `dx`: :type `dx`: int :param `dy`: :type `dy`: int **~~~** **Offset** `(self, pt)` :param `pt`: :type `pt`: Point **~~~** .. method:: SetBottom(self, bottom) Set the bottome edge of th rectangle. :param `bottom`: :type `bottom`: int .. method:: SetBottomLeft(self, p) Set the bottom-left point of the rectangle. :param `p`: :type `p`: Point .. method:: SetBottomRight(self, p) Set the bottom-right point of the rectangle. :param `p`: :type `p`: Point .. method:: SetHeight(self, height) Sets the height. :param `height`: :type `height`: int .. method:: SetLeft(self, left) Set the left side of the rectangle. :param `left`: :type `left`: int .. method:: SetRight(self, right) Set the right side of the rectangle. :param `right`: :type `right`: int .. method:: SetSize(self, s) Sets the size. :param `s`: :type `s`: Size .. seealso:: :meth:`GetSize` .. method:: SetTop(self, top) Set the top edge of the rectangle. :param `top`: :type `top`: int .. method:: SetTopLeft(self, p) Set the top-left point of the rectangle. :param `p`: :type `p`: Point .. method:: SetTopRight(self, p) Set the top-right point of the rectangle. :param `p`: :type `p`: Point .. method:: SetWidth(self, width) Sets the width. :param `width`: :type `width`: int .. method:: SetX(self, x) Sets the x position. :param `x`: :type `x`: int .. method:: SetY(self, y) Sets the y position. :param `y`: :type `y`: int .. method:: Union(self, *args, **kw) Modifies the rectangle to contain the bounding box of this rectangle and the one passed in as parameter. .. method:: __getitem__(self, idx) .. method:: __len__(self) .. method:: __nonzero__(self) .. method:: __reduce__(self) .. method:: __repr__(self) .. method:: __setitem__(self, idx, val) .. method:: __str__(self) .. method:: __imul__(self) Returns the intersection of two rectangles (which may be empty). :param `r`: :type `r`: Rect .. method:: __iadd__(self) Like :meth:`Union` , but doesn't treat empty rectangles specially. :param `r`: :type `r`: Rect .. attribute:: Bottom See :meth:`~Rect.GetBottom` and :meth:`~Rect.SetBottom` .. attribute:: BottomLeft See :meth:`~Rect.GetBottomLeft` and :meth:`~Rect.SetBottomLeft` .. attribute:: BottomRight See :meth:`~Rect.GetBottomRight` and :meth:`~Rect.SetBottomRight` .. attribute:: Height See :meth:`~Rect.GetHeight` and :meth:`~Rect.SetHeight` .. attribute:: Left See :meth:`~Rect.GetLeft` and :meth:`~Rect.SetLeft` .. attribute:: Position See :meth:`~Rect.GetPosition` .. attribute:: Right See :meth:`~Rect.GetRight` and :meth:`~Rect.SetRight` .. attribute:: Size See :meth:`~Rect.GetSize` and :meth:`~Rect.SetSize` .. attribute:: Top See :meth:`~Rect.GetTop` and :meth:`~Rect.SetTop` .. attribute:: TopLeft See :meth:`~Rect.GetTopLeft` and :meth:`~Rect.SetTopLeft` .. attribute:: TopRight See :meth:`~Rect.GetTopRight` and :meth:`~Rect.SetTopRight` .. attribute:: Width See :meth:`~Rect.GetWidth` and :meth:`~Rect.SetWidth` .. attribute:: X See :meth:`~Rect.GetX` and :meth:`~Rect.SetX` .. attribute:: Y See :meth:`~Rect.GetY` and :meth:`~Rect.SetY` .. attribute:: bottom See :meth:`~Rect.GetBottom` and :meth:`~Rect.SetBottom` .. attribute:: bottomLeft See :meth:`~Rect.GetBottomLeft` and :meth:`~Rect.SetBottomLeft` .. attribute:: bottomRight See :meth:`~Rect.GetBottomRight` and :meth:`~Rect.SetBottomRight` .. attribute:: left See :meth:`~Rect.GetLeft` and :meth:`~Rect.SetLeft` .. attribute:: right See :meth:`~Rect.GetRight` and :meth:`~Rect.SetRight` .. attribute:: top See :meth:`~Rect.GetTop` and :meth:`~Rect.SetTop` .. attribute:: topLeft See :meth:`~Rect.GetTopLeft` and :meth:`~Rect.SetTopLeft` .. attribute:: topRight See :meth:`~Rect.GetTopRight` and :meth:`~Rect.SetTopRight`