MCPcopy Create free account
hub / github.com/KAlO2/PerfectShow / vec2

Class vec2

jni/venus/vec2.h:9–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7
8template <typename T>
9class vec2
10{
11public:
12
13// https://msdn.microsoft.com/en-us/library/2c8f766e.aspx
14#ifdef _WIN32
15# pragma warning(push)
16# pragma warning(disable: 4201) // warning C4201: nonstandard extension used: nameless struct/union
17#endif
18 union
19 {
20 T data[2];
21 struct { T x, y; }; // 2D coordinate
22 struct { T i, j; }; // index, integer pair
23 struct { T s, t; }; // texture
24 struct { T u, v; }; // texture
25
26 struct { T gray, alpha; }; // color
27 struct { T rho, theta; }; // polar coordinate
28 struct { T width, height; }; // size
29 struct { T column, row; }; // grid, index, notice the order
30 struct { T min, max; }; // 1D AABB
31 struct { T slice, stack; }; // cut shape
32 };
33
34#ifdef _WIN32
35# pragma warning(pop)
36#endif
37
38 typedef T value_type;
39
40public:
41 vec2() = default;
42 ~vec2() = default;
43
44 explicit vec2(const T *array): x(array[0]), y(array[1]) { }
45 explicit vec2(T scalar): x(scalar), y(scalar) { }
46 vec2(T x, T y): x(x), y(y) { }
47
48 vec2(const vec2<T>& v): x(v.x), y(v.y) {}
49
50 vec2<T>& operator =(const vec2<T>& rhs)
51 {
52 if(this != &rhs)
53 {
54 x = rhs.x;
55 y = rhs.y;
56 }
57 return *this;
58 }
59
60 // assignment operators
61 vec2<T>& operator +=(const vec2<T>& rhs) { x += rhs.x; y += rhs.y; return *this; }
62 vec2<T>& operator -=(const vec2<T>& rhs) { x -= rhs.x; y -= rhs.y; return *this; }
63 vec2<T>& operator *=(T value) { x *= value; y *= value; return *this; }
64 vec2<T>& operator /=(T value) { x /= value; y /= value; return *this; }
65
66 /**

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected