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

XYPosition.cs 1.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. namespace Preparation.Utility
  3. {
  4. public struct XYPosition
  5. {
  6. public int x;
  7. public int y;
  8. public XYPosition(int x, int y)
  9. {
  10. this.x = x;
  11. this.y = y;
  12. }
  13. public override string ToString()
  14. {
  15. return "(" + x.ToString() + "," + y.ToString() + ")";
  16. }
  17. public static XYPosition operator +(XYPosition p1, XYPosition p2)
  18. {
  19. return new XYPosition(p1.x + p2.x, p1.y + p2.y);
  20. }
  21. public static XYPosition operator -(XYPosition p1, XYPosition p2)
  22. {
  23. return new XYPosition(p1.x - p2.x, p1.y - p2.y);
  24. }
  25. public static double Distance(XYPosition p1, XYPosition p2)
  26. {
  27. return Math.Sqrt(((long)(p1.x - p2.x) * (p1.x - p2.x)) + ((long)(p1.y - p2.y) * (p1.y - p2.y)));
  28. }
  29. /*public static XYPosition[] GetSquareRange(uint edgeLen) // 从THUAI4的BULLET.CS移植而来,不知还有用否
  30. {
  31. XYPosition[] range = new XYPosition[edgeLen * edgeLen];
  32. int offset = (int)(edgeLen >> 1);
  33. for (int i = 0; i < (int)edgeLen; ++i)
  34. {
  35. for (int j = 0; j < (int)edgeLen; ++j)
  36. {
  37. range[i * edgeLen + j].x = i - offset;
  38. range[i * edgeLen + j].y = j - offset;
  39. }
  40. }
  41. return range;
  42. }*/
  43. public Vector2 ToVector2()
  44. {
  45. return new Vector2(this.x, this.y);
  46. }
  47. }
  48. }