Last active
March 24, 2018 14:37
-
-
Save Broxzier/3d986be6117e03dd6298cb4affdf707a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Rotation | |
{ | |
const uint8 & Value() const | |
{ | |
Guard::Assert(_rotation == (_rotation & 3)); | |
return _rotation; | |
} | |
Rotation & operator=(Rotation rhs) | |
{ | |
_rotation = rhs._rotation; | |
return *this; | |
} | |
Rotation & operator+=(const Rotation & rhs) | |
{ | |
_rotation = (_rotation + rhs._rotation) & 3; | |
return *this; | |
} | |
Rotation & operator-=(const Rotation & rhs) | |
{ | |
_rotation = (_rotation - rhs._rotation) & 3; | |
return *this; | |
} | |
Rotation & operator++() | |
{ | |
_rotation = (_rotation + 1) & 3; | |
return *this; | |
} | |
Rotation operator++(int) | |
{ | |
Rotation tmp(*this); | |
operator++(); | |
return tmp; | |
} | |
private: | |
uint8 _rotation; | |
}; | |
inline Rotation operator+(Rotation lhs, const Rotation & rhs) | |
{ | |
lhs += rhs; | |
return lhs; | |
} | |
inline Rotation operator-(Rotation lhs, const Rotation & rhs) | |
{ | |
lhs += rhs; | |
return lhs; | |
} | |
inline bool operator==(const Rotation & lhs, const Rotation & rhs) | |
{ | |
return lhs.Value() == rhs.Value(); | |
} | |
inline bool operator!=(const Rotation & lhs, const Rotation & rhs) | |
{ | |
return !operator==(lhs, rhs); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment