Skip to content

Instantly share code, notes, and snippets.

@Broxzier
Last active March 24, 2018 14:37
Show Gist options
  • Save Broxzier/3d986be6117e03dd6298cb4affdf707a to your computer and use it in GitHub Desktop.
Save Broxzier/3d986be6117e03dd6298cb4affdf707a to your computer and use it in GitHub Desktop.
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