// all points that are inside the rectangle
 public Iterable<Point2D> range(RectHV rect) {
   if (rect == null) throw new NullPointerException("rect");
   ArrayList<Point2D> rectPoints = new ArrayList<Point2D>();
   for (Point2D point : points) {
     if (rect.contains(point)) rectPoints.add(point);
   }
   return rectPoints;
 }
Beispiel #2
0
 // all points that are inside the rectangle
 public Iterable<Point2D> range(RectHV rect) {
   if (rect == null) throw new NullPointerException("RectHV cannot be null!");
   // Create a queue and fill it with points that are inside rect
   LinkedQueue<Point2D> q = new LinkedQueue<Point2D>();
   for (Point2D point : set) {
     if (rect.contains(point)) q.enqueue(point);
   }
   return q;
 }
Beispiel #3
0
 public void range(RectHV rect, List<Point2D> list) {
   if (left != null && left.rect.intersects(rect)) {
     left.range(rect, list);
   }
   if (rect.contains(value)) {
     list.add(value);
   }
   if (right != null && right.rect.intersects(rect)) {
     right.range(rect, list);
   }
 }
Beispiel #4
0
  private void collect(TreeSet<Point2D> points, KdNode nd, RectHV rect) {
    if (nd == null) return;

    // Pruning, return if the box not intersect with that of the node
    if (!nd.rect.intersects(rect)) return;

    if (rect.contains(nd.point)) {
      points.add(nd.point);
    }

    collect(points, nd.left, rect);
    collect(points, nd.right, rect);
  }
Beispiel #5
0
  private void findPoints(ArrayList<Point2D> r, RectHV rect, Node x) {
    if (!rect.intersects(x.rect)) {
      return;
    }

    if (rect.contains(x.p)) {
      r.add(x.p);
    }

    if (x.lb != null) {
      findPoints(r, rect, x.lb);
    }

    if (x.rt != null) {
      findPoints(r, rect, x.rt);
    }
  }
Beispiel #6
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);
      }
    }
  }