30 #ifndef PLANNER_CSPACE_CYCLIC_VEC_H 31 #define PLANNER_CSPACE_CYCLIC_VEC_H 34 #define _USE_MATH_DEFINES 37 #include <initializer_list> 40 #include <unordered_map> 43 #include <boost/chrono.hpp> 54 inline void convert(
const int val,
float& ret)
58 inline void convert(
const float val,
int& ret)
75 template <
int DIM,
int NONCYCLIC,
typename T>
80 std::is_same<float, T>() || std::is_same<int, T>(),
"T must be float or int");
83 template <
typename T2,
typename... ArgList>
84 void setElements(
const int i,
const T2& first,
const ArgList&... rest) noexcept
89 setElements(i + 1, rest...);
96 template <
typename... ArgList>
99 const int res,
const ArgList&... rest)
104 if (e_[i] < res / 2 - res)
106 else if (e_[i] >= res / 2)
109 cycleElements(i + 1, rest...);
115 template <
typename... ArgList>
118 const int res,
const ArgList&... rest)
126 cycleUnsignedElements(i + 1, rest...);
134 template <
typename T2>
137 for (
int i = 0; i < DIM; i++)
140 template <
typename... ArgList>
143 setElements(0, v,
args...);
145 template <
typename... ArgList>
148 setElements(0, v,
args...);
153 template <
typename T2>
156 for (
int i = 0; i < DIM; i++)
157 if (v.
e_[i] != e_[i])
161 template <
typename T2>
164 return !(*
this == v);
166 template <
typename T2>
170 for (
int i = 0; i < DIM; i++)
176 template <
typename T2>
180 for (
int i = 0; i < DIM; i++)
186 template <
typename T2>
190 for (
int i = 0; i < DIM; i++)
192 out[i] = e_[i] * v[i];
198 return (*
this)[0] * a[1] - (*this)[1] * a[0];
202 return (*
this)[0] * a[0] + (*this)[1] * a[1];
208 return (b - a).cross2d((*
this) - a) / (b - a).len();
214 const auto to_a = (*this) - a;
215 if ((b - a).dot2d(to_a) <= 0)
217 const auto to_b = (*this) - b;
218 if ((a - b).dot2d(to_b) <= 0)
220 return fabs(distLine2d(a, b));
233 for (
int i = 0; i < NONCYCLIC; i++)
235 out += e_[i] * e_[i];
241 return sqrtf(sqlen());
245 const auto l = len();
246 return l /
static_cast<int>(l);
251 for (
int i = 0; i < DIM; i++)
253 out += powf(e_[i], 2.0);
260 const auto tmp = *
this;
261 const float cos_v = cosf(ang);
262 const float sin_v = sinf(ang);
266 this->e_[2] = tmp[2] + ang;
271 template <
typename... ArgList>
272 void cycle(
const int res,
const ArgList&... rest)
275 std::is_same<int, T>(),
"cycle is provided only for int");
276 cycleElements(NONCYCLIC, res, rest...);
278 template <
typename... ArgList>
282 std::is_same<int, T>(),
"cycle is provided only for int");
283 cycleUnsignedElements(NONCYCLIC, res, rest...);
288 std::is_same<int, T>(),
"cycle is provided only for int");
289 for (
int i = NONCYCLIC; i < DIM; ++i)
290 cycleElements(i, res[i]);
295 std::is_same<int, T>(),
"cycle is provided only for int");
296 for (
int i = NONCYCLIC; i < DIM; ++i)
297 cycleUnsignedElements(i, res[i]);
303 size_t hash =
static_cast<size_t>(key.
e_[0]);
304 for (
int i = 1; i < DIM; i++)
306 const size_t n = 8 *
sizeof(std::size_t) * i / DIM;
307 const size_t x =
static_cast<size_t>(key.
e_[i]);
308 hash ^= (x << n) | (x >> ((8 *
sizeof(size_t)) - n));
316 std::is_same<int, T>(),
"isExceeded is provided only for T=int");
317 for (
int i = 0; i < NONCYCLIC; ++i)
319 if (static_cast<unsigned int>((*
this)[i]) >= static_cast<unsigned int>(v[i]))
326 template <
int DIM,
int NONCYCLIC>
328 template <
int DIM,
int NONCYCLIC>
331 #endif // PLANNER_CSPACE_CYCLIC_VEC_H size_t operator()(const CyclicVecBase &key) const
const T & operator[](const int &x) const
void cycleUnsigned(const int res, const ArgList &...rest)
CyclicVecBase< DIM, NONCYCLIC, T2 > operator+(const CyclicVecBase< DIM, NONCYCLIC, T2 > &v) const
void cycleElements(const int i, const int res, const ArgList &...rest)
void rotate(const float ang)
bool operator==(const CyclicVecBase< DIM, NONCYCLIC, T2 > &v) const
float distLinestrip2d(const CyclicVecBase< DIM, NONCYCLIC, T > &a, const CyclicVecBase< DIM, NONCYCLIC, T > &b) const
CyclicVecBase(const CyclicVecBase< DIM, NONCYCLIC, T2 > &c) noexcept
void cycleUnsigned(const CyclicVecBase< DIM, NONCYCLIC, T > &res)
T & operator[](const int &x)
void cycleElements(const int i)
bool operator!=(const CyclicVecBase< DIM, NONCYCLIC, T2 > &v) const
CyclicVecBase< DIM, NONCYCLIC, T2 > operator*(const CyclicVecBase< DIM, NONCYCLIC, T2 > &v) const
float distLine2d(const CyclicVecBase< DIM, NONCYCLIC, T > &a, const CyclicVecBase< DIM, NONCYCLIC, T > &b) const
TFSIMD_FORCE_INLINE const tfScalar & x() const
bool isExceeded(const CyclicVecBase< DIM, NONCYCLIC, int > &v) const
void cycle(const CyclicVecBase< DIM, NONCYCLIC, T > &res)
void setElements(const int i, const T2 &first, const ArgList &...rest) noexcept
float dot2d(const CyclicVecBase< DIM, NONCYCLIC, T > &a) const
float gridToLenFactor() const
CyclicVecBase< DIM, NONCYCLIC, T2 > operator-(const CyclicVecBase< DIM, NONCYCLIC, T2 > &v) const
void cycleUnsignedElements(const int i, const int res, const ArgList &...rest)
void normalizeFloatAngle(float &val)
float cross2d(const CyclicVecBase< DIM, NONCYCLIC, T > &a) const
void convert(const T val, float &ret)
void setElements(const int i) noexcept
void cycleUnsignedElements(const int i)
void cycle(const int res, const ArgList &...rest)
CyclicVecBase(const float &v, const ArgList &...args) noexcept
CyclicVecBase(const int &v, const ArgList &...args) noexcept