Vector2.cs 940 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2012-2016 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. using System.Collections;
  6. using System;
  7. namespace Crown
  8. {
  9. public struct Vector2
  10. {
  11. public float x, y;
  12. public Vector2(float x, float y)
  13. {
  14. this.x = x;
  15. this.y = y;
  16. }
  17. public Vector2(ArrayList arr)
  18. {
  19. this.x = (float)(double)arr[0];
  20. this.y = (float)(double)arr[1];
  21. }
  22. public static Vector2 operator+(Vector2 a, Vector2 b)
  23. {
  24. return new Vector2(a.x + b.x, a.y + b.y);
  25. }
  26. public static Vector2 operator-(Vector2 a, Vector2 b)
  27. {
  28. return new Vector2(a.x - b.x, a.y - b.y);
  29. }
  30. public static Vector2 operator*(Vector2 a, float k)
  31. {
  32. return new Vector2(a.x * k, a.y * k);
  33. }
  34. public static Vector2 operator*(float k, Vector2 a)
  35. {
  36. return a * k;
  37. }
  38. public override string ToString()
  39. {
  40. return string.Format("{0}, {1}", x, y);
  41. }
  42. }
  43. }