private void contains(Rectangle r, intproc v) { // find all rectangles in the tree that are contained by the passed rectangle // written to be non-recursive (should model other searches on this?) parents.Clear(); parents.Push(rootNodeId); parentsEntry.Clear(); parentsEntry.Push(-1); // TODO: possible shortcut here - could test for intersection with the // MBR of the root node. If no intersection, return immediately. while (parents.Count > 0) { Node <T> n = getNode(parents.Peek()); int startIndex = parentsEntry.Peek() + 1; if (!n.isLeaf()) { // go through every entry in the index Node<T> to check // if it intersects the passed rectangle. If so, it // could contain entries that are contained. bool intersects = false; for (int i = startIndex; i < n.entryCount; i++) { if (r.intersects(n.entries[i])) { parents.Push(n.ids[i]); parentsEntry.Pop(); parentsEntry.Push(i); // this becomes the start index when the child has been searched parentsEntry.Push(-1); intersects = true; break; // ie go to next iteration of while() } } if (intersects) { continue; } } else { // go through every entry in the leaf to check if // it is contained by the passed rectangle for (int i = 0; i < n.entryCount; i++) { if (r.contains(n.entries[i])) { v(n.ids[i]); } } } parents.Pop(); parentsEntry.Pop(); } }
private void Nearest(Point p, intproc v, double furthestDistance) { var rootNode = GetNode(rootNodeId); Nearest(p, rootNode, furthestDistance); foreach (var id in nearestIds) v(id); nearestIds.Clear(); }
private void nearest(Point p, intproc v, float furthestDistance) { Node <T> rootNode = getNode(rootNodeId); nearest(p, rootNode, furthestDistance); foreach (int id in nearestIds) { v(id); } nearestIds.Clear(); }
private void nearest(SubSequence p, intproc v, double furthestDistance) { Node <T> rootNode = getNode(rootNodeId); nearest(p, rootNode, furthestDistance); foreach (int id in nearestIds) { v(id); } nearestIds.Clear(); }
private void contains(Rectangle r, intproc v) { // find all rectangles in the tree that are contained by the passed rectangle parents.Clear(); parents.Push(rootNodeId); parentsEntry.Clear(); parentsEntry.Push(-1); while (parents.Count > 0) { Node <T> n = getNode(parents.Peek()); int startIndex = parentsEntry.Peek() + 1; if (!n.isLeaf()) { // go through every entry in the index Node<T> to check // if it intersects the passed rectangle. If so, it // could contain entries that are contained. bool intersects = false; for (int i = startIndex; i < n.entryCount; i++) { if (r.intersects(n.entries[i])) { parents.Push(n.ids[i]); parentsEntry.Pop(); parentsEntry.Push(i); // this becomes the start index when the child has been searched parentsEntry.Push(-1); intersects = true; break; // ie go to next iteration of while() } } if (intersects) { continue; } } else { // go through every entry in the leaf to check if // it is contained by the passed rectangle for (int i = 0; i < n.entryCount; i++) { if (r.contains(n.entries[i])) { v(n.ids[i]); } } } parents.Pop(); parentsEntry.Pop(); } }
/// <summary> /// Recursively searches the tree for all intersecting entries. /// Immediately calls execute() on the passed IntProcedure when /// a matching entry is found. /// [x] TODO rewrite this to be non-recursive? Make sure it /// doesn't slow it down. /// </summary> /// <param name="r"></param> /// <param name="v"></param> /// <param name="n"></param> private void intersects(Rectangle r, intproc v, Node <T> n) { for (int i = 0; i < n.entryCount; i++) { if (r.intersects(n.entries[i])) { if (n.isLeaf()) { v(n.ids[i]); } else { Node <T> childNode = getNode(n.ids[i]); intersects(r, v, childNode); } } } }
/// <summary> /// Recursively searches the tree for all intersecting entries. /// Immediately calls execute() on the passed IntProcedure when /// a matching entry is found. /// [x] TODO rewrite this to be non-recursive? Make sure it /// doesn't slow it down. /// </summary> /// <param name="r"></param> /// <param name="v"></param> /// <param name="n"></param> private void Intersects(Rectangle r, intproc v, [NotNull] Node<T> n) { for (var i = 0; i < n.entryCount; i++) { if (r.Intersects(n.entries[i])) { if (n.IsLeaf()) { v(n.ids[i]); } else { var childNode = GetNode(n.ids[i]); Intersects(r, v, childNode); } } } }
void Intersects(RBox box, intproc v, Node n) { for (int i = 0; i < n.entryCount; i++) { if (box.Intersects(n.entries[i])) { if (n.level == 1) { v(n.ids[i]); } else { Node childNode = nodeMap[n.ids[i]]; Intersects(box, v, childNode); } } } }
private void intersects(Rectangle r, intproc v) { Node <T> rootNode = getNode(rootNodeId); intersects(r, v, rootNode); }
private void Intersects(Rectangle r, intproc v) { var rootNode = GetNode(rootNodeId); Intersects(r, v, rootNode); }
void Intersects(RBox box, intproc v) { Node rootNode = nodeMap[rootNodeId]; Intersects(box, v, rootNode); }