blob: ea6eba5f322670cc73d3a035279c54b56c49803f (
plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#ifndef MGLPP_VEC_HPP
#define MGLPP_VEC_HPP
namespace mgl {
template <typename T>
struct vec2 {
vec2(T x = 0, T y = 0) : x(x), y(y) {}
vec2<T> operator + (vec2<T> other) const {
return { x + other.x, y + other.y };
}
vec2<T> operator - (vec2<T> other) const {
return { x - other.x, y - other.y };
}
vec2<T> operator * (vec2<T> other) const {
return { x * other.x, y * other.y };
}
vec2<T> operator * (T v) const {
return { x * v, y * v };
}
vec2<T> operator / (T v) const {
return { x / v, y / v };
}
vec2<T>& operator += (vec2<T> other) {
x += other.x;
y += other.y;
return *this;
}
vec2<T>& operator -= (vec2<T> other) {
x -= other.x;
y -= other.y;
return *this;
}
vec2<T>& operator *= (vec2<T> other) {
x *= other.x;
y *= other.y;
return *this;
}
vec2<T>& operator *= (T v) {
x *= v;
y *= v;
return *this;
}
vec2<T>& operator /= (T v) {
x /= v;
y /= v;
return *this;
}
vec2<float> to_vec2f() const {
return { (float)x, (float)y };
}
T x;
T y;
};
using vec2f = vec2<float>;
using vec2d = vec2<double>;
using vec2i = vec2<int>;
using vec2u = vec2<unsigned int>;
}
#endif /* MGLPP_VEC_HPP */
|