// This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0.If a copy of the MPL was not distributed with this // file, You can obtain one at https ://mozilla.org/MPL/2.0/. #ifndef ANGLE_H #define ANGLE_H namespace Passer { namespace LinearAlgebra { static float pi = 3.1415927410125732421875F; static float Rad2Deg = 360.0f / (pi * 2); static float Deg2Rad = (pi * 2) / 360.0f; template class AngleOf { public: AngleOf(); static AngleOf Degrees(float f); static AngleOf Radians(float f); static AngleOf Binary(T x); // const static AngleOf zero; // const static AngleOf deg90; // const static AngleOf deg180; float InDegrees() const; float InRadians() const; inline T GetBinary() const { return this->value; } inline void SetBinary(T x) { this->value = x; } bool operator==(const AngleOf a) const; bool operator>(AngleOf a) const; bool operator>=(AngleOf a) const; bool operator<(AngleOf a) const; bool operator<=(AngleOf a) const; static signed int Sign(AngleOf a); static AngleOf Abs(AngleOf a); AngleOf operator-() const; AngleOf operator-(const AngleOf &a) const; AngleOf operator+(const AngleOf &a) const; AngleOf operator+=(const AngleOf &a); friend AngleOf operator*(const AngleOf &a, float f) { return AngleOf::Degrees((float)a.InDegrees() * f); } friend AngleOf operator*(float f, const AngleOf &a) { return AngleOf::Degrees((float)f * a.InDegrees()); } void Normalize(); static AngleOf Normalize(AngleOf a); static AngleOf Clamp(AngleOf a, AngleOf min, AngleOf max); // static AngleOf Difference(AngleOf a, AngleOf b) { // AngleOf r = Normalize(b.InDegrees() - a.InDegrees()); // return r; // }; static AngleOf MoveTowards(AngleOf fromAngle, AngleOf toAngle, float maxAngle); static float Cos(AngleOf a); static float Sin(AngleOf a); static float Tan(AngleOf a); static AngleOf Acos(float f); static AngleOf Asin(float f); static AngleOf Atan(float f); static AngleOf Atan2(float f1, float f2); static float CosineRuleSide(float a, float b, AngleOf gamma); static AngleOf CosineRuleAngle(float a, float b, float c); static AngleOf SineRuleAngle(float a, AngleOf beta, float c); private: T value; AngleOf(T value); // These are deprecated, will move to private. // Use Degrees/Radians instead // AngleOf(signed int f); // AngleOf(float f); }; using Angle = AngleOf; using AngleSingle = AngleOf; using Angle16 = AngleOf; using Angle8 = AngleOf; } // namespace LinearAlgebra } // namespace Passer using namespace Passer::LinearAlgebra; #endif