Vec.cs 775 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. namespace Day17;
  2. public record struct Vec
  3. {
  4. public int X { get; }
  5. public int Y { get; }
  6. public Vec(int x, int y)
  7. {
  8. X = x;
  9. Y = y;
  10. }
  11. public Vec RotatePositive()
  12. {
  13. // clockwise
  14. return new Vec(-1 * Y, X);
  15. }
  16. public Vec RotateNegative()
  17. {
  18. // counter-clockwise
  19. return new Vec(Y, -1 * X);
  20. }
  21. public Vec Add(Vec other)
  22. {
  23. return new Vec(X + other.X, Y + other.Y);
  24. }
  25. public char Arrow()
  26. {
  27. if (Y == 0)
  28. {
  29. return X > 0
  30. ? '>'
  31. : '<';
  32. }
  33. else
  34. {
  35. return Y > 0
  36. ? 'v'
  37. : '^';
  38. }
  39. }
  40. }