-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMyStruct.cpp
More file actions
62 lines (54 loc) · 1.14 KB
/
MyStruct.cpp
File metadata and controls
62 lines (54 loc) · 1.14 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
#include "MyStruct.h"
long max(long left,long right)
{
if(left > right)
{
return left;
}
else
{
return right;
}
}
long min(long left,long right)
{
if(left < right)
{
return left;
}
else
{
return right;
}
}
bool MRect::IntersectRect(MRect& source1,MRect& source2)
{
long maxX = max(source1.left,source2.left);
long maxY = max(source1.top,source2.top);
long minX = min(source1.right,source2.right);
long minY = min(source1.bottom,source2.bottom);
if(maxX < minX && maxY < minY)
{
this->top = maxY;
this->left = maxX;
this->bottom = minY;
this->right = minX;
return 1;
}
else
{
this->top = this->left = this->bottom = this->right = 0;
return 0;
}
}
void MRect::UnionRect(MRect& source1,MRect& source2)
{
long minX = min(source1.left,source2.left);
long minY = min(source1.top,source2.top);
long maxX = max(source1.right,source2.right);
long maxY = max(source1.bottom,source2.bottom);
this->top = minY;
this->left = minX;
this->bottom = maxY;
this->right = maxX;
}