12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System.Xml.Serialization;
- using System.Windows.Shapes;
- using System.Windows.Controls;
- using System.Collections.Generic;
- namespace DrawGraph
- {
- public class Node
- {
- [XmlAttribute("positionX")]
- public int X { get; set; }
- [XmlAttribute("positionY")]
- public int Y { get; set; }
- public Node(int x, int y)
- {
- X = x;
- Y = y;
- }
- /// <summary>
- /// Get center X-coordinate of node
- /// </summary>
- public int CenterByX => (X * 2 + (Settings.NodeWidth/2)) / 2;
- /// <summary>
- /// Get center Y-coordinate of node
- /// </summary>
- public int CenterByY => (Y * 2 + (Settings.NodeHeight / 2)) / 2;
- /// <summary>
- /// Compare two nodes
- /// </summary>
- /// <param name="node1">First node to compare</param>
- /// <param name="node2">Second node to compare</param>
- /// <returns>True if nodes are equal, false if not equal</returns>
- public static bool Compare(Node node1, Node node2)
- {
- if (Equals(node1, node2))
- return true;
- if (node1 == node2)
- return true;
- if (node1.X == node2.X && node1.Y == node2.Y)
- return true;
- return false;
- }
- /// <summary>
- /// Compare nodes and returns true if they are overlaid
- /// </summary>
- /// <param name="node1"></param>
- /// <param name="node2"></param>
- /// <returns>True if overlaid, false if not</returns>
- public static bool IsNodeOverlaid(Node node1, Node node2)
- {
- var x = node1.X - node2.X;
- var y = node1.Y - node2.Y;
- if(x<=Settings.NodeWidth/2 && x>=0)
- if (y <= Settings.NodeHeight / 2 && y > 0)
- return true;
- x = node2.X - node1.X;
- y = node2.Y - node1.Y;
- if (x <= Settings.NodeWidth / 2 && x >= 0)
- if (y <= Settings.NodeHeight / 2 && y > 0)
- return true;
- return false;
- }
- }
- }
|