public static Rect getTilesRect(final BoundingBox pBB,
                                    final int pZoomLevel) {
        final int mapTileUpperBound = 1 << pZoomLevel;
        final int right = MapView.getTileSystem().getTileXFromLongitude(pBB.getLonEast(), pZoomLevel);
        final int bottom = MapView.getTileSystem().getTileYFromLatitude(pBB.getLatSouth(), pZoomLevel);
        final int left = MapView.getTileSystem().getTileXFromLongitude(pBB.getLonWest(), pZoomLevel);
        final int top = MapView.getTileSystem().getTileYFromLatitude(pBB.getLatNorth(), pZoomLevel);
        int width = right - left + 1; // handling the modulo
        if (width <= 0) {
            width += mapTileUpperBound;
        }
        int height = bottom - top + 1; // handling the modulo
        if (height <= 0) {
            height += mapTileUpperBound;
        }
        return new Rect(left, top, left + width - 1, top + height - 1);
    }
@Test
    public void testGetTilesRectWholeWorld() {
        final TileSystem tileSystem = MapView.getTileSystem();
        final BoundingBox box = new BoundingBox( // whole world
                tileSystem.getMaxLatitude(), tileSystem.getMaxLongitude(),
                tileSystem.getMinLatitude(), tileSystem.getMinLongitude());
        for (int zoom = 0; zoom <= TileSystem.getMaximumZoomLevel(); zoom++) {
            final Rect rect = CacheManager.getTilesRect(box, zoom);
            Assert.assertEquals(0, rect.left);
            Assert.assertEquals(0, rect.top);
            final int maxSize = -1 + (1 << zoom);
            Assert.assertEquals(maxSize, rect.bottom);
            Assert.assertEquals(maxSize, rect.right);
        }
    }