Rectangle class

Rectangle class

Stores a set of four integers that represent the location and size of a rectangle. Compatible with .NET System.Drawing.Rectangle.

The Rectangle type exposes the following members:

Constructors

ConstructorDescription
__init__(self, x=0, y=0, width=0, height=0)Creates a rectangle with the specified location and size. Float values are truncated to integers.

Properties

PropertyDescription
xGets the x-coordinate of the upper-left corner of this rectangle.
Read-only int.
yGets the y-coordinate of the upper-left corner of this rectangle.
Read-only int.
widthGets the width of this rectangle.
Read-only int.
heightGets the height of this rectangle.
Read-only int.
leftGets the x-coordinate of the left edge of this rectangle. Equals to x.
Read-only int.
topGets the y-coordinate of the top edge of this rectangle. Equals to y.
Read-only int.
rightGets the x-coordinate that is the sum of x and width of this rectangle.
Read-only int.
bottomGets the y-coordinate that is the sum of y and height of this rectangle.
Read-only int.
is_emptySpecifies whether all numeric properties of this rectangle have values of zero.
Read-only bool.

Methods

MethodDescription
contains(self, x, y)Determines if the specified point is contained within this rectangle.
contains(self, point)Determines if the specified point is contained within this rectangle.
contains(self, rect)Determines if the rectangular region represented by rect is entirely contained within this rectangle.

Remarks

Rectangles are compared by their location and size with == and can be used as dictionary keys or set members.

See Also