Rect

struct Rect : public SDL_FRect

A 2D rectangle.

Public Functions

Rect() = default
inline Rect(float x, float y, float w, float h)

Construct a new rectangle.

Parameters:
  • x – The x position.

  • y – The y position.

  • w – The width.

  • h – The height.

inline Rect(int x, int y, int w, int h)
math::Vec2 getPos()

Get the position of the rectangle.

Returns:

The position of the rectangle.

math::Vec2 getSize()

Get the size of the rectangle.

Returns:

The size of the rectangle.

void setSize(const math::Vec2 &size)

Set the size of the rectangle.

Parameters:

size – The new size.

bool collidePoint(const math::Vec2 &pos) const

Check if the rectangle collides with a point.

Parameters:

pos – The point to check.

Returns:

Whether the rectangle collides with a point.

bool collideRect(const Rect &rect) const

Check if the rectangle collides with another rectangle.

Parameters:

rect – The rectangle to check.

Returns:

Whether the rectangle collides with another rectangle.

void clamp(const math::Vec2 &min, const math::Vec2 &max)

Clamp the rectangle.

Parameters:
  • min – The minimum value.

  • max – The maximum value.

void setCenter(const math::Vec2 &pos)
void setLeft(float x)
void setRight(float x)
void setTop(float y)
void setBottom(float y)
void setTopLeft(const math::Vec2 &pos)
void setTopMid(const math::Vec2 &pos)
void setTopRight(const math::Vec2 &pos)
void setBottomLeft(const math::Vec2 &pos)
void setBottomMid(const math::Vec2 &pos)
void setBottomRight(const math::Vec2 &pos)
void setLeftMid(const math::Vec2 &pos)
void setRightMid(const math::Vec2 &pos)
math::Vec2 getCenter()
float getLeft() const
float getRight() const
float getTop() const
float getBottom() const
math::Vec2 getTopLeft()
math::Vec2 getTopMid()
math::Vec2 getTopRight()
math::Vec2 getBottomLeft()
math::Vec2 getBottomMid()
math::Vec2 getBottomRight()
math::Vec2 getLeftMid()
math::Vec2 getRightMid()