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.

Vector.cs 1.1 kB

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