@Test public void testBounds () { int minBinX = 1000; int maxBinX = -1000; int minBinY = 1000; int maxBinY = -1000; for (int i=0; i<10000000; ++i) { double longitude = Math.random()*180-180; double latitude = Math.random()*90-90; Point2D pt = new Point2D.Double(longitude, latitude); TileIndex tile = _mercator.rootToTile(pt, 1); if (0 != tile.getX() || 0 != tile.getY()) continue; BinIndex bin = _mercator.rootToBin(pt, tile); if (bin.getX() < minBinX) minBinX = bin.getX(); if (bin.getX() > maxBinX) maxBinX = bin.getX(); if (bin.getY() < minBinY) minBinY = bin.getY(); if (bin.getY() > maxBinY) maxBinY = bin.getY(); } Assert.assertEquals(0, minBinX); Assert.assertEquals(0, minBinY); Assert.assertEquals(255, maxBinX); Assert.assertEquals(255, maxBinY); }
@Test public void testRoundTripTransformation () { for (int level=0; level<4; ++level) { int pow2 = 1 << level; for (int x = 0; x<pow2; ++x) { for (int y=0; y<pow2; ++y) { TileIndex t0 = new TileIndex(level, x, y); Rectangle2D tileBounds = _mercator.getTileBounds(t0); TileIndex t1 = _mercator.rootToTile(getCenter(tileBounds), level); Assert.assertEquals(t0, t1); for (int dx=0; dx<t0.getXBins(); ++dx) { for (int dy=0; dy<t0.getYBins(); ++dy) { BinIndex b0 = new BinIndex(dx, dy); Rectangle2D binBounds = _mercator.getBinBounds(t0, b0); BinIndex b1 = _mercator.rootToBin(getCenter(binBounds), t0); Assert.assertEquals(b0, b1); } } } } } }