123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using System.Drawing;
- using System.Windows.Shapes;
- namespace DrawGraph
- {
- public class Edge
- {
- public Line Line { get; }
- public ArrowLine ArrowLine { get; }
- public Node StartNode { get; }
- public Node FinishNode { get; }
- public int? Weight { get; set; }
- public bool IsFocused { get; }
- public Edge(Line line, Node v1, Node v2)
- {
- Line = line;
- StartNode = v1;
- FinishNode = v2;
- IsFocused = false;
- }
- public Edge(ArrowLine line, Node v1, Node v2)
- {
- ArrowLine = line;
- StartNode = v1;
- FinishNode = v2;
- IsFocused = true;
- }
- public Edge(Line line, Node v1, Node v2, int weight)
- {
- Line = line;
- StartNode = v1;
- FinishNode = v2;
- Weight = weight;
- IsFocused = false;
- }
- public Edge(ArrowLine line, Node v1, Node v2, int weight)
- {
- ArrowLine = line;
- StartNode = v1;
- FinishNode = 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.FinishNode.X + edge.StartNode.X) / 2;
- return x;
- }
- public static double GetCenterByY(Edge edge)
- {
- var y = (edge.FinishNode.Y + edge.StartNode.Y) / 2;
- return y;
- }
- public static bool IsCursorOnNode(System.Windows.Point cursorPosition, Node Node)
- {
- 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;
- }
- public static bool IsNodeBelongToEdge(Edge edge, Node Node)
- {
- if (Node.Compare(Node, edge.StartNode) || Node.Compare(Node, edge.FinishNode))
- return true;
- return false;
- }
- }
- }
|