EHS
Rect.h
Go to the documentation of this file.
1#pragma once
2
3#include "EHS.h"
4#include "Vec2.h"
5#include "Vec3.h"
6#include "Vec4.h"
7
8namespace ehs
9{
10 template<typename T>
11 class Rect
12 {
13 public:
14 T x;
15 T y;
16 T w;
17 T h;
18
19 Rect(const T scalar = 0)
20 : x(scalar), y(scalar), w(scalar), h(scalar)
21 {
22 }
23
24 Rect(const T x, const T y, const T w, const T h)
25 : x(x), y(y), w(w), h(h)
26 {
27 }
28
29 template<typename C>
30 Rect(const Vec2<C>& vec, const T w = 0, const T h = 0)
31 : x((T)vec.x), y((T)vec.y), w(w), h(h)
32 {
33 }
34
35 template<typename C>
36 Rect(const Vec3<C>& vec, const T h = 0)
37 : x((T)vec.x), y((T)vec.y), w((T)vec.z), h(h)
38 {
39 }
40
41 template<typename C>
42 Rect(const Vec4<C>& vec)
43 : x((T)vec.x), y((T)vec.y), w((T)vec.z), h((T)vec.w)
44 {
45 }
46
47 template<typename C>
48 Rect(const Rect<C>& rect)
49 : x((T)rect.x), y((T)rect.y), w((T)rect.w), h((T)rect.h)
50 {
51 }
52
53 template<typename C>
55 {
56 x = (T)vec.x;
57 y = (T)vec.y;
58 w = 0;
59 h = 0;
60
61 return *this;
62 }
63
64 template<typename C>
66 {
67 x = (T)vec.x;
68 y = (T)vec.y;
69 w = (T)vec.z;
70 h = 0;
71
72 return *this;
73 }
74
75 template<typename C>
77 {
78 x = (T)vec.x;
79 y = (T)vec.y;
80 w = (T)vec.z;
81 h = (T)vec.w;
82
83 return *this;
84 }
85
86 template<typename C>
88 {
89 if (this == &rect)
90 return *this;
91
92 x = (T)rect.x;
93 y = (T)rect.y;
94 w = (T)rect.w;
95 h = (T)rect.h;
96
97 return *this;
98 }
99
100 bool operator==(const Vec4<T>& vec)
101 {
102 return x == vec.x && y == vec.y && w == vec.z && h == vec.w;
103 }
104
105 bool operator!=(const Vec4<T>& vec)
106 {
107 return x != vec.x || y != vec.y || w != vec.z || h != vec.w;
108 }
109
110 bool operator==(const Rect<T>& rect)
111 {
112 return x == rect.x && y == rect.y && w == rect.w && h == rect.h;
113 }
114
115 bool operator!=(const Rect<T>& rect)
116 {
117 return x != rect.x || y != rect.y || w != rect.w || h != rect.h;
118 }
119
120 T operator[](const UInt_64 index) const
121 {
122 switch (index)
123 {
124 case 0:
125 return x;
126 case 1:
127 return y;
128 case 2:
129 return w;
130 case 3:
131 return h;
132 default:
133 EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Rectangle.");
134 return x;
135 }
136 }
137
138 T& operator[](const UInt_64 index)
139 {
140 switch (index)
141 {
142 case 0:
143 return x;
144 case 1:
145 return y;
146 case 2:
147 return w;
148 case 3:
149 return h;
150 default:
151 EHS_LOG_INT(LogType::ERR, 0, "Index of, \"" + Str_8::FromNum(index) + "\" is out of range for a Rectangle.");
152 return x;
153 }
154 }
155
156 operator Vec4<T>()
157 {
158 return Vec4<T>(x, y, w, h);
159 }
160
162 {
163 return {x, y};
164 }
165
167 {
168 return {w, h};
169 }
170 };
171
186}
#define EHS_LOG_INT(type, code, msg)
Definition: Log.h:137
Definition: Rect.h:12
bool operator==(const Vec4< T > &vec)
Definition: Rect.h:100
Rect(const T x, const T y, const T w, const T h)
Definition: Rect.h:24
bool operator==(const Rect< T > &rect)
Definition: Rect.h:110
bool operator!=(const Rect< T > &rect)
Definition: Rect.h:115
T operator[](const UInt_64 index) const
Definition: Rect.h:120
Rect(const T scalar=0)
Definition: Rect.h:19
Rect< T > & operator=(const Rect< C > &rect)
Definition: Rect.h:87
T & operator[](const UInt_64 index)
Definition: Rect.h:138
T x
Definition: Rect.h:14
Rect(const Rect< C > &rect)
Definition: Rect.h:48
Rect(const Vec4< C > &vec)
Definition: Rect.h:42
Rect< T > & operator=(const Vec4< C > &vec)
Definition: Rect.h:76
Vec2< T > GetPos() const
Definition: Rect.h:161
T y
Definition: Rect.h:15
Rect< T > & operator=(const Vec2< C > &vec)
Definition: Rect.h:54
bool operator!=(const Vec4< T > &vec)
Definition: Rect.h:105
T h
Definition: Rect.h:17
T w
Definition: Rect.h:16
Rect(const Vec2< C > &vec, const T w=0, const T h=0)
Definition: Rect.h:30
Rect(const Vec3< C > &vec, const T h=0)
Definition: Rect.h:36
Vec2< T > GetScale() const
Definition: Rect.h:166
Rect< T > & operator=(const Vec3< C > &vec)
Definition: Rect.h:65
static Str< Char_8, UInt_64 > FromNum(const SInt_64 num)
Definition: Str.h:1399
Definition: Vec2.h:13
T y
Definition: Vec2.h:16
T x
Definition: Vec2.h:15
Definition: Vec3.h:14
T x
Definition: Vec3.h:16
T z
Definition: Vec3.h:18
T y
Definition: Vec3.h:17
Definition: Vec4.h:15
T z
Definition: Vec4.h:19
T y
Definition: Vec4.h:18
T x
Definition: Vec4.h:17
T w
Definition: Vec4.h:20
Definition: Anchor.h:6
Rect< SInt_8 > Rect_s8
Definition: Rect.h:182
Rect< UInt_8 > Rect_u8
Definition: Rect.h:181
Rect< Int_16 > Rect_16
Definition: Rect.h:180
Rect< double > Rect_d
Definition: Rect.h:185
Rect< Int_64 > Rect_64
Definition: Rect.h:174
Rect< SInt_64 > Rect_s64
Definition: Rect.h:173
Rect< Int_32 > Rect_32
Definition: Rect.h:177
Rect< UInt_64 > Rect_u64
Definition: Rect.h:172
Rect< Int_8 > Rect_8
Definition: Rect.h:183
Rect< float > Rect_f
Definition: Rect.h:184
Rect< SInt_32 > Rect_s32
Definition: Rect.h:176
Rect< UInt_16 > Rect_u16
Definition: Rect.h:178
Rect< UInt_32 > Rect_u32
Definition: Rect.h:175
Rect< SInt_16 > Rect_s16
Definition: Rect.h:179