Skip to content

RectangleI

Generated from engine/math/rectanglei.h at aceb130. The text under each declaration is the header's own comment, word for word. About the reference says how these pages are made.

Browse the math module

Audience: game code.

#include "engine/math/rectanglei.h" · namespace labrador

struct RectangleI
int x = 0;
int y = 0;
int width = 0;
int height = 0;
RectangleI() = default;
RectangleI(const RectangleI&) = default;
RectangleI& operator=(const RectangleI&) = default;
constexpr RectangleI(int x, int y, int width, int height);
RectangleI(const Vector2I& position,
const Vector2I& size);

constexpr and defined here so zero is constant-initialised. See Vector2F's constants for what the dynamic alternative risks.

RectangleI(const Vector2F& position,
const Vector2F& size);
explicit RectangleI(const RectangleF& rectangle);

Each of x, y, width and height truncates toward zero on its own, as static_cast<int> does; the corners are not rounded outward, so (0.5, 0.5, 2.9, 2.9) becomes (0, 0, 2, 2). Both float constructors throw std::invalid_argument for non-finite input and std::out_of_range if a truncated field does not fit in int.

int left() const;
int top() const;
int right() const;
int bottom() const;

right() is x + width and bottom() is y + height.

Vector2I position() const;
Vector2I size() const;
Vector2I top_left() const;
Vector2I bottom_right() const;
bool operator==(const RectangleI& other) const;
bool operator!=(const RectangleI& other) const;
bool contains(const Vector2I& point) const;
bool contains(const RectangleI& other) const;

Both are inclusive at all four edges: a point on right() or bottom() is contained, and a rectangle contains itself.

void offset(int horizontal_amount, int vertical_amount);
void offset(const Vector2I& amount);
void set_position(const Vector2I& position);
void set_size(const Vector2I& size);

offset and set_position move the rectangle and keep its size; set_size keeps the top left.

static const RectangleI zero;

Named in the public declarations above: RectangleF, Vector2F, Vector2I.

The files that include this header directly. A file can also reach it through another header.

Development documentation (unreleased). Built from Labrador aceb130 of 2026-11-20.

All documentation versions