sort tiles to make labeling more deterministic
This commit is contained in:
parent
f266d61a35
commit
dd3c0a71c3
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user