vecrec.Rect
- class vecrec.Rect(left, bottom, width, height)[source]
Bases:
vecrec.shapes.Shape
Represent a mutable two-dimensional rectangle.
Public Data Attributes:
Public Methods:
__init__
(left, bottom, width, height)__repr__
()Return repr(self).
__str__
()Return str(self).
__eq__
(other)Return self==value.
__add__
(vector)__iadd__
(vector)__sub__
(vector)__isub__
(vector)__contains__
(other)null
()Create a rectangle with everything set to zero.
from_size
(width, height)Create a rectangle with the given width and height.
from_width
(width[, ratio])Create a rectangle with the given width.
from_height
(height[, ratio])Create a rectangle with the given height.
from_square
(size)Create a rectangle with the same width and height.
from_dimensions
(left, bottom, width, height)Create a rectangle with the given dimensions.
from_sides
(left, top, right, bottom)Create a rectangle with the specified edge coordinates.
from_corners
(v1, v2)Create the rectangle defined by the two corners.
from_bottom_left
(position, width, height)Create a rectangle with the given width, height, and bottom-left corner.
from_center
(position, width, height)Create a rectangle with the given dimensions centered at the given position.
from_vector
(position)Create a rectangle from a vector.
from_points
(*points)Create a rectangle that contains all the given points.
from_shape
(shape)Create a rectangle from an object that implements the
Shape
interface.from_pygame_surface
(surface)Create a rectangle from a
pygame.Surface
.from_pyglet_window
(window)Create a rectangle from a
pyglet.window.Window
.from_pyglet_image
(image)Create a rectangle from a
pyglet.image.AbstractImage
.from_union
(*inputs)Create a rectangle that contains all the given inputs.
from_intersection
(*inputs)Create a rectangle that represents the overlapping area between all the given inputs.
grow
(*padding)Grow this rectangle by the given padding on all sides.
shrink
(*padding)Shrink this rectangle by the given padding on all sides.
displace
(vector)Displace this rectangle by the given vector.
round
(*args)Round the dimensions of the given rectangle to the given number of digits.
set
(shape)Fill this rectangle with the dimensions of the given shape.
copy
()Return a copy of this rectangle.
inside
(other)Return true if this rectangle is inside the given shape.
outside
(other)Return true if this rectangle is outside the given shape.
touching
(other)Return true if this rectangle is touching the given shape.
contains
(other)Return true if the given shape is inside this rectangle.
align_left
(target)Make the left coordinate of this rectangle equal to that of the given rectangle.
align_center_x
(target)Make the center-x coordinate of this rectangle equal to that of the given rectangle.
align_right
(target)Make the right coordinate of this rectangle equal to that of the given rectangle.
align_top
(target)Make the top coordinate of this rectangle equal to that of the given rectangle.
align_center_y
(target)Make the center-y coordinate of this rectangle equal to that of the given rectangle.
align_bottom
(target)Make the bottom coordinate of this rectangle equal to that of the given rectangle.
get_left
()set_left
(x)set_center_x
(x)set_right
(x)get_top
()set_top
(y)set_center_y
(y)set_bottom
(y)get_area
()set_width
(width)set_height
(height)set_half_width
(half_width)set_half_height
(half_height)set_top_left
(point)set_top_center
(point)set_top_right
(point)set_center_left
(point)set_center
(point)set_center_right
(point)set_bottom_left
(point)set_bottom_center
(point)set_bottom_right
(point)set_vertices
(vertices)get_size
()set_size
(width, height)get_union
(*rectangles)get_intersection
(*rectangles)get_grown
(padding)get_shrunk
(padding)get_rounded
(*args)
- __hash__ = None
- align_bottom(target)[source]
Make the bottom coordinate of this rectangle equal to that of the given rectangle.
- align_center_x(target)[source]
Make the center-x coordinate of this rectangle equal to that of the given rectangle.
- align_center_y(target)[source]
Make the center-y coordinate of this rectangle equal to that of the given rectangle.
- align_left(target)[source]
Make the left coordinate of this rectangle equal to that of the given rectangle.
- align_right(target)[source]
Make the right coordinate of this rectangle equal to that of the given rectangle.
- align_top(target)[source]
Make the top coordinate of this rectangle equal to that of the given rectangle.
- property area
- property bottom
- property bottom_center
- property bottom_left
- property bottom_right
- property center
- property center_left
- property center_right
- property center_x
- property center_y
- property dimensions
- static from_bottom_left(position, width, height)[source]
Create a rectangle with the given width, height, and bottom-left corner.
- static from_center(position, width, height)[source]
Create a rectangle with the given dimensions centered at the given position.
- static from_corners(v1, v2)[source]
Create the rectangle defined by the two corners. The corners can be specified in any order.
- static from_dimensions(left, bottom, width, height)[source]
Create a rectangle with the given dimensions. This is an alias for the constructor.
- static from_height(height, ratio=1.618033988749895)[source]
Create a rectangle with the given height. The width will be calculated from the given ratio, or the golden ratio by default.
- static from_intersection(*inputs)[source]
Create a rectangle that represents the overlapping area between all the given inputs. Each input must implement the
Shape
interface.
- static from_pygame_surface(surface)[source]
Create a rectangle from a
pygame.Surface
.
- static from_pyglet_image(image)[source]
Create a rectangle from a
pyglet.image.AbstractImage
.
- static from_pyglet_window(window)[source]
Create a rectangle from a
pyglet.window.Window
.
- static from_shape(shape)[source]
Create a rectangle from an object that implements the
Shape
interface.
- static from_sides(left, top, right, bottom)[source]
Create a rectangle with the specified edge coordinates.
- static from_size(width, height)[source]
Create a rectangle with the given width and height. The bottom-left corner will be on the origin.
- static from_union(*inputs)[source]
Create a rectangle that contains all the given inputs. Each input must implement the
Shape
interface.
- static from_vector(position)[source]
Create a rectangle from a vector. The rectangle will have no area, and its bottom-let corner will be the same as the vector.
- static from_width(width, ratio=0.6180339887498948)[source]
Create a rectangle with the given width. The height will be calculated from the given ratio, or the golden ratio by default.
- property half_height
- property half_width
- property height
- property intersection
- property left
- static null()[source]
Create a rectangle with everything set to zero. It will be located at the origin and have no area.
- property right
- property rounded
- shrink(*padding)[source]
Shrink this rectangle by the given padding on all sides.
The padding can either be a single number (to be applied to all sides), or a tuple of 4 number (to be applied to the left, right, top, and bottom, respectively).
- property size
- property size_as_int
- property top
- property top_center
- property top_left
- property top_right
- property tuple
- property union
- property vertices
- property width