using System; using System.Xml.Serialization; namespace DrawGraph { public class Edge { [XmlAttribute("source")] public Node SourceNode { get; } [XmlAttribute("target")] public Node TargetNode { get; } [XmlAttribute("weight")] public int? Weight { get; set; } public bool IsFocused { get; } public Edge(Node v1, Node v2, bool IsFocused) { SourceNode = v1; TargetNode = v2; this.IsFocused = IsFocused; } public Edge(Node sourceNode, Node targetNode, int weight, bool IsFocused) { SourceNode = sourceNode; TargetNode = targetNode; Weight = weight; this.IsFocused = IsFocused; } public static double GetCenterByX(Edge edge) { var x = (edge.TargetNode.X + edge.SourceNode.X) / 2; return x; } public static double GetCenterByY(Edge edge) { var y = (edge.TargetNode.Y + edge.SourceNode.Y) / 2; return y; } public static bool IsCursorOnNode(System.Windows.Point cursorPosition, Node Node) { try { if (Node.CenterByX - cursorPosition.X <= Settings.NodeWidth / 2 && Node.CenterByX - cursorPosition.X >= 0) { if (Node.CenterByY - cursorPosition.Y <= Settings.NodeHeight / 2 && Node.CenterByY - cursorPosition.Y >= 0) { return true; } } if (cursorPosition.X - Node.CenterByX <= Settings.NodeWidth / 2 && cursorPosition.X - Node.CenterByX >= 0) { if (cursorPosition.Y - Node.CenterByY <= Settings.NodeWidth / 2 && cursorPosition.Y - Node.CenterByY >= 0) { return true; } return false; } return false; } catch(Exception ex) { throw new Exception(ex.Message); } } public static bool IsNodeBelongToEdge(Edge edge, Node Node) { if (Node.Compare(Node, edge.SourceNode) || Node.Compare(Node, edge.TargetNode)) return true; return false; } } }