From cc152f16c8b0f88e84638b397ec2f7c848c66984 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Tue, 26 Nov 2013 16:34:15 +0100 Subject: [PATCH 1/2] Fix small offset by replacing float -> double --- OsmAnd-java/src/net/osmand/data/QuadRect.java | 24 +++++++++---------- OsmAnd-java/src/net/osmand/data/QuadTree.java | 12 +++++----- .../plus/activities/MapActivityActions.java | 8 +++---- .../net/osmand/plus/render/TextRenderer.java | 22 ++++++++++------- .../net/osmand/plus/views/MapTileLayer.java | 9 ++++--- 5 files changed, 39 insertions(+), 36 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/data/QuadRect.java b/OsmAnd-java/src/net/osmand/data/QuadRect.java index fced8e7c9a..237d56fbd0 100644 --- a/OsmAnd-java/src/net/osmand/data/QuadRect.java +++ b/OsmAnd-java/src/net/osmand/data/QuadRect.java @@ -1,12 +1,12 @@ package net.osmand.data; public class QuadRect { - public float left; - public float right; - public float top; - public float bottom; + public double left; + public double right; + public double top; + public double bottom; - public QuadRect(float left, float top, float right, float bottom) { + public QuadRect(double left, double top, double right, double bottom) { this.left = left; this.right = right; this.top = top; @@ -20,15 +20,15 @@ public class QuadRect { public QuadRect() { } - public float width() { + public double width() { return right - left; } - public float height() { + public double height() { return bottom - top; } - public boolean contains(float left, float top, float right, float bottom) { + public boolean contains(double left, double top, double right, double bottom) { return this.left < this.right && this.top < this.bottom && this.left <= left && this.top <= top && this.right >= right && this.bottom >= bottom; } @@ -41,15 +41,15 @@ public class QuadRect { return a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom; } - public float centerX() { + public double centerX() { return (left + right) / 2; } - public float centerY() { + public double centerY() { return (top + bottom) / 2; } - public void offset(float dx, float dy) { + public void offset(double dx, double dy) { left += dx; top += dy; right += dx; @@ -57,7 +57,7 @@ public class QuadRect { } - public void inset(float dx, float dy) { + public void inset(double dx, double dy) { left += dx; top += dy; right -= dx; diff --git a/OsmAnd-java/src/net/osmand/data/QuadTree.java b/OsmAnd-java/src/net/osmand/data/QuadTree.java index 92c726556a..e9bd2f1a99 100644 --- a/OsmAnd-java/src/net/osmand/data/QuadTree.java +++ b/OsmAnd-java/src/net/osmand/data/QuadTree.java @@ -86,13 +86,13 @@ public class QuadTree { void splitBox(QuadRect node_extent, QuadRect[] n) { // coord2d c=node_extent.center(); - float width = node_extent.width(); - float height = node_extent.height(); + double width = node_extent.width(); + double height = node_extent.height(); - float lox = node_extent.left; - float loy = node_extent.top; - float hix = node_extent.right; - float hiy = node_extent.bottom; + double lox = node_extent.left; + double loy = node_extent.top; + double hix = node_extent.right; + double hiy = node_extent.bottom; n[0] = new QuadRect(lox, loy, lox + width * ratio, loy + height * ratio); n[1] = new QuadRect(hix - width * ratio, loy, hix, loy + height * ratio); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index f001d6b717..c9b3a936d6 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -483,10 +483,10 @@ public class MapActivityActions implements DialogProvider { } final RotatedTileBox tb = mapView.getCurrentRotatedTileBox(); final QuadRect tilesRect = tb.getTileBounds(); - int left = (int) FloatMath.floor(tilesRect.left); - int top = (int) FloatMath.floor(tilesRect.top); - int width = (int) (FloatMath.ceil(tilesRect.right) - left); - int height = (int) (FloatMath.ceil(tilesRect.bottom) - top); + int left = (int) Math.floor(tilesRect.left); + int top = (int) Math.floor(tilesRect.top); + int width = (int) (Math.ceil(tilesRect.right) - left); + int height = (int) (Math.ceil(tilesRect.bottom) - top); for (int i = 0; i = 0 && points[i].x <= rc.width && points[i].x >= 0 && points[i].y <= rc.height; if (i > 0) { - float d = FloatMath.sqrt(sqr(points[i].x - points[i - 1].x) + - sqr(points[i].y - points[i - 1].y)); + float d = FloatMath.sqrt(fsqr(points[i].x - points[i - 1].x) + + fsqr(points[i].y - points[i - 1].y)); distances[i-1]= d; roadLength += d; if(inside) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java b/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java index 987c085ba9..23ab270a24 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapTileLayer.java @@ -16,7 +16,6 @@ import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.RectF; -import android.util.FloatMath; import android.widget.Toast; public class MapTileLayer extends BaseMapLayer { @@ -142,10 +141,10 @@ public class MapTileLayer extends BaseMapLayer { } - int left = (int) FloatMath.floor(tilesRect.left); - int top = (int) FloatMath.floor(tilesRect.top + ellipticTileCorrection); - int width = (int) FloatMath.ceil(tilesRect.right - left); - int height = (int) FloatMath.ceil(tilesRect.bottom + ellipticTileCorrection - top); + int left = (int) Math.floor(tilesRect.left); + int top = (int) Math.floor(tilesRect.top + ellipticTileCorrection); + int width = (int) Math.ceil(tilesRect.right - left); + int height = (int) Math.ceil(tilesRect.bottom + ellipticTileCorrection - top); boolean useInternet = settings.USE_INTERNET_TO_DOWNLOAD_TILES.get() && settings.isInternetConnectionAvailable() && map.couldBeDownloadedFromInternet(); From 9798a3b55cf7ff5ad41657226f1add5a88a9290c Mon Sep 17 00:00:00 2001 From: vshcherb Date: Tue, 26 Nov 2013 17:11:29 +0100 Subject: [PATCH 2/2] Fix small shifts (use double) --- OsmAnd-java/src/net/osmand/RenderingContext.java | 6 +++--- .../src/net/osmand/plus/render/MapRenderRepositories.java | 6 +++--- OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/RenderingContext.java b/OsmAnd-java/src/net/osmand/RenderingContext.java index 4297912146..d6536b3a90 100644 --- a/OsmAnd-java/src/net/osmand/RenderingContext.java +++ b/OsmAnd-java/src/net/osmand/RenderingContext.java @@ -28,13 +28,13 @@ public class RenderingContext { } - public float leftX; - public float topY; + public double leftX; + public double topY; public int width; public int height; public int zoom; - public float tileDivisor; + public double tileDivisor; public float rotate; // debug purpose diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index 938a87d1be..7f3a049a82 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -586,11 +586,11 @@ public class MapRenderRepositories { final QuadPointDouble lt = requestedBox.getLeftTopTile(requestedBox.getZoom()); // LatLon ltn = requestedBox.getLeftTopLatLon(); final float mapDensity = (float) Math.pow(2, requestedBox.getZoomScale()); - final float tileDivisor = (float) MapUtils.getPowZoom(31 - requestedBox.getZoom() - + final double tileDivisor = MapUtils.getPowZoom(31 - requestedBox.getZoom() - requestedBox.getZoomScale()); - currentRenderingContext.leftX = (float) (lt.x * MapUtils.getPowZoom(requestedBox.getZoomScale())); + currentRenderingContext.leftX = lt.x * MapUtils.getPowZoom(requestedBox.getZoomScale()); // MapUtils.get31TileNumberX(ltn.getLongitude()) / tileDivisor; - currentRenderingContext.topY = (float) (lt.y * MapUtils.getPowZoom(requestedBox.getZoomScale())); + currentRenderingContext.topY = lt.y * MapUtils.getPowZoom(requestedBox.getZoomScale()); //MapUtils.get31TileNumberY(ltn.getLatitude()) / tileDivisor; currentRenderingContext.zoom = requestedBox.getZoom(); currentRenderingContext.rotate = requestedBox.getRotate(); diff --git a/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java b/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java index 2874069451..259fdc22be 100644 --- a/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java +++ b/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java @@ -415,10 +415,10 @@ public class OsmandRenderer { private PointF calcPoint(int xt, int yt, RenderingContext rc){ rc.pointCount ++; - float tx = xt / rc.tileDivisor; - float ty = yt / rc.tileDivisor; - float dTileX = tx - rc.leftX; - float dTileY = ty - rc.topY; + double tx = xt / rc.tileDivisor; + double ty = yt / rc.tileDivisor; + float dTileX = (float) (tx - rc.leftX); + float dTileY = (float) (ty - rc.topY); float x = rc.cosRotateTileSize * dTileX - rc.sinRotateTileSize * dTileY; float y = rc.sinRotateTileSize * dTileX + rc.cosRotateTileSize * dTileY; rc.tempPoint.set(x, y);