-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutilities.cpp
More file actions
41 lines (35 loc) · 1008 Bytes
/
utilities.cpp
File metadata and controls
41 lines (35 loc) · 1008 Bytes
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
#include "utilities.h"
Rectangle::Rectangle() {
_x = 0;
_y = 0;
_w = 0;
_h = 0;
}
Rectangle::Rectangle(float x, float y, float w, float h) {
_x = x;
_y = y;
_w = w;
_h = h;
}
void Rectangle::operator=(Rectangle r) {
_x = r.getX();
_y = r.getY();
_w = r.getW();
_h = r.getH();
}
bool Rectangle::containsPoint(Point p) {
return containsPoint(p.getX(), p.getY());
}
bool Rectangle::containsPoint(float x, float y) {
return _x <= x && _x + _w >= x && _y <= y && _y + _h >= y;
}
bool Rectangle::collidesWith(Rectangle target) {
return containsPoint(target.getX(), target.getY()) ||
containsPoint(target.getX() + target.getW(), target.getY()) ||
containsPoint(target.getX(), target.getY() + target.getH()) ||
containsPoint(target.getX() + target.getW(), target.getY() + target.getH()) ||
target.containsPoint(_x, _y) ||
target.containsPoint(_x + _h, _y) ||
target.containsPoint(_x, _y + _h) ||
target.containsPoint(_x + _h, _y + _h);
}