Rect

Rectangle related functions


Clamp

clamp(rect: Rect, min: Vec2, max: Vec2) Rect

Clamp a rectangle to be within the specified bounds.

Args

  • rect : The rectangle to clamp.
  • min : The minimum bounds as (min_x, min_y).
  • max : The maximum bounds as (max_x, max_y).

Returns

Rect : A new rectangle clamped within the bounds.

Raises

  • ValueError : If min >= max or rectangle is larger than the clamp area.

clamp(rect: Rect, other: Rect) Rect

Clamp a rectangle to be within another rectangle.

Args

  • rect : The rectangle to clamp.
  • other : The rectangle to clamp within.

Returns

Rect : A new rectangle clamped within the other rectangle.

Raises

  • ValueError : If rect is larger than the clamp area.

Move

move(rect: Rect, offset: Vec2) Rect

Move a rectangle by the given offset.

Args

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

Returns

Rect : A new rectangle moved by the offset.

Scale By

scale_by(rect: Rect, factor: SupportsFloat) Rect

Scale a rectangle by a uniform factor.

Args

  • rect : The rectangle to scale.
  • factor : The scaling factor (must be > 0).

Returns

Rect : A new rectangle scaled by the factor.

Raises

  • ValueError : If factor is <= 0.

scale_by(rect: Rect, factor: Vec2) Rect

Scale a rectangle by different factors for width and height.

Args

  • rect : The rectangle to scale.
  • factor : The scaling factors as (scale_x, scale_y).

Returns

Rect : A new rectangle scaled by the factors.

Raises

  • ValueError : If any factor is <= 0.

Scale To

scale_to(rect: Rect, size: Vec2) Rect

Scale a rectangle to the specified size.

Args

  • rect : The rectangle to scale.
  • size : The new size as (width, height).

Returns

Rect : A new rectangle scaled to the specified size.

Raises

  • ValueError : If width or height is <= 0.