Hi All,
I’ve been able to test the code out on smaller list sizes and it works exactly as intended. But when its scaled up (from 200 entries to 2000) unity just freezes. In case the subject isn’t very clear I’m trying to sort a list of V2 so that each entry is the closest to the previous entry. Any ideas would be very helpful.
Thank you!
List<Vector2> sorted = new List<Vector2>();
List<Vector2> unsorted = new List<Vector2>();
foreach (Vector2 V in S.DataPoints)
{
unsorted.Add(V);
}
while (unsorted.Count > 0)
{
Vector2 current = new Vector2();
current = unsorted[0];
sorted.Add(current);
unsorted.Remove(current);
if (unsorted.Count > 1)
{
foreach (Vector2 V1 in unsorted)
{
unsorted = unsorted.OrderBy(x => Vector2.Distance(current, x)).ToList();
}
}
else
{
if (unsorted.Count > 0)
{
current = unsorted[0];
sorted.Add(current);
unsorted.Remove(current);
}
}
}
S.DataPoints.Clear();
foreach(Vector2 V2 in sorted)
{
S.DataPoints.Add(V2);
}