30 #ifndef PLANNER_CSPACE_CYCLIC_VEC_H 31 #define PLANNER_CSPACE_CYCLIC_VEC_H 33 #define _USE_MATH_DEFINES 36 #include <initializer_list> 40 #include <unordered_map> 43 #include <boost/chrono.hpp> 49 namespace cyclic_vec_type_conversion_rule
56 inline void convert(
const int val,
float& ret)
60 inline void convert(
const float val,
int& ret)
62 ret = std::lround(val);
77 template <
int DIM,
int NONCYCLIC,
typename T>
82 std::is_same<float, T>() || std::is_same<int, T>(),
"T must be float or int");
85 template <
typename T2,
typename... ArgList>
86 void setElements(
const int i,
const T2& first,
const ArgList&... rest) noexcept
91 setElements(i + 1, rest...);
98 template <
typename... ArgList>
101 const int res,
const ArgList&... rest)
103 cycleElement(i, res);
104 cycleElements(i + 1, rest...);
111 if (e_[i] < res / 2 - res)
113 else if (e_[i] >= res / 2)
120 template <
typename... ArgList>
123 const int res,
const ArgList&... rest)
125 cycleUnsignedElement(i, res);
126 cycleUnsignedElements(i + 1, rest...);
142 template <
typename T2>
145 for (
int i = 0; i < DIM; i++)
148 template <
typename... ArgList>
151 setElements(0, v,
args...);
153 template <
typename... ArgList>
156 setElements(0, v,
args...);
160 for (
int i = 0; i < DIM; i++)
163 template <
typename T2>
166 for (
int i = 0; i < DIM; i++)
167 if (v.
e_[i] != e_[i])
171 template <
typename T2>
174 return !(*
this == v);
176 template <
typename T2>
180 for (
int i = 0; i < DIM; i++)
186 template <
typename T2>
190 for (
int i = 0; i < DIM; i++)
196 template <
typename T2>
200 for (
int i = 0; i < DIM; i++)
202 out[i] = e_[i] * v[i];
208 return (*
this)[0] * a[1] - (*this)[1] * a[0];
212 return (*
this)[0] * a[0] + (*this)[1] * a[1];
218 return (b - a).cross2d((*
this) - a) / (b - a).len();
224 const auto to_a = (*this) - a;
225 if ((b - a).dot2d(to_a) <= 0)
227 const auto to_b = (*this) - b;
228 if ((a - b).dot2d(to_b) <= 0)
230 return std::abs(distLine2d(a, b));
243 for (
int i = 0; i < NONCYCLIC; i++)
245 out += e_[i] * e_[i];
251 return std::sqrt(sqlen());
255 const auto l = len();
256 return l /
static_cast<int>(l);
261 for (
int i = 0; i < DIM; i++)
263 out += std::pow(e_[i], 2);
265 return std::sqrt(out);
270 const auto tmp = *
this;
271 const float cos_v = cosf(ang);
272 const float sin_v = sinf(ang);
276 this->e_[2] = tmp[2] + ang;
281 template <
typename... ArgList>
282 void cycle(
const int res,
const ArgList&... rest)
285 std::is_same<int, T>(),
"cycle is provided only for int");
286 cycleElements(NONCYCLIC, res, rest...);
288 template <
typename... ArgList>
292 std::is_same<int, T>(),
"cycle is provided only for int");
293 cycleUnsignedElements(NONCYCLIC, res, rest...);
298 std::is_same<int, T>(),
"cycle is provided only for int");
299 for (
int i = NONCYCLIC; i < DIM; ++i)
300 cycleElement(i, res[i]);
305 std::is_same<int, T>(),
"cycle is provided only for int");
306 for (
int i = NONCYCLIC; i < DIM; ++i)
307 cycleUnsignedElement(i, res[i]);
313 size_t hash =
static_cast<size_t>(key.
e_[0]);
314 for (
int i = 1; i < DIM; i++)
316 const size_t n = 8 *
sizeof(std::size_t) * i / DIM;
317 const size_t x =
static_cast<size_t>(key.
e_[i]);
318 hash ^= (x << n) | (x >> ((8 *
sizeof(size_t)) - n));
326 std::is_same<int, T>(),
"isExceeded is provided only for T=int");
327 for (
int i = 0; i < NONCYCLIC; ++i)
329 if (static_cast<unsigned int>((*
this)[i]) >= static_cast<unsigned int>(v[i]))
336 template <
int DIM,
int NONCYCLIC>
338 template <
int DIM,
int NONCYCLIC>
343 #endif // PLANNER_CSPACE_CYCLIC_VEC_H void cycle(const int res, const ArgList &...rest)
const T & operator[](const int &x) const
CyclicVecBase(const int &v, const ArgList &...args) noexcept
void cycle(const CyclicVecBase< DIM, NONCYCLIC, T > &res)
void setElements(const int i, const T2 &first, const ArgList &...rest) noexcept
void cycleUnsigned(const int res, const ArgList &...rest)
float dot2d(const CyclicVecBase< DIM, NONCYCLIC, T > &a) const
size_t operator()(const CyclicVecBase &key) const
void cycleUnsigned(const CyclicVecBase< DIM, NONCYCLIC, T > &res)
void setElements(const int i) noexcept
CyclicVecBase(const float &v, const ArgList &...args) noexcept
void cycleUnsignedElements(const int i, const int res, const ArgList &...rest)
CyclicVecBase< DIM, NONCYCLIC, T2 > operator-(const CyclicVecBase< DIM, NONCYCLIC, T2 > &v) const
void normalizeFloatAngle(float &val)
float cross2d(const CyclicVecBase< DIM, NONCYCLIC, T > &a) const
void cycleElement(const int i, const int res)
CyclicVecBase< DIM, NONCYCLIC, T2 > operator*(const CyclicVecBase< DIM, NONCYCLIC, T2 > &v) const
void rotate(const float ang)
float distLine2d(const CyclicVecBase< DIM, NONCYCLIC, T > &a, const CyclicVecBase< DIM, NONCYCLIC, T > &b) const
CyclicVecBase(const CyclicVecBase< DIM, NONCYCLIC, T2 > &c) noexcept
TFSIMD_FORCE_INLINE const tfScalar & x() const
void cycleUnsignedElements(const int i)
bool operator!=(const CyclicVecBase< DIM, NONCYCLIC, T2 > &v) const
bool isExceeded(const CyclicVecBase< DIM, NONCYCLIC, int > &v) const
void cycleElements(const int i, const int res, const ArgList &...rest)
void cycleUnsignedElement(const int i, const int res)
float gridToLenFactor() const
T & operator[](const int &x)
float distLinestrip2d(const CyclicVecBase< DIM, NONCYCLIC, T > &a, const CyclicVecBase< DIM, NONCYCLIC, T > &b) const
CyclicVecBase< DIM, NONCYCLIC, T2 > operator+(const CyclicVecBase< DIM, NONCYCLIC, T2 > &v) const
void convert(const T val, float &ret)
void cycleElements(const int i)
bool operator==(const CyclicVecBase< DIM, NONCYCLIC, T2 > &v) const