-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.cpp
More file actions
121 lines (108 loc) · 1.78 KB
/
util.cpp
File metadata and controls
121 lines (108 loc) · 1.78 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#if !defined(UTIL_CPP)
#define UTIL_CPP
internal inline int32
MinInt32(int32 a, int32 b){
if(a < b){
return a;
}
return b;
}
internal inline int32
MaxInt32(int32 a, int32 b){
if(a > b){
return a;
}
return b;
}
internal inline real32
MinReal32(real32 a, real32 b){
if(a < b){
return a;
}
return b;
}
internal inline real32
MaxReal32(real32 a, real32 b){
if(a > b){
return a;
}
return b;
}
internal uint32
CapInt32(int32 a, int32 t, int32 b){
if(t < a){
return a;
}else if (t > b){
return b; }
return t;
}
internal inline real32
ClampReal32(real32 t, real32 a, real32 b){
if(t < a){
return a;
}
if(b < t){
return b;
}
return t;
}
real32 Min3Real32(real32 A, real32 B, real32 C){
if (A < B){
if(C < A){
return C;
}
return A;
}
//B < A
if(C < B){
return C;
}
return B;
}
real32 Max3Real32(real32 A, real32 B, real32 C){
if (A > B){
if(C > A){
return C;
}
return A;
}
//B > A
if(C > B){
return C;
}
return B;
}
internal inline bool32
IsInBounds(int32 i, int32 j, int32 MaxI, int32 MaxJ){
if(i < 0 || j < 0 || i >= MaxI || j >= MaxJ){
return false;
}
return true;
}
internal inline bool32
IsPInBounds(vec2i P, int32 MaxI, int32 MaxJ){
return IsInBounds(P.X, P.Y, MaxI, MaxJ);
}
internal inline bool32
IsInBounds(real32 i, real32 j, real32 MaxI, real32 MaxJ){
if(i < 0 || j < 0 || i >= MaxI || j >= MaxJ){
return false;
}
return true;
}
internal inline bool32
IsPInBounds(vec2f P, real32 MaxI, real32 MaxJ){
return IsInBounds(P.X, P.Y, MaxI, MaxJ);
}
internal bool
IsInsideRect(real32 X, real32 Y, rectangle Rect){
if(X >= Rect.MinX && X < Rect.MaxX && Y >= Rect.MinY && Y < Rect.MaxY){
return true;
}
return false;
}
internal bool
IsPInsideRect(vec2f P, rectangle Rect){
return IsInsideRect(P.X, P.Y, Rect);
}
#endif //UTIL_CPP