Face Engine SDK 5.25.0
A face detection, recognition and tracking engine.
Loading...
Searching...
No Matches
Vector2.h
1#pragma once
2
3#include <cassert>
4
5namespace fsdk {
9 template <typename T>
10 struct Vector2 {
11 T x;
12 T y;
13
16 Vector2() noexcept
17 : x((T)0)
18 , y(T(0)) {
19 }
20
24 explicit Vector2(T x_) noexcept
25 : x(x_)
26 , y(x_) {
27 }
28
33 Vector2(T x_, T y_) noexcept
34 : x(x_)
35 , y(y_) {
36 }
37
41 template <typename Other>
42 Vector2<T>(const Vector2<Other>& other) noexcept {
43 *this = other;
44 }
45
50 template <typename Other>
51 Vector2<T>& operator=(const Vector2<Other>& other) noexcept {
52 x = static_cast<T>(other.x);
53 y = static_cast<T>(other.y);
54 return *this;
55 }
56
57 // Vector2<T>
58
63 bool operator==(const Vector2& other) const noexcept {
64 return x == other.x && y == other.y;
65 }
66
71 bool operator!=(const Vector2& other) const noexcept {
72 return !(*this == other);
73 }
74
80 bool operator>(const Vector2& other) const noexcept {
81 return x > other.x && y > other.y;
82 }
83
89 bool operator>=(const Vector2& other) const noexcept {
90 return x >= other.x && y >= other.y;
91 }
92
98 bool operator<(const Vector2& other) const noexcept {
99 return x < other.x && y < other.y;
100 }
101
107 bool operator<=(const Vector2& other) const noexcept {
108 return x <= other.x && y <= other.y;
109 }
110
115 T& operator[](int n) noexcept {
116 assert(n < 2);
117 if(n == 0)
118 return x;
119 else
120 return y;
121 }
122
127 const T& operator[](int n) const noexcept {
128 assert(n < 2);
129 if(n == 0)
130 return x;
131 else
132 return y;
133 }
134
138 Vector2 operator-(void) const noexcept {
139 return Vector2(-x, -y);
140 }
141
146 Vector2 operator+(const Vector2& rhs) const noexcept {
147 return Vector2(x + rhs.x, y + rhs.y);
148 }
149
154 Vector2 operator-(const Vector2& rhs) const noexcept {
155 return Vector2(x - rhs.x, y - rhs.y);
156 }
157
162 Vector2 operator*(const Vector2& rhs) const noexcept {
163 return Vector2(x * rhs.x, y * rhs.y);
164 }
165
170 Vector2 operator/(const Vector2& rhs) const noexcept {
171 return Vector2(x / rhs.x, y / rhs.y);
172 }
173
178 Vector2& operator+=(const Vector2& rhs) noexcept {
179 *this = *this + rhs;
180 return *this;
181 }
182
187 Vector2& operator-=(const Vector2& rhs) noexcept {
188 *this = *this - rhs;
189 return *this;
190 }
191
196 Vector2& operator*=(const Vector2& rhs) noexcept {
197 *this = *this * rhs;
198 return *this;
199 }
200
205 Vector2& operator/=(const Vector2& rhs) noexcept {
206 *this = *this / rhs;
207 return *this;
208 }
209
215 Vector2 operator+(T rhs) const noexcept {
216 return Vector2(x + rhs, y + rhs);
217 }
218
224 Vector2 operator-(T rhs) const noexcept {
225 return Vector2(x - rhs, y - rhs);
226 }
227
233 Vector2 operator*(T rhs) const noexcept {
234 return Vector2(x * rhs, y * rhs);
235 }
236
242 Vector2 operator/(T rhs) const noexcept {
243 return Vector2(x / rhs, y / rhs);
244 }
245
251 Vector2& operator+=(T rhs) noexcept {
252 *this = *this + rhs;
253 return *this;
254 }
255
261 Vector2& operator-=(T rhs) noexcept {
262 *this = *this - rhs;
263 return *this;
264 }
265
271 Vector2& operator*=(T rhs) noexcept {
272 *this = *this * rhs;
273 return *this;
274 }
275
281 Vector2& operator/=(T rhs) noexcept {
282 *this = *this / rhs;
283 return *this;
284 }
285 };
286
289
292
295
298
301
304} // namespace fsdk
SDK namespace.
Definition IAGSEstimator.h:8
Vector2< float > Point2f
Definition Vector2.h:288
Vector2< unsigned int > Point2u
Definition Vector2.h:297
Vector2< int > Size
Definition Vector2.h:303
Vector2< double > Point2d
Definition Vector2.h:291
Vector2< int > Point2i
Definition Vector2.h:294
Vector2< unsigned short > Point2us
Definition Vector2.h:300
Generic 2D vector.
Definition Vector2.h:10
bool operator<=(const Vector2 &other) const noexcept
Checks if both coordinates are smaller or equal to respective coordinates of another vector.
Definition Vector2.h:107
Vector2 operator+(const Vector2 &rhs) const noexcept
Adds (per-element) two vectors.
Definition Vector2.h:146
Vector2 & operator-=(T rhs) noexcept
Subtracts (per-element) a constant to each element of the vector.
Definition Vector2.h:261
T x
x coordinate.
Definition Vector2.h:11
Vector2 operator-(const Vector2 &rhs) const noexcept
Subtracts (per-element) two vectors.
Definition Vector2.h:154
Vector2 operator/(const Vector2 &rhs) const noexcept
Divides (per-element) two vectors.
Definition Vector2.h:170
Vector2 & operator*=(T rhs) noexcept
Multiplies (per-element) a constant to each element of the vector.
Definition Vector2.h:271
Vector2 & operator+=(T rhs) noexcept
Adds (per-element) a constant to each element of the vector.
Definition Vector2.h:251
Vector2() noexcept
Initializes a vector with zeroes.
Definition Vector2.h:16
Vector2 operator*(const Vector2 &rhs) const noexcept
Multiplies (per-element) two vectors.
Definition Vector2.h:162
bool operator!=(const Vector2 &other) const noexcept
Checks if two vectors are not equal.
Definition Vector2.h:71
const T & operator[](int n) const noexcept
Indexes the vector.
Definition Vector2.h:127
T & operator[](int n) noexcept
Indexes the vector.
Definition Vector2.h:115
bool operator>(const Vector2 &other) const noexcept
Checks if both coordinates are greater then respective coordinates of another vector.
Definition Vector2.h:80
Vector2 & operator-=(const Vector2 &rhs) noexcept
Subtracts (per-element) two vectors.
Definition Vector2.h:187
Vector2(T x_, T y_) noexcept
Initializes elements with given value.
Definition Vector2.h:33
Vector2 operator-(T rhs) const noexcept
Subtracts (per-element) a constant to each element of the vector.
Definition Vector2.h:224
bool operator<(const Vector2 &other) const noexcept
Checks if both coordinates are smaller then respective coordinates of another vector.
Definition Vector2.h:98
Vector2 operator-(void) const noexcept
Negates all elements.
Definition Vector2.h:138
bool operator>=(const Vector2 &other) const noexcept
Checks if both coordinates are greater or equal to respective coordinates of another vector.
Definition Vector2.h:89
Vector2(T x_) noexcept
Initializes all elements with the same value.
Definition Vector2.h:24
Vector2 & operator+=(const Vector2 &rhs) noexcept
Adds (per-element) two vectors.
Definition Vector2.h:178
T y
y coordinate.
Definition Vector2.h:12
Vector2< T > & operator=(const Vector2< Other > &other) noexcept
Copies another vector.
Definition Vector2.h:51
bool operator==(const Vector2 &other) const noexcept
Checks if two vectors are equal.
Definition Vector2.h:63
Vector2 & operator/=(T rhs) noexcept
Divides (per-element) a constant to each element of the vector.
Definition Vector2.h:281
Vector2 & operator/=(const Vector2 &rhs) noexcept
Divides (per-element) two vectors.
Definition Vector2.h:205
Vector2 operator/(T rhs) const noexcept
Divides (per-element) a constant to each element of the vector.
Definition Vector2.h:242
Vector2 operator+(T rhs) const noexcept
Adds (per-element) a constant to each element of the vector.
Definition Vector2.h:215
Vector2 operator*(T rhs) const noexcept
Multiplies (per-element) a constant to each element of the vector.
Definition Vector2.h:233
Vector2 & operator*=(const Vector2 &rhs) noexcept
Multiplies (per-element) two vectors.
Definition Vector2.h:196