Ignore:
Timestamp:
2022-04-28T21:26:26+02:00 (3 years ago)
Author:
taylor.smock
Message:

ElevationProfile: fix tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/HgtReader.java

    r35964 r35967  
    2020import org.openstreetmap.josm.data.Preferences;
    2121import org.openstreetmap.josm.data.coor.ILatLon;
    22 import org.openstreetmap.josm.data.coor.LatLon;
    2322import org.openstreetmap.josm.io.Compression;
    2423import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    8382    }
    8483
    85     public static Bounds read(File file) throws FileNotFoundException, IOException {
     84    public static Bounds read(File file) throws IOException {
    8685        String location = file.getName();
    8786        for (String ext : COMPRESSION_EXT) {
     
    9190        // Overwrite the cache file (assume that is desired)
    9291        cache.put(location, sb);
    93         Pattern pattern = Pattern.compile("(N|S)([0-9]{2})(E|W)([0-9]{3})");
     92        Pattern pattern = Pattern.compile("([NS])(\\d{2})([EW])(\\d{3})");
    9493        Matcher matcher = pattern.matcher(location);
    9594        if (matcher.lookingAt()) {
    96             int lat = (matcher.group(1) == "S" ? -1 : 1) * Integer.parseInt(matcher.group(2));
    97             int lon = (matcher.group(3) == "W" ? -1 : 1) * Integer.parseInt(matcher.group(4));
     95            int lat = ("S".equals(matcher.group(1)) ? -1 : 1) * Integer.parseInt(matcher.group(2));
     96            int lon = ("W".equals(matcher.group(3)) ? -1 : 1) * Integer.parseInt(matcher.group(4));
    9897            return new Bounds(lat, lon, lat + 1, lon + 1);
    9998        }
     
    101100    }
    102101
    103     private static short[][] readHgtFile(String file) throws FileNotFoundException, IOException {
     102    private static short[][] readHgtFile(String file) throws IOException {
    104103        CheckParameterUtil.ensureParameterNotNull(file);
    105104
     
    135134     * @return the elevation value or <code>Double.NaN</code>, if no value is present
    136135     */
    137     public static double readElevation(LatLon coor) {
     136    public static double readElevation(ILatLon coor) {
    138137        String tag = getHgtFileName(coor);
    139138        return readElevation(coor, tag);
     
    205204        double lonDegrees = latLon.lon();
    206205
    207         float fraction = ((float) SRTM_EXTENT) / mapSize;
    208         int latitude = (int) Math.floor(Math.abs(latDegrees - (int) latDegrees) / fraction);
    209         int longitude = (int) Math.floor(Math.abs(lonDegrees - (int) lonDegrees) / fraction);
     206        float fraction = ((float) SRTM_EXTENT) / (mapSize - 1);
     207        int latitude = (int) Math.round(frac(latDegrees) / fraction);
     208        int longitude = (int) Math.round(frac(lonDegrees) / fraction);
    210209        if (latDegrees >= 0)
    211210        {
    212             latitude = mapSize - 1 - latitude;
     211            latitude = mapSize - latitude - 1;
    213212        }
    214213        if (lonDegrees < 0)
    215214        {
    216             longitude = mapSize - 1 - longitude;
     215            longitude = mapSize - longitude - 1;
    217216        }
    218217        return new int[] { latitude, longitude };
     
    243242        }
    244243
    245         return latPref + lat + lonPref + lon + HGT_EXT;
     244        return String.format("%s%2d%s%03d" + HGT_EXT, latPref, lat, lonPref, lon);
    246245    }
    247246
Note: See TracChangeset for help on using the changeset viewer.