-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.cpp
164 lines (143 loc) · 2.97 KB
/
node.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "node.h"
#include <QtDebug>
Node::Node()
{
x = 0;
x = 0;
padding = 0;
size = 0;
is_obstacle = false;
is_visited = false;
is_start_node = false;
is_end_node = false;
parent = nullptr;
}
Node::Node(int x, int y, int padding, int size)
{
this->x = x;
this->y = y;
this->padding = padding;
this->size = size;
is_obstacle = false;
is_visited = false;
is_start_node = false;
is_end_node = false;
parent = nullptr;
}
Node::~Node()
{
}
int Node::get_x()
{
return x;
}
int Node::get_y()
{
return y;
}
void Node::add_neighbour(Node *neighbour)
{
neighbours.push_back(neighbour);
}
std::vector<Node *> Node::get_neighbours_list()
{
return neighbours;
}
void Node::mark_as_start(bool marked)
{
is_end_node = false;
is_obstacle = false;
is_visited = false;
is_start_node = marked;
update();
}
void Node::mark_as_end(bool marked)
{
is_start_node = false;
is_obstacle = false;
is_visited = false;
is_end_node = marked;
update();
}
void Node::restart()
{
global_goal = INFINITY;
local_goal = INFINITY;
set_visited(false);
parent = nullptr;
}
void Node::set_local_goal(float value)
{
local_goal = value;
}
float Node::get_local_goal()
{
return local_goal;
}
bool Node::get_is_visited()
{
return is_visited;
}
float Node::get_global_goal()
{
return global_goal;
}
void Node::set_global_goal(float value)
{
global_goal = value;
}
void Node::set_visited(bool value)
{
is_visited = value;
update();
}
QRectF Node::boundingRect() const
{
return QRectF(x + padding, y + padding, size - 10, size - 10);
}
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
if(is_obstacle)
{
painter->setPen(QPen(QColor(160, 161, 164)));
painter->setBrush(QBrush(QColor(160, 161, 164)));
painter->drawRect(boundingRect());
return;
}
if(is_start_node)
{
painter->setPen(QPen(QColor(105, 240, 174)));
painter->setBrush(QBrush(QColor(105, 240, 174)));
painter->drawRect(boundingRect());
return;
}
if (is_end_node)
{
painter->setPen(QPen(QColor(255, 82, 82)));
painter->setBrush(QBrush(QColor(255, 82, 82)));
painter->drawRect(boundingRect());
return;
}
if(is_path)
{
painter->setPen(QPen(QColor(255, 196, 0)));
painter->setBrush(QBrush(QColor(255, 196, 0)));
painter->drawRect(boundingRect());
return;
}
if (is_visited)
{
painter->setPen(QPen(QColor(90, 91, 104)));
painter->setBrush(QBrush(QColor(90, 91, 104)));
painter->drawRect(boundingRect());
return;
}
painter->setPen(QPen(QColor(70, 71, 84)));
painter->setBrush(QBrush(QColor(70, 71, 84)));
painter->drawRect(boundingRect());
}
void Node::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
is_obstacle = !is_obstacle;
update();
}