c# find nearest element in list / sort by distance
public void TestMinDistance(){List list = new List(){new Point(1, 1),new Point(2, 1),new Point(2, 0),}; Point pivot = new Point(3, 1); Func DistanceTo = (point1, point2) =>{var a = (double)(point2.X - point1.X);var b = (double)(point2.Y - point1.Y); return Math.Sqrt(a * a + b * b);}; Point nearest = list.Aggregate((x, y) => DistanceTo(x, pivot) < DistanceTo(y, pivot) ? x : y); Debug.WriteLine(ne..
2017. 12. 27.