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
| 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) → NoneInflate the rectangle from the center by the given offset.
Parameters
offset: The amount to inflate the rectangle.
Fit
fit(other: Rect) → NoneFit the rectangle inside another rectangle while maintaining aspect ratio.
Parameters
other: The other rectangle to fit inside.
Clamp
clamp(other: Rect) → NoneClamp the rectangle inside another rectangle.
Parameters
other: The other rectangle to clamp inside.
clamp(min: Vec2, max: Vec2) → NoneClamp 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) → NoneScale the rectangle by a given factor.
Parameters
factor: The scale factor.
scale_by(factor: Vec2) → NoneScale the rectangle by different factors for width and height.
Parameters
factor: The scale factors.
Scale To
scale_to(size: Vec2) → NoneScale the rectangle to the given size.
Parameters
size: The new size of the rectangle.
Move
move(offset: Vec2) → NoneMove the rectangle by the given offset.
Parameters
offset: The offset to move by as (dx, dy).
Copy
copy() → RectCreate a copy of this rectangle.
Returns
Rect : A new Rect with the same position and size.