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.

XY.cs 906 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. namespace Preparation.Utility
  3. {
  4. public struct XY
  5. {
  6. public int x;
  7. public int y;
  8. public XY(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 int operator *(XY v1, XY v2)
  18. {
  19. return (v1.x * v2.x) + (v1.y * v2.y);
  20. }
  21. public static XY operator +(XY v1, XY v2)
  22. {
  23. return new XY(v1.x + v2.x, v1.y + v2.y);
  24. }
  25. public static XY operator -(XY v1, XY v2)
  26. {
  27. return new XY(v1.x - v2.x, v1.y - v2.y);
  28. }
  29. public static double Distance(XY p1, XY p2)
  30. {
  31. return Math.Sqrt(((long)(p1.x - p2.x) * (p1.x - p2.x)) + ((long)(p1.y - p2.y) * (p1.y - p2.y)));
  32. }
  33. }
  34. }