VInt.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. [Serializable]
  3. public struct VInt
  4. {
  5. public int i;
  6. public float scalar
  7. {
  8. get
  9. {
  10. return (float)this.i * 0.001f;
  11. }
  12. }
  13. public VInt(int i)
  14. {
  15. this.i = i;
  16. }
  17. public VInt(float f)
  18. {
  19. this.i = (int)Math.Round((double)(f * 1000f));
  20. }
  21. public override bool Equals(object o)
  22. {
  23. if (o == null)
  24. {
  25. return false;
  26. }
  27. VInt vInt = (VInt)o;
  28. return this.i == vInt.i;
  29. }
  30. public override int GetHashCode()
  31. {
  32. return this.i.GetHashCode();
  33. }
  34. public static VInt Min(VInt a, VInt b)
  35. {
  36. return new VInt(Math.Min(a.i, b.i));
  37. }
  38. public static VInt Max(VInt a, VInt b)
  39. {
  40. return new VInt(Math.Max(a.i, b.i));
  41. }
  42. public override string ToString()
  43. {
  44. return this.scalar.ToString();
  45. }
  46. public static explicit operator VInt(float f)
  47. {
  48. return new VInt((int)Math.Round((double)(f * 1000f)));
  49. }
  50. public static implicit operator VInt(int i)
  51. {
  52. return new VInt(i);
  53. }
  54. public static explicit operator float(VInt ob)
  55. {
  56. return (float)ob.i * 0.001f;
  57. }
  58. public static explicit operator long(VInt ob)
  59. {
  60. return (long)ob.i;
  61. }
  62. public static VInt operator +(VInt a, VInt b)
  63. {
  64. return new VInt(a.i + b.i);
  65. }
  66. public static VInt operator -(VInt a, VInt b)
  67. {
  68. return new VInt(a.i - b.i);
  69. }
  70. public static bool operator ==(VInt a, VInt b)
  71. {
  72. return a.i == b.i;
  73. }
  74. public static bool operator !=(VInt a, VInt b)
  75. {
  76. return a.i != b.i;
  77. }
  78. }