You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

64 rivejä
1.3 KiB

  1. using System;
  2. using UnityEngine;
  3. namespace SUISSEngine
  4. {
  5. public struct GridPoint
  6. {
  7. public GridPoint(float u, float v)
  8. {
  9. this.u = u;
  10. this.v = v;
  11. }
  12. public GridPoint(GridIndex index)
  13. {
  14. this.u = (float)index.u;
  15. this.v = (float)index.v;
  16. }
  17. public override string ToString()
  18. {
  19. return string.Format("({0}, {1})", this.u, this.v);
  20. }
  21. public float DistanceTo(GridPoint other)
  22. {
  23. return Mathf.Sqrt((this.u - other.u) * (this.u - other.u) + (this.v - other.v) * (this.v - other.v));
  24. }
  25. public static GridPoint operator -(GridPoint left, GridPoint right)
  26. {
  27. return new GridPoint(left.u - right.u, left.v - right.v);
  28. }
  29. public static GridPoint operator +(GridPoint left, GridPoint right)
  30. {
  31. return new GridPoint(left.u + right.u, left.v + right.v);
  32. }
  33. public GridPoint normalized
  34. {
  35. get
  36. {
  37. float num = Mathf.Sqrt(this.u * this.u + this.v * this.v) + 5E-05f;
  38. return new GridPoint(this.u / num, this.v / num);
  39. }
  40. }
  41. public GridPoint times(float mag)
  42. {
  43. return new GridPoint(this.u * mag, this.v * mag);
  44. }
  45. public static GridPoint GetRandom(float urange, float vrange)
  46. {
  47. return new GridPoint(UnityEngine.Random.Range(-urange, urange), UnityEngine.Random.Range(-vrange, vrange));
  48. }
  49. public float u;
  50. public float v;
  51. }
  52. }