Node.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Xml.Serialization;
  2. using System.Windows.Shapes;
  3. using System.Windows.Controls;
  4. using System.Collections.Generic;
  5. namespace DrawGraph
  6. {
  7. public class Node
  8. {
  9. [XmlAttribute("positionX")]
  10. public int X { get; set; }
  11. [XmlAttribute("positionY")]
  12. public int Y { get; set; }
  13. public Node(int x, int y)
  14. {
  15. X = x;
  16. Y = y;
  17. }
  18. /// <summary>
  19. /// Get center X-coordinate of node
  20. /// </summary>
  21. public int CenterByX => (X * 2 + (Settings.NodeWidth/2)) / 2;
  22. /// <summary>
  23. /// Get center Y-coordinate of node
  24. /// </summary>
  25. public int CenterByY => (Y * 2 + (Settings.NodeHeight / 2)) / 2;
  26. /// <summary>
  27. /// Compare two nodes
  28. /// </summary>
  29. /// <param name="node1">First node to compare</param>
  30. /// <param name="node2">Second node to compare</param>
  31. /// <returns>True if nodes are equal, false if not equal</returns>
  32. public static bool Compare(Node node1, Node node2)
  33. {
  34. if (Equals(node1, node2))
  35. return true;
  36. if (node1 == node2)
  37. return true;
  38. if (node1.X == node2.X && node1.Y == node2.Y)
  39. return true;
  40. return false;
  41. }
  42. /// <summary>
  43. /// Compare nodes and returns true if they are overlaid
  44. /// </summary>
  45. /// <param name="node1"></param>
  46. /// <param name="node2"></param>
  47. /// <returns>True if overlaid, false if not</returns>
  48. public static bool IsNodeOverlaid(Node node1, Node node2)
  49. {
  50. var x = node1.X - node2.X;
  51. var y = node1.Y - node2.Y;
  52. if(x<=Settings.NodeWidth/2 && x>=0)
  53. if (y <= Settings.NodeHeight / 2 && y > 0)
  54. return true;
  55. x = node2.X - node1.X;
  56. y = node2.Y - node1.Y;
  57. if (x <= Settings.NodeWidth / 2 && x >= 0)
  58. if (y <= Settings.NodeHeight / 2 && y > 0)
  59. return true;
  60. return false;
  61. }
  62. }
  63. }