#pragma once #include "EHS.h" #include "Vec2.h" #include "Vec3.h" #include "Vec4.h" namespace ehs { template class Rect { public: T x; T y; T w; T h; Rect(const T scalar = 0) : x(scalar), y(scalar), w(scalar), h(scalar) { } Rect(const T x, const T y, const T w, const T h) : x(x), y(y), w(w), h(h) { } template Rect(const Vec2& vec, const T w = 0, const T h = 0) : x((T)vec.x), y((T)vec.y), w(w), h(h) { } template Rect(const Vec3& vec, const T h = 0) : x((T)vec.x), y((T)vec.y), w((T)vec.z), h(h) { } template Rect(const Vec4& vec) : x((T)vec.x), y((T)vec.y), w((T)vec.z), h((T)vec.w) { } template Rect(const Rect& rect) : x((T)rect.x), y((T)rect.y), w((T)rect.w), h((T)rect.h) { } template Rect& operator=(const Vec2& vec) { x = (T)vec.x; y = (T)vec.y; w = 0; h = 0; return *this; } template Rect& operator=(const Vec3& vec) { x = (T)vec.x; y = (T)vec.y; w = (T)vec.z; h = 0; return *this; } template Rect& operator=(const Vec4& vec) { x = (T)vec.x; y = (T)vec.y; w = (T)vec.z; h = (T)vec.w; return *this; } template Rect& operator=(const Rect& rect) { if (this == &rect) return *this; x = (T)rect.x; y = (T)rect.y; w = (T)rect.w; h = (T)rect.h; return *this; } bool operator==(const Vec4& vec) { return x == vec.x && y == vec.y && w == vec.z && h == vec.w; } bool operator!=(const Vec4& vec) { return x != vec.x || y != vec.y || w != vec.z || h != vec.w; } bool operator==(const Rect& rect) { return x == rect.x && y == rect.y && w == rect.w && h == rect.h; } bool operator!=(const Rect& rect) { return x != rect.x || y != rect.y || w != rect.w || h != rect.h; } T operator[](const UInt_64 index) const { switch (index) { case 0: return x; case 1: return y; case 2: return w; case 3: return h; default: EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Rectangle."); return x; } } T& operator[](const UInt_64 index) { switch (index) { case 0: return x; case 1: return y; case 2: return w; case 3: return h; default: EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Rectangle."); return x; } } operator Vec4() { return Vec4(x, y, w, h); } Vec2 GetPos() const { return {x, y}; } Vec2 GetScale() const { return {w, h}; } }; typedef Rect Rect_u64; typedef Rect Rect_s64; typedef Rect Rect_64; typedef Rect Rect_u32; typedef Rect Rect_s32; typedef Rect Rect_32; typedef Rect Rect_u16; typedef Rect Rect_s16; typedef Rect Rect_16; typedef Rect Rect_u8; typedef Rect Rect_s8; typedef Rect Rect_8; typedef Rect Rect_f; typedef Rect Rect_d; }