diff --git a/src/main/java/org/orekit/rugged/raster/TilesCache.java b/src/main/java/org/orekit/rugged/raster/TilesCache.java index 8a654f96c476fcf521482e408b87f3f884c8a4a6..2d7a96ab2aafc2689e3b40025358247e1c88c0f8 100644 --- a/src/main/java/org/orekit/rugged/raster/TilesCache.java +++ b/src/main/java/org/orekit/rugged/raster/TilesCache.java @@ -353,11 +353,14 @@ public class TilesCache<T extends Tile> { switch (latitudeHemisphere) { case NORTH: - // Defines the zipper min latitude wrt the current tile max latitude minus 2 zipper step in latitude + // Defines the zipper min latitude (center of the cell) wrt the current tile Northern latitude // Explanation: we want the 2 first rows belongs to the current tile and 2 last rows to the Northern tile - // If zipperLatStep = latStep, the 2 first rows = exactly lines of the current tile - // otherwise (latStep > North tile step), the 2 first rows will be smaller (in latitude) than the 2 lines of the current tile - zipperLatMin = currentTileMinLat + currentTileLatRows * currentTileLatStep - 2 * zipperLatStep; + // If zipperLatStep = currentTileLatStep, the 2 first rows = exactly lines of the current tile + // otherwise (currentTileLatStep > North tile step), the 2 first rows will be smaller (in latitude) than the 2 lines of the current tile + final double currentTileNorthernLatitude = currentTileMinLat - 0.5 * currentTileLatStep + currentTileLatRows * currentTileLatStep; + // Zipper min latitude = center of the Southern zipper cell in latitude + // In case of resolution change zipperLatStep may be different from currentTileLatStep + zipperLatMin = currentTileNorthernLatitude - 2 * zipperLatStep + 0.5 * zipperLatStep; // Define the zipper min longitude = current tile min longitude zipperLonMin = currentTileMinLon; @@ -369,11 +372,15 @@ public class TilesCache<T extends Tile> { break; case SOUTH: - // Defines the zipper min latitude wrt the current tile min latitude + // Defines the zipper min latitude wrt the current tile Southern latitude // Explanation: we want the 2 last rows belongs to the current tile and 2 first rows to the Southern tile - // If zipperLatStep = latStep, the 2 last rows = exactly lines of the current tile - // otherwise (latStep > South tile step), the 2 last rows will be smaller (in latitude) than the 2 lines of the current tile - zipperLatMin = currentTileMinLat - 2 * zipperLatStep; + // If zipperLatStep = currentTileLatStep, the 2 last rows = exactly lines of the current tile + // otherwise (currentTileLatStep > South tile step), the 2 last rows will be smaller (in latitude) than the 2 lines of the current tile + final double currentTileSouthernLatitude = currentTileMinLat - 0.5 * currentTileLatStep; + // Zipper min latitude = center of the Southern zipper cell in latitude + // In case of resolution change zipperLatStep may be different from currentTileLatStep + zipperLatMin = currentTileSouthernLatitude - 2 * zipperLatStep + 0.5 * zipperLatStep; + // Define the zipper min longitude = current tile min longitude zipperLonMin = currentTileMinLon; @@ -470,7 +477,9 @@ public class TilesCache<T extends Tile> { * @since X.x */ private int computeLatitudeIndex(final double latitude, final double latitudeMin, final double latitudeStep, final int latitudeRows) { - final double doubleLatitudeIndex = (latitude - latitudeMin) / latitudeStep; + // Compute the difference in latitude wrt the Southern edge latitude of the tile + // TBN: latitude min is at the center of the Southern cell tiles. + final double doubleLatitudeIndex = (latitude - (latitudeMin - 0.5 * latitudeStep)) / latitudeStep; return FastMath.max(0, FastMath.min(latitudeRows - 1, (int) FastMath.floor(doubleLatitudeIndex))); } @@ -483,7 +492,9 @@ public class TilesCache<T extends Tile> { * @since X.x */ private int computeLongitudeIndex(final double longitude, final double longitudeMin, final double longitudeStep, final int longitudeColumns) { - final double doubleLongitudeIndex = (longitude - longitudeMin) / longitudeStep; + // Compute the difference in longitude wrt the Western edge longitude of the tile + // TBN: longitude min is at the center of the Western cell tiles. + final double doubleLongitudeIndex = (longitude - (longitudeMin - 0.5 * longitudeStep)) / longitudeStep; return FastMath.max(0, FastMath.min(longitudeColumns - 1, (int) FastMath.floor(doubleLongitudeIndex))); } diff --git a/src/test/java/org/orekit/rugged/raster/DummySRTMsimpleElevationUpdater.java b/src/test/java/org/orekit/rugged/raster/DummySRTMsimpleElevationUpdater.java index 27feb6b7204b2430b58fb256b8565fedf6c6eda8..39a07832ccf9bdd5bf2bdc9df6c7c601a15713cd 100644 --- a/src/test/java/org/orekit/rugged/raster/DummySRTMsimpleElevationUpdater.java +++ b/src/test/java/org/orekit/rugged/raster/DummySRTMsimpleElevationUpdater.java @@ -35,6 +35,9 @@ public class DummySRTMsimpleElevationUpdater implements TileUpdater { /** SRTM tile number of rows and columns */ private int n; + + /** Factor to change resolution above 60 degrees and below 60 degrees */ + private int resolutionChange; private double elevation1; private double elevation2; @@ -44,11 +47,13 @@ public class DummySRTMsimpleElevationUpdater implements TileUpdater { * @param rowCol SRTM tile number of rows and column * @param elevation1 chosen elevation1 (m) * @param elevation2 chosen elevation2 (m) + * @param resolutionChange factor to change resolution at +/- 60 degrees */ - public DummySRTMsimpleElevationUpdater(final int rowCol, final double elevation1, final double elevation2) { + public DummySRTMsimpleElevationUpdater(final int rowCol, final double elevation1, final double elevation2, final int resolutionChange) { this.n = rowCol; this.stepRad = FastMath.toRadians(this.tileSizeDeg / this.n); + this.resolutionChange = resolutionChange; this.elevation1 = elevation1; this.elevation2 = elevation2; @@ -66,9 +71,9 @@ public class DummySRTMsimpleElevationUpdater implements TileUpdater { // Change the tile step for latitude above 60 degrees and below 60 degrees if (FastMath.toDegrees(latitude) > 60. || FastMath.toDegrees(latitude) < -60.) { - // step * 3 for latitude > 60 or < -60 - this.stepRad = FastMath.toRadians(this.tileSizeDeg*3 / this.n); - numberOfStep = this.n/3; + // step * resolutionChange for latitude > 60 or < -60 + this.stepRad = FastMath.toRadians(this.tileSizeDeg*this.resolutionChange / this.n); + numberOfStep = this.n/this.resolutionChange; } else { // step = tile size / n this.stepRad = FastMath.toRadians(this.tileSizeDeg / this.n); diff --git a/src/test/java/org/orekit/rugged/raster/TilesCacheTest.java b/src/test/java/org/orekit/rugged/raster/TilesCacheTest.java index b22f03493ff554d7ef7bcbc8790504ac18d00e33..a018563bf889e11faa894a95d15da96e921c1281 100644 --- a/src/test/java/org/orekit/rugged/raster/TilesCacheTest.java +++ b/src/test/java/org/orekit/rugged/raster/TilesCacheTest.java @@ -20,12 +20,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.FileNotFoundException; -import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.net.URISyntaxException; -import java.util.Locale; import java.util.Map; import org.hipparchus.random.RandomGenerator; @@ -33,7 +31,6 @@ import org.hipparchus.random.Well19937a; import org.hipparchus.util.FastMath; import org.hipparchus.util.MathUtils; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; /** @@ -182,10 +179,8 @@ public class TilesCacheTest { // Simple SRTM with 2 elevations int rowCols = 1000; - DummySRTMsimpleElevationUpdater srtmUpdater = new DummySRTMsimpleElevationUpdater(rowCols, 10.0, 20.0); - + DummySRTMsimpleElevationUpdater srtmUpdater = new DummySRTMsimpleElevationUpdater(rowCols, 10.0, 20.0, 3); double tileSizeDeg = srtmUpdater.getTileSizeDeg(); - double rasterStepDeg = srtmUpdater.getTileStepDeg(); CountingFactory factory = new CountingFactory(); TilesCache<SimpleTile> cache = new TilesCache<SimpleTile>(factory, srtmUpdater , 5, false); @@ -365,7 +360,7 @@ public class TilesCacheTest { clearFactoryMaps(CountingFactory.class); rowCols = 10; - srtmUpdater = new DummySRTMsimpleElevationUpdater(rowCols, 10.0, 20.0); + srtmUpdater = new DummySRTMsimpleElevationUpdater(rowCols, 10.0, 20.0, 2); tileSizeDeg = srtmUpdater.getTileSizeDeg(); factory = new CountingFactory(); @@ -373,6 +368,9 @@ public class TilesCacheTest { // Above 60 degrees // ================ + + // Current tile is below 60 degrees + // -------------------------------- latTileDeg = 59.; lonTileDeg = 12.3; @@ -391,8 +389,31 @@ public class TilesCacheTest { check4cornersZipperTiles(tileAround60deg, tileSizeDeg, cache, epsilonLatLon, isDifferentStep); isDifferentStep = false; + // Current tile is above 60 degrees + // -------------------------------- + latTileDeg = 61.; + lonTileDeg = 12.3; + + tileAround60deg = cache.getTile(FastMath.toRadians(latTileDeg), FastMath.toRadians(lonTileDeg)); + + // Latitude South of the tile + latDeg = getSouthernEdgeOfTile(tileAround60deg); + lonDeg = lonTileDeg; + + isDifferentStep = true; + searchAndVerifyZipperTile(latDeg, lonDeg, Tile.Location.SOUTH, tileAround60deg, tileSizeDeg, cache, epsilonLatLon, isDifferentStep); + isDifferentStep = false; + + // Check the 4 corner zipper tiles + isDifferentStep = true; + check4cornersZipperTiles(tileAround60deg, tileSizeDeg, cache, epsilonLatLon, isDifferentStep); + isDifferentStep = false; + // Below -60 degrees // ================= + + // Current tile is above -60 degrees + // -------------------------------- latTileDeg = -59.; lonTileDeg = 12.3; @@ -410,6 +431,27 @@ public class TilesCacheTest { isDifferentStep = true; check4cornersZipperTiles(tileAroundMinus60deg, tileSizeDeg, cache, epsilonLatLon, isDifferentStep); isDifferentStep = false; + + // Current tile is below -60 degrees + // -------------------------------- + latTileDeg = -61.; + lonTileDeg = 12.3; + + tileAroundMinus60deg = cache.getTile(FastMath.toRadians(latTileDeg), FastMath.toRadians(lonTileDeg)); + + // Latitude North of the tile + latDeg = getNorthernEdgeOfTile(tileAroundMinus60deg); + lonDeg = lonTileDeg; + + isDifferentStep = true; + searchAndVerifyZipperTile(latDeg, lonDeg, Tile.Location.NORTH, tileAroundMinus60deg, tileSizeDeg, cache, epsilonLatLon, isDifferentStep); + isDifferentStep = false; + + // Check the 4 corner zipper tiles + isDifferentStep = true; + check4cornersZipperTiles(tileAroundMinus60deg, tileSizeDeg, cache, epsilonLatLon, isDifferentStep); + isDifferentStep = false; + } /** @@ -728,36 +770,36 @@ public class TilesCacheTest { double zipperLatitude3 = cornerZipperTile.getLatitudeAtIndex(3) + deltaLat; // Longitudes for column 0 of corner zipper - double aboveLeftDoubleLongitudeIndex0 = (zipperLongitude0 - aboveLeft.getMinimumLongitude()) / aboveLeft.getLongitudeStep(); + double aboveLeftDoubleLongitudeIndex0 = computeLongitudeIndexDifferentStep(zipperLongitude0, aboveLeft); int aboveLeftLongitudeIndex0 = FastMath.max(0, FastMath.min(aboveLeft.getLongitudeColumns() - 1, (int) FastMath.floor(aboveLeftDoubleLongitudeIndex0))); - double belowLeftDoubleLongitudeIndex0 = (zipperLongitude0 - belowLeft.getMinimumLongitude()) / belowLeft.getLongitudeStep(); + double belowLeftDoubleLongitudeIndex0 = computeLongitudeIndexDifferentStep(zipperLongitude0, belowLeft); int belowLeftLongitudeIndex0 = FastMath.max(0, FastMath.min(belowLeft.getLongitudeColumns() - 1, (int) FastMath.floor(belowLeftDoubleLongitudeIndex0))); // Longitudes for column 1 of corner zipper - double aboveLeftDoubleLongitudeIndex1 = (zipperLongitude1 - aboveLeft.getMinimumLongitude()) / aboveLeft.getLongitudeStep(); + double aboveLeftDoubleLongitudeIndex1 = computeLongitudeIndexDifferentStep(zipperLongitude1, aboveLeft); int aboveLeftLongitudeIndex1 = FastMath.max(0, FastMath.min(aboveLeft.getLongitudeColumns() - 1, (int) FastMath.floor(aboveLeftDoubleLongitudeIndex1))); - double belowLeftDoubleLongitudeIndex1 = (zipperLongitude1 - belowLeft.getMinimumLongitude()) / belowLeft.getLongitudeStep(); + double belowLeftDoubleLongitudeIndex1 = computeLongitudeIndexDifferentStep(zipperLongitude1, belowLeft); int belowLeftLongitudeIndex1 = FastMath.max(0, FastMath.min(belowLeft.getLongitudeColumns() - 1, (int) FastMath.floor(belowLeftDoubleLongitudeIndex1))); // Longitudes for column 2 of corner zipper - double aboveRightDoubleLongitudeIndex2 = (zipperLongitude2 - aboveRight.getMinimumLongitude()) / aboveRight.getLongitudeStep(); + double aboveRightDoubleLongitudeIndex2 = computeLongitudeIndexDifferentStep(zipperLongitude2, aboveRight); int aboveRightLongitudeIndex2 = FastMath.max(0, FastMath.min(aboveRight.getLongitudeColumns() - 1, (int) FastMath.floor(aboveRightDoubleLongitudeIndex2))); - double belowRightDoubleLongitudeIndex2 = (zipperLongitude2 - belowRight.getMinimumLongitude()) / belowRight.getLongitudeStep(); + double belowRightDoubleLongitudeIndex2 = computeLongitudeIndexDifferentStep(zipperLongitude2, belowRight); int belowRightLongitudeIndex2 = FastMath.max(0, FastMath.min(belowRight.getLongitudeColumns() - 1, (int) FastMath.floor(belowRightDoubleLongitudeIndex2))); // Longitudes for column 3 of corner zipper - double aboveRightDoubleLongitudeIndex3 = (zipperLongitude3 - aboveRight.getMinimumLongitude()) / aboveRight.getLongitudeStep(); + double aboveRightDoubleLongitudeIndex3 = computeLongitudeIndexDifferentStep(zipperLongitude3, aboveRight); int aboveRightLongitudeIndex3 = FastMath.max(0, FastMath.min(aboveRight.getLongitudeColumns() - 1, (int) FastMath.floor(aboveRightDoubleLongitudeIndex3))); - double belowRightDoubleLongitudeIndex3 = (zipperLongitude3 - belowRight.getMinimumLongitude()) / belowRight.getLongitudeStep(); + double belowRightDoubleLongitudeIndex3 = computeLongitudeIndexDifferentStep(zipperLongitude3, belowRight); int belowRightLongitudeIndex3 = FastMath.max(0, FastMath.min(belowRight.getLongitudeColumns() - 1, (int) FastMath.floor(belowRightDoubleLongitudeIndex3))); // row 0 of zipper - double belowLeftDoubleLatitudeIndex0 = (zipperLatitude0 - belowLeft.getMinimumLatitude()) / belowLeft.getLatitudeStep(); + double belowLeftDoubleLatitudeIndex0 = computeLatitudeIndexDifferentStep(zipperLatitude0, belowLeft); int belowLeftLatitudeIndex0 = FastMath.max(0, FastMath.min(belowLeft.getLatitudeRows() - 1, (int) FastMath.floor(belowLeftDoubleLatitudeIndex0))); double belowLeftElevation = belowLeft.getElevationAtIndices(belowLeftLatitudeIndex0, belowLeftLongitudeIndex0); @@ -769,7 +811,7 @@ public class TilesCacheTest { assertEquals(belowLeftElevation, cornerZipperElevation, epsilonLatLon); - double belowRightDoubleLatitudeIndex0 = (zipperLatitude0 - belowRight.getMinimumLatitude()) / belowRight.getLatitudeStep(); + double belowRightDoubleLatitudeIndex0 = computeLatitudeIndexDifferentStep(zipperLatitude0, belowRight); int belowRightLatitudeIndex0 = FastMath.max(0, FastMath.min(belowRight.getLatitudeRows() - 1, (int) FastMath.floor(belowRightDoubleLatitudeIndex0))); double belowRightElevation = belowRight.getElevationAtIndices(belowRightLatitudeIndex0, belowRightLongitudeIndex2); @@ -782,7 +824,7 @@ public class TilesCacheTest { // row 1 of zipper - double belowLeftDoubleLatitudeIndex1 = (zipperLatitude1 - belowLeft.getMinimumLatitude()) / belowLeft.getLatitudeStep(); + double belowLeftDoubleLatitudeIndex1 = computeLatitudeIndexDifferentStep(zipperLatitude1, belowLeft); int belowLeftLatitudeIndex1 = FastMath.max(0, FastMath.min(belowLeft.getLatitudeRows() - 1, (int) FastMath.floor(belowLeftDoubleLatitudeIndex1))); belowLeftElevation = belowLeft.getElevationAtIndices(belowLeftLatitudeIndex1, belowLeftLongitudeIndex0); @@ -794,7 +836,7 @@ public class TilesCacheTest { assertEquals(belowLeftElevation, cornerZipperElevation, epsilonLatLon); - double belowRightDoubleLatitudeIndex1 = (zipperLatitude1 - belowRight.getMinimumLatitude()) / belowRight.getLatitudeStep(); + double belowRightDoubleLatitudeIndex1 = computeLatitudeIndexDifferentStep(zipperLatitude1, belowRight); int belowRightLatitudeIndex1 = FastMath.max(0, FastMath.min(belowRight.getLatitudeRows() - 1, (int) FastMath.floor(belowRightDoubleLatitudeIndex1))); belowRightElevation = belowRight.getElevationAtIndices(belowRightLatitudeIndex1, belowRightLongitudeIndex2); @@ -806,7 +848,7 @@ public class TilesCacheTest { assertEquals(belowRightElevation, cornerZipperElevation, epsilonLatLon); // row 2 of zipper - double aboveLeftDoubleLatitudeIndex2 = (zipperLatitude2 - aboveLeft.getMinimumLatitude()) / aboveLeft.getLatitudeStep(); + double aboveLeftDoubleLatitudeIndex2 = computeLatitudeIndexDifferentStep(zipperLatitude2, aboveLeft); int aboveLeftLatitudeIndex2 = FastMath.max(0, FastMath.min(aboveLeft.getLatitudeRows() - 1, (int) FastMath.floor(aboveLeftDoubleLatitudeIndex2))); double aboveLeftELevation = aboveLeft.getElevationAtIndices(aboveLeftLatitudeIndex2, aboveLeftLongitudeIndex0); @@ -818,7 +860,7 @@ public class TilesCacheTest { assertEquals(aboveLeftELevation, cornerZipperElevation, epsilonLatLon); - double aboveRightDoubleLatitudeIndex2 = (zipperLatitude2 - aboveRight.getMinimumLatitude()) / aboveRight.getLatitudeStep(); + double aboveRightDoubleLatitudeIndex2 = computeLatitudeIndexDifferentStep(zipperLatitude2, aboveRight); int aboveRightLatitudeIndex2 = FastMath.max(0, FastMath.min(aboveRight.getLatitudeRows() - 1, (int) FastMath.floor(aboveRightDoubleLatitudeIndex2))); double aboveRightElevation = aboveRight.getElevationAtIndices(aboveRightLatitudeIndex2, aboveRightLongitudeIndex2); @@ -830,7 +872,7 @@ public class TilesCacheTest { assertEquals(aboveRightElevation, cornerZipperElevation, epsilonLatLon); // row 3 of zipper - double aboveLeftDoubleLatitudeIndex3 = (zipperLatitude3 - aboveLeft.getMinimumLatitude()) / aboveLeft.getLatitudeStep(); + double aboveLeftDoubleLatitudeIndex3 = computeLatitudeIndexDifferentStep(zipperLatitude3, aboveLeft); int aboveLeftLatitudeIndex3 = FastMath.max(0, FastMath.min(aboveLeft.getLatitudeRows() - 1, (int) FastMath.floor(aboveLeftDoubleLatitudeIndex3))); aboveLeftELevation = aboveLeft.getElevationAtIndices(aboveLeftLatitudeIndex3, aboveLeftLongitudeIndex0); @@ -841,7 +883,7 @@ public class TilesCacheTest { cornerZipperElevation = cornerZipperTile.getElevationAtIndices(3, 1); assertEquals(aboveLeftELevation, cornerZipperElevation, epsilonLatLon); - double aboveRightDoubleLatitudeIndex3 = (zipperLatitude3 - aboveRight.getMinimumLatitude()) / aboveRight.getLatitudeStep(); + double aboveRightDoubleLatitudeIndex3 = computeLatitudeIndexDifferentStep(zipperLatitude3, aboveRight); int aboveRightLatitudeIndex3 = FastMath.max(0, FastMath.min(aboveRight.getLatitudeRows() - 1, (int) FastMath.floor(aboveRightDoubleLatitudeIndex3))); aboveRightElevation = aboveRight.getElevationAtIndices(aboveRightLatitudeIndex3, aboveRightLongitudeIndex2); @@ -853,6 +895,7 @@ public class TilesCacheTest { assertEquals(aboveRightElevation, cornerZipperElevation, epsilonLatLon); } + private void checkZipperTile(SimpleTile zipperTile, Tile.Location zipperLocation, SimpleTile originTile, double tileSizeDeg, TilesCache<SimpleTile> cache, double epsilonLatLon) { @@ -971,15 +1014,15 @@ public class TilesCacheTest { double deltaLon = 0.1*zipperTile.getLongitudeStep(); double zipperLongitude = zipperTile.getLongitudeAtIndex(jLon) + deltaLon; - double originTileDoubleLongitudeIndex = (zipperLongitude - originTile.getMinimumLongitude()) / originTile.getLongitudeStep(); + double originTileDoubleLongitudeIndex = computeLongitudeIndexDifferentStep(zipperLongitude, originTile); int originTileLongitudeIndex = FastMath.max(0, FastMath.min(originTile.getLongitudeColumns() - 1, (int) FastMath.floor(originTileDoubleLongitudeIndex))); - double belowTileDoubleLongitudeIndex = (zipperLongitude - tileBelow.getMinimumLongitude()) / tileBelow.getLongitudeStep(); + double belowTileDoubleLongitudeIndex = computeLongitudeIndexDifferentStep(zipperLongitude, tileBelow); int belowTileLongitudeIndex = FastMath.max(0, FastMath.min(tileBelow.getLongitudeColumns() - 1, (int) FastMath.floor(belowTileDoubleLongitudeIndex))); // row 0 of zipper double zipperLat0 = zipperTile.getMinimumLatitude() + 0.1*zipperTile.getLatitudeStep(); - double belowTileDoubleLatitudeIndex = (zipperLat0 - tileBelow.getMinimumLatitude()) / tileBelow.getLatitudeStep(); + double belowTileDoubleLatitudeIndex = computeLatitudeIndexDifferentStep(zipperLat0, tileBelow); int belowTileLatitudeIndex0 = FastMath.max(0, FastMath.min(tileBelow.getLatitudeRows() - 1, (int) FastMath.floor(belowTileDoubleLatitudeIndex))); double zipperElevation = zipperTile.getElevationAtIndices(0, jLon); @@ -988,7 +1031,7 @@ public class TilesCacheTest { // row 1 of zipper double zipperLat1 = zipperLat0 + zipperTile.getLatitudeStep(); - belowTileDoubleLatitudeIndex = (zipperLat1 - tileBelow.getMinimumLatitude()) / tileBelow.getLatitudeStep(); + belowTileDoubleLatitudeIndex = computeLatitudeIndexDifferentStep(zipperLat1, tileBelow); int originTileLatitudeIndex1 = FastMath.max(0, FastMath.min(tileBelow.getLatitudeRows() - 1, (int) FastMath.floor(belowTileDoubleLatitudeIndex))); zipperElevation = zipperTile.getElevationAtIndices(1, jLon); @@ -997,7 +1040,7 @@ public class TilesCacheTest { // row 2 of zipper double zipperLat2 = zipperLat0 + 2*zipperTile.getLatitudeStep(); - double originTileDoubleLatitudeIndex = (zipperLat2 - originTile.getMinimumLatitude()) / originTile.getLatitudeStep(); + double originTileDoubleLatitudeIndex = computeLatitudeIndexDifferentStep(zipperLat2, originTile); int originTileLatitudeIndex2 = FastMath.max(0, FastMath.min(originTile.getLatitudeRows() - 1, (int) FastMath.floor(originTileDoubleLatitudeIndex))); zipperElevation = zipperTile.getElevationAtIndices(2, jLon); @@ -1006,7 +1049,7 @@ public class TilesCacheTest { // row 3 of zipper double zipperLat3 = zipperLat0 + 3*zipperTile.getLatitudeStep(); - originTileDoubleLatitudeIndex = (zipperLat3 - originTile.getMinimumLatitude()) / originTile.getLatitudeStep(); + originTileDoubleLatitudeIndex = computeLatitudeIndexDifferentStep(zipperLat3, originTile); int originTileLatitudeIndex3 = FastMath.max(0, FastMath.min(originTile.getLatitudeRows() - 1, (int) FastMath.floor(originTileDoubleLatitudeIndex))); zipperElevation = zipperTile.getElevationAtIndices(3, jLon); @@ -1023,15 +1066,15 @@ public class TilesCacheTest { double deltaLon = 0.1*zipperTile.getLongitudeStep(); double zipperLongitude = zipperTile.getLongitudeAtIndex(jLon) + deltaLon; - double originTileDoubleLongitudeIndex = (zipperLongitude - originTile.getMinimumLongitude()) / originTile.getLongitudeStep(); + double originTileDoubleLongitudeIndex = computeLongitudeIndexDifferentStep(zipperLongitude,originTile); int originTileLongitudeIndex = FastMath.max(0, FastMath.min(originTile.getLongitudeColumns() - 1, (int) FastMath.floor(originTileDoubleLongitudeIndex))); - double aboveTileDoubleLongitudeIndex = (zipperLongitude - tileAbove.getMinimumLongitude()) / tileAbove.getLongitudeStep(); + double aboveTileDoubleLongitudeIndex = computeLongitudeIndexDifferentStep(zipperLongitude, tileAbove); int aboveTileLongitudeIndex = FastMath.max(0, FastMath.min(tileAbove.getLongitudeColumns() - 1, (int) FastMath.floor(aboveTileDoubleLongitudeIndex))); // row 0 of zipper double zipperLat0 = zipperTile.getMinimumLatitude() + 0.1*zipperTile.getLatitudeStep(); - double originTileDoubleLatitudeIndex = (zipperLat0 - originTile.getMinimumLatitude()) / originTile.getLatitudeStep(); + double originTileDoubleLatitudeIndex = computeLatitudeIndexDifferentStep(zipperLat0, originTile); int originTileLatitudeIndex0 = FastMath.max(0, FastMath.min(originTile.getLatitudeRows() - 1, (int) FastMath.floor(originTileDoubleLatitudeIndex))); double zipperElevation = zipperTile.getElevationAtIndices(0, jLon); @@ -1040,7 +1083,7 @@ public class TilesCacheTest { // row 1 of zipper double zipperLat1 = zipperLat0 + zipperTile.getLatitudeStep(); - originTileDoubleLatitudeIndex = (zipperLat1 - originTile.getMinimumLatitude()) / originTile.getLatitudeStep(); + originTileDoubleLatitudeIndex = computeLatitudeIndexDifferentStep(zipperLat1, originTile); int originTileLatitudeIndex1 = FastMath.max(0, FastMath.min(originTile.getLatitudeRows() - 1, (int) FastMath.floor(originTileDoubleLatitudeIndex))); zipperElevation = zipperTile.getElevationAtIndices(1, jLon); @@ -1049,7 +1092,7 @@ public class TilesCacheTest { // row 2 of zipper double zipperLat2 = zipperLat0 + 2*zipperTile.getLatitudeStep(); - double aboveTileDoubleLatitudeIndex = (zipperLat2 - tileAbove.getMinimumLatitude()) / tileAbove.getLatitudeStep(); + double aboveTileDoubleLatitudeIndex = computeLatitudeIndexDifferentStep(zipperLat2, tileAbove); int aboveTileLatitudeIndex2 = FastMath.max(0, FastMath.min(tileAbove.getLatitudeRows() - 1, (int) FastMath.floor(aboveTileDoubleLatitudeIndex))); zipperElevation = zipperTile.getElevationAtIndices(2, jLon); @@ -1058,7 +1101,7 @@ public class TilesCacheTest { // row 3 of zipper double zipperLat3 = zipperLat0 + 3*zipperTile.getLatitudeStep(); - aboveTileDoubleLatitudeIndex = (zipperLat3 - tileAbove.getMinimumLatitude()) / tileAbove.getLatitudeStep(); + aboveTileDoubleLatitudeIndex = computeLatitudeIndexDifferentStep(zipperLat3, tileAbove); int aboveTileLatitudeIndex3 = FastMath.max(0, FastMath.min(tileAbove.getLatitudeRows() - 1, (int) FastMath.floor(aboveTileDoubleLatitudeIndex))); zipperElevation = zipperTile.getElevationAtIndices(3, jLon); @@ -1114,6 +1157,16 @@ public class TilesCacheTest { } } } + + private double computeLatitudeIndexDifferentStep(double latitude, SimpleTile tileToSearchLatitudeIndex) { + // Formula different from code + return 0.5 + latitude/ tileToSearchLatitudeIndex.getLatitudeStep() - tileToSearchLatitudeIndex.getMinimumLatitude() / tileToSearchLatitudeIndex.getLatitudeStep(); + } + + private double computeLongitudeIndexDifferentStep(double longitude, SimpleTile tileToSearchLongitudeIndex) { + // Formula different from code + return 0.5 + longitude/ tileToSearchLongitudeIndex.getLongitudeStep() - tileToSearchLongitudeIndex.getMinimumLongitude() / tileToSearchLongitudeIndex.getLongitudeStep(); + } private final static double getNorthernEdgeOfTile(SimpleTile tile) { double northernLatitudeForTile = getNorthernLatitudeForTile(tile);