private void FindAllCandidatesNoAlloc(Vector2 position, float maxDistance, IList <Node> candidates) { if (IntersectWithCircle(position, maxDistance)) { if (HasSubRegions()) { foreach (var subregion in subregions) { subregion?.FindAllCandidatesNoAlloc(position, maxDistance, candidates); } } else { var maxDistanceSquared = maxDistance * maxDistance; foreach (var node in nodes) { if (node != null) { var distanceSquared = Vector2Extensions.SqrDistance(position, node.Position); if (distanceSquared < maxDistanceSquared) { candidates.Add(node); } } } } } }
private Node FindNearestCandidateNoAlloc(Vector2 position, float maxDistance, IList <Node> candidates) { Node nearestNode = null; var maxDistanceSquared = maxDistance * maxDistance; var nearestDistanceSquared = float.MaxValue; foreach (var node in candidates) { if (node != null) { var distanceSquared = Vector2Extensions.SqrDistance(position, node.Position); if (distanceSquared < maxDistanceSquared && distanceSquared < nearestDistanceSquared) { nearestNode = node; nearestDistanceSquared = distanceSquared; } } } return(nearestNode); }