public static int FindIndexOfNearestPoint(Point target, IList<Point> points)
{
int index = 0;
int resultIndex = -1;
double minDist = double.MaxValue;
foreach (Point p in points)
{
var distance = Distance(p.X, p.Y, target.X, target.Y);
if (distance < minDist)
{
resultIndex = index;
minDist = distance;
}
index++;
}
return resultIndex;
}