예제 #1
0
 // 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;
 }
예제 #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;
 }
예제 #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);
   }
 }
예제 #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);
  }
예제 #5
0
파일: KdTree.java 프로젝트: desperius/algs
  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);
    }
  }
예제 #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);
      }
    }
  }