internal static void AddDistance(Double[] f, Double[] disp, Double testdist, Double testdisp)
{
// Compare the given distance to the ones already in f
if (testdist >= f[3]) return;
var index = 3;
while (index > 0 && testdist < f[index - 1]) index--;
for (var i = 3; i-- > index; )
{
f[i + 1] = f[i];
disp[i + 1] = disp[i];
}
f[index] = testdist;
disp[index] = testdisp;
}