Rect

An AABB object with a position and size.

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

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.

Contains

contains(other: Rect) bool

Check if the rectangle fully contains another rectangle.

Parameters

  • other : The other rectangle to check.

Returns

bool : True if this rectangle contains the other, False otherwise.

Collide Point

collide_point(point: Vec2) bool

Check if a point is colliding with the rectangle.

Parameters

  • point : The point to check.

Returns

bool : True if the point is colliding with the rectangle, False otherwise.

Collide Rect

collide_rect(other: Rect) bool

Check if the rectangle is colliding with another rectangle.

Parameters

  • other : The other rectangle to check.

Returns

bool : True if the rectangles are colliding, False otherwise.

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.