fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace CircleGesture
  11. {
  12. public partial class Form1 : Form
  13. {
  14. private List<Point> points;
  15. private bool capturing;
  16. private bool isCircle;
  17. private Point centroid;
  18. private double radius;
  19.  
  20. private double Distance( Point a, Point b ) {
  21. return Math.Sqrt((b.X - a.X) * (b.X - a.X) + (b.Y - a.Y) * (b.Y - a.Y));
  22. }
  23. private bool isApproxCircle() {
  24. int k = points.Count;
  25. radius = 0;
  26. foreach (Point p in points)
  27. radius += Distance(centroid, p);
  28. radius /= k;
  29.  
  30. const double eps = 0.35; // 35% difference to average is still ok.
  31.  
  32. foreach (Point p in points)
  33. {
  34. double r = Distance(centroid, p);
  35. if (Math.Abs((radius-r)/radius)>eps)
  36. return false;
  37. }
  38. return true;
  39. }
  40.  
  41. public Form1()
  42. {
  43. InitializeComponent();
  44. points = new List<Point>();
  45. }
  46.  
  47. private void Form1_MouseDown(object sender, MouseEventArgs e)
  48. {
  49. points.Clear();
  50. capturing = true;
  51. points.Add(e.Location);
  52. centroid.X = e.Location.X; centroid.Y = e.Location.Y;
  53. }
  54.  
  55. private void Form1_MouseMove(object sender, MouseEventArgs e)
  56. {
  57. if (capturing) {
  58. points.Add(e.Location);
  59. centroid.X += e.Location.X; centroid.Y += e.Location.Y;
  60. }
  61. }
  62.  
  63. private void Form1_MouseUp(object sender, MouseEventArgs e)
  64. {
  65. if (capturing) {
  66. points.Add(e.Location);
  67. centroid.X += e.Location.X; centroid.Y += e.Location.Y;
  68. centroid.X /= points.Count; centroid.Y /= points.Count;
  69. capturing = false;
  70. isCircle = isApproxCircle();
  71. Invalidate();
  72. }
  73. }
  74.  
  75. private void Form1_Paint(object sender, PaintEventArgs e)
  76. {
  77. System.Drawing.Graphics graphicsObj = this.CreateGraphics();
  78. Pen myPen = new Pen(System.Drawing.Color.Black, 2);
  79. int cnt = points.Count;
  80. if (cnt > 0)
  81. {
  82. Point[] pts = new Point[cnt];
  83. for (int i = 0; i < cnt; ++i)
  84. {
  85. pts[i] = points[i];
  86. graphicsObj.DrawLine(myPen, centroid, pts[i]);
  87. }
  88. graphicsObj.DrawPolygon(myPen, pts);
  89. if (isCircle)
  90. {
  91. Int32 r = Convert.ToInt32(radius);
  92. Rectangle myRectangle = new Rectangle(centroid.X - r, centroid.Y - r, 2*r, 2*r);
  93. graphicsObj.DrawEllipse(myPen, myRectangle);
  94. }
  95. }
  96. }
  97. }
  98. }
  99.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(4,14): error CS0234: The type or namespace name `Data' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(5,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(8,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
Compilation failed: 3 error(s), 0 warnings
stdout
Standard output is empty