-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpath.h
60 lines (54 loc) · 1.48 KB
/
path.h
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
#ifndef PATH_H
#define PATH_H
#include<QList>
#include<QPoint>
#include "Road.h"
//路径上的点和车在该点的角度
struct PathPoint
{
QPointF point;
qreal dir = 0;
Road::Action action = Road::Action::none;
int pointId; // 为了做直角生成的辅助节点的id为-1
PathPoint(): point(QPoint(0, 0)), pointId(-2) {}
PathPoint(QPointF p, qreal d, Road::Action a=Road::Action::none, int id=-1):
point(p), action(a), pointId(id) {
while (d < 0 || d > 360) {
if (d < 0)
d += 360;
else if (d > 360)
d -= 360;
}
dir = d;
}
PathPoint(const PathPoint& another) {
point = another.point;
dir = another.dir;
pointId = another.pointId;
action = another.action;
}
void operator=(const PathPoint& another);
bool operator==(const PathPoint& another) const {
return (point == another.point && dir == another.dir);
}
bool operator==(const PathPoint& another) {
return (point == another.point && dir == another.dir);
}
};
class Path
{
public:
Path();
Path(int);
Path(PathPoint points[], int i);
PathPoint getPoint(int i);
void addPoint(int i, const PathPoint &point);
void addPoint(const PathPoint &point);
bool isEmpty();
int pointsCount();
PathPoint getNext();
void regularize(); // 如果三点共线,移除中间那个点
private:
QList<PathPoint> path;
};
#endif // PATH_H