-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.cpp
More file actions
69 lines (65 loc) · 1.98 KB
/
Copy pathMap.cpp
File metadata and controls
69 lines (65 loc) · 1.98 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
63
64
65
66
67
68
69
#include "Map.h"
bool Map::isObstacle(CoordSet position){
for(int i = 0; i < lineStartPoints.size(); i++){
// When position x or y is on the as the linePoint
if(lineStartPoints[i].x == position.x || lineStartPoints[i].y == position.y){
// Vertical line
if(lineStartPoints[i].x == lineEndPoints[i].x){
CoordSet lowerY,
higherY;
// Check which CoordSet is highest and lowest
if(lineStartPoints[i].y >= lineEndPoints[i].y){
lowerY = lineEndPoints[i];
higherY = lineStartPoints[i];
} else{
lowerY = lineStartPoints[i];
higherY = lineEndPoints[i];
}
// Check if position.y is between the linePoints y's
if(position.y >= lowerY.y && position.y <= higherY.y)
return true;
}
// Horizontal line
if(lineStartPoints[i].y == lineEndPoints[i].y){
CoordSet lowerX,
higherX;
// Check which CoordSet is highest and lowest
if(lineStartPoints[i].x >= lineEndPoints[i].x){
lowerX = lineEndPoints[i];
higherX = lineStartPoints[i];
} else{
lowerX = lineStartPoints[i];
higherX = lineEndPoints[i];
}
// Check if position.x is between the linePoints x's
if(position.x >= lowerX.x && position.x <= higherX.x)
return true;
}
}
}
return false;
}
void Map::setLinePoints(CoordSet start, CoordSet end){
lineStartPoints.push_back(start);
lineEndPoints.push_back(end);
}
CoordSet* Map::getHorizontalLinePoints(CoordSet point){
for(int i = 0; i < lineStartPoints.size(); i++){
// Horizontal line
if(lineStartPoints[i].y == lineEndPoints[i].y)
// If the linePoint's y is the same as the point.y
if(lineStartPoints[i].y == point.y)
return &lineStartPoints[i];
}
return NULL;
}
CoordSet* Map::getVerticalLinePoints(CoordSet point){
for(int i = 0; i < lineStartPoints.size(); i++){
// Vertical line
if(lineStartPoints[i].x == lineEndPoints[i].x)
// If the linePoint's x is the same as the point.x
if(lineStartPoints[i].x == point.x)
return &lineStartPoints[i];
}
return NULL;
}