| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System;
- [Serializable]
- public struct VInt
- {
- public int i;
- public float scalar
- {
- get
- {
- return (float)this.i * 0.001f;
- }
- }
- public VInt(int i)
- {
- this.i = i;
- }
- public VInt(float f)
- {
- this.i = (int)Math.Round((double)(f * 1000f));
- }
- public override bool Equals(object o)
- {
- if (o == null)
- {
- return false;
- }
- VInt vInt = (VInt)o;
- return this.i == vInt.i;
- }
- public override int GetHashCode()
- {
- return this.i.GetHashCode();
- }
- public static VInt Min(VInt a, VInt b)
- {
- return new VInt(Math.Min(a.i, b.i));
- }
- public static VInt Max(VInt a, VInt b)
- {
- return new VInt(Math.Max(a.i, b.i));
- }
- public override string ToString()
- {
- return this.scalar.ToString();
- }
- public static explicit operator VInt(float f)
- {
- return new VInt((int)Math.Round((double)(f * 1000f)));
- }
- public static implicit operator VInt(int i)
- {
- return new VInt(i);
- }
- public static explicit operator float(VInt ob)
- {
- return (float)ob.i * 0.001f;
- }
- public static explicit operator long(VInt ob)
- {
- return (long)ob.i;
- }
- public static VInt operator +(VInt a, VInt b)
- {
- return new VInt(a.i + b.i);
- }
- public static VInt operator -(VInt a, VInt b)
- {
- return new VInt(a.i - b.i);
- }
- public static bool operator ==(VInt a, VInt b)
- {
- return a.i == b.i;
- }
- public static bool operator !=(VInt a, VInt b)
- {
- return a.i != b.i;
- }
- }
|