-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.h
executable file
·82 lines (59 loc) · 1.8 KB
/
math.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
70
71
72
73
74
75
76
77
78
79
80
81
82
// APK - Copyright (c) 2024 by Robin Southern. https://github.com/betajaen/apk
// Licensed under the MIT License; see LICENSE file.
#pragma once
#include "pod.h"
namespace apk {
inline uint32 mul_320(uint32 x) {
return (x << 8) + (x << 6);
}
template<typename T>
inline T MIN(const T& lhs, const T& rhs) {
return (lhs < rhs ? lhs : rhs);
}
template<typename T1, typename T2>
inline T1 MIN(const T1& lhs, const T2& rhs) {
return (lhs < rhs ? lhs : rhs);
}
template<typename T>
inline T ABS(T v) {
return v < 0 ? -v : v;
}
template<typename T>
inline T MAX(T lhs, T rhs) {
return (lhs > rhs) ? lhs : rhs;
}
template<typename T>
inline T CLIP(T x, T min, T max) {
if (x < min)
x = min;
else if (x > max)
x = max;
return x;
}
struct Point {
int16 x, y;
Point() : x(0), y(0) {}
Point(int16 X, int16 Y) : x(X), y(Y) {}
};
struct Rect {
int16 top, left, right, bottom;
Rect() : top(0), left(0), right(0), bottom(0) {}
Rect(int16 L, int16 T, int16 R, int16 H) : top(L), left(T), right(R), bottom(H) {}
Rect(int16 R, int16 B) : top(0), left(0), right(R), bottom(B) {}
bool contains(int16 x, int16 y) const {
return (left <= x) && (x < right) && (top <= y) && (y < bottom);
}
bool isEmpty() const {
return (left >= right || top >= bottom);
}
bool intersects(Rect& rect) {
return (left < rect.right) && (rect.left < right) && (top < rect.bottom) && (rect.top < bottom);
}
int16 width() const {
return right - left;
}
int16 height() const {
return bottom - top;
}
};
}