using System; using UnityEngine; namespace SUISSEngine { public struct GridPoint { public GridPoint(float u, float v) { this.u = u; this.v = v; } public GridPoint(GridIndex index) { this.u = (float)index.u; this.v = (float)index.v; } public override string ToString() { return string.Format("({0}, {1})", this.u, this.v); } public float DistanceTo(GridPoint other) { return Mathf.Sqrt((this.u - other.u) * (this.u - other.u) + (this.v - other.v) * (this.v - other.v)); } public static GridPoint operator -(GridPoint left, GridPoint right) { return new GridPoint(left.u - right.u, left.v - right.v); } public static GridPoint operator +(GridPoint left, GridPoint right) { return new GridPoint(left.u + right.u, left.v + right.v); } public GridPoint normalized { get { float num = Mathf.Sqrt(this.u * this.u + this.v * this.v) + 5E-05f; return new GridPoint(this.u / num, this.v / num); } } public GridPoint times(float mag) { return new GridPoint(this.u * mag, this.v * mag); } public static GridPoint GetRandom(float urange, float vrange) { return new GridPoint(UnityEngine.Random.Range(-urange, urange), UnityEngine.Random.Range(-vrange, vrange)); } public float u; public float v; } }