private void rangeNode(Node2d node, Stack<Point2D> stack, RectHV rect) { if (node == null) return; if (!node.rect.intersects(rect)) return; if (rect.contains(node.p)) stack.push(node.p); rangeNode(node.left, stack, rect); rangeNode(node.right, stack, rect); }
public Iterable<Point2D> range( RectHV rect) { // all points in the set that are inside the rectangle Stack<Point2D> stack = new Stack<Point2D>(); rangeNode(root, stack, rect); return stack; }