2D Integer Box
// 2D integer box.
class RVAPI B2i
{
public:
// Minimum point.
S2i a;
// Maximum point.
S2i b;
// Check if box has a positive area.
bool IsValid() const { return b.x > a.x && b.y > a.y; };
// Check if box intersects [scalar].
bool IsIntersect(const S2i &scalar) const;
// Check if this box intersects [box].
bool IsIntersect(const B2i &box) const;
// Check [box] is inside this box.
bool IsInside(const B2i &box) const;
// Get box dimensions.
S2i Dims() const { return b - a; }
// Get box area.
int Area() const { return (b.x - a.x) * (b.y - a.y); }
// Check if box points are both zero.
bool operator ! () const { return !a && !b; }
// Get sum of boxes.
B2i operator + (const B2i &box) const { return B2i(a + box.a, b + box.b); }
// Get difference of boxes.
B2i operator - (const B2i &box) const { return B2i(a - box.a, b - box.b); }
// Get product of boxes.
B2i operator * (const B2i &box) const { return B2i(a * box.a, b * box.b); }
// Get division of boxes.
B2i operator / (const B2i &box) const { return B2i(a / box.a, b / box.b); }
// Get modulo of boxes.
B2i operator % (const B2i &box) const { return B2i(a % box.a, b % box.b); }
// Add [box] to this box.
B2i &operator += (const B2i &box) { return *this = *this + box; }
// Subtract [box] from this box.
B2i &operator -= (const B2i &box) { return *this = *this - box; }
// Multiply [box] by this box.
B2i &operator *= (const B2i &box) { return *this = *this * box; }
// Divide [box] into this box.
B2i &operator /= (const B2i &box) { return *this = *this / box; }
// Modulo [box] into this box.
B2i &operator %= (const B2i &box) { return *this = *this % box; }
// Get point within this box using normalized coordinates [x] and [y].
S2i Point(float x, float y) const;
// Get intersection of this box and [box].
B2i Intersect(const B2i &box) const;
// Constrain [scalar] inside this box.
S2i Constrain(const S2i &scalar) const;
// Constrain [box] inside this box.
B2i Constrain(const B2i &box) const;
// Resize this box to enclose [scalar].
void Enclose(const S2i &scalar);
// Resize this box to enclose [box].
void Enclose(const B2i &box);
// Construct box from scalars.
B2i(const S2i &scalarA, const S2i &scalarB) : a(scalarA), b(scalarB) {}
// Construct box from coordinates.
B2i(int ax, int ay, int bx, int by) : a(ax, ay), b(bx, by) {}
// Construct box from origin and dimensions. Set [dimsMode] to true.
B2i(int ax, int ay, int dx, int dy, bool/*dimsMode*/) : a(ax, ay), b(ax + dx, ay + dy) {}
// Construct box from single coordinate value.
B2i(int n = 0) : a(n), b(n) {}
// Destruct box.
~B2i() {}
};