static void EliminateTinySections(List<Section> list, int minLineLengthPx)
{
// Eliminate tiny sections
Section cur;
int i;
while ((cur = list[i = list.IndexOfMin(s => s.LengthPx)]).LengthPx < minLineLengthPx)
{
var prev = list.TryGet(i - 1, null);
var next = list.TryGet(i + 1, null);
if (PickMerge(ref prev, cur, ref next))
{
if (prev != null)
list[i - 1] = prev;
if (next != null)
list[i + 1] = next;
list.RemoveAt(i);
}
else
break;
}
// Merge adjacent sections that now have the same mod-8 angle
for (i = 1; i < list.Count; i++)
{
Section s0 = list[i - 1], s1 = list[i];
if (s0.AngleMod8 == s1.AngleMod8)
{
s0.EndSS = s1.EndSS;
s0.iEnd = s1.iEnd;
s0.LengthPx += s1.LengthPx;
list.RemoveAt(i);
i--;
}
}
}
static double AngleError(VectorT vec, int angleMod8)