From 150b956f209d95ed9077e44ea655bdbfb5d88721 Mon Sep 17 00:00:00 2001 From: rsudev Date: Thu, 17 Jan 2013 17:48:26 +0100 Subject: Extend zoom calculation to nxm tilesets Previously tile sets generated for the live map where fixed to max 2x2 tiles. In order to enhance the flexibility of the live-map algorithms, now the generation of more fine-grained tile sets or even a lower bound for the zoom level to use is supported. --- .../cgeo/geocaching/connector/gc/AutoZoomTest.java | 49 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'tests/src/cgeo/geocaching/connector') diff --git a/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java b/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java index 234ff26..fb49949 100644 --- a/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java @@ -1,6 +1,9 @@ package cgeo.geocaching.connector.gc; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.geopoint.Viewport; + +import java.util.Set; import junit.framework.TestCase; @@ -10,16 +13,58 @@ public class AutoZoomTest extends TestCase { Geopoint bottomLeft = new Geopoint(49.3, 8.3); Geopoint topRight = new Geopoint(49.4, 8.4); - int zoom = Tile.calcZoomLat(bottomLeft, topRight); + int zoom = Tile.calcZoomLat(bottomLeft, topRight, 2); assertTrue(Math.abs(new Tile(bottomLeft, zoom).getY() - new Tile(topRight, zoom).getY()) == 1); assertTrue(Math.abs(new Tile(bottomLeft, zoom + 1).getY() - new Tile(topRight, zoom + 1).getY()) > 1); - zoom = Tile.calcZoomLon(bottomLeft, topRight); + zoom = Tile.calcZoomLon(bottomLeft, topRight, 2); assertTrue(new Tile(bottomLeft, zoom).getX() + 1 == new Tile(topRight, zoom).getX()); assertTrue(new Tile(bottomLeft, zoom + 1).getX() + 1 < new Tile(topRight, zoom + 1).getX()); } + public static void testZoom2() { + Geopoint bottomLeft = new Geopoint(49.3, 8.3); + Geopoint topRight = new Geopoint(49.4, 8.4); + + int zoom = Tile.calcZoomLat(bottomLeft, topRight, 3); + + assertTrue(Math.abs(new Tile(bottomLeft, zoom).getY() - new Tile(topRight, zoom).getY()) >= 2); + assertTrue(Math.abs(new Tile(bottomLeft, zoom + 1).getY() - new Tile(topRight, zoom + 1).getY()) > 2); + + zoom = Tile.calcZoomLon(bottomLeft, topRight, 3); + + assertTrue(Math.abs(new Tile(bottomLeft, zoom).getX() - new Tile(topRight, zoom).getX()) >= 2); + assertTrue(Math.abs(new Tile(bottomLeft, zoom + 1).getX() - new Tile(topRight, zoom + 1).getX()) > 2); + + } + + public static void testTiles1x2() { + Geopoint bottomLeft = new Geopoint(49.3, 8.3); + Geopoint topRight = new Geopoint(49.4, 8.4); + + Set tiles = Tile.getTilesForViewport(new Viewport(bottomLeft, topRight)); + + assertEquals(2, tiles.size()); + } + + public static void testTiles2x3() { + Geopoint bottomLeft = new Geopoint(49.3, 8.3); + Geopoint topRight = new Geopoint(49.4, 8.4); + + Set tiles = Tile.getTilesForViewport(new Viewport(bottomLeft, topRight), 3, Tile.ZOOMLEVEL_MIN); + + assertEquals(6, tiles.size()); + } + + public static void testTilesZoom13() { + Geopoint bottomLeft = new Geopoint(49.3, 8.3); + Geopoint topRight = new Geopoint(49.4, 8.4); + + Set tiles = Tile.getTilesForViewport(new Viewport(bottomLeft, topRight), 3, 13); + + assertEquals(16, tiles.size()); + } } -- cgit v1.1