using System.Xml.Serialization; using System.Windows.Shapes; using System.Windows.Controls; using System.Collections.Generic; using System.Runtime.Serialization; using System; 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; } /// /// Identifier of node (numeric) /// Returns identifier "NXX" /// Where XX - established numeric value /// /// /// Get center of node by X-coordinate /// /// Center of node by X public int GetCenterByX() { return (X * 2 + (Settings.NodeWidth / 2)) / 2; } /// /// Get center of node by Y-coordinate /// /// Center of node by Y public int GetCenterByY() { return (Y * 2 + (Settings.NodeHeight / 2)) / 2; } /// /// Compare two nodes /// /// First node to compare /// Second node to compare /// True if nodes are equal, false if not equal 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; } /// /// Compare nodes and returns true if they are overlaid /// /// /// /// True if overlaid, false if not 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; } /// /// Check if node has neighbors /// /// Node to check /// Edges array /// public static bool HasNeighbors(Node node, Edge[] edges) { foreach(var edge in edges) { if (Compare(node, edge.SourceNode) || Compare(node, edge.TargetNode)) return true; } return false; } public static bool HasNeighbors(Node node, List edges) { var a = edges.ToArray(); return HasNeighbors(node, a); } } }