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
Name | Description | Type |
---|---|---|
x | The top left x-coordinate of the rectangle's position | float |
y | The top left y-coordinate of the rectangle's position | float |
w | The width of the rectangle | float |
h | The height of the rectangle | float |
left | The left edge x-coordinate of the rectangle | float |
right | The right edge x-coordinate of the rectangle | float |
top | The top edge y-coordinate of the rectangle | float |
bottom | The bottom edge y-coordinate of the rectangle | float |
size | The size of the rectangle as a Vec2 | Vec2 |
top_left | The top left corner of the rectangle as a Vec2 | Vec2 |
top_mid | The top middle point of the rectangle as a Vec2 | Vec2 |
top_right | The top right corner of the rectangle as a Vec2 | Vec2 |
mid_left | The middle left point of the rectangle as a Vec2 | Vec2 |
center | The center point of the rectangle as a Vec2 | Vec2 |
mid_right | The middle right point of the rectangle as a Vec2 | Vec2 |
bottom_left | The bottom left corner of the rectangle as a Vec2 | Vec2 |
bottom_mid | The bottom middle point of the rectangle as a Vec2 | Vec2 |
bottom_right | The bottom right corner of the rectangle as a Vec2 | Vec2 |
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.