Rectangle¶
Provide functions for the creation and manipulation of 2D Rectangles.
Rectangles are represented using a numpy.array of shape (2,2,).
The first value is a vector of x, y position of the rectangle. The second value is a vector with the width, height of the rectangle.
- pyrr.rectangle.abs_height(rect)[source]¶
Returns the absolute height of the rectangle.
This caters for rectangles with a negative height.
- Return type:
float
- Returns:
The absolute height of the rectangle.
- pyrr.rectangle.abs_size(rect)[source]¶
Returns the absolute size of the rectangle.
- Return type:
numpy.array
- Returns:
The absolute size of the rectangle.
- pyrr.rectangle.abs_width(rect)[source]¶
Returns the absolute width of the rectangle.
This caters for rectangles with a negative width.
- Return type:
float
- Returns:
The absolute width of the rectangle.
- pyrr.rectangle.bottom(rect)[source]¶
Returns the bottom most Y value of the rectangle.
This caters for rectangles with a negative height.
- Return type:
float
- Returns:
The smallest Y value.
- pyrr.rectangle.bounds(rect)[source]¶
Returns the absolute boundaries of the rectangle.
This caters for rectangles with a negative width.
- Return type:
Tuple of 4 floats
- Returns:
The absolute left, right, bottom and top of the rectangle.
- pyrr.rectangle.create(x=0.0, y=0.0, width=1.0, height=1.0, dtype=None)[source]¶
Creates a rectangle from the specified position and sizes.
This function will interpret the values literally. A negative width or height will be represented by the returned value.
- Return type:
numpy.array
- Returns:
Returns a rectangle with the specified values.
- pyrr.rectangle.create_from_bounds(left, right, bottom, top, dtype=None)[source]¶
Creates a rectangle from the specified boundaries.
This caters for the left and right, and for the top and bottom being swapped.
- Return type:
numpy.array
- Returns:
Returns a rectangle with the specified values. The rectangle will have a positive width and height regardless of the values passed in.
- pyrr.rectangle.height(rect)[source]¶
Returns the literal height of the rectangle.
- Return type:
float
- Returns:
The height of the rectangle. This can be a negative value.
- class pyrr.rectangle.index[source]¶
- position = 0¶
The index of the position vector within the rectangle
- size = 1¶
The index of the size vector within the rectangle
- pyrr.rectangle.left(rect)[source]¶
Returns the left most X value of the rectangle.
This caters for rectangles with a negative width.
- Return type:
float
- Returns:
The smallest X value.
- pyrr.rectangle.position(rect)[source]¶
Returns the literal position of the rectangle.
This is the bottom-left point of the rectangle for rectangles with positive width and height
- Return type:
numpy.array
- Returns:
The position of the rectangle.
- pyrr.rectangle.right(rect)[source]¶
Returns the right most X value of the rectangle.
This caters for rectangles with a negative width.
- Return type:
float
- Returns:
The biggest X value.
- pyrr.rectangle.scale_by_vector(rect, vec)[source]¶
Scales a rectangle by a 2D vector.
Note that this will also scale the X,Y value of the rectangle, which will cause the rectangle to move, not just increase in size.
- Parameters:
rect (numpy.array) – the rectangle to scale. Both x,y and width,height will be scaled.
vec – A 2D vector to scale the rect by.
- Return type:
numpy.array.
- pyrr.rectangle.size(rect)[source]¶
Returns the literal size of the rectangle.
These values may be negative.
- Return type:
numpy.array
- Returns:
The size of the rectangle.
- pyrr.rectangle.top(rect)[source]¶
Returns the top most Y value of the rectangle.
This caters for rectangles with a negative height.
- Return type:
float
- Returns:
The biggest Y value.
- pyrr.rectangle.width(rect)[source]¶
Returns the literal width of the rectangle.
- Return type:
float
- Returns:
The width of the rectangle. This can be a negative value.