| Face Engine SDK 4.7.0 A face detection, recognition and tracking engine.

Vector2.h
1 #pragma once
2
3 #include <cassert>
4
5 namespace fsdk
6 {
10 template<typename T>
11 struct Vector2 {
13 union {
15 struct {
16 T x;
17 T y;
18 };
19
20 T array[2];
21 };
22
25 Vector2() noexcept
26 : x((T)0), y(T(0)) {}
27
31 explicit Vector2(T x_) noexcept
32 : x(x_), y(x_) {}
33
38 Vector2(T x_, T y_) noexcept
39 : x(x_), y(y_) {}
40
44 template<typename Other>
45 Vector2<T>(const Vector2<Other>& other) noexcept {
46 *this = other;
47 }
48
53 template <typename Other>
54 Vector2<T>& operator = (const Vector2<Other>& other) noexcept {
55 x = static_cast<T>(other.x);
56 y = static_cast<T>(other.y);
57 return *this;
58 }
59
60 //Vector2<T>
61
66 bool operator == (const Vector2& other) const noexcept {
67 return x == other.x &&
68 y == other.y;
69 }
70
75 bool operator != (const Vector2& other) const noexcept {
76 return !(*this == other);
77 }
78
84 bool operator > (const Vector2& other) const noexcept {
85 return x > other.x && y > other.y;
86 }
87
93 bool operator >= (const Vector2& other) const noexcept {
94 return x >= other.x && y >= other.y;
95 }
96
102 bool operator < (const Vector2& other) const noexcept {
103 return x < other.x && y < other.y;
104 }
105
111 bool operator <= (const Vector2& other) const noexcept {
112 return x <= other.x && y <= other.y;
113 }
114
119 T& operator [] (int n) noexcept {
120 assert(n < 2);
121 return array[n];
122 }
123
128 const T& operator [] (int n) const noexcept {
129 assert(n < 2);
130 return array[n];
131 }
132
136 Vector2 operator - (void) const noexcept {
137 return Vector2(-x, -y);
138 }
139
144 Vector2 operator + (const Vector2& rhs) const noexcept {
145 return Vector2(x + rhs.x, y + rhs.y);
146 }
147
152 Vector2 operator - (const Vector2& rhs) const noexcept {
153 return Vector2(x - rhs.x, y - rhs.y);
154 }
155
160 Vector2 operator * (const Vector2& rhs) const noexcept {
161 return Vector2(x * rhs.x, y * rhs.y);
162 }
163
168 Vector2 operator / (const Vector2& rhs) const noexcept {
169 return Vector2(x / rhs.x, y / rhs.y);
170 }
171
176 Vector2& operator += (const Vector2& rhs) noexcept {
177 *this = *this + rhs;
178 return *this;
179 }
180
185 Vector2& operator -= (const Vector2& rhs) noexcept {
186 *this = *this - rhs;
187 return *this;
188 }
189
194 Vector2& operator *= (const Vector2& rhs) noexcept {
195 *this = *this * rhs;
196 return *this;
197 }
198
203 Vector2& operator /= (const Vector2& rhs) noexcept {
204 *this = *this / rhs;
205 return *this;
206 }
207
213 Vector2 operator + (T rhs) const noexcept {
214 return Vector2(x + rhs, y + rhs);
215 }
216
222 Vector2 operator - (T rhs) const noexcept {
223 return Vector2(x - rhs, y - rhs);
224 }
225
231 Vector2 operator * (T rhs) const noexcept {
232 return Vector2(x * rhs, y * rhs);
233 }
234
240 Vector2 operator / (T rhs) const noexcept {
241 return Vector2(x / rhs, y / rhs);
242 }
243
249 Vector2& operator += (T rhs) noexcept {
250 *this = *this + rhs;
251 return *this;
252 }
253
259 Vector2& operator -= (T rhs) noexcept {
260 *this = *this - rhs;
261 return *this;
262 }
263
269 Vector2& operator *= (T rhs) noexcept {
270 *this = *this * rhs;
271 return *this;
272 }
273
279 Vector2& operator /= (T rhs) noexcept {
280 *this = *this / rhs;
281 return *this;
282 }
283 };
284
286 typedef Vector2<float> Point2f;
287
289 typedef Vector2<double> Point2d;
290
292 typedef Vector2<int> Point2i;
293
295 typedef Vector2<unsigned int> Point2u;
296
298 typedef Vector2<unsigned short> Point2us;
299
301 typedef Vector2<int> Size;
302 }
fsdk::Vector2::operator!=
bool operator!=(const Vector2 &other) const noexcept
Checks if two vectors are not equal.
Definition: Vector2.h:75
fsdk::Vector2::operator-
Vector2 operator-(void) const noexcept
Negates all elements.
Definition: Vector2.h:136
fsdk::Vector2::operator=
Vector2< T > & operator=(const Vector2< Other > &other) noexcept
Copies another vector.
Definition: Vector2.h:54
fsdk::Vector2::Vector2
Vector2(const Vector2< Other > &other) noexcept
Copies another vector.
Definition: Vector2.h:45
fsdk::Vector2::operator*
Vector2 operator*(const Vector2 &rhs) const noexcept
Multiplies (per-element) two vectors.
Definition: Vector2.h:160
fsdk::Vector2::operator<=
bool operator<=(const Vector2 &other) const noexcept
Checks if both coordinates are smaller or equal to respective coordinates of another vector.
Definition: Vector2.h:111
fsdk::Vector2
Generic 2D vector.
Definition: Vector2.h:11
fsdk::Point2f
Vector2< float > Point2f
Definition: Vector2.h:286
fsdk
SDK namespace.
Definition: IAGSEstimator.h:8
fsdk::Point2us
Vector2< unsigned short > Point2us
Definition: Vector2.h:298
fsdk::Vector2::Vector2
Vector2() noexcept
Initializes a vector with zeroes.
Definition: Vector2.h:25
fsdk::Vector2::x
T x
x coordinate.
Definition: Vector2.h:16
fsdk::Vector2::Vector2
Vector2(T x_) noexcept
Initializes all elements with the same value.
Definition: Vector2.h:31
fsdk::Vector2::operator==
bool operator==(const Vector2 &other) const noexcept
Checks if two vectors are equal.
Definition: Vector2.h:66
fsdk::Vector2::operator+
Vector2 operator+(const Vector2 &rhs) const noexcept
Adds (per-element) two vectors.
Definition: Vector2.h:144
fsdk::Size
Vector2< int > Size
Definition: Vector2.h:301
fsdk::Vector2::operator/
Vector2 operator/(const Vector2 &rhs) const noexcept
Divides (per-element) two vectors.
Definition: Vector2.h:168
fsdk::Vector2::operator>
bool operator>(const Vector2 &other) const noexcept
Checks if both coordinates are greater then respective coordinates of another vector.
Definition: Vector2.h:84
fsdk::Point2i
Vector2< int > Point2i
Definition: Vector2.h:292
fsdk::Vector2::operator<
bool operator<(const Vector2 &other) const noexcept
Checks if both coordinates are smaller then respective coordinates of another vector.
Definition: Vector2.h:102
fsdk::Vector2::y
T y
y coordinate.
Definition: Vector2.h:17
fsdk::Vector2::array
T array[2]
Array for iteration.
Definition: Vector2.h:20
fsdk::Vector2::operator-=
Vector2 & operator-=(const Vector2 &rhs) noexcept
Subtracts (per-element) two vectors.
Definition: Vector2.h:185
fsdk::Vector2::operator+=
Vector2 & operator+=(const Vector2 &rhs) noexcept
Adds (per-element) two vectors.
Definition: Vector2.h:176
fsdk::Point2d
Vector2< double > Point2d
Definition: Vector2.h:289
fsdk::Vector2::operator>=
bool operator>=(const Vector2 &other) const noexcept
Checks if both coordinates are greater or equal to respective coordinates of another vector.
Definition: Vector2.h:93
fsdk::Vector2::operator*=
Vector2 & operator*=(const Vector2 &rhs) noexcept
Multiplies (per-element) two vectors.
Definition: Vector2.h:194
fsdk::Vector2::operator/=
Vector2 & operator/=(const Vector2 &rhs) noexcept
Divides (per-element) two vectors.
Definition: Vector2.h:203
fsdk::Point2u
Vector2< unsigned int > Point2u
Definition: Vector2.h:295
fsdk::Vector2::operator[]
T & operator[](int n) noexcept
Indexes the vector.
Definition: Vector2.h:119