Represents a rectangle with position and size.
Rect() → RectRect() → Rect
Rect(size: Vec2) → RectRect(size: Vec2) → Rect
Rect(x: float, y: float, w: float, h: float) → RectRect(x: float, y: float, w: float, h: float) → Rect
Rect(x: float, y: float, size: Vec2) → RectRect(x: float, y: float, size: Vec2) → Rect
Rect(pos: Vec2, w: float, h: float) → RectRect(pos: Vec2, w: float, h: float) → Rect
Rect(pos: Vec2, size: Vec2) → RectRect(pos: Vec2, size: Vec2) → Rect
Represents a rectangle with position and size.
| Name | Description | Type |
|---|---|---|
bottom | The y coordinate of the bottom edge. | float |
bottom_left | The position of the bottom-left corner as (x, y). | Vec2 |
bottom_mid | The position of the bottom-middle point as (x, y). | Vec2 |
bottom_right | The position of the bottom-right corner as (x, y). | Vec2 |
center | The position of the center point as (x, y). | Vec2 |
h | The height of the rectangle. | float |
left | The x coordinate of the left edge. | float |
mid_left | The position of the middle-left point as (x, y). | Vec2 |
mid_right | The position of the middle-right point as (x, y). | Vec2 |
pos | The position of the top-left corner as (x, y). | Vec2 |
right | The x coordinate of the right edge. | float |
size | The size of the rectangle as (width, height). | Vec2 |
top | The y coordinate of the top edge. | float |
top_left | The position of the top-left corner as (x, y). | Vec2 |
top_mid | The position of the top-middle point as (x, y). | Vec2 |
top_right | The position of the top-right corner as (x, y). | Vec2 |
w | The width of the rectangle. | float |
x | The x coordinate of the top-left corner. | float |
y | The y coordinate of the top-left corner. | float |
clamp(other: Rect) → Noneclamp(other: Rect) → NoneClamp this rectangle to be within another rectangle.
Args
other : The rectangle to clamp within.Raises
ValueError : If this rectangle is larger than the clamp area.clamp(min: Vec2, max: Vec2) → Noneclamp(min: Vec2, max: Vec2) → NoneClamp this rectangle to be within the specified bounds.
Args
min : The minimum bounds as (min_x, min_y).max : The maximum bounds as (max_x, max_y).Raises
ValueError : If min >= max or rectangle is larger than the clamp area.clamped(other: Rect) → Rectclamped(other: Rect) → RectReturn a new Rect clamped within another rectangle.
Args
other : The rectangle to clamp within.Returns
Rect : A new clamped rectangle.
clamped(min: Vec2, max: Vec2) → Rectclamped(min: Vec2, max: Vec2) → RectReturn a new Rect clamped within the specified bounds.
Args
min : The minimum bounds as (min_x, min_y).max : The maximum bounds as (max_x, max_y).Returns
Rect : A new clamped rectangle.
copy() → Rectcopy() → RectCreate a copy of this rectangle.
Returns
Rect : A new Rect with the same position and size.
fit(other: Rect) → Nonefit(other: Rect) → NoneScale this rectangle to fit inside another rectangle while maintaining aspect ratio.
Args
other : The rectangle to fit inside.Raises
ValueError : If other rectangle has non-positive dimensions.get_corners() → list[Vec2]get_corners() → list[Vec2]Get the corners of the rectangle.
Returns
List[Vec2] : A list of the four corners in the order: top-left, top-right, bottom-right, bottom-left.
get_edges() → list[Line]get_edges() → list[Line]Get the edges of the rectangle as Line segments.
Returns
List[Line] : A list of the four edges as Line objects in the order: top, right, bottom, left.
inflate(offset: Vec2) → Noneinflate(offset: Vec2) → NoneInflate the rectangle by the given offset.
The rectangle grows in all directions. The position is adjusted to keep the center in the same place.
Args
offset : The amount to inflate by as (dw, dh).move(offset: Vec2) → Nonemove(offset: Vec2) → NoneMove the rectangle by the given offset.
Args
offset : The offset to move by as (dx, dy).moved(offset: Vec2) → Rectmoved(offset: Vec2) → RectReturn a new Rect moved by the given offset.
Args
offset : The offset to move by.Returns
Rect : A new rectangle moved by the offset.
scale_by(factor: float) → Nonescale_by(factor: float) → NoneScale the rectangle by a uniform factor.
Args
factor : The scaling factor (must be > 0).Raises
ValueError : If factor is <= 0.scale_by(factor: Vec2) → Nonescale_by(factor: Vec2) → NoneScale the rectangle by different factors for width and height.
Args
factor : The scaling factors as (scale_x, scale_y).Raises
ValueError : If any factor is <= 0.scale_to(size: Vec2) → Nonescale_to(size: Vec2) → NoneScale the rectangle to the specified size.
Args
size : The new size as (width, height).Raises
ValueError : If width or height is <= 0.scaled_by(factor: float) → Rectscaled_by(factor: float) → RectReturn a new Rect scaled by a uniform factor.
Args
factor : The scaling factor (must be > 0).Returns
Rect : A new scaled rectangle.
scaled_by(factor: Vec2) → Rectscaled_by(factor: Vec2) → RectReturn a new Rect scaled by different factors for width and height.
Args
factor : The scaling factors as (scale_x, scale_y).Returns
Rect : A new scaled rectangle.