Class Rect
object --+
|
Rect
Type to store and manipulate rectangular coordinates.
This class provides the description of a rectangle and means to access
and modify its properties in an easy way.
Useful properties are:
-
left (or "x")
-
right
-
top (or "y")
-
bottom
-
center_x
-
center_y
-
width (or "w")
-
height (or "h")
-
top_left
-
top_right
-
bottom_left
-
bottom_right
-
center
-
pos
-
size
-
area
Useful methods are:
-
normalize
-
contains
-
intercepts
-
clip
-
union
-
clamp
-
move_by
-
inflate
Usage example:
>>> r1 = Rect(10, 20, 30, 40)
>>> r2 = Rect((0, 0), (100, 100))
>>> r1
Rect(x=10, y=20, w=30, h=40)
>>> r2
Rect(x=0, y=0, w=100, h=100)
>>> r1.contains(r2)
False
>>> r2.contains(r1)
True
>>> r1 in r2
True
>>> r1.intercepts(r2)
True
Attention:
this is not a graphical object! Do not confuse with Rectangle.
|
__contains__(x,
y)
y in x |
|
|
|
|
|
|
|
|
|
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature |
|
|
|
|
|
|
|
|
a new object with type S, a subtype of T
|
|
|
|
|
|
|
|
|
clamp(...)
Returns a new Rect that represents current moved inside given
parameter. |
|
|
|
clip(...)
Returns a new Rect that represents current cropped inside parameter. |
|
|
|
contains(...)
Checks if contains given rectangle. |
|
|
|
contains_point(...)
Checks if contains the given point. |
|
|
|
inflate(...)
Returns a new Rect that represents current inflated by given amount. |
|
|
|
intercepts(...)
Checks if intercepts given rectangle. |
|
|
|
move_by(...)
Returns a new Rect that represents current moved by given offsets. |
|
|
|
normalize(...)
Normalize coordinates so both width and height are positive. |
|
|
|
union(...)
Returns a new Rect that covers both rectangles. |
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__reduce__ ,
__reduce_ex__ ,
__setattr__ ,
__sizeof__ ,
__subclasshook__
|
|
area
|
|
bottom
|
|
bottom_left
|
|
bottom_right
|
|
center
|
|
center_x
|
|
center_y
|
|
h
|
|
height
|
|
left
|
|
pos
|
|
right
|
|
size
|
|
top
|
|
top_left
|
|
top_right
|
|
w
|
|
width
|
|
x
|
|
y
|
Inherited from object :
__class__
|
__init__(...)
(Constructor)
|
|
x.__init__(...) initializes x; see x.__class__.__doc__ for
signature
- Overrides:
object.__init__
|
- Returns: a new object with type S, a subtype of T
- Overrides:
object.__new__
|
__repr__(...)
(Representation operator)
|
|
repr(x)
- Overrides:
object.__repr__
- (inherited documentation)
|
__str__(...)
(Informal representation operator)
|
|
str(x)
- Overrides:
object.__str__
- (inherited documentation)
|
Returns a new Rect that represents current moved inside given
parameter.
If given rectangle is smaller, it'll be centered.
|