Coordinate system

micro provides two template types — basic_point<T> and basic_rect<T> — with concrete aliases for the most common component types.

Point

using point  = basic_point<int>;
using pointf = basic_point<float>;

A 2D vector with components x and y. Supports arithmetic, vector math, and implicit conversion between component types.

Construction

micro::pointf p1{1.0f, 1.5f};
micro::point  p2{3, 4};
micro::pointf p3 = p2;   // implicit conversion from point → pointf

Arithmetic

Component-wise operations between two points:

auto sum  = p1 + p2;
auto diff = p1 - p2;
auto prod = p1 * p2;
auto quot = p1 / p2;
auto neg  = -p1;

Scalar multiplication and division (the scalar can be on either side):

micro::pointf vel{100.f, 0.f};
micro::pointf displacement = vel * dt;    // scale by float
micro::pointf half = displacement / 2.f;
micro::pointf same = dt * vel;            // commutative

All operators have compound-assignment equivalents (+=, -=, *=, /=).

Vector operations

The following are available for floating-point points (pointf):

float len = p.length();               // √(x² + y²)
float sq  = p.length_sqr();           // x² + y² — no sqrt, safe for comparisons
pointf n  = p.normalized();           // unit vector, or {0,0} if zero
float dot = p.dot(other);             // |p|·|other|·cos(θ)
float crs = p.cross(other);           // |p|·|other|·sin(θ), positive if other is CCW from p
pointf l  = p.lerp(other, t);         // linear interpolation, t not clamped
pointf c  = p.clamp(lo, hi);          // component-wise clamp

length_sqr() and clamp() are also available for integer points.

Equality

bool eq = p1 == p2;

Rect

using rect  = basic_rect<int>;
using rectf = basic_rect<float>;

A 2D axis-aligned rectangle stored as (x, y, w, h). All geometry uses half-open intervals: a point p is inside when x <= p.x < x+w and y <= p.y < y+h.

Construction

micro::rect r1{20, 10};              // {x=0, y=0, w=20, h=10}
micro::rect r2{5, 5, 20, 10};       // {x=5, y=5, w=20, h=10}
micro::rectf rf{r2};                 // explicit conversion (int → float)

Accessors

auto pos  = r.position();    // basic_point<T>{x, y}
auto size = r.size();        // basic_point<T>{w, h}
int  w    = r.width();
int  h    = r.height();

Hit testing

bool inside = r.contains(micro::point{5, 5});   // point in rect?
bool sub    = r.contains(other_rect);            // rect fully inside?
bool hit    = r.intersects(other_rect);          // overlap?

Intersection

auto [hit, overlap] = r.intersection(other_rect);
if (hit) {
    // overlap is the overlapping region
}

Explicit conversion

Converting a rectf to rect (or vice versa) requires an explicit constructor call to avoid accidental precision loss:

micro::rect ri{some_rectf};  // explicit constructor — float components truncated to int