CmDegree.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include "CmPrerequisitesUtil.h"
  3. #include "CmRadian.h"
  4. namespace CamelotFramework
  5. {
  6. /**
  7. * @brief Wrapper class which indicates a given angle value is in Degrees.
  8. *
  9. * @note Degree values are interchangeable with Radian values, and conversions
  10. * will be done automatically between them.
  11. */
  12. class CM_UTILITY_EXPORT Degree
  13. {
  14. float mDeg; // if you get an error here - make sure to define/typedef 'float' first
  15. public:
  16. explicit Degree(float d = 0.0f) : mDeg(d) {}
  17. Degree(const Radian& r);
  18. Degree& operator= (const float& f) { mDeg = f; return *this; }
  19. Degree& operator= (const Degree& d) { mDeg = d.mDeg; return *this; }
  20. Degree& operator= (const Radian& r);
  21. float valueDegrees() const { return mDeg; }
  22. float valueRadians() const;
  23. const Degree& operator+ () const { return *this; }
  24. Degree operator+ (const Degree& d) const { return Degree (mDeg + d.mDeg); }
  25. Degree operator+ (const Radian& r) const;
  26. Degree& operator+= (const Degree& d) { mDeg += d.mDeg; return *this; }
  27. Degree& operator+= (const Radian& r);
  28. Degree operator- () const { return Degree(-mDeg); }
  29. Degree operator- (const Degree& d) const { return Degree (mDeg - d.mDeg); }
  30. Degree operator- (const Radian& r) const;
  31. Degree& operator-= (const Degree& d) { mDeg -= d.mDeg; return *this; }
  32. Degree& operator-= (const Radian& r);
  33. Degree operator* (float f) const { return Degree (mDeg * f); }
  34. Degree operator* (const Degree& f) const { return Degree (mDeg * f.mDeg); }
  35. Degree& operator*= (float f) { mDeg *= f; return *this; }
  36. Degree operator/ (float f) const { return Degree (mDeg / f); }
  37. Degree& operator/= (float f) { mDeg /= f; return *this; }
  38. friend Degree operator* (float lhs, const Degree& rhs) { return Degree(lhs * rhs.mDeg); }
  39. friend Degree operator/ (float lhs, const Degree& rhs) { return Degree(lhs / rhs.mDeg); }
  40. friend Degree operator+ (Degree& lhs, float rhs) { return Degree(lhs.mDeg + rhs); }
  41. friend Degree operator+ (float lhs, const Degree& rhs) { return Degree(lhs + rhs.mDeg); }
  42. friend Degree operator- (const Degree& lhs, float rhs) { return Degree(lhs.mDeg - rhs); }
  43. friend Degree operator- (const float lhs, const Degree& rhs) { return Degree(lhs - rhs.mDeg); }
  44. bool operator< (const Degree& d) const { return mDeg < d.mDeg; }
  45. bool operator<= (const Degree& d) const { return mDeg <= d.mDeg; }
  46. bool operator== (const Degree& d) const { return mDeg == d.mDeg; }
  47. bool operator!= (const Degree& d) const { return mDeg != d.mDeg; }
  48. bool operator>= (const Degree& d) const { return mDeg >= d.mDeg; }
  49. bool operator> (const Degree& d) const { return mDeg > d.mDeg; }
  50. };
  51. }