-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.cpp
42 lines (35 loc) · 872 Bytes
/
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
#include "Node.h"
//static id, used when a new node is created.
static int globalId = 0;
//default constructor
Node::Node(float _x, float _y) : id(globalId++) {
edges = std::vector<Edge>();
x = _x;
y = _y;
cost = INT_MAX;
prev = NULL;
onPath = false;
visited = false;
obstacle = false;
}
//determines the opposing node on an edge.
//if the edge does not contain the current node, it will return the current node
Node Node::getOtherNode(Edge e) {
if (e.n1.getId() == getId()) {
return e.n2;
}
else if (e.n2.getId() == getId()) {
return e.n1;
}
else {
return *this;
}
}
//links two nodes together via and edge. Updates both nodes edges vector
void Node::addNode(Node& n, int edgeCost) {
//creates an edge corresponding to nodes
Edge e = { *this, n, edgeCost };
//adds the edge to the vector in both nodes.
(*this).addEdge(e);
n.addEdge(e);
}