Covellite++  Version: 2.3.0 Revision: ??? Platform: x64 Build: 23:13 04.01.2025
Кроссплатформенный фреймворк для разработки приложений на С++
Загрузка...
Поиск...
Не найдено
CubeCoords.hpp
1
2#pragma once
3
4namespace basement
5{
6
7namespace model
8{
9
25class CubeCoords final
26{
27 static constexpr uint64_t Offset = 8 * sizeof(uint64_t) / 2;
28 static constexpr uint32_t HalfRange =
29 static_cast<uint32_t>(1) << (8 * sizeof(int32_t) - 1);
30
31public:
32 inline int GetX(void) const { return X; }
33 inline int GetY(void) const { return Y; }
34 inline int GetZ(void) const { return -(X + Y); }
35
36public:
37 CubeCoords operator + (const CubeCoords &) const;
38 CubeCoords operator - (const CubeCoords &) const;
39 CubeCoords operator * (const int32_t) const;
40 CubeCoords TurnLeft(void) const { return CubeCoords{ -Y, X + Y }; }
41 inline CubeCoords TurnRight(void) const { return CubeCoords{ X + Y, -X }; }
42 CubeCoords TurnLeft(const uint32_t) const;
43 CubeCoords TurnRight(const uint32_t) const;
44 ::std::pair<float, float> ToPlane(void) const;
45 uint64_t GetHash(void) const;
46
47private:
48 int32_t X, Y;
49
50public:
51 explicit CubeCoords(const int = 0, const int = 0);
52 explicit CubeCoords(const uint64_t);
53};
54
55inline CubeCoords CubeCoords::operator + (const CubeCoords & _CubeCoords) const
56{
57 return CubeCoords{ X + _CubeCoords.X, Y + _CubeCoords.Y };
58}
59
60inline CubeCoords CubeCoords::operator - (const CubeCoords & _CubeCoords) const
61{
62 return CubeCoords{ X - _CubeCoords.X, Y - _CubeCoords.Y };
63}
64
65inline CubeCoords CubeCoords::operator * (const int32_t _Value) const
66{
67 return CubeCoords{ X * _Value, Y * _Value };
68}
69
70inline uint64_t CubeCoords::GetHash(void) const
71{
72# if BOOST_COMP_MSVC
73# pragma warning(push)
74# pragma warning(disable: 26451)
75# endif
76
77 return (static_cast<uint64_t>(Y + HalfRange) << Offset) +
78 static_cast<uint64_t>(X + HalfRange);
79
80# if BOOST_COMP_MSVC
81# pragma warning(pop)
82# endif
83}
84
85} // namespace model
86
87} // namespace basement
Definition Common.hpp:10
Класс входит в проект Example Класс манипуляции кубическими координатами.
Definition CubeCoords.hpp:26