blob: e9b25896e795dad0d4ff0dd5a6aece94b81bbe6f (
plain) (
blame)
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
|
#pragma once
class CRect
{
public:
float left; // x min
float bottom; // y max
float right; // x max
float top; // y min
CRect(void);
CRect(float l, float t, float r, float b);
void ContainPoint(CVector const &v){
if(v.x < left) left = v.x;
if(v.x > right) right = v.x;
if(v.y < top) top = v.y;
if(v.y > bottom) bottom = v.y;
}
void ContainRect(const CRect &r){
if(r.left < left) left = r.left;
if(r.right > right) right = r.right;
if(r.top < top) top = r.top;
if(r.bottom > bottom) bottom = r.bottom;
}
bool IsPointInside(const CVector2D &p){
return p.x >= left &&
p.x <= right &&
p.y >= top &&
p.y <= bottom;
}
bool IsPointInside(const CVector2D &p, float extraRadius){
return p.x >= left-extraRadius &&
p.x <= right+extraRadius &&
p.y >= top-extraRadius &&
p.y <= bottom+extraRadius;
}
void Translate(float x, float y){
left += x;
right += x;
bottom += y;
top += y;
}
void Grow(float r) {
left -= r;
right += r;
top -= r;
bottom += r;
}
void Grow(float l, float r)
{
left -= l;
top -= l;
right += r;
bottom += r;
}
void Grow(float l, float r, float t, float b)
{
left -= l;
top -= t;
right += r;
bottom += b;
}
float GetWidth(void) { return right - left; }
float GetHeight(void) { return bottom - top; }
};
|