1
|
/*
|
2
|
Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft
|
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
of this software and associated documentation files (the "Software"), to deal
|
5
|
in the Software without restriction, including without limitation the rights
|
6
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
copies of the Software, and to permit persons to whom the Software is
|
8
|
furnished to do so, subject to the following conditions:
|
9
|
|
10
|
The above copyright notice and this permission notice shall be included in
|
11
|
all copies or substantial portions of the Software.
|
12
|
|
13
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
SOFTWARE.
|
20
|
*/
|
21
|
|
22
|
using System;
|
23
|
using System.Drawing;
|
24
|
using System.Collections;
|
25
|
using System.ComponentModel;
|
26
|
using System.Windows.Forms;
|
27
|
using System.Diagnostics;
|
28
|
using C5;
|
29
|
|
30
|
namespace GConvexHull
|
31
|
{
|
32
|
/// <summary>
|
33
|
/// Summary description for Form1.
|
34
|
/// </summary>
|
35
|
public class TesterForm : System.Windows.Forms.Form
|
36
|
{
|
37
|
//My data
|
38
|
|
39
|
//My GUI stuff
|
40
|
private System.Windows.Forms.Panel drawarea;
|
41
|
|
42
|
private Graphics drawg;
|
43
|
|
44
|
//Std stuff
|
45
|
private System.Windows.Forms.Button runButton;
|
46
|
private TextBox pointCount;
|
47
|
|
48
|
/// <summary>
|
49
|
/// Required designer variable.
|
50
|
/// </summary>
|
51
|
private System.ComponentModel.Container components = null;
|
52
|
|
53
|
|
54
|
public TesterForm()
|
55
|
{
|
56
|
//
|
57
|
// Required for Windows Form Designer support
|
58
|
//
|
59
|
InitializeComponent();
|
60
|
|
61
|
//
|
62
|
// TODO: Add any constructor code after InitializeComponent call
|
63
|
//
|
64
|
drawg = drawarea.CreateGraphics();
|
65
|
reset();
|
66
|
}
|
67
|
|
68
|
|
69
|
/// <summary>
|
70
|
/// Clean up any resources being used.
|
71
|
/// </summary>
|
72
|
protected override void Dispose(bool disposing)
|
73
|
{
|
74
|
if (disposing)
|
75
|
{
|
76
|
if (components != null)
|
77
|
{
|
78
|
components.Dispose();
|
79
|
}
|
80
|
}
|
81
|
|
82
|
base.Dispose(disposing);
|
83
|
}
|
84
|
|
85
|
#region Windows Form Designer generated code
|
86
|
/// <summary>
|
87
|
/// Required method for Designer support - do not modify
|
88
|
/// the contents of this method with the code editor.
|
89
|
/// </summary>
|
90
|
private void InitializeComponent()
|
91
|
{
|
92
|
this.drawarea = new System.Windows.Forms.Panel();
|
93
|
this.runButton = new System.Windows.Forms.Button();
|
94
|
this.pointCount = new System.Windows.Forms.TextBox();
|
95
|
this.SuspendLayout();
|
96
|
//
|
97
|
// drawarea
|
98
|
//
|
99
|
this.drawarea.BackColor = System.Drawing.Color.White;
|
100
|
this.drawarea.Location = new System.Drawing.Point(8, 9);
|
101
|
this.drawarea.Name = "drawarea";
|
102
|
this.drawarea.Size = new System.Drawing.Size(500, 500);
|
103
|
this.drawarea.TabIndex = 0;
|
104
|
this.drawarea.Paint += new System.Windows.Forms.PaintEventHandler(this.drawarea_Paint);
|
105
|
this.drawarea.Invalidated += new System.Windows.Forms.InvalidateEventHandler(this.drawarea_Invalidated);
|
106
|
this.drawarea.MouseMove += new System.Windows.Forms.MouseEventHandler(this.drawarea_MouseMove);
|
107
|
this.drawarea.MouseClick += new System.Windows.Forms.MouseEventHandler(this.drawarea_MouseClick);
|
108
|
//
|
109
|
// runButton
|
110
|
//
|
111
|
this.runButton.Location = new System.Drawing.Point(8, 516);
|
112
|
this.runButton.Name = "runButton";
|
113
|
this.runButton.Size = new System.Drawing.Size(42, 20);
|
114
|
this.runButton.TabIndex = 1;
|
115
|
this.runButton.Text = "Run";
|
116
|
this.runButton.Click += new System.EventHandler(this.runButton_Click);
|
117
|
//
|
118
|
// pointCount
|
119
|
//
|
120
|
this.pointCount.Location = new System.Drawing.Point(97, 517);
|
121
|
this.pointCount.Name = "pointCount";
|
122
|
this.pointCount.Size = new System.Drawing.Size(55, 20);
|
123
|
this.pointCount.TabIndex = 5;
|
124
|
//
|
125
|
// TesterForm
|
126
|
//
|
127
|
this.ClientSize = new System.Drawing.Size(524, 550);
|
128
|
this.Controls.Add(this.pointCount);
|
129
|
this.Controls.Add(this.runButton);
|
130
|
this.Controls.Add(this.drawarea);
|
131
|
this.Name = "TesterForm";
|
132
|
this.Text = "C5 Tester";
|
133
|
this.Load += new System.EventHandler(this.TesterForm_Load);
|
134
|
this.ResumeLayout(false);
|
135
|
this.PerformLayout();
|
136
|
|
137
|
}
|
138
|
#endregion
|
139
|
|
140
|
/// <summary>
|
141
|
/// The main entry point for the application.
|
142
|
/// </summary>
|
143
|
[STAThread]
|
144
|
static void Main()
|
145
|
{
|
146
|
Application.EnableVisualStyles();
|
147
|
Application.Run(new TesterForm());
|
148
|
}
|
149
|
|
150
|
Point[] pts;
|
151
|
Point[] chpts;
|
152
|
|
153
|
private void runButton_Click(object sender, System.EventArgs e)
|
154
|
{
|
155
|
int N = int.Parse(pointCount.Text);
|
156
|
pts = new Point[N];
|
157
|
for (int i = 0; i < N; i++)
|
158
|
pts[i] = Point.Random(500, 500);
|
159
|
chpts = Convexhull.ConvexHull(pts);
|
160
|
|
161
|
drawarea.Invalidate();
|
162
|
}
|
163
|
|
164
|
|
165
|
private void drawarea_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
|
166
|
{
|
167
|
mydraw();
|
168
|
}
|
169
|
|
170
|
|
171
|
private void resetButton_Click(object sender, System.EventArgs e)
|
172
|
{
|
173
|
reset();
|
174
|
}
|
175
|
|
176
|
|
177
|
private void reset()
|
178
|
{
|
179
|
drawarea.Invalidate();//(new Rectangle(0, 0, 40, 40));
|
180
|
}
|
181
|
|
182
|
|
183
|
|
184
|
public void mydraw()
|
185
|
{
|
186
|
if (pts == null)
|
187
|
{
|
188
|
return;
|
189
|
}
|
190
|
for (int i = 0; i < pts.Length; i++)
|
191
|
{
|
192
|
Point p = pts[i];
|
193
|
drawg.DrawEllipse(new Pen(Color.Red), transx(p.x) - 2, transy(p.y) - 2, 4, 4);
|
194
|
}
|
195
|
for (int i = 0; i < chpts.Length; i++)
|
196
|
{
|
197
|
int j = i + 1 < chpts.Length ? i + 1 : 0;
|
198
|
drawg.DrawEllipse(new Pen(Color.Blue), transx(chpts[i].x) - 2, transy(chpts[i].y) - 2, 4, 4);
|
199
|
drawg.DrawLine(new Pen(Color.LawnGreen), transx(chpts[i].x), transx(chpts[i].y), transx(chpts[j].x), transx(chpts[j].y));
|
200
|
}
|
201
|
}
|
202
|
|
203
|
|
204
|
|
205
|
private int transx(double x)
|
206
|
{
|
207
|
return (int)x;
|
208
|
}
|
209
|
|
210
|
|
211
|
private int transy(double y)
|
212
|
{
|
213
|
return (int)y;
|
214
|
}
|
215
|
|
216
|
|
217
|
private void dumpButton_Click(object sender, System.EventArgs e)
|
218
|
{
|
219
|
Debug.WriteLine("###############");
|
220
|
Debug.WriteLine("###############");
|
221
|
}
|
222
|
|
223
|
|
224
|
private void graphTypeControlArray_Click(object sender, System.EventArgs e)
|
225
|
{
|
226
|
Debug.WriteLine(e.GetType());
|
227
|
Debug.WriteLine(sender.GetType());
|
228
|
drawarea.Invalidate();
|
229
|
}
|
230
|
|
231
|
|
232
|
private void drawarea_MouseMove(object sender, MouseEventArgs e)
|
233
|
{
|
234
|
}
|
235
|
|
236
|
|
237
|
private void drawarea_MouseClick(object sender, MouseEventArgs e)
|
238
|
{
|
239
|
//double x = untransx(e.X), y = untransy(e.Y);
|
240
|
|
241
|
}
|
242
|
|
243
|
|
244
|
private void drawarea_Invalidated(object sender, InvalidateEventArgs e)
|
245
|
{
|
246
|
//msg.Text = e.InvalidRect + "";
|
247
|
//mydraw();
|
248
|
}
|
249
|
|
250
|
|
251
|
private void preparedFigureSelection_SelectedIndexChanged(object sender, System.EventArgs e)
|
252
|
{
|
253
|
}
|
254
|
|
255
|
private void voronoiButton_CheckedChanged(object sender, EventArgs e)
|
256
|
{
|
257
|
graphTypeControlArray_Click(sender, e);
|
258
|
}
|
259
|
|
260
|
private void delaunayButton_CheckedChanged(object sender, EventArgs e)
|
261
|
{
|
262
|
graphTypeControlArray_Click(sender, e);
|
263
|
}
|
264
|
|
265
|
private void TesterForm_Load(object sender, EventArgs e)
|
266
|
{
|
267
|
|
268
|
}
|
269
|
|
270
|
}
|
271
|
}
|