sort tiles to make labeling more deterministic

This commit is contained in:
Hannes Janetzek 2013-01-10 06:50:19 +01:00
parent f266d61a35
commit dd3c0a71c3
2 changed files with 29 additions and 8 deletions

View File

@ -324,18 +324,15 @@ public class TileManager {
boolean changed = (mNewTiles.cnt != mCurrentTiles.cnt); boolean changed = (mNewTiles.cnt != mCurrentTiles.cnt);
for (int i = 0, n = mNewTiles.cnt; i < n && !changed; i++) { Arrays.sort(mNewTiles.tiles, 0, mNewTiles.cnt, TileSet.coordComparator);
MapTile t = newTiles[i];
boolean found = false;
for (int j = 0, m = mCurrentTiles.cnt; j < m; j++) { if (!changed) {
if (t == curTiles[j]) { for (int i = 0, n = mNewTiles.cnt; i < n; i++) {
found = true; if (newTiles[i] != curTiles[i]) {
changed = true;
break; break;
} }
} }
if (!found)
changed = true;
} }
if (changed) { if (changed) {

View File

@ -14,6 +14,8 @@
*/ */
package org.oscim.renderer; package org.oscim.renderer;
import java.util.Comparator;
/** /**
* use with TileManager.getActiveTiles(TileSet) to get the current tiles. tiles * use with TileManager.getActiveTiles(TileSet) to get the current tiles. tiles
* are locked to not be modifed until getActiveTiles passes them back on a * are locked to not be modifed until getActiveTiles passes them back on a
@ -31,4 +33,26 @@ public final class TileSet {
TileSet(int numTiles) { TileSet(int numTiles) {
tiles = new MapTile[numTiles]; tiles = new MapTile[numTiles];
} }
public static Comparator<MapTile> coordComparator = new CoordComparator();
public static class CoordComparator implements Comparator<MapTile> {
@Override
public int compare(MapTile lhs, MapTile rhs) {
if (lhs.tileX == rhs.tileX) {
if (lhs.tileY == rhs.tileY)
return 0;
if (lhs.tileY < rhs.tileY)
return 1;
return -1;
}
if (lhs.tileX < rhs.tileX)
return 1;
return -1;
}
}
} }