Degree.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace BansheeEngine
  6. {
  7. public struct Degree
  8. {
  9. readonly float value;
  10. public Degree(float value = 0.0f)
  11. {
  12. this.value = value;
  13. }
  14. public Degree(Radian r)
  15. {
  16. this.value = r.GetDegrees();
  17. }
  18. public static implicit operator Degree(float value)
  19. {
  20. return new Degree(value);
  21. }
  22. public static implicit operator Degree(Radian r)
  23. {
  24. return new Degree(r.GetDegrees());
  25. }
  26. public static explicit operator float(Degree d)
  27. {
  28. return d.value;
  29. }
  30. public float GetDegrees()
  31. {
  32. return value;
  33. }
  34. public float GetRadians()
  35. {
  36. return value * MathEx.Deg2Rad;
  37. }
  38. public static Degree operator+(Degree a)
  39. {
  40. return a;
  41. }
  42. public static Degree operator+(Degree a, Degree b)
  43. {
  44. return new Degree(a.value + b.value);
  45. }
  46. public static Degree operator+(Degree a, Radian r)
  47. {
  48. return new Degree (a.value + r.GetDegrees());
  49. }
  50. public static Degree operator-(Degree a)
  51. {
  52. return new Degree(-a.value);
  53. }
  54. public static Degree operator-(Degree a, Degree b)
  55. {
  56. return new Degree(a.value - b.value);
  57. }
  58. public static Degree operator-(Degree a, Radian r)
  59. {
  60. return new Degree (a.value - r.GetDegrees());
  61. }
  62. public static Degree operator*(Degree a, float s)
  63. {
  64. return new Degree(a.value * s);
  65. }
  66. public static Degree operator*(Degree a, Degree b)
  67. {
  68. return new Degree(a.value * b.value);
  69. }
  70. public static Degree operator/(Degree a, float s)
  71. {
  72. return new Degree(a.value / s);
  73. }
  74. public static Degree operator /(Degree a, Degree b)
  75. {
  76. return new Degree(a.value / b.value);
  77. }
  78. public static bool operator<(Degree a, Degree b)
  79. {
  80. return a.value < b.value;
  81. }
  82. public static bool operator>(Degree a, Degree b)
  83. {
  84. return a.value > b.value;
  85. }
  86. public static bool operator<=(Degree a, Degree b)
  87. {
  88. return a.value <= b.value;
  89. }
  90. public static bool operator>=(Degree a, Degree b)
  91. {
  92. return a.value >= b.value;
  93. }
  94. public static bool operator==(Degree a, Degree b)
  95. {
  96. return a.value == b.value;
  97. }
  98. public static bool operator!=(Degree a, Degree b)
  99. {
  100. return a.value != b.value;
  101. }
  102. public override bool Equals(object other)
  103. {
  104. if (!(other is Degree))
  105. return false;
  106. Degree degree = (Degree)other;
  107. if (value.Equals(degree.value))
  108. return true;
  109. return false;
  110. }
  111. public override int GetHashCode()
  112. {
  113. return value.GetHashCode();
  114. }
  115. };
  116. }