Changeset 5235 in josm


Ignore:
Timestamp:
May 12, 2012 7:11:58 PM (12 months ago)
Author:
bastiK
Message:

no rounding for projection bounds, to avoid 42 being dispayed as 41.99999999999

Location:
trunk/src/org/openstreetmap/josm
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Bounds.java

    r4580 r5235  
    4343    } 
    4444 
     45    public Bounds(LatLon min, LatLon max, boolean roundToOsmPrecision) { 
     46        this(min.lat(), min.lon(), max.lat(), max.lon(), roundToOsmPrecision); 
     47    } 
     48 
    4549    public Bounds(LatLon b) { 
     50        this(b, true); 
     51    } 
     52     
     53    public Bounds(LatLon b, boolean roundToOsmPrecision) { 
    4654        // Do not call this(b, b) to avoid GPX performance issue (see #7028) until roundToOsmPrecision() is improved 
    47         this.minLat = LatLon.roundToOsmPrecision(b.lat()); 
    48         this.minLon = LatLon.roundToOsmPrecision(b.lon()); 
     55        if (roundToOsmPrecision) { 
     56            this.minLat = LatLon.roundToOsmPrecision(b.lat()); 
     57            this.minLon = LatLon.roundToOsmPrecision(b.lon()); 
     58        } else { 
     59            this.minLat = b.lat(); 
     60            this.minLon = b.lon(); 
     61        } 
    4962        this.maxLat = this.minLat; 
    5063        this.maxLon = this.minLon; 
     
    5265 
    5366    public Bounds(double minlat, double minlon, double maxlat, double maxlon) { 
    54         this.minLat = LatLon.roundToOsmPrecision(minlat); 
    55         this.minLon = LatLon.roundToOsmPrecision(minlon); 
    56         this.maxLat = LatLon.roundToOsmPrecision(maxlat); 
    57         this.maxLon = LatLon.roundToOsmPrecision(maxlon); 
     67        this(minlat, minlon, maxlat, maxlon, true); 
     68    } 
     69 
     70    public Bounds(double minlat, double minlon, double maxlat, double maxlon, boolean roundToOsmPrecision) { 
     71        if (roundToOsmPrecision) { 
     72            this.minLat = LatLon.roundToOsmPrecision(minlat); 
     73            this.minLon = LatLon.roundToOsmPrecision(minlon); 
     74            this.maxLat = LatLon.roundToOsmPrecision(maxlat); 
     75            this.maxLon = LatLon.roundToOsmPrecision(maxlon); 
     76        } else { 
     77            this.minLat = minlat; 
     78            this.minLon = minlon; 
     79            this.maxLat = maxlat; 
     80            this.maxLon = maxlon; 
     81        } 
    5882    } 
    5983 
    6084    public Bounds(double [] coords) { 
     85        this(coords, true); 
     86    } 
     87 
     88    public Bounds(double [] coords, boolean roundToOsmPrecision) { 
    6189        CheckParameterUtil.ensureParameterNotNull(coords, "coords"); 
    6290        if (coords.length != 4) 
    6391            throw new IllegalArgumentException(MessageFormat.format("Expected array of length 4, got {0}", coords.length)); 
    64         this.minLat = LatLon.roundToOsmPrecision(coords[0]); 
    65         this.minLon = LatLon.roundToOsmPrecision(coords[1]); 
    66         this.maxLat = LatLon.roundToOsmPrecision(coords[2]); 
    67         this.maxLon = LatLon.roundToOsmPrecision(coords[3]); 
     92        if (roundToOsmPrecision) { 
     93            this.minLat = LatLon.roundToOsmPrecision(coords[0]); 
     94            this.minLon = LatLon.roundToOsmPrecision(coords[1]); 
     95            this.maxLat = LatLon.roundToOsmPrecision(coords[2]); 
     96            this.maxLon = LatLon.roundToOsmPrecision(coords[3]); 
     97        } else { 
     98            this.minLat = coords[0]; 
     99            this.minLon = coords[1]; 
     100            this.maxLat = coords[2]; 
     101            this.maxLon = coords[3]; 
     102        } 
    68103    } 
    69104 
     
    73108 
    74109    public Bounds(String asString, String separator, ParseMethod parseMethod) throws IllegalArgumentException { 
     110        this(asString, separator, parseMethod, true); 
     111    } 
     112 
     113    public Bounds(String asString, String separator, ParseMethod parseMethod, boolean roundToOsmPrecision) throws IllegalArgumentException { 
    75114        CheckParameterUtil.ensureParameterNotNull(asString, "asString"); 
    76115        String[] components = asString.split(separator); 
     
    88127        switch (parseMethod) { 
    89128            case LEFT_BOTTOM_RIGHT_TOP: 
    90                 this.minLat = initLat(values[1]); 
    91                 this.minLon = initLon(values[0]); 
    92                 this.maxLat = initLat(values[3]); 
    93                 this.maxLon = initLon(values[2]); 
     129                this.minLat = initLat(values[1], roundToOsmPrecision); 
     130                this.minLon = initLon(values[0], roundToOsmPrecision); 
     131                this.maxLat = initLat(values[3], roundToOsmPrecision); 
     132                this.maxLon = initLon(values[2], roundToOsmPrecision); 
    94133                break; 
    95134            case MINLAT_MINLON_MAXLAT_MAXLON: 
    96135            default: 
    97                 this.minLat = initLat(values[0]); 
    98                 this.minLon = initLon(values[1]); 
    99                 this.maxLat = initLat(values[2]); 
    100                 this.maxLon = initLon(values[3]); 
    101         } 
    102     } 
    103      
    104     protected static double initLat(double value) { 
     136                this.minLat = initLat(values[0], roundToOsmPrecision); 
     137                this.minLon = initLon(values[1], roundToOsmPrecision); 
     138                this.maxLat = initLat(values[2], roundToOsmPrecision); 
     139                this.maxLon = initLon(values[3], roundToOsmPrecision); 
     140        } 
     141    } 
     142     
     143    protected static double initLat(double value, boolean roundToOsmPrecision) { 
    105144        if (!LatLon.isValidLat(value)) 
    106145            throw new IllegalArgumentException(tr("Illegal latitude value ''{0}''", value)); 
    107         return LatLon.roundToOsmPrecision(value); 
    108     } 
    109  
    110     protected static double initLon(double value) { 
     146        return roundToOsmPrecision ? LatLon.roundToOsmPrecision(value) : value; 
     147    } 
     148 
     149    protected static double initLon(double value, boolean roundToOsmPrecision) { 
    111150        if (!LatLon.isValidLon(value)) 
    112151            throw new IllegalArgumentException(tr("Illegal longitude value ''{0}''", value)); 
    113         return LatLon.roundToOsmPrecision(value); 
     152        return roundToOsmPrecision ? LatLon.roundToOsmPrecision(value) : value; 
    114153    } 
    115154 
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r4869 r5235  
    4545        // a comma separated list of coordinates. 
    4646        cDdFormatter = (DecimalFormat) NumberFormat.getInstance(Locale.UK); 
    47         cDdFormatter.applyPattern("###0.0000000"); 
     47        cDdFormatter.applyPattern("###0.0######"); 
    4848    } 
    4949 
  • trunk/src/org/openstreetmap/josm/data/projection/BelgianLambert1972.java

    r5072 r5235  
    4747        return new Bounds( 
    4848                new LatLon(49.51, 2.54), 
    49                 new LatLon(51.50, 6.40)); 
     49                new LatLon(51.50, 6.40), false); 
    5050    } 
    5151 
  • trunk/src/org/openstreetmap/josm/data/projection/BelgianLambert2008.java

    r5072 r5235  
    4646        return new Bounds( 
    4747                new LatLon(49.51, 2.54), 
    48                 new LatLon(51.50, 6.40)); 
     48                new LatLon(51.50, 6.40), false); 
    4949    } 
    5050 
  • trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java

    r5234 r5235  
    343343                parseAngle(numStr[0], "minlon (+bounds)"), 
    344344                parseAngle(numStr[3], "maxlat (+bounds)"), 
    345                 parseAngle(numStr[2], "maxlon (+bounds)")); 
     345                parseAngle(numStr[2], "maxlon (+bounds)"), false); 
    346346    } 
    347347 
  • trunk/src/org/openstreetmap/josm/data/projection/Epsg3008.java

    r5066 r5235  
    5454    public Bounds getWorldBoundsLatLon() { 
    5555        return new Bounds( 
    56                 new LatLon(55.2, 12.1),     // new LatLon(-90.0, -180.0), 
    57                 new LatLon(62.26, 14.65));  // new LatLon(90.0, 180.0)); 
     56                new LatLon(55.2, 12.1), 
     57                new LatLon(62.26, 14.65), false); 
    5858    } 
    5959 
  • trunk/src/org/openstreetmap/josm/data/projection/Epsg4326.java

    r2516 r5235  
    4444        return new Bounds( 
    4545                new LatLon(-90.0, -180.0), 
    46                 new LatLon(90.0, 180.0)); 
     46                new LatLon(90.0, 180.0), false); 
    4747    } 
    4848 
  • trunk/src/org/openstreetmap/josm/data/projection/GaussKrueger.java

    r5234 r5235  
    1717 
    1818    private static Bounds[] bounds = { 
    19         new Bounds(new LatLon(-5, 3.5), new LatLon(85, 8.5)), 
    20         new Bounds(new LatLon(-5, 6.5), new LatLon(85, 11.5)), 
    21         new Bounds(new LatLon(-5, 9.5), new LatLon(85, 14.5)), 
    22         new Bounds(new LatLon(-5, 12.5), new LatLon(85, 17.5)), 
     19        new Bounds(new LatLon(-5, 3.5), new LatLon(85, 8.5), false), 
     20        new Bounds(new LatLon(-5, 6.5), new LatLon(85, 11.5), false), 
     21        new Bounds(new LatLon(-5, 9.5), new LatLon(85, 14.5), false), 
     22        new Bounds(new LatLon(-5, 12.5), new LatLon(85, 17.5), false), 
    2323    }; 
    2424 
  • trunk/src/org/openstreetmap/josm/data/projection/Lambert.java

    r5234 r5235  
    143143        Bounds b= new Bounds( 
    144144                new LatLon(Math.max(zoneLimitsDegree[layoutZone][1] - cMaxOverlappingZonesDegree, Math.toDegrees(cMinLatZone1Radian)), Math.toDegrees(cMinLonZonesRadian)), 
    145                 new LatLon(Math.min(zoneLimitsDegree[layoutZone][0] + cMaxOverlappingZonesDegree, Math.toDegrees(cMaxLatZone1Radian)), Math.toDegrees(cMaxLonZonesRadian))); 
     145                new LatLon(Math.min(zoneLimitsDegree[layoutZone][0] + cMaxOverlappingZonesDegree, Math.toDegrees(cMaxLatZone1Radian)), Math.toDegrees(cMaxLonZonesRadian)), 
     146                false); 
    146147        return b; 
    147148    } 
  • trunk/src/org/openstreetmap/josm/data/projection/Lambert93.java

    r5066 r5235  
    4545        return new Bounds( 
    4646                new LatLon(41.0, -5.5), 
    47                 new LatLon(51.0, 10.2)); 
     47                new LatLon(51.0, 10.2), false); 
    4848    } 
    4949 
  • trunk/src/org/openstreetmap/josm/data/projection/LambertCC9Zones.java

    r5234 r5235  
    9090        return new Bounds( 
    9191                new LatLon(Math.max(medLatZone - 1.0 - cMaxOverlappingZones, cMinLatZonesDegree), -5.5), 
    92                 new LatLon(Math.min(medLatZone + 1.0 + cMaxOverlappingZones, Math.toDegrees(cMaxLatZonesRadian)), 10.2)); 
     92                new LatLon(Math.min(medLatZone + 1.0 + cMaxOverlappingZones, Math.toDegrees(cMaxLatZonesRadian)), 10.2), 
     93                false); 
    9394    } 
    9495 
  • trunk/src/org/openstreetmap/josm/data/projection/LambertEST.java

    r5066 r5235  
    6363        return new Bounds( 
    6464                new LatLon(56.05, 21.64), 
    65                 new LatLon(61.13, 28.58)); 
     65                new LatLon(61.13, 28.58), false); 
    6666    } 
    6767 
  • trunk/src/org/openstreetmap/josm/data/projection/Mercator.java

    r5066 r5235  
    6060        return new Bounds( 
    6161                new LatLon(-85.05112877980659, -180.0), 
    62                 new LatLon(85.05112877980659, 180.0)); 
     62                new LatLon(85.05112877980659, 180.0), false); 
    6363    } 
    6464 
  • trunk/src/org/openstreetmap/josm/data/projection/Puwg.java

    r5234 r5235  
    121121            return new Bounds( 
    122122                    new LatLon(49.00, 14.12), 
    123                     new LatLon(54.84, 24.15)); 
     123                    new LatLon(54.84, 24.15), false); 
    124124        } 
    125125 
     
    164164            return new Bounds( 
    165165                    new LatLon(49.00, (3 * getZone()) - 1.5), 
    166                     new LatLon(54.84, (3 * getZone()) + 1.5)); 
     166                    new LatLon(54.84, (3 * getZone()) + 1.5), false); 
    167167        } 
    168168 
  • trunk/src/org/openstreetmap/josm/data/projection/SwissGrid.java

    r5234 r5235  
    6363    @Override 
    6464    public Bounds getWorldBoundsLatLon() { 
    65         return new Bounds(new LatLon(45.7, 5.7), new LatLon(47.9, 10.6)); 
     65        return new Bounds(new LatLon(45.7, 5.7), new LatLon(47.9, 10.6), false); 
    6666    } 
    6767 
  • trunk/src/org/openstreetmap/josm/data/projection/TransverseMercatorLV.java

    r5066 r5235  
    5656        return new Bounds( 
    5757                new LatLon(-90.0, -180.0), 
    58                 new LatLon(90.0, 180.0)); 
     58                new LatLon(90.0, 180.0), false); 
    5959    } 
    6060} 
  • trunk/src/org/openstreetmap/josm/data/projection/UTM.java

    r5234 r5235  
    100100            return new Bounds( 
    101101                    new LatLon(-5.0, getUtmCentralMeridianDeg(getzone())-5.0), 
    102                     new LatLon(85.0, getUtmCentralMeridianDeg(getzone())+5.0)); 
     102                    new LatLon(85.0, getUtmCentralMeridianDeg(getzone())+5.0), false); 
    103103        else 
    104104            return new Bounds( 
    105105                    new LatLon(-85.0, getUtmCentralMeridianDeg(getzone())-5.0), 
    106                     new LatLon(5.0, getUtmCentralMeridianDeg(getzone())+5.0)); 
     106                    new LatLon(5.0, getUtmCentralMeridianDeg(getzone())+5.0), false); 
    107107    } 
    108108 
  • trunk/src/org/openstreetmap/josm/data/projection/UTM_France_DOM.java

    r5234 r5235  
    1919public class UTM_France_DOM extends AbstractProjection { 
    2020 
    21     private final static Bounds FortMarigotBounds = new Bounds( new LatLon(17.6,-63.25), new LatLon(18.5,-62.5)); 
    22     private final static Bounds SainteAnneBounds = new Bounds( new LatLon(15.8,-61.9), new LatLon(16.6,-60.9)); 
    23     private final static Bounds MartiniqueBounds = new Bounds( new LatLon(14.25,-61.25), new LatLon(15.025,-60.725)); 
    24     private final static Bounds ReunionBounds = new Bounds( new LatLon(-25.92,37.58), new LatLon(-10.6, 58.27)); 
    25     private final static Bounds GuyaneBounds = new Bounds( new LatLon(2.16 , -54.0), new LatLon(9.06 , -49.62)); 
     21    private final static Bounds FortMarigotBounds = new Bounds( new LatLon(17.6,-63.25), new LatLon(18.5,-62.5), false); 
     22    private final static Bounds SainteAnneBounds = new Bounds( new LatLon(15.8,-61.9), new LatLon(16.6,-60.9), false); 
     23    private final static Bounds MartiniqueBounds = new Bounds( new LatLon(14.25,-61.25), new LatLon(15.025,-60.725), false); 
     24    private final static Bounds ReunionBounds = new Bounds( new LatLon(-25.92,37.58), new LatLon(-10.6, 58.27), false); 
     25    private final static Bounds GuyaneBounds = new Bounds( new LatLon(2.16 , -54.0), new LatLon(9.06 , -49.62), false); 
    2626    private final static Bounds[] utmBounds = { FortMarigotBounds, SainteAnneBounds, MartiniqueBounds, ReunionBounds, GuyaneBounds }; 
    2727 
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java

    r5234 r5235  
    198198        Bounds b = proj.getWorldBoundsLatLon(); 
    199199        CoordinateFormat cf = CoordinateFormat.getDefaultFormat(); 
    200         bounds.setText(b.getMin().latToString(cf)+"; "+b.getMin().lonToString(cf)+" : "+b.getMax().latToString(cf)+"; "+b.getMax().lonToString(cf)); 
     200        bounds.setText(b.getMin().lonToString(cf)+", "+b.getMin().latToString(cf)+" : "+b.getMax().lonToString(cf)+", "+b.getMax().latToString(cf)); 
    201201        boolean showCode = true; 
    202202        if (pc instanceof SubPrefsOptions) { 
Note: See TracChangeset for help on using the changeset viewer.