@Test
    public void testNNMany () {
	int numRects = 100000;
	List<Rectangle2D> rects = new ArrayList<Rectangle2D> (numRects);
	for (int i = 0; i < numRects; i++)
	    rects.add (new Rectangle2D.Double (i * 10, i * 10, 10, 10));
	tree.load (rects);

	DistanceCalculator<Rectangle2D> dc = new RectDistance ();
	DistanceResult<Rectangle2D> nnRes = tree.nearestNeighbour (dc, -1, -1);
	assertEquals ("Got wrong element back", rects.get (0), nnRes.get ());

	nnRes = tree.nearestNeighbour (dc, 105, 99);
	assertEquals ("Got wrong element back", rects.get (10), nnRes.get ());

	Random random = new Random (6789);  // same random every time
	for (int r = 0; r < 1000; r++) {
	    double dd = numRects * 10 * random.nextDouble ();
	    double x = dd + random.nextInt (2000) - 1000;
	    double y = dd + random.nextInt (2000) - 1000;
	    nnRes = tree.nearestNeighbour (dc, x, y);
	    double minDist = Double.MAX_VALUE;
	    Rectangle2D minRect = null;
	    for (int i = 0; i < numRects; i++) {
		Rectangle2D rx = rects.get (i);
		double rdist = dc.distanceTo (rx, x, y);
		if (rdist < minDist) {
		    minDist = rdist;
		    minRect = rx;
		}
	    }
	    assertEquals ("Got wrong element back", minRect, nnRes.get ());
	}
    }