-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrectcollider.cpp
More file actions
50 lines (42 loc) · 1.29 KB
/
rectcollider.cpp
File metadata and controls
50 lines (42 loc) · 1.29 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
#include "rectcollider.h"
#include "coordinate.h"
RectCollider::RectCollider(Coordinate* v1, Coordinate* v2)
: v1(v1),
v2(v2) {}
RectCollider::~RectCollider() {
delete v1;
delete v2;
}
bool RectCollider::checkCollision(const RectCollider& other) {
bool x_overlap = !(this->getMinXBound() > other.getMaxXBound() || this->getMaxXBound() < other.getMinXBound());
bool y_overlap = !(this->getMinYBound() > other.getMaxYBound() || this->getMaxYBound() < other.getMinYBound());
return x_overlap && y_overlap;
}
double RectCollider::getMinXBound() const {
if (v1->getXCoordinate() < v2->getXCoordinate()) {
return v1->getXCoordinate();
} else {
return v2->getXCoordinate();
}
}
double RectCollider::getMaxXBound() const {
if (v1->getXCoordinate() > v2->getXCoordinate()) {
return v1->getXCoordinate();
} else {
return v2->getXCoordinate();
}
}
double RectCollider::getMinYBound() const {
if (v1->getYCoordinate() < v2->getYCoordinate()) {
return v1->getYCoordinate();
} else {
return v2->getYCoordinate();
}
}
double RectCollider::getMaxYBound() const {
if (v1->getYCoordinate() > v2->getYCoordinate()) {
return v1->getYCoordinate();
} else {
return v2->getYCoordinate();
}
}