coord tests

master
Thomas Rudin 2018-04-17 11:20:40 +00:00
parent 20b693b7a7
commit c2b703ac08
2 changed files with 46 additions and 4 deletions

View File

@ -18,8 +18,8 @@ public class CoordinateResolver {
double deltaFactor = Math.pow(2, zoom - this.zoom);
info.zoom = zoom;
info.x = (int)(this.x * deltaFactor);
info.y = (int)(this.y * deltaFactor);
info.x = (int)(this.x * deltaFactor) + (int)((this.x * deltaFactor) % 2);
info.y = (int)(this.y * deltaFactor) + (int)((this.y * deltaFactor) % 2);
info.height = this.height / deltaFactor;
info.width = this.width / deltaFactor;

View File

@ -50,7 +50,7 @@ public class CoordinateResolverTest {
}
@Test
public void testTileZoom() {
public void testTileZoomOut() {
TileInfo tileInfo = CoordinateResolver.fromCoordinates(32, -32);
Assert.assertEquals(9, tileInfo.zoom);
Assert.assertEquals(1, tileInfo.width, 0.1);
@ -62,10 +62,52 @@ public class CoordinateResolverTest {
Assert.assertEquals(8, tileInfo.zoom);
Assert.assertEquals(2, tileInfo.width, 0.1);
Assert.assertEquals(2, tileInfo.height, 0.1);
Assert.assertEquals(1, tileInfo.x);
Assert.assertEquals(1, tileInfo.y);
tileInfo = tileInfo.toZoom(7); //zoom out
Assert.assertEquals(7, tileInfo.zoom);
Assert.assertEquals(4, tileInfo.width, 0.1);
Assert.assertEquals(4, tileInfo.height, 0.1);
Assert.assertEquals(0, tileInfo.x);
Assert.assertEquals(0, tileInfo.y);
}
@Test
public void testTileZoomIn() {
TileInfo tileInfo = CoordinateResolver.fromCoordinates(32, -32);
Assert.assertEquals(9, tileInfo.zoom);
Assert.assertEquals(1, tileInfo.width, 0.1);
Assert.assertEquals(1, tileInfo.height, 0.1);
Assert.assertEquals(2, tileInfo.x);
Assert.assertEquals(2, tileInfo.y);
tileInfo = tileInfo.toZoom(10); //zoom in
Assert.assertEquals(10, tileInfo.zoom);
Assert.assertEquals(0.5, tileInfo.width, 0.1);
Assert.assertEquals(0.5, tileInfo.height, 0.1);
Assert.assertEquals(4, tileInfo.x);
Assert.assertEquals(4, tileInfo.y);
}
@Test
public void testTileZoomIn2() {
TileInfo tileInfo = CoordinateResolver.fromCoordinates(16, -16);
Assert.assertEquals(9, tileInfo.zoom);
Assert.assertEquals(1, tileInfo.width, 0.1);
Assert.assertEquals(1, tileInfo.height, 0.1);
Assert.assertEquals(1, tileInfo.x);
Assert.assertEquals(1, tileInfo.y);
tileInfo = tileInfo.toZoom(10); //zoom in
Assert.assertEquals(10, tileInfo.zoom);
Assert.assertEquals(0.5, tileInfo.width, 0.1);
Assert.assertEquals(0.5, tileInfo.height, 0.1);
Assert.assertEquals(2, tileInfo.x);
Assert.assertEquals(2, tileInfo.y);
}
}