Efficient 16-bit angle representation optimized for Saturn hardware.
Represents angles using a 16-bit integer where the full circle (360°) maps from 0x0000 to 0xFFFF. This provides an angle resolution of approximately 0.0055 degrees (360° / 65536).
This representation is designed for optimal performance on Saturn hardware, allowing for fast angle calculations with automatic wrap-around behavior.
Common angle values:
#include <angle.hpp>
Public Member Functions | |
constexpr const uint16_t & | RawValue () const |
Returns a const reference to the internal raw angle value. | |
constexpr Fxp | ToFxp () const |
Converts to fixed-point representation. | |
Constructors | |
constexpr | Angle () |
Default constructor. Initializes angle to 0. | |
constexpr | Angle (const Fxp &turns) |
Constructs angle from fixed-point turns. | |
template<typename T> requires std::integral<T> || std::floating_point<T> | |
constexpr | Angle (const T &turns) |
Template constructor that converts numeric types to Angle via Fxp. | |
Arithmetic Operations | |
Basic angle arithmetic with automatic wrap-around. These operations handle angle arithmetic with automatic wrap-around behavior due to the 16-bit representation. | |
constexpr Angle | operator+ (const Angle &other) const |
Adds two angles. | |
constexpr Angle | operator- (const Angle &other) const |
Subtracts two angles. | |
constexpr Angle | operator* (const Fxp &fxp) const |
Multiplies an angle by a fixed-point scalar value. | |
template<typename T> requires std::integral<T> | |
constexpr Angle | operator* (T scalar) const |
Multiplies an angle by an integer scalar value. | |
constexpr Angle | operator/ (const Fxp &fxp) const |
Divides an angle by a fixed-point scalar value. | |
template<typename T> requires std::integral<T> | |
constexpr Angle | operator/ (T scalar) const |
Divides an angle by an integer scalar value. | |
constexpr Angle & | operator*= (const Fxp &fxp) |
Multiplies an angle by a fixed-point scalar value. | |
template<typename T> requires std::integral<T> | |
constexpr Angle & | operator*= (T scalar) |
Multiplies an angle by an integer scalar value. | |
constexpr Angle & | operator/= (const Fxp &fxp) |
Divides an angle by a fixed-point scalar value. | |
template<typename T> requires std::integral<T> | |
constexpr Angle & | operator/= (T scalar) |
Divides an angle by an integer scalar value. | |
constexpr Angle & | operator+= (const Angle &other) |
Adds two angles. | |
constexpr Angle & | operator-= (const Angle &other) |
Subtracts two angles. | |
constexpr Angle | operator- () const |
Negates the angle, effectively adding half a turn (180 degrees). | |
constexpr bool | operator== (const Angle &other) const |
Compares two angles for equality. | |
constexpr bool | operator!= (const Angle &other) const |
Compares two angles for inequality. | |
constexpr bool | operator< (const Angle &other) const |
Compares if this angle is less than another angle. | |
constexpr bool | operator> (const Angle &other) const |
Compares if this angle is greater than another angle. | |
constexpr bool | operator<= (const Angle &other) const |
Compares if this angle is less than or equal to another angle. | |
constexpr bool | operator>= (const Angle &other) const |
Compares if this angle is greater than or equal to another angle. | |
Static Public Member Functions | |
static constexpr Angle | BuildRaw (uint16_t rawValue) |
Creates an angle from a raw 16-bit value. | |
Constant Angles | |
Common angle constants available at compile-time. | |
static consteval Angle | Zero () |
0° (0x0000) | |
static consteval Angle | Pi () |
180° (0x8000) | |
static consteval Angle | HalfPi () |
90° (0x4000) | |
static consteval Angle | QuarterPi () |
45° (0x2000) | |
static consteval Angle | ThreeQuarterPi () |
270° (0xC000) | |
static consteval Angle | TwoPi () |
360° (wraps to 0x0000) | |
static consteval Angle | Right () |
90° (0x4000) | |
static consteval Angle | Straight () |
180° (0x8000) | |
static consteval Angle | Full () |
360° (wraps to 0x0000) | |
Angle Conversions | |
Functions for converting between different angle representations. These functions allow conversion between radians, degrees, and the internal 16-bit representation. Performance warnings are included to encourage using the native angle representation when possible. | |
static consteval Angle | FromRadians (double radians) |
Creates angle from radians at compile time. | |
static constexpr Angle | FromRadians (const Fxp &radianTurns) |
Creates angle from radians. | |
static consteval Angle | FromDegrees (double degrees) |
Creates angle from degrees at compile time. | |
static constexpr Angle | FromDegrees (const Fxp °reeTurns) |
Creates angle from degrees. | |
static consteval Angle | FromTurns (float turns) |
Creates an angle from a floating-point value in turns. | |
constexpr Fxp | ToRadians () const |
Converts angle to radians. | |
constexpr Fxp | ToDegrees () const |
Converts angle to degrees. | |
constexpr Fxp | ToTurns () const |
Converts angle to turns. | |