public void nearestNeighborQuery(int k, final IShape query, final IVisitorQT v) {
		PriorityQueue<NNEntry> queue = new PriorityQueue<NNEntry>();
		queue.add(new NNEntry(this, query));
		
		int count = 0;
		double knearest = 0.0;
		
		while (!queue.isEmpty()) {
			NNEntry first = queue.poll();
			
			if (first.tree != null) {
				QuadTree tree = first.tree;
				if (tree.chTree == null) { // leaf
					for (int i = 0; i < tree.cnt; ++i) {
						queue.add(new NNEntry(tree.entries.get(i), query));
					}
				} else {
					for (int i = 0; i < tree.chTree.length; ++i) {
						if (tree.chTree[i] != null) queue.add(new NNEntry(tree.chTree[i], query));
					}
				}
			} else {
				if (count >= k && first.minDist > knearest) break;
				
				v.visitEntry(first.entry);
				count++;
				knearest = first.minDist;
			}
		}
	}