vecrec.Rect

class vecrec.Rect(left, bottom, width, height)[source]

Bases: vecrec.shapes.Shape

Represent a mutable two-dimensional rectangle.

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)

get_center_x()

set_center_x(x)

get_right()

set_right(x)

get_top()

set_top(y)

get_center_y()

set_center_y(y)

get_bottom()

set_bottom(y)

get_area()

get_width()

set_width(width)

get_height()

set_height(height)

get_half_width()

set_half_width(half_width)

get_half_height()

set_half_height(half_height)

get_top_left()

set_top_left(point)

get_top_center()

set_top_center(point)

get_top_right()

set_top_right(point)

get_center_left()

set_center_left(point)

get_center()

set_center(point)

get_center_right()

set_center_right(point)

get_bottom_left()

set_bottom_left(point)

get_bottom_center()

set_bottom_center(point)

get_bottom_right()

set_bottom_right(point)

get_vertices()

set_vertices(vertices)

get_size()

set_size(width, height)

get_size_as_int()

get_dimensions()

get_tuple()

get_union(*rectangles)

get_intersection(*rectangles)

get_grown(padding)

get_shrunk(padding)

get_rounded(*args)

Inherited from Shape

get_bottom()

get_left()

get_width()

get_height()


__add__(vector)[source]
__contains__(other)[source]
__eq__(other)[source]

Return self==value.

__hash__ = None
__iadd__(vector)[source]
__init__(left, bottom, width, height)[source]
__isub__(vector)[source]
__repr__()[source]

Return repr(self).

__str__()[source]

Return str(self).

__sub__(vector)[source]
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
contains(other)[source]

Return true if the given shape is inside this rectangle.

copy()[source]

Return a copy of this rectangle.

property dimensions
displace(vector)[source]

Displace this rectangle by the given vector.

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_points(*points)[source]

Create a rectangle that contains all the given points.

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_square(size)[source]

Create a rectangle with the same width and height.

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.

get_area()[source]
get_bottom()[source]
get_bottom_center()[source]
get_bottom_left()[source]
get_bottom_right()[source]
get_center()[source]
get_center_left()[source]
get_center_right()[source]
get_center_x()[source]
get_center_y()[source]
get_dimensions()[source]
get_grown(padding)[source]
get_half_height()[source]
get_half_width()[source]
get_height()[source]
get_intersection(*rectangles)[source]
get_left()[source]
get_right()[source]
get_rounded(*args)[source]
get_shrunk(padding)[source]
get_size()[source]
get_size_as_int()[source]
get_top()[source]
get_top_center()[source]
get_top_left()[source]
get_top_right()[source]
get_tuple()[source]
get_union(*rectangles)[source]
get_vertices()[source]
get_width()[source]
grow(*padding)[source]

Grow this rectangle by the given padding on all sides.

property half_height
property half_width
property height
inside(other)[source]

Return true if this rectangle is inside the given shape.

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.

outside(other)[source]

Return true if this rectangle is outside the given shape.

property right
round(*args)[source]

Round the dimensions of the given rectangle to the given number of digits.

property rounded
set(shape)[source]

Fill this rectangle with the dimensions of the given shape.

set_bottom(y)[source]
set_bottom_center(point)[source]
set_bottom_left(point)[source]
set_bottom_right(point)[source]
set_center(point)[source]
set_center_left(point)[source]
set_center_right(point)[source]
set_center_x(x)[source]
set_center_y(y)[source]
set_half_height(half_height)[source]
set_half_width(half_width)[source]
set_height(height)[source]
set_left(x)[source]
set_right(x)[source]
set_size(width, height)[source]
set_top(y)[source]
set_top_center(point)[source]
set_top_left(point)[source]
set_top_right(point)[source]
set_vertices(vertices)[source]
set_width(width)[source]
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
touching(other)[source]

Return true if this rectangle is touching the given shape.

property tuple
property union
property vertices
property width