/
Route.cs
115 lines (94 loc) · 2.89 KB
/
Route.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
using System;
using System.Drawing;
using System.Collections;
using System.Runtime.Serialization;
namespace GBusManager
{
[Serializable()]
/// <summary>
/// Description of Route.
/// </summary>
public class Route
{
public string rs;
public int[] nodes;
// статический счетчик экземпляров
static int count;
public int n;
public Color color;
public int Length {
get {
return nodes.Length;
}
}
public Route(string s)
{
n = count;
count++;
rs = s;
Random rndm = new Random();
color = Color.FromArgb(rndm.Next(255), rndm.Next(255), rndm.Next(255));
string[] ns = s.Split();
nodes = new int[ns.Length];
//if (ns.Length < 2) { throw new Exception("Route must have at least 2 nodes length"); }
for (int i = 0; i< ns.Length; i++){
nodes[i] = int.Parse(ns[i]);
}
}
public Route(int[] nn){
nodes = nn;
}
public override string ToString()
{
return ""+n+"." + "[" + rs + "]";
}
public int Near(int n, int d)
{
int i = 0;// = rs.IndexOf(n.ToString());
try
{
for (i = 0; i < nodes.Length && nodes[i] != n; i++)
;
//ArrayList a;
//a.AddRange();
//if (i+d)
return nodes[i + d];
}
catch { return nodes[i - d]; }
}
public static Color RandomColor()
{
Random random = new Random();
int red = random.Next(random.Next(255));
int green = random.Next(random.Next(255));
int blue = random.Next(random.Next(255));
Color color;
color = Color.FromArgb(red, green, blue);
//color = Color.F
return color;
}
public static Color RandomColorHSV(double hue, double saturation, double value)
{
int hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6;
double f = hue / 60 - Math.Floor(hue / 60);
value = value * 255;
int v = Convert.ToInt32(value);
int p = Convert.ToInt32(value * (1 - saturation));
int q = Convert.ToInt32(value * (1 - f * saturation));
int t = Convert.ToInt32(value * (1 - (1 - f) * saturation));
if (hi == 0)
return Color.FromArgb(255, v, t, p);
else if (hi == 1)
return Color.FromArgb(255, q, v, p);
else if (hi == 2)
return Color.FromArgb(255, p, v, t);
else if (hi == 3)
return Color.FromArgb(255, p, q, v);
else if (hi == 4)
return Color.FromArgb(255, t, p, v);
else
return Color.FromArgb(255, v, p, q);
}
}
}