2 * Copyright (C) 2005-2013 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOSSERVER_PATH_H
20 #define MANGOSSERVER_PATH_H
27 PathNode(): x(0.0f
), y(0.0f
), z(0.0f
) { }
28 PathNode(float _x
, float _y
, float _z
): x(_x
), y(_y
), z(_z
) { }
32 template<typename PathElem
, typename PathNode
= PathElem
>
36 size_t size() const { return i_nodes
.size(); }
37 bool empty() const { return i_nodes
.empty(); }
38 void resize(unsigned int sz
) { i_nodes
.resize(sz
); }
39 void crop(unsigned int start
, unsigned int end
)
41 while (start
&& !i_nodes
.empty())
47 while (end
&& !i_nodes
.empty())
54 void clear() { i_nodes
.clear(); }
56 float GetTotalLength(uint32 start
, uint32 end
) const
59 for (unsigned int idx
= start
+ 1; idx
< end
; ++idx
)
61 PathNode
const& node
= i_nodes
[idx
];
62 PathNode
const& prev
= i_nodes
[idx
- 1];
63 float xd
= node
.x
- prev
.x
;
64 float yd
= node
.y
- prev
.y
;
65 float zd
= node
.z
- prev
.z
;
66 len
+= sqrtf(xd
* xd
+ yd
* yd
+ zd
* zd
);
71 float GetTotalLength() const { return GetTotalLength(0, size()); }
73 float GetPassedLength(uint32 curnode
, float x
, float y
, float z
) const
75 float len
= GetTotalLength(0, curnode
);
79 PathNode
const& node
= i_nodes
[curnode
- 1];
80 float xd
= x
- node
.x
;
81 float yd
= y
- node
.y
;
82 float zd
= z
- node
.z
;
83 len
+= sqrtf(xd
* xd
+ yd
* yd
+ zd
* zd
);
89 PathNode
& operator[](size_t idx
) { return i_nodes
[idx
]; }
90 PathNode
const& operator[](size_t idx
) const { return i_nodes
[idx
]; }
92 void set(size_t idx
, PathElem elem
) { i_nodes
[idx
] = elem
; }
95 std::deque
<PathElem
> i_nodes
;
98 typedef Path
<PathNode
> PointPath
;