PurplePen.Reports.FindNearbyControls C# (CSharp) Method

FindNearbyControls() private method

private FindNearbyControls ( EventDB eventDB, float distanceLimit ) : List
eventDB EventDB
distanceLimit float
return List
        private List<NearbyControls> FindNearbyControls(EventDB eventDB, float distanceLimit)
        {
            ICollection<Id<ControlPoint>> allPoints = eventDB.AllControlPointIds;
            List<NearbyControls> list = new List<NearbyControls>();

            // Go through every pair of normal controls. If the distance between them is less than the distance limit, add to the list.
            foreach (Id<ControlPoint> controlId1 in allPoints) {
                ControlPoint control1 = eventDB.GetControl(controlId1);
                if (control1.kind != ControlPointKind.Normal)
                    continue;     // only deal with normal points.
                string symbol1 = SymbolOfControl(control1);

                // Check all other controls with greater ids (so each pair considered only once)
                foreach (Id<ControlPoint> controlId2 in allPoints) {
                    ControlPoint control2 = eventDB.GetControl(controlId2);
                    if (control2.kind != ControlPointKind.Normal || controlId2.id <= controlId1.id)
                        continue;     // only deal with normal points with greater id.
                    string symbol2 = SymbolOfControl(control2);

                    float distance = QueryEvent.ComputeStraightLineControlDistance(eventDB, controlId1, controlId2);

                    if (distance < distanceLimit) {
                        NearbyControls nearbyControls;
                        nearbyControls.controlId1 = controlId1;
                        nearbyControls.controlId2 = controlId2;
                        nearbyControls.distance = distance;
                        nearbyControls.sameSymbol = (symbol1 != null && symbol2 != null && symbol1 == symbol2); // only same symbol if both have symbols!
                        list.Add(nearbyControls);
                    }
                }
            }

            // Sort the list by distance.
            list.Sort((x1, x2) => x1.distance.CompareTo(x2.distance));

            return list;
        }