Skip to content

Commit

Permalink
Ignore NN bits if we have an extended list
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Mar 15, 2022
1 parent aa2c50f commit eb77b64
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions src/main/java/dev/osm/mapsplit/AbstractOsmMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,41 +89,49 @@ public List<Integer> getAllTiles(long key) {

int tx = tileX(value);
int ty = tileY(value);
int neighbour = neighbour(value);

List<Integer> result;

if ((value & TILE_EXT_MASK) != 0) {
int idx = (int) (value & TILE_EXT_INDEX_MASK);
result = new ArrayList<>(asList(extendedSet[idx]));
result = asList(extendedSet[idx]);
result.add(TileCoord.encode(tx, ty));
} else {
result = parseMarker(value);
result.add(TileCoord.encode(tx, ty));
// add possible neighbours
int neighbour = neighbour(value);
if ((neighbour & OsmMap.NEIGHBOURS_EAST) != 0) {
addTileIfNotPresent(tx, ty, result);
}
if ((neighbour & OsmMap.NEIGHBOURS_SOUTH) != 0) {
addTileIfNotPresent(tx, ty + 1, result);
}
if ((neighbour & OsmMap.NEIGHBOURS_SOUTH_EAST) == OsmMap.NEIGHBOURS_SOUTH_EAST) {
addTileIfNotPresent(tx + 1, ty + 1, result);
}
}
return result;
}

// TODO: some tiles (neighbour-tiles) might be double-included in the list, is this a problem?!

// add the tile (and possible neighbours)
result.add(TileCoord.encode(tx, ty));
if ((neighbour & OsmMap.NEIGHBOURS_EAST) != 0) {
result.add(TileCoord.encode(tx + 1, ty));
}
if ((neighbour & OsmMap.NEIGHBOURS_SOUTH) != 0) {
result.add(TileCoord.encode(tx, ty + 1));
}
if ((neighbour & OsmMap.NEIGHBOURS_SOUTH_EAST) == OsmMap.NEIGHBOURS_SOUTH_EAST) {
result.add(TileCoord.encode(tx + 1, ty + 1));
/**
* Add an encoded tile to result if not already present
*
* @param tx tile x coord
* @param ty tile y coord
* @param result a List holding the tiles
*/
public void addTileIfNotPresent(int tx, int ty, @NotNull List<Integer> result) {
int t = TileCoord.encode(tx + 1, ty);
if (!result.contains(t)) {
result.add(t);
}

return result;
}

@Override
public void updateInt(long key, Collection<Integer> tiles) {

List<Long> longTiles = tiles.stream().map(tile -> createValue(TileCoord.decodeX(tile), TileCoord.decodeY(tile), NEIGHBOURS_NONE)).collect(toList());

this.update(key, longTiles);

}

/**
Expand Down Expand Up @@ -361,12 +369,9 @@ private static int[] merge(@NotNull int[] old, @NotNull int[] add, int len) {
@NotNull
private static List<Integer> asList(@NotNull int[] set) {
List<Integer> result = new ArrayList<>();

for (int i = 0; i < set.length; i++) {
result.add(set[i]);
}

return result;
}

}

0 comments on commit eb77b64

Please sign in to comment.