-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoints.cs
More file actions
196 lines (147 loc) · 4.34 KB
/
Points.cs
File metadata and controls
196 lines (147 loc) · 4.34 KB
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.Collections;
using System.Linq;
using System.Text;
namespace GBusManager
{
public class PointsEventArgs : EventArgs
{
public Point point;
public PointsEventArgs(Point p)
{
point = p;
}
}
public delegate void PointHandler(object sender, PointsEventArgs e);
/// <summary>
/// Контейнер для точек с операциями доступа и событиями
/// </summary>
/// TODO
class Points:ICollection<Point>,IList<Point>
{
public event PointHandler PointAdded;
public event PointHandler PointDeleted;
protected virtual void OnPointAdded(PointsEventArgs e)
{
//PointsEventArgs pea = new PointsEventArgs(points[cnt]);
//pea.p = points[cnt];
Console.WriteLine("Была добавлена точка {0}", e.point.ToString());
PointAdded(this, e);
}
protected virtual void OnPointDeleted(PointsEventArgs e)
{
//PointsEventArgs pea = new PointsEventArgs(points[cnt]);
//pea.p = points[cnt];
Console.WriteLine("Была удалена точка {0}", e.point.ToString());
PointDeleted(this, e);
}
Point[] points;
//ArrayList<Point> p;
int capacity;
int cnt;
public Points(int capacity)
{
cnt = 0;
points = new Point[capacity];
this.capacity = capacity;
}
#region Члены ICollection<Point>
public void Add(Point item)
{
if (cnt == capacity)
{
Console.WriteLine("Нужно увеличить емкость Points");
capacity = capacity * 2;
Point[] newpoints = new Point[capacity];
for (int i = 0; i < points.Length; i++)
{
newpoints[i] = points[i];
}
points = newpoints;
}
points[cnt++] = item;
OnPointAdded(new PointsEventArgs(item));
}
public void Clear()
{
cnt = 0;
points = new Point[capacity];
}
public bool Contains(Point item)
{
throw new NotImplementedException();
}
public void CopyTo(Point[] array, int arrayIndex)
{
throw new NotImplementedException();
}
public int Count
{
get { return cnt; }
}
public bool IsReadOnly
{
get { throw new NotImplementedException(); }
}
public bool Remove(Point item)
{
for (int i = 0; i < cnt; i++)
{
if (points[i] == item)
{
points[i] = null;
OnPointDeleted(new PointsEventArgs(item));
return true;
}
}
return false;
}
#endregion
#region Члены IEnumerable<Point>
public IEnumerator<Point> GetEnumerator()
{
throw new NotImplementedException();
}
#endregion
#region Члены IEnumerable
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
#endregion
#region Члены IList<Point>
public int IndexOf(Point item)
{
throw new NotImplementedException();
}
public void Insert(int index, Point item)
{
throw new NotImplementedException();
}
public void RemoveAt(int index)
{
throw new NotImplementedException();
}
public Point this[int index]
{
get
{
if (index <= capacity)
{
return points[index];
}
else throw new IndexOutOfRangeException();
}
set
{
if (index <= capacity)
{
points[index] = value;
}
else throw new IndexOutOfRangeException();
}
}
#endregion
}
}