-
Notifications
You must be signed in to change notification settings - Fork 0
/
vec2.h
41 lines (28 loc) · 1.42 KB
/
vec2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#pragma once
template<typename T>
class vec2
{
public:
T x;
T y;
vec2() : x(0), y(0) {}
vec2(const T& vX, const T& vY) : x(vX), y(vY) {}
vec2(const vec2<T>& v) : vec2(v.x, v.y) {}
~vec2() {}
vec2<T> operator+ (const vec2<T>& v) const { return vec2(x + v.x, y + v.y); }
vec2<T> operator- (const vec2<T>& v) const { return vec2(x - v.x, y - v.y); }
vec2<T> operator* (const vec2<T>& v) const { return vec2(x * v.x, y * v.y); }
vec2<T> operator/ (const vec2<T>& v) const { return vec2(x / v.x, y / v.y); }
vec2<T> operator* (const T& val ) const { return vec2(x * val, y * val); }
vec2<T> operator/ (const T& val ) const { return vec2(x / val, y / val); }
vec2<T>&& operator+= (const vec2<T>& v) { return *this + v; }
vec2<T>&& operator-= (const vec2<T>& v) { return *this - v; }
vec2<T>&& operator*= (const vec2<T>& v) { return *this * v; }
vec2<T>&& operator/= (const vec2<T>& v) { return *this / v; }
vec2<T>&& operator*= (const T& val ) { return *this * val; }
vec2<T>&& operator/= (const T& val ) { return *this / val; }
T& operator[] (const size_t i) { return *((T*)this + i); }
const T& operator[] (const size_t i) const { return *((T*)this + i); }
inline void mPrint() const { std::cout << x << " " << y << "\n"; }
vec2<T> mGetSwapped() const { return vec2<T>(y, x); }
};