瀏覽代碼

cleaned up the code a bit

bmallred 12 年之前
父節點
當前提交
559524d612
共有 1 個文件被更改,包括 40 次插入18 次删除
  1. 40 18
      EuclideanDistance/Main.cs

+ 40 - 18
EuclideanDistance/Main.cs

17
		/// </param>
17
		/// </param>
18
		public static void Main(string[] args)
18
		public static void Main(string[] args)
19
		{
19
		{
20
			var points = new List<IEnumerable<double>>();
21
			IEnumerable<double> input;
22
23
			// Accumalate the intial data points needed before computation.
20
			// Accumalate the intial data points needed before computation.
21
			var points = InitialDataPoints();
22
23
			// Retrieve the focal point to determine our distances.
24
			var input = FocalPoint(points);
25
26
			// Store all the distances.
27
			var distances = points.Select(x => input.EuclideanDistance(x)).ToList();
28
29
			// Display both the closest and furthest data points from the focal point.
30
			Console.WriteLine();
31
			Console.WriteLine("Minimum distance: {0}", points.ElementAt(distances.IndexOf(distances.Min())).ToPoint());
32
			Console.WriteLine("Maximum distance: {0}", points.ElementAt(distances.IndexOf(distances.Max())).ToPoint());
33
		}
34
35
		/// <summary>
36
		/// Initials the data points.
37
		/// </summary>
38
		/// <returns>
39
		/// The data points.
40
		/// </returns>
41
		private static IEnumerable<IEnumerable<double>> InitialDataPoints()
42
		{
43
			var points = new List<IEnumerable<double>>();
24
			Console.WriteLine("Please enter the initial points");
44
			Console.WriteLine("Please enter the initial points");
45
25
			while (true)
46
			while (true)
26
			{
47
			{
27
				Console.Write("Point [blank to stop]: ");
48
				Console.Write("Point [blank to stop]: ");
48
				}
69
				}
49
			}
70
			}
50
71
51
			// Retrieve the focal point to determine our distances.
72
			return points;
73
		}
74
75
		/// <summary>
76
		/// Focals the point.
77
		/// </summary>
78
		/// <returns>
79
		/// The point.
80
		/// </returns>
81
		/// <param name='points'>
82
		/// Points.
83
		/// </param>
84
		private static IEnumerable<double> FocalPoint(IEnumerable<IEnumerable<double>> points)
85
		{
52
			Console.WriteLine();
86
			Console.WriteLine();
53
			Console.WriteLine("Please enter a focal point");
87
			Console.WriteLine("Please enter a focal point");
88
54
			while (true)
89
			while (true)
55
			{
90
			{
56
				Console.Write("Point: ");
91
				Console.Write("Point: ");
66
				}
101
				}
67
				else
102
				else
68
				{
103
				{
69
					input = p;
70
					break;
104
					return p;
71
				}
105
				}
72
			}
106
			}
73
74
			// Store all the distances.
75
			var distances = new List<double>();
76
			foreach (var p in points)
77
			{
78
				distances.Add(input.EuclideanDistance(p));
79
			}
80
81
			// Display both the closest and furthest data points from the focal point.
82
			Console.WriteLine();
83
			Console.WriteLine("Minimum distance: {0}", points[distances.IndexOf(distances.Min())].ToPoint());
84
			Console.WriteLine("Maximum distance: {0}", points[distances.IndexOf(distances.Max())].ToPoint());
85
		}
107
		}
86
	}
108
	}
87
}
109
}