DHART
Loading...
Searching...
No Matches
path.cpp
Go to the documentation of this file.
1
7
8#include <path.h>
9#include <algorithm>
10
11namespace HF::SpatialStructures {
12 void Path::AddNode(int node, float cost) {
13 members.push_back(PathMember{ cost, node });
14 }
15
16 bool Path::empty() const {
17 return members.size() == 0;
18 }
19
20 int Path::size() const {
21 return members.size();
22 }
23
25 std::reverse(members.begin(), members.end());
26 }
27
28 bool Path::operator==(const Path& P2) const {
29
30 // Return early if the sizes of this and P2 don't match
31 if (P2.size() != this->size()) return false;
32
33 // Otherwise, comapre elements one by one
34 for (int i = 0; i < this->size(); i++)
35 {
36 auto our_pm = (*this)[i];
37 auto their_pm = P2[i];
38
39 if (our_pm != their_pm)
40 return false;
41 }
42
43 // If we've gotten this far, then all path members
44 // must be equal.
45 return true;
46 }
47
49 return this->members[i];
50 }
51
52 Path::Path(const std::vector<PathMember> & pm) {
53 this->members = pm;
54 }
55
57 return this->members.data();
58 }
59}
Contains definitions for the Path structure.
Contains standard fundamental data structures for representing space used throughout DHARTAPI.
The ID of a node, and the cost cost to the node after it.
Definition: path.h:19
A collection of nodes that form a path.
Definition: path.h:76
int size() const
Determine how many nodes are in this path.
Definition: path.cpp:20
bool empty() const
Determine if this path has any nodes in it.
Definition: path.cpp:16
PathMember operator[](int i) const
Retrieve the node and cost in this path at index i.
Definition: path.cpp:48
void AddNode(int node, float cost)
Add a new node to the path.
Definition: path.cpp:12
Path::Path()
Construct an empty path.
Definition: path.h:88
std::vector< PathMember > members
Ordered array of PathMembers that comprise the path.
Definition: path.h:78
PathMember * GetPMPointer()
Get a pointer to the path's underlying path members vector.
Definition: path.cpp:56
bool operator==(const Path &p2) const
Determine if this path is identical to p2.
Definition: path.cpp:28
void Reverse()
Reverse the direction of this path.
Definition: path.cpp:24