Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
Path.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#ifndef SKYFIRESERVER_PATH_H
7#define SKYFIRESERVER_PATH_H
8
9#include "Common.h"
10#include <deque>
11
13{
14 PathNode() : x(0.0f), y(0.0f), z(0.0f) { }
15 PathNode(float _x, float _y, float _z) : x(_x), y(_y), z(_z) { }
16 float x, y, z;
17};
18template<typename PathElem, typename PathNode = PathElem>
19
20class Path
21{
22public:
23 size_t size() const { return i_nodes.size(); }
24 bool empty() const { return i_nodes.empty(); }
25 void resize(unsigned int sz) { i_nodes.resize(sz); }
26 void clear() { i_nodes.clear(); }
27 void erase(uint32 idx) { i_nodes.erase(i_nodes.begin() + idx); }
28 void crop(unsigned int start, unsigned int end)
29 {
30 while (start && !i_nodes.empty())
31 {
32 i_nodes.pop_front();
33 --start;
34 }
35
36 while (end && !i_nodes.empty())
37 {
38 i_nodes.pop_back();
39 --end;
40 }
41 }
42
43 float GetTotalLength(uint32 start, uint32 end) const
44 {
45 float len = 0.0f;
46 for (uint32 idx = start + 1; idx < end; ++idx)
47 {
48 PathNode const& node = i_nodes[idx];
49 PathNode const& prev = i_nodes[idx - 1];
50 float xd = node.x - prev.x;
51 float yd = node.y - prev.y;
52 float zd = node.z - prev.z;
53 len += sqrtf(xd * xd + yd * yd + zd * zd);
54 }
55 return len;
56 }
57
58 float GetTotalLength() const { return GetTotalLength(0, size()); }
59
60 float GetPassedLength(uint32 curnode, float x, float y, float z) const
61 {
62 float len = GetTotalLength(0, curnode);
63
64 if (curnode > 0)
65 {
66 PathNode const& node = i_nodes[curnode - 1];
67 float xd = x - node.x;
68 float yd = y - node.y;
69 float zd = z - node.z;
70 len += sqrtf(xd * xd + yd * yd + zd * zd);
71 }
72
73 return len;
74 }
75
76 PathNode& operator[](size_t idx) { return i_nodes[idx]; }
77 PathNode const& operator[](size_t idx) const { return i_nodes[idx]; }
78
79 void set(size_t idx, PathElem elem) { i_nodes[idx] = elem; }
80
81protected:
82 std::deque<PathElem> i_nodes;
83};
84
86
87#endif
std::uint32_t uint32
Definition Define.h:77
Path< PathNode > SimplePath
Definition Path.h:85
Definition Path.h:21
float GetPassedLength(uint32 curnode, float x, float y, float z) const
Definition Path.h:60
void set(size_t idx, PathElem elem)
Definition Path.h:79
void erase(uint32 idx)
Definition Path.h:27
std::deque< TaxiPathNodePtr > i_nodes
Definition Path.h:82
void crop(unsigned int start, unsigned int end)
Definition Path.h:28
void clear()
Definition Path.h:26
void resize(unsigned int sz)
Definition Path.h:25
float GetTotalLength(uint32 start, uint32 end) const
Definition Path.h:43
size_t size() const
Definition Path.h:23
bool empty() const
Definition Path.h:24
PathNode & operator[](size_t idx)
Definition Path.h:76
float GetTotalLength() const
Definition Path.h:58
PathNode const & operator[](size_t idx) const
Definition Path.h:77
PathNode(float _x, float _y, float _z)
Definition Path.h:15
float z
Definition Path.h:16
PathNode()
Definition Path.h:14
float x
Definition Path.h:16
float y
Definition Path.h:16