-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.h
70 lines (55 loc) · 1.29 KB
/
util.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
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
#pragma once
using uint = unsigned int;
using uchar = unsigned char;
template <typename T, int N>
constexpr int lengthof(T(&array)[N]) {
return N;
}
constexpr int max(int left, int right) {
if (left < right) {
return right;
}
return left;
}
constexpr int min(int left, int right) {
if (left < right) {
return left;
}
return right;
}
constexpr int iceil(float input) {
const int trunced = int(input);
return trunced + (trunced < input);
}
constexpr int iround(float input) {
return iceil(input - 0.5f);
}
enum Direction : uchar {
Horizontal,
Vertical
};
template <typename T>
union vec2 {
struct {
T x, y;
};
T xy[2];
constexpr vec2 operator +(vec2 other) const {
return { x + other.x, y + other.y };
}
constexpr vec2 operator -(vec2 other) const {
return { x - other.x, y - other.y };
}
constexpr vec2 operator *(T number) const {
return { x * number, y * number };
}
constexpr vec2 operator >>(T number) const {
return { x >> number, y >> number };
}
constexpr vec2 operator &(T number) const {
return { x & number, y & number };
}
constexpr bool operator ==(vec2 other) const {
return x == other.x && y == other.y;
}
};