Degree.cs 3.3 KB

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