-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEdge.cs
196 lines (182 loc) · 5.22 KB
/
Edge.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace Maximum_flow
{
/// <summary>
/// Class Edge: represents an Edge
/// </summary>
class Edge
{
private float myflowrate;
private float mycurrent_flowrate;
private string myname;
private Node myflow_out_node;
private Node myflow_in_node;
private Point mystart;
private Point myend;
private decimal mygradient;
private decimal myaxisintercept;
private bool mycolortrue;
/// <summary>
/// Constructor
/// </summary>
/// <param name="flowrate">Flowrate of this Edge</param>
/// <param name="flow_out_node">Node of which Edge flows out</param>
/// <param name="flow_in_node">Node of which Edge flows in</param>
public Edge(string name, float flowrate, Node flow_out_node, Node flow_in_node, Point start, Point end)
{
this.myname = name;
this.myflowrate = flowrate;
this.myflow_out_node = flow_out_node;
this.myflow_in_node = flow_in_node;
this.myflow_out_node.Add_Flow_Out(this);
this.myflow_in_node.Add_Flow_In(this);
this.mystart = start;
this.myend = end;
this.mycurrent_flowrate = 0;
this.mycolortrue = false;
if (myend.X == mystart.X)
{
this.mygradient = 10 ^ 10;
}
else
{
this.mygradient = Convert.ToDecimal(mystart.Y - myend.Y) / Convert.ToDecimal(myend.X - mystart.X);
}
this.myaxisintercept = -mystart.Y - mygradient * mystart.X;
}
public Node Flow_Out_Node
{
get
{
return myflow_out_node;
}
set
{
myflow_out_node = value;
}
}
public Node Flow_In_Node
{
get
{
return myflow_in_node;
}
set
{
myflow_in_node = value;
}
}
public float Flowrate
{
get
{
return myflowrate;
}
set
{
myflowrate = value;
}
}
public string Name
{
get
{
return myname;
}
set
{
myname = value;
}
}
public bool Is_Mouse_Over(int mouseX, int mouseY)
{
if (-mygradient * mouseX - myaxisintercept < mouseY + 5 && -mygradient * mouseX - myaxisintercept > mouseY - 5)
{
if (myend.X >= mystart.X)
{
if (mouseX >= mystart.X - 5 && mouseX < myend.X + 5)
{
return true;
}
}
else
{
if (mouseX <= mystart.X + 5 && mouseX > myend.X - 5)
{
return true;
}
}
}
else if (myend.X == mystart.X)
{
if (mouseX >= mystart.X - 5 && mouseX < myend.X + 5)
{
if (myend.Y >= mystart.Y)
{
if (mouseY <= myend.Y + 5 && mouseY > mystart.Y - 5)
{
return true;
}
}
else
{
if (mouseY >= myend.Y - 5 && mouseY < mystart.Y + 5)
{
return true;
}
}
}
}
return false;
}
public Point Start_Point()
{
return mystart;
}
public Point End_Point()
{
return myend;
}
public float Current_Flowrate
{
get
{
return mycurrent_flowrate;
}
set
{
mycurrent_flowrate = value;
}
}
public bool Color_True
{
get
{
return mycolortrue;
}
set
{
mycolortrue = value;
}
}
public void Function(Point new_start_point, Point new_end_point)
{
mystart = new_start_point;
myend = new_end_point;
if (myend.X == mystart.X)
{
mygradient = 10 ^ 10;
}
else
{
mygradient = Convert.ToDecimal(mystart.Y - myend.Y) / Convert.ToDecimal(myend.X - mystart.X);
}
myaxisintercept = -mystart.Y - mygradient * mystart.X;
}
}
}