#ifndef JGEOMETRY_H #define JGEOMETRY_H #include "dolphin/types.h" namespace JGeometry { template struct TVec3 { T x; T y; T z; }; /* template <> struct TVec3 { TVec3(Vec& v) { } }; */ template struct TVec2 { TVec2() {} TVec2(T x, T y) { set(x, y); } void set(T x, T y) { this->x = x; this->y = y; } void set(const TVec2& other) { x = other.x; y = other.y; } void setMin(const TVec2& min) { if (min.x <= x) x = min.x; if (min.y <= y) y = min.y; } void setMax(const TVec2& max) { if (x <= max.x) x = max.x; if (y <= max.y) y = max.y; } void add(const TVec2& other) { x += other.x; y += other.y; } bool isAbove(const TVec2& other) const { return (other.x <= x) && (other.y <= y) ? true : false; } T x; T y; }; template struct TBox { TBox() : i(), f() {} TBox(const TBox& other) : i(other.f), f(other.y) {} T i, f; }; // clang-format off template<> struct TBox > { f32 getWidth() const { return f.x - i.x; } f32 getHeight() const { return f.y - i.y; } inline void operator= (const TBox >& rhs) { // ??? *(u32*)&i.x = *(u32*)&rhs.i.x; *(u32*)&i.y = *(u32*)&rhs.i.y; *(u32*)&f.x = *(u32*)&rhs.f.x; *(u32*)&f.y = *(u32*)&rhs.f.y; } bool isValid() const { return f.isAbove(i); } void addPos(const TVec2& pos) { i.add(pos); f.add(pos); } bool intersect(const TBox >& other) { i.setMax(other.i); f.setMin(other.f); return isValid(); } TVec2 i, f; }; template struct TBox2 : TBox > { TBox2() {} TBox2(f32 x0, f32 y0, f32 x1, f32 y1) { set(x0, y0, x1, y1); } inline const TBox2& operator=(const TBox2& rhs) { *(TBox >*)this = rhs; } void set(const TBox2& other) { set(other.i, other.f); } void set(const TVec2& i, const TVec2 f) { this->i.set(i), this->f.set(f); } void set(f32 x0, f32 y0, f32 x1, f32 y1) { i.set(x0, y0); f.set(x1, y1); } }; // clang-format on } // namespace JGeometry #endif