private IList <Vector2> SearchBuildings(Vector2 building, float distanceFromBuilding) { Debug.WriteLine("Searching for buildings in a range of " + distanceFromBuilding + " points, from point " + building.ToPoint()); SearchInfoContainer sic = new SearchInfoContainer(building, distanceFromBuilding); List <Vector2> container = new List <Vector2>(20); return(FindValues(vectorTree, sic, container)); }
private IList <Vector2> FindValues(KDNode <Vector2> node, SearchInfoContainer info, IList <Vector2> foundValues) { //Debug.WriteLine("Arived at node: "+node.Value.ToString()); float compareValue; float compareBeginValue; float compareEndValue; if (node.Dimension == Dimension.X) { compareValue = node.Value.X; compareBeginValue = info.BeginX; compareEndValue = info.EndX; } else { compareValue = node.Value.Y; compareBeginValue = info.BeginY; compareEndValue = info.EndY; } if (compareValue > compareBeginValue) { if (node.HasLeftChild()) { //Debug.WriteLine("Going to node: " + node.LeftChild.Value.ToString() + " from node " + node.Value.ToString()); FindValues(node.LeftChild, info, foundValues); } } if (compareValue < compareEndValue) { if (node.HasRightChild()) { //Debug.WriteLine("Going to node: " + node.RightChild.Value.ToString() + " from node " + node.Value.ToString()); FindValues(node.RightChild, info, foundValues); } } if ((node.Value.X >= info.BeginX && node.Value.X <= info.EndX) && (node.Value.Y >= info.BeginY && node.Value.Y <= info.EndY)) { Debug.WriteLine("Found possible value at node " + node.Value.ToString()); if (node.Value.EuclideanDistance(info.Vector) < info.Range) { Debug.WriteLine("Found value at node " + node.Value.ToString()); foundValues.Add(node.Value); } } nodeTravelCount++; return(foundValues); }