Skip to content

Commit

Permalink
iter
Browse files Browse the repository at this point in the history
  • Loading branch information
iverase committed Oct 13, 2023
1 parent 500d165 commit 3c8fe2b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,13 @@ private static double tileToLon(double xTile, double tiles) {
*/
public static double tileToLat(int yTile, int tiles) {
final double lat = tileToLat((double) yTile, tiles);
// need to quantize to keep it consistent with the adjusted values
final double qLat = GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(lat));
if (tiles < MAX_TILES_FULL_PRECISION || yTile == 0 || yTile == tiles) {
return lat; // precise case, don't need to do more work
return qLat; // precise case, don't need to do more work
}
// Maybe adjust latitude due to numerical errors
final double qLat = GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(lat));

final int computedYTile = getYTile(qLat, tiles);
// the idea here is that the latitude returned belongs to the tile and the next latitude up belongs to the next tile
// therefore we can be in the current tile and we need to find the point up just before the next tile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ public void testPointToTile() {
// check corners
assertThat(GeoTileUtils.getXTile(rectangle.getMinX(), tiles), equalTo(xTile));
assertThat(GeoTileUtils.getXTile(rectangle.getMaxX(), tiles), equalTo(Math.min(tiles - 1, xTile + 1)));
assertThat(GeoTileUtils.getYTile(rectangle.getMaxY(), tiles), anyOf(equalTo(yTile - 1), equalTo(yTile)));
assertThat(GeoTileUtils.getYTile(rectangle.getMinY(), tiles), anyOf(equalTo(yTile + 1), equalTo(yTile)));
assertThat(GeoTileUtils.getYTile(rectangle.getMaxY(), tiles), equalTo(yTile));
assertThat(GeoTileUtils.getYTile(rectangle.getMinY(), tiles), equalTo(Math.min(tiles - 1, yTile + 1)));
// check point inside
double x = randomDoubleBetween(rectangle.getMinX(), rectangle.getMaxX(), false);
double y = randomDoubleBetween(rectangle.getMinY(), rectangle.getMaxY(), false);
Expand Down

0 comments on commit 3c8fe2b

Please sign in to comment.