DHART
Loading...
Searching...
No Matches
path.h
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <vector>
12#include <iostream>
13
14#include "Constants.h"
15
17{
19 struct PathMember {
20 float cost;
21 int node;
22
26
41 inline bool operator==(const PathMember& p2) const {
42 // unsafe to test floating point values for equality using == return(cost == p2.cost &&
43 // node == p2.node);
44
45 // Take absolute value of cost - p2.cost, compare to ROUNDING_PRECISION If true, cost
46 // and p2.cost are approximately equal
47 bool approx_equal = std::abs(cost - p2.cost) < HF::SpatialStructures::ROUNDING_PRECISION;
48 return approx_equal && node == p2.node;
49 }
50
54
70 inline bool operator!=(const PathMember& p2) const {
71 return (!((*this) == p2));
72 }
73 };
74
76 struct Path {
77 public:
78 std::vector<PathMember> members;
79
81
89
91
108 Path::Path(const std::vector<PathMember> & pm);
109
114
138 void AddNode(int node, float cost);
139
143
159 bool empty() const;
160
163
185 int size() const;
186
189
209 void Reverse();
210
217
257 bool operator==(const Path& p2) const;
258
262
287 PathMember operator[](int i) const;
288
290
319 };
320};
321
322namespace std {
344 inline ostream& operator<<(ostream& os, const HF::SpatialStructures::Path p) {
345 for (int i = 0; i < p.size(); i++) {
346 const auto& pm = p[i];
347
348 os << "(" << pm.node << ")";
349 if (i != p.size()) {
350 os << " -" << pm.cost << "-> ";
351 }
352 }
353 os << std::endl;
354 return os;
355 }
356}
Contains definitions for the HF::SpatialStructures namespace.
STL namespace.
ostream & operator<<(ostream &os, const HF::SpatialStructures::Node n)
Create a string containing the x,y,z position of this node.
Definition: node.h:433
Contains standard fundamental data structures for representing space used throughout DHARTAPI.
constexpr float ROUNDING_PRECISION
Minimum value that can be represented in DHART_API.
Definition: Constants.h:30
The ID of a node, and the cost cost to the node after it.
Definition: path.h:19
bool operator!=(const PathMember &p2) const
Determines if this pathmember amd p2 do NOT have equal cost/node values.
Definition: path.h:70
float cost
Cost of traversing to the next path member in the path.
Definition: path.h:20
int node
ID of the node this represents in the graph.
Definition: path.h:21
bool operator==(const PathMember &p2) const
Compare the id and cost of this node with p2.
Definition: path.h:41
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