Rect

An AABB object with a position and size.

Constructor

  • Rect()
  • Rect(pos: Vec2, size: Vec2)
  • Rect(pos: Vec2, w: float, h: float)
  • Rect(x: float, y: float, size: Vec2)
  • Rect(x: float, y: float, w: float, h: float)

Parameters

  • pos : The position as a Vec2 (x, y).
  • size : The size as a Vec2 (width, height).
  • x : The x coordinate of the top-left corner.
  • y : The y coordinate of the top-left corner.
  • w : The width of the rectangle.
  • h : The height of the rectangle.

Properties


NameDescriptionType
xThe top left x-coordinate of the rectangle's positionfloat
yThe top left y-coordinate of the rectangle's positionfloat
wThe width of the rectanglefloat
hThe height of the rectanglefloat
leftThe left edge x-coordinate of the rectanglefloat
rightThe right edge x-coordinate of the rectanglefloat
topThe top edge y-coordinate of the rectanglefloat
bottomThe bottom edge y-coordinate of the rectanglefloat
sizeThe size of the rectangle as a Vec2Vec2
top_leftThe top left corner of the rectangle as a Vec2Vec2
top_midThe top middle point of the rectangle as a Vec2Vec2
top_rightThe top right corner of the rectangle as a Vec2Vec2
mid_leftThe middle left point of the rectangle as a Vec2Vec2
centerThe center point of the rectangle as a Vec2Vec2
mid_rightThe middle right point of the rectangle as a Vec2Vec2
bottom_leftThe bottom left corner of the rectangle as a Vec2Vec2
bottom_midThe bottom middle point of the rectangle as a Vec2Vec2
bottom_rightThe bottom right corner of the rectangle as a Vec2Vec2

Methods


Inflate

inflate(offset: Vec2) None

Inflate the rectangle from the center by the given offset.

Parameters

  • offset : The amount to inflate the rectangle.

Fit

fit(other: Rect) None

Fit the rectangle inside another rectangle while maintaining aspect ratio.

Parameters

  • other : The other rectangle to fit inside.

Clamp

clamp(other: Rect) None

Clamp the rectangle inside another rectangle.

Parameters

  • other : The other rectangle to clamp inside.

clamp(min: Vec2, max: Vec2) None

Clamp the rectangle inside the given min and max bounds.

Parameters

  • min : The minimum bounds to clamp inside.
  • max : The maximum bounds to clamp inside.

Scale By

scale_by(factor: float) None

Scale the rectangle by a given factor.

Parameters

  • factor : The scale factor.

scale_by(factor: Vec2) None

Scale the rectangle by different factors for width and height.

Parameters

  • factor : The scale factors.

Scale To

scale_to(size: Vec2) None

Scale the rectangle to the given size.

Parameters

  • size : The new size of the rectangle.

Move

move(offset: Vec2) None

Move the rectangle by the given offset.

Parameters

  • offset : The offset to move by as (dx, dy).

Copy

copy() Rect

Create a copy of this rectangle.

Returns

Rect : A new Rect with the same position and size.