private Cluster MoveToClosestCluster(ref Cluster Current, ref List<Cluster> parents) { int indexOfClosest = -1; double min = double.MaxValue; for (int i = 0; i < parents.Count; i++) { if (parents[i].X == Current.X && parents[i].Y == Current.Y) continue; if (min > GetLength(Current.Location, parents[i].Location)) { min = GetLength(Current.Location, parents[i].Location); indexOfClosest = i; } } return parents[indexOfClosest]; }
private double GetLength(Tape tape, Cluster cluster, ref bool start) { double distance1 = Math.Sqrt(Math.Pow(tape.StartPoint.X - cluster.X, 2) + Math.Pow(tape.StartPoint.Y - cluster.Y, 2)); double distance2 = Math.Sqrt(Math.Pow(tape.EndPoint.X - cluster.X, 2) + Math.Pow(tape.EndPoint.Y - cluster.Y, 2)); distance1 = Math.Min(distance1, distance2); start = Math.Min(distance1, distance2) == distance1; return distance1; }