Beispiel #1
0
  private void range(
      final Node node, final RectHV rect, final Queue<Point2D> ranged, final boolean vertical) {

    if (node == null) {
      return;
    }

    if (rect.contains(node.key)) {
      ranged.enqueue(node.key);
      range(node.left, rect, ranged, !vertical);
      range(node.right, rect, ranged, !vertical);
    } else {
      if (onTheLeft(node.key, rect, vertical)) {
        range(node.left, rect, ranged, !vertical);
      } else if (onTheRight(node.key, rect, vertical)) {
        range(node.right, rect, ranged, !vertical);
      } else {
        range(node.left, rect, ranged, !vertical);
        range(node.right, rect, ranged, !vertical);
      }
    }
  }
Beispiel #2
0
  public Iterable<Point2D> range(final RectHV rect) {

    Queue<Point2D> ranged = new Queue<>();
    range(root, rect, ranged, true);
    return ranged;
  }