Coordinates.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace PixiEditorDotNetCore3.Models.Position
  7. {
  8. public struct Coordinates
  9. {
  10. public int X { get; set; }
  11. public int Y { get; set; }
  12. public Coordinates(int x, int y)
  13. {
  14. X = x;
  15. Y = y;
  16. }
  17. public override string ToString() => $"x: {X}, y: {Y}";
  18. public static bool operator ==(Coordinates c1, Coordinates c2)
  19. {
  20. if (c1 == null || c2 == null) return false;
  21. return c2.X == c1.X && c2.Y == c1.Y;
  22. }
  23. public static bool operator !=(Coordinates c1, Coordinates c2)
  24. {
  25. return !(c1 == c2);
  26. }
  27. public override bool Equals(object obj)
  28. {
  29. if (obj.GetType() != typeof(Coordinates)) return false;
  30. return this == (Coordinates)obj;
  31. }
  32. public override int GetHashCode()
  33. {
  34. unchecked
  35. {
  36. const int HashingBase = (int)2166136261;
  37. const int HashingMultiplier = 16777619;
  38. int hash = HashingBase;
  39. hash = (hash * HashingMultiplier) ^ (!ReferenceEquals(null, X) ? X.GetHashCode() : 0);
  40. hash = (hash * HashingMultiplier) ^ (!ReferenceEquals(null, Y) ? Y.GetHashCode() : 0);
  41. return hash;
  42. }
  43. }
  44. }
  45. }