18 #ifndef ION_MATH_ANGLE_H_
19 #define ION_MATH_ANGLE_H_
42 : radians_(static_cast<
T>(other.
Radians())) {}
51 return Angle(DegreesToRadians(angle));
56 T Degrees()
const {
return RadiansToDegrees(radians_); }
88 return a0.radians_ == a1.radians_;
91 return a0.radians_ != a1.radians_;
96 return a0.radians_ < a1.radians_;
99 return a0.radians_ > a1.radians_;
102 return a0.radians_ <= a1.radians_;
105 return a0.radians_ >= a1.radians_;
109 explicit Angle(
const T angle_rad) {
110 radians_ = angle_rad;
113 static T RadiansToDegrees(
const T& radians) {
114 static const T kRadToDeg = 180 /
static_cast<T>(M_PI);
115 return radians * kRadToDeg;
118 static T DegreesToRadians(
const T& degrees) {
119 static const T kDegToRad =
static_cast<T>(M_PI) / 180;
120 return degrees * kDegToRad;
129 template <
typename T>
130 std::ostream& operator<<(std::ostream& out, const Angle<T>& a) {
131 return out << a.Degrees() <<
" deg";
134 template <
typename T>
162 #endif // ION_MATH_ANGLE_H_
friend bool operator!=(const Angle &a0, const Angle &a1)
void operator-=(const Angle &a)
Angle< float > Anglef
Type-specific typedefs.
friend const Angle operator*(T s, const Angle &a)
void operator+=(const Angle &a)
Self-modifying operators.
friend bool operator>=(const Angle &a0, const Angle &a1)
A simple class to represent angles.
T Radians() const
Get the angle in degrees or radians.
const Angle operator-() const
Unary negation operator.
friend bool operator<=(const Angle &a0, const Angle &a1)
friend const Angle operator-(const Angle &a0, const Angle &a1)
std::istream & GetExpectedString(std::istream &in, const std::string &expected)
Attempts to read a string from the stream and returns the stream.
friend const Angle operator+(const Angle &a0, const Angle &a1)
Binary operators.
static Angle FromRadians(const T &angle)
Create a angle from radians (no conversion).
friend const Angle operator/(const Angle &a, T s)
friend bool operator==(const Angle &a0, const Angle &a1)
Exact equality and inequality comparisons.
static Angle FromDegrees(const T &angle)
Create a angle from degrees (requires conversion).
friend const Angle operator*(const Angle &a, T s)
Angle(const Angle< U > other)
Copy constructor from an instance of any value type that is compatible (via static_cast) with this in...
Angle()
The default constructor creates an angle of 0 (in any unit).
std::istream & operator>>(std::istream &in, Angle< T > &a)
friend bool operator<(const Angle &a0, const Angle &a1)
Comparisons.
friend bool operator>(const Angle &a0, const Angle &a1)