using System.Drawing; using System.Windows.Shapes; namespace DrawGraph { public class Edge { public Line Line { get; } public ArrowLine ArrowLine { get; } public Vertex StartVertex { get; } public Vertex FinishVertex { get; } public int? Weight { get; set; } public bool IsFocused { get; } public Edge(Line line, Vertex v1, Vertex v2) { Line = line; StartVertex = v1; FinishVertex = v2; IsFocused = false; } public Edge(ArrowLine line, Vertex v1, Vertex v2) { ArrowLine = line; StartVertex = v1; FinishVertex = v2; IsFocused = true; } public Edge(Line line, Vertex v1, Vertex v2, int weight) { Line = line; StartVertex = v1; FinishVertex = v2; Weight = weight; IsFocused = false; } public Edge(ArrowLine line, Vertex v1, Vertex v2, int weight) { ArrowLine = line; StartVertex = v1; FinishVertex = v2; IsFocused = true; Weight = weight; ArrowLine.X1 = v1.CenterByX; ArrowLine.X2 = v2.CenterByX; ArrowLine.Y1 = v1.CenterByY; ArrowLine.Y2 = v2.CenterByY; ArrowLine.StrokeThickness = 2; } public static double GetCenterByX(Edge edge) { var x = (edge.FinishVertex.X + edge.StartVertex.X) / 2; return x; } public static double GetCenterByY(Edge edge) { var y = (edge.FinishVertex.Y + edge.StartVertex.Y) / 2; return y; } public static bool IsCursorOnVertex(Point cursorPosition, Vertex vertex) { if (vertex.CenterByX - cursorPosition.X <= Settings.VertexWidth / 2 && vertex.CenterByX - cursorPosition.X >= 0) { if (vertex.CenterByY - cursorPosition.Y <= Settings.VertexHeight / 2 && vertex.CenterByY - cursorPosition.Y >= 0) { return true; } } if (cursorPosition.X - vertex.CenterByX <= Settings.VertexWidth / 2 && cursorPosition.X - vertex.CenterByX >= 0) { if (cursorPosition.Y - vertex.CenterByY <= Settings.VertexWidth / 2 && cursorPosition.Y - vertex.CenterByY >= 0) { return true; } return false; } return false; } public static bool IsVertexBelongToEdge(Edge edge, Vertex vertex) { if (Vertex.Compare(vertex, edge.StartVertex) || Vertex.Compare(vertex, edge.FinishVertex)) return true; return false; } } }