# 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)

  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)

  Returns the absolute size of the rectangle.

  Return type:

    numpy.array

  Returns:

    The absolute size of the rectangle.

pyrr.rectangle.abs_width(rect)

  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.aspect_ratio(rect)

pyrr.rectangle.bottom(rect)

  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)

  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)

  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)

  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.create_zeros(dtype=None)

pyrr.rectangle.height(rect)

  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
  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)

  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)

  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)

  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)

  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)

  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)

  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)

  Returns the literal width of the rectangle.

  Return type:

    float

  Returns:

    The width of the rectangle. This can be a negative value.

pyrr.rectangle.x(rect)

  Returns the X position of the rectangle.

  This will be the left for rectangles with positive height values.

  Return type:

    float

  Returns:

    The X position of the rectangle. This value will be further right than the ‘right’ if the width is negative.

pyrr.rectangle.y(rect)

  Returns the Y position of the rectangle.

  This will be the bottom for rectangles with positive height values.

  Return type:

    float

  Returns:

    The Y position of the rectangle. This value will be above the bottom if the height is negative.