CCT.NUI.Core.Point.FindIndexOfNearestPoint C# (CSharp) Method

FindIndexOfNearestPoint() public static method

public static FindIndexOfNearestPoint ( Point target, IList points ) : int
target Point
points IList
return int
        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;
        }