Skip to content

Vector2I

Generated from engine/math/vector2i.h at f525bc6. 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/vector2i.h" · namespace labrador

struct Vector2I
int x = 0;
int y = 0;
Vector2I() = default;
Vector2I(const Vector2I&) = default;
Vector2I& operator=(const Vector2I&) = default;
constexpr Vector2I(int x, int y);

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

explicit Vector2I(const Vector2F& vector);

Each component truncates toward zero, as static_cast<int> does: (2.9, -2.9) becomes (2, -2). Throws std::invalid_argument for non-finite input and std::out_of_range if a truncated component cannot be represented as int.

bool operator==(const Vector2I& other) const;
bool operator!=(const Vector2I& other) const;
Vector2I& operator+=(const Vector2I& other);
Vector2I& operator-=(const Vector2I& other);
Vector2I& operator*=(const Vector2I& other);
Vector2I& operator*=(int other);
Vector2I& operator/=(const Vector2I& other);
Vector2I& operator/=(int other);

Division is int division per component, truncating toward zero: (7, -7) / 2 is (3, -3). Throws std::invalid_argument for a zero divisor and std::overflow_error for INT_MIN / -1. Failure leaves both components unchanged.

void offset(int horizontal_amount, int vertical_amount);
void scale(int horizontal_amount, int vertical_amount);
void set(int x, int y);
static const Vector2I zero;
Vector2I operator+ (const Vector2I& a, const Vector2I& b);
Vector2I operator- (const Vector2I& a, const Vector2I& b);
Vector2I operator* (const Vector2I& a, const Vector2I& b);
Vector2I operator* (const Vector2I& a, int scale);
Vector2I operator* (int scale, const Vector2I& a);
Vector2I operator/ (const Vector2I& a, const Vector2I& b);
Vector2I operator/ (const Vector2I& a, int scale);

Per component, truncating toward zero with the checked contract of operator/=.

Named in the public declarations above: Vector2F.

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

Documentation for Labrador v0.4.0. Built from Labrador f525bc6 of 2026-11-17.

All documentation versions