Core generalization
This commit is contained in:
parent
320abc0498
commit
2d58b71e08
3 changed files with 9 additions and 184 deletions
|
@ -1,175 +0,0 @@
|
|||
package net.osmand.plus;
|
||||
import net.osmand.osm.MapUtils;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
import android.util.FloatMath;
|
||||
|
||||
public class RotatedTileBox {
|
||||
private float leftTileX;
|
||||
private float topTileY;
|
||||
private float tileWidth;
|
||||
private float tileHeight;
|
||||
private float rotate;
|
||||
private float zoom;
|
||||
private float rotateCos;
|
||||
private float rotateSin;
|
||||
|
||||
public RotatedTileBox(float leftTileX, float topTileY, float tileWidth, float tileHeight, float rotate, int zoom) {
|
||||
set(leftTileX, topTileY, tileWidth, tileHeight, rotate, zoom);
|
||||
}
|
||||
|
||||
public RotatedTileBox(RotatedTileBox r){
|
||||
set(r.leftTileX, r.topTileY, r.tileWidth, r.tileHeight, r.rotate, r.zoom);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
float rad = (float) Math.toRadians(this.rotate);
|
||||
rotateCos = FloatMath.cos(rad);
|
||||
rotateSin = FloatMath.sin(rad);
|
||||
}
|
||||
|
||||
public void set(float leftTileX, float topTileY, float tileWidth, float tileHeight, float rotate, float zoom) {
|
||||
this.leftTileX = leftTileX;
|
||||
if(rotate < 0){
|
||||
rotate += 360;
|
||||
} else if(rotate > 360){
|
||||
rotate -= 360;
|
||||
}
|
||||
this.rotate = rotate;
|
||||
this.tileHeight = tileHeight;
|
||||
this.tileWidth = tileWidth;
|
||||
this.topTileY = topTileY;
|
||||
this.zoom = zoom;
|
||||
init();
|
||||
}
|
||||
|
||||
public float getRotateCos() {
|
||||
return rotateCos;
|
||||
}
|
||||
|
||||
public float getRotateSin() {
|
||||
return rotateSin;
|
||||
}
|
||||
|
||||
public float getZoom() {
|
||||
return zoom;
|
||||
}
|
||||
|
||||
public int getIntZoom() {
|
||||
return Math.round(zoom);
|
||||
}
|
||||
|
||||
public float getRotate() {
|
||||
return rotate;
|
||||
}
|
||||
|
||||
public float getTileHeight() {
|
||||
return tileHeight;
|
||||
}
|
||||
|
||||
public float getTileWidth() {
|
||||
return tileWidth;
|
||||
}
|
||||
|
||||
public float getLeftTileX() {
|
||||
return leftTileX;
|
||||
}
|
||||
|
||||
public float getTopTileY() {
|
||||
return topTileY;
|
||||
}
|
||||
|
||||
public boolean containsTileBox(RotatedTileBox box) {
|
||||
PointF temp = new PointF();
|
||||
if(box.zoom != zoom){
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
box.calcPointTile(0, 0, temp);
|
||||
if(!containsPoint(temp.x, temp.y)){
|
||||
return false;
|
||||
}
|
||||
box.calcPointTile(box.tileWidth, 0, temp);
|
||||
if(!containsPoint(temp.x, temp.y)){
|
||||
return false;
|
||||
}
|
||||
box.calcPointTile(0, box.tileHeight, temp);
|
||||
if(!containsPoint(temp.x, temp.y)){
|
||||
return false;
|
||||
}
|
||||
box.calcPointTile(box.tileWidth, box.tileHeight, temp);
|
||||
if(!containsPoint(temp.x, temp.y)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public RectF calculateLatLonBox(RectF rectF) {
|
||||
float tx = calcPointTileX(tileWidth, 0);
|
||||
float tx2 = calcPointTileX(tileWidth, tileHeight);
|
||||
float tx3 = calcPointTileX(0, tileHeight);
|
||||
float minTileX = Math.min(Math.min(leftTileX, tx), Math.min(tx2, tx3)) ;
|
||||
float maxTileX = Math.max(Math.max(leftTileX, tx), Math.max(tx2, tx3)) ;
|
||||
int max = (int) MapUtils.getPowZoom(zoom);
|
||||
if(minTileX < 0){
|
||||
minTileX = 0;
|
||||
}
|
||||
if(maxTileX > max){
|
||||
maxTileX = max;
|
||||
}
|
||||
|
||||
rectF.left = (float) MapUtils.getLongitudeFromTile(zoom, minTileX);
|
||||
rectF.right = (float) MapUtils.getLongitudeFromTile(zoom, maxTileX);
|
||||
|
||||
float ty = calcPointTileY(tileWidth, 0);
|
||||
float ty2 = calcPointTileY(tileWidth, tileHeight);
|
||||
float ty3 = calcPointTileY(0, tileHeight);
|
||||
|
||||
float minTileY = Math.min(Math.min(topTileY, ty), Math.min(ty2, ty3)) ;
|
||||
float maxTileY = Math.max(Math.max(topTileY, ty), Math.max(ty2, ty3)) ;
|
||||
if(minTileY < 0){
|
||||
minTileY = 0;
|
||||
}
|
||||
if(maxTileY > max){
|
||||
maxTileY = max;
|
||||
}
|
||||
|
||||
rectF.top = (float) MapUtils.getLatitudeFromTile(zoom, minTileY);
|
||||
rectF.bottom = (float) MapUtils.getLatitudeFromTile(zoom, maxTileY);
|
||||
|
||||
return rectF;
|
||||
}
|
||||
|
||||
public boolean containsPoint(float tileX, float tileY) {
|
||||
tileX -= leftTileX;
|
||||
tileY -= topTileY;
|
||||
double tx = rotateCos * tileX - rotateSin * tileY;
|
||||
double ty = rotateSin * tileX + rotateCos * tileY;
|
||||
return tx >= 0 && tx <= tileWidth && ty >= 0 && ty <= tileHeight;
|
||||
}
|
||||
|
||||
protected PointF calcPointTile(float dx, float dy, PointF p){
|
||||
float tx = rotateCos * dx + rotateSin * dy + leftTileX;
|
||||
float ty = - rotateSin * dx + rotateCos * dy + topTileY;
|
||||
p.set(tx, ty);
|
||||
return p;
|
||||
}
|
||||
|
||||
protected float calcPointTileX(float dx, float dy){
|
||||
return rotateCos * dx + rotateSin * dy + leftTileX;
|
||||
}
|
||||
|
||||
protected float calcPointTileY(float dx, float dy){
|
||||
return - rotateSin * dx + rotateCos * dy + topTileY;
|
||||
}
|
||||
|
||||
public float getRightBottomTileX() {
|
||||
return calcPointTileX(tileWidth, tileHeight);
|
||||
}
|
||||
|
||||
public float getRightBottomTileY() {
|
||||
return calcPointTileY(tileWidth, tileHeight);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -23,6 +23,7 @@ import net.osmand.Algoritms;
|
|||
import net.osmand.IProgress;
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.NativeLibrary.NativeSearchResult;
|
||||
import net.osmand.QuadRect;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.binary.BinaryMapDataObject;
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
|
@ -49,7 +50,6 @@ import org.apache.commons.logging.Log;
|
|||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.widget.Toast;
|
||||
|
@ -66,7 +66,7 @@ public class MapRenderRepositories {
|
|||
|
||||
|
||||
// lat/lon box of requested vector data
|
||||
private RectF cObjectsBox = new RectF();
|
||||
private QuadRect cObjectsBox = new QuadRect();
|
||||
// cached objects in order to render rotation without reloading data from db
|
||||
private List<BinaryMapDataObject> cObjects = new LinkedList<BinaryMapDataObject>();
|
||||
private NativeSearchResult cNativeObjects = null;
|
||||
|
@ -220,7 +220,7 @@ public class MapRenderRepositories {
|
|||
}
|
||||
|
||||
|
||||
private boolean loadVectorDataNative(RectF dataBox, final int zoom, final RenderingRuleSearchRequest renderingReq,
|
||||
private boolean loadVectorDataNative(QuadRect dataBox, final int zoom, final RenderingRuleSearchRequest renderingReq,
|
||||
NativeOsmandLibrary library) {
|
||||
int leftX = MapUtils.get31TileNumberX(dataBox.left);
|
||||
int rightX = MapUtils.get31TileNumberX(dataBox.right);
|
||||
|
@ -256,7 +256,7 @@ public class MapRenderRepositories {
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean loadVectorData(RectF dataBox, final int zoom, final RenderingRuleSearchRequest renderingReq) {
|
||||
private boolean loadVectorData(QuadRect dataBox, final int zoom, final RenderingRuleSearchRequest renderingReq) {
|
||||
double cBottomLatitude = dataBox.bottom;
|
||||
double cTopLatitude = dataBox.top;
|
||||
double cLeftLongitude = dataBox.left;
|
||||
|
@ -419,7 +419,7 @@ public class MapRenderRepositories {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void validateLatLonBox(RectF box) {
|
||||
private void validateLatLonBox(QuadRect box) {
|
||||
if (box.top > 90) {
|
||||
box.top = 85.5f;
|
||||
}
|
||||
|
@ -478,7 +478,7 @@ public class MapRenderRepositories {
|
|||
requestedBox = new RotatedTileBox(tileRect);
|
||||
|
||||
// calculate data box
|
||||
RectF dataBox = requestedBox.calculateLatLonBox(new RectF());
|
||||
QuadRect dataBox = requestedBox.calculateLatLonBox(new QuadRect());
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
if (cObjectsBox.left > dataBox.left || cObjectsBox.top > dataBox.top || cObjectsBox.right < dataBox.right
|
||||
|
@ -618,7 +618,7 @@ public class MapRenderRepositories {
|
|||
} catch (OutOfMemoryError e) {
|
||||
log.error("Out of memory error", e); //$NON-NLS-1$
|
||||
cObjects = new ArrayList<BinaryMapDataObject>();
|
||||
cObjectsBox = new RectF();
|
||||
cObjectsBox = new QuadRect();
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -650,7 +650,7 @@ public class MapRenderRepositories {
|
|||
|
||||
public synchronized void clearCache() {
|
||||
cObjects = new ArrayList<BinaryMapDataObject>();
|
||||
cObjectsBox = new RectF();
|
||||
cObjectsBox = new QuadRect();
|
||||
|
||||
requestedBox = prevBmpLocation = null;
|
||||
// Do not clear main bitmap to not cause a screen refresh
|
||||
|
|
|
@ -8,10 +8,10 @@ import java.util.Collections;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.QuadRect;
|
||||
import net.osmand.binary.BinaryMapDataObject;
|
||||
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
|
||||
import net.osmand.data.QuadTree;
|
||||
import net.osmand.data.QuadTree.QuadRect;
|
||||
import net.osmand.plus.render.OsmandRenderer.RenderingContext;
|
||||
import net.osmand.render.RenderingRuleSearchRequest;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
|
|
Loading…
Reference in a new issue