PCB Environment 2

Loading...
Searching...
No Matches
GridDirection.hpp
1
2#ifndef GYM_PCB_GRIDDIRECTION_H
3#define GYM_PCB_GRIDDIRECTION_H
4
5 class GridDirection
6{
7 public:
8 constexpr static const uint FirstVertical = 8;
9 constexpr static const uint Count = 10;
10 constexpr GridDirection(uint8_t i) : id(i) { assert(id <= 0xa); }
11 constexpr GridDirection() { }
12 GridDirection(const IVector_3&);
13 uint n() const { return id; }
14 constexpr uint32_t mask() const { return (1 << id); }
15 bool _isDiagonal() const { assert(!isVertical()); return id & 0x1; }
16 bool isDiagonal() const { return (id & 0x1) && (id < 8); }
17 bool isZero() const { return id == 0xa; }
18 bool isVertical() const { return (id == 8) || (id == 9); }
19 bool is2D() const { return id < 8; }
20 bool operator==(const GridDirection &d) const { return id == d.id; }
21 GridDirection& operator++() { id += 1; return *this; }
22 GridDirection& operator=(const GridDirection &d) { id = d.id; return *this; }
23 int dx() const { return dXYZ[id][0]; }
24 int dy() const { return dXYZ[id][1]; }
25 int dz() const { return dXYZ[id][2]; }
26 IVector_3 ivec3() const { return IVector_3(dXYZ[id][0], dXYZ[id][1], dXYZ[id][2]); }
27 Vector_2 vec2() const { assert(id <= 7); return sVec[id]; }
28 int deg() const { assert(id <= 7); return 90 - id * 45 + (id >= 3 ? 0 : 360); }
29 GridDirection opposite() const { return GridDirection(sOpposites[id]); }
30 GridDirection rotatedCcw45(uint n = 1) const { assert(id < 8); return GridDirection((id - n) & 0x7); }
31 GridDirection rotatedCw45(uint n = 1) const { assert(id < 8); return GridDirection((id + n) & 0x7); }
32 GridDirection rotatedCcw(int degrees) const;
33 uint8_t get45DegreeStepsBetween(const GridDirection &d) const;
34 const char *str() const { return sStrings[std::min(id, uint8_t(10))]; }
35 static GridDirection Degrees(int); // 0° == R, ccw
36 static GridDirection fromSigns(const Vector_2&, Real zeroThreshold = 0x1.0p-10);
37 constexpr static GridDirection begin() { return GridDirection(0); }
38 constexpr static GridDirection hend() { return GridDirection(8); }
39 constexpr static GridDirection vend() { return GridDirection(10); }
40 constexpr static GridDirection U() { return GridDirection(0); }
41 constexpr static GridDirection UR() { return GridDirection(1); }
42 constexpr static GridDirection R() { return GridDirection(2); }
43 constexpr static GridDirection DR() { return GridDirection(3); }
44 constexpr static GridDirection D() { return GridDirection(4); }
45 constexpr static GridDirection DL() { return GridDirection(5); }
46 constexpr static GridDirection L() { return GridDirection(6); }
47 constexpr static GridDirection UL() { return GridDirection(7); }
48 constexpr static GridDirection A() { return GridDirection(8); }
49 constexpr static GridDirection V() { return GridDirection(9); }
50 constexpr static GridDirection Z() { return GridDirection(10); }
51 static const int dXYZ[11][3];
52 static const Vector_2 sVec[11];
53 static const uint8_t sOpposites[11];
54 static const char *sStrings[11];
55 private:
56 uint8_t id;
57};
58 inline uint8_t GridDirection::get45DegreeStepsBetween(const GridDirection &d) const
59{
60 if ((id | d.id) & 0x8)
61 return 0;
62 auto n = std::abs(id - d.id);
63 return (n > 4) ? (uint8_t(8) - n) : n;
64}
65
66#endif // GYM_PCB_GRIDDIRECTION_H
67
GridDirection
Definition GridDirection.hpp:6
IVector_3
Definition IPoint3.hpp:8