-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath.cpp
58 lines (48 loc) · 1.18 KB
/
path.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
#include "path.h"
#include <cmath>
Path::Path()
{
}
Path::~Path()
{
}
// Zwraca i-ty węzeł ze ścieżki
// Jeżeli ścieżka nie ma i węzłów
// to zwraca ostani
const Node* Path::getNode(size_t i)const
{
if(i >= nodes.size())
{
return nodes.back();
}
return nodes[i];
}
// Zwraca dlugość scieżki, oblicza odległości między węzłami
// mogło by być odrobinę szybsze gdyby zastosować
// wektor map jako kontener na krawędzie
realT Path::getLength()const
{
realT length = 0;
realT partialLength = 0;
realT previousX = this->nodes.at(0)->getPositionX();
realT previousY = this->nodes.at(0)->getPositionY();
realT currentX, currentY;
for (auto i = 1; i < this->nodes.size(); i++)
{
currentX = this->nodes.at(i)->getPositionX();
currentY = this->nodes.at(i)->getPositionY();
partialLength = sqrt( pow( currentX - previousX, 2 ) + pow( currentY - previousY, 2 ) );
length += partialLength;
if (i != (this->nodes.size() - 1))
{
previousX = currentX;
previousY = currentY;
}
}
return length;
}
// Dodawanie podanego węzła na koniec ścieżki
void Path::addNodeToPath(const Node* node)
{
this->nodes.push_back(node);
}