blob: 7cd208ad868f2f87e9c98579c11933ef72a3a933 (
plain)
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
|
#include "stdafx.h"
#include "Rect2i.h"
Rect2i::Rect2i(int x, int y, int width, int height)
{
xPos = x;
yPos = y;
this->width = width;
this->height = height;
}
Rect2i *Rect2i::intersect(const Rect2i *other)
{
int x0 = xPos;
int y0 = yPos;
int x1 = xPos + width;
int y1 = yPos + height;
int x2 = other->getX();
int y2 = other->getY();
int x3 = x2 + other->getWidth();
int y3 = y2 + other->getHeight();
xPos = max(x0, x2);
yPos = max(y0, y2);
width = max(0, min(x1, x3) - xPos);
height = max(0, min(y1, y3) - yPos);
return this;
}
int Rect2i::getX() const
{
return xPos;
}
int Rect2i::getY() const
{
return yPos;
}
void Rect2i::setX(int x)
{
xPos = x;
}
void Rect2i::setY(int y)
{
yPos = y;
}
int Rect2i::getWidth() const
{
return width;
}
int Rect2i::getHeight() const
{
return height;
}
void Rect2i::setWidth(int width)
{
this->width = width;
}
void Rect2i::setHeight(int height)
{
this->height = height;
}
void Rect2i::setPosition(int x, int y)
{
xPos = x;
yPos = y;
}
|