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);
for (int i = 0, n = mNewTiles.cnt; i < n && !changed; i++) {
MapTile t = newTiles[i];
boolean found = false;
Arrays.sort(mNewTiles.tiles, 0, mNewTiles.cnt, TileSet.coordComparator);
for (int j = 0, m = mCurrentTiles.cnt; j < m; j++) {
if (t == curTiles[j]) {
found = true;
if (!changed) {
for (int i = 0, n = mNewTiles.cnt; i < n; i++) {
if (newTiles[i] != curTiles[i]) {
changed = true;
break;
}
}
if (!found)
changed = true;
}
if (changed) {

View File

@ -14,6 +14,8 @@
*/
package org.oscim.renderer;
import java.util.Comparator;
/**
* use with TileManager.getActiveTiles(TileSet) to get the current tiles. tiles
* are locked to not be modifed until getActiveTiles passes them back on a
@ -31,4 +33,26 @@ public final class TileSet {
TileSet(int 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;
}
}
}