![]() ![]() Iterate through all indexes in the 3x3 Var areaNearestPoint = GetNearestPoint(p, cells) While ((nearestPoint = null || minDist2 > minCellSize2 * (radius - 1)) & radius findAction = (i, j) => Int maxRadius = Math.Max(Math.Max(pi, cells.GetLength(0) - pi), Math.Max(pj, cells.GetLength(1) - pj)) ĭouble minDist2 = // To avoid access to modified closure Int j = (int)((p.Y - minY) / (maxY - minY) * gridNy) Ĭells.AddLast(p) Int i = (int)((p.X - minX) / (maxX - minX) * gridNx) Find the entire space occupied by the pointsĭouble minCellSize2 = Pow2(Math.Min((maxX - minX) / gridNx, (maxY - minY) / gridNy)) Public static List OrderByDistance(List points, int gridNx, int gridNy) Next we search for the nearest point in the range I-1 GeneratePoints(int count)įor (int i = 0 i GetNearestPoint(Point toPoint, LinkedList points) Since the grid is regular, for a given point we can easily calculate its cell index (I, J). The main idea is to cover the entire space occupied by points with a rectangular regular grid.Įach grid cell contains a small subset of points which are located within the cell. Var distance = Distance(currentPoint, pointList) ĬurrentPoint = pointList PointList.RemoveAt(pointList.IndexOf(currentPoint)) įor (var i = 0 i < pointList.Count i++) Private List OrderByDistance(List pointList) private static double Distance(Point p1, Point p2) I would like some help optimizing my function to make it operate as fast as possible. The main problem with my code is: it's incredibly slow when dealing with lists that contain tons of points. it will search for the closest point to point #2. It will then add point #2 to the list of ordered by distance points.Īnd then. It will then search for the closest point to point #1. It will add point #1 to the list of ordered by distance points. ![]() The function will start with point #1 in the list. I wrote a function that will take a list of points and then order them so they sort of. ![]()
0 Comments
Leave a Reply. |