Changeset 2943 in josm


Ignore:
Timestamp:
Feb 5, 2010 10:30:40 PM (3 years ago)
Author:
mjulius
Message:

generally round Bounds to LatLon.MAX_SERVER_PRECISION

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java

    r2942 r2943  
    5353        List<Area> areas = new ArrayList<Area>(); 
    5454        for(DataSource ds : getEditLayer().data.dataSources) { 
    55             areas.add(new Area(ds.bounds.getRoundedToOsmPrecision().asRect())); 
     55            areas.add(new Area(ds.bounds.asRect())); 
    5656        } 
    5757 
  • trunk/src/org/openstreetmap/josm/data/Bounds.java

    r2942 r2943  
    1313/** 
    1414 * This is a simple data class for "rectangular" areas of the world, given in 
    15  * lat/lon min/max values. 
     15 * lat/lon min/max values.  The values are rounded to LatLon.OSM_SERVER_PRECISION 
    1616 * 
    1717 * @author imi 
     
    4343 
    4444    public Bounds(double minlat, double minlon, double maxlat, double maxlon) { 
    45         this.minLat = minlat; 
    46         this.minLon = minlon; 
    47         this.maxLat = maxlat; 
    48         this.maxLon = maxlon; 
     45        this.minLat = roundToOsmPrecision(minlat); 
     46        this.minLon = roundToOsmPrecision(minlon); 
     47        this.maxLat = roundToOsmPrecision(maxlat); 
     48        this.maxLon = roundToOsmPrecision(maxlon); 
    4949    } 
    5050 
     
    5353        if (coords.length != 4) 
    5454            throw new IllegalArgumentException(MessageFormat.format("Expected array of length 4, got {0}", coords.length)); 
    55         this.minLat = coords[0]; 
    56         this.minLon = coords[1]; 
    57         this.maxLat = coords[2]; 
    58         this.maxLon = coords[3]; 
     55        this.minLat = roundToOsmPrecision(coords[0]); 
     56        this.minLon = roundToOsmPrecision(coords[1]); 
     57        this.maxLat = roundToOsmPrecision(coords[2]); 
     58        this.maxLon = roundToOsmPrecision(coords[3]); 
    5959    } 
    6060 
     
    8181            throw new IllegalArgumentException(tr("Illegal latitude value ''{0}''", values[3])); 
    8282 
    83         this.minLat = values[0]; 
    84         this.minLon = values[1]; 
    85         this.maxLat = values[2]; 
    86         this.maxLon = values[3]; 
     83        this.minLat = roundToOsmPrecision(values[0]); 
     84        this.minLon = roundToOsmPrecision(values[1]); 
     85        this.maxLat = roundToOsmPrecision(values[2]); 
     86        this.maxLon = roundToOsmPrecision(values[3]); 
    8787    } 
    8888 
     
    114114            throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' > 0.0 exptected, got {1}", "lonExtent", lonExtent)); 
    115115 
    116         this.minLat = center.lat() - latExtent / 2; 
    117         this.minLon = center.lon() - lonExtent / 2; 
    118         this.maxLat = center.lat() + latExtent / 2; 
    119         this.maxLon = center.lon() + lonExtent / 2; 
     116        this.minLat = roundToOsmPrecision(center.lat() - latExtent / 2); 
     117        this.minLon = roundToOsmPrecision(center.lon() - lonExtent / 2); 
     118        this.maxLat = roundToOsmPrecision(center.lat() + latExtent / 2); 
     119        this.maxLon = roundToOsmPrecision(center.lon() + lonExtent / 2); 
    120120    } 
    121121 
     
    145145    public void extend(LatLon ll) { 
    146146        if (ll.lat() < minLat) { 
    147             minLat = ll.lat(); 
     147            minLat = roundToOsmPrecision(ll.lat()); 
    148148        } 
    149149        if (ll.lon() < minLon) { 
    150             minLon = ll.lon(); 
     150            minLon = roundToOsmPrecision(ll.lon()); 
    151151        } 
    152152        if (ll.lat() > maxLat) { 
    153             maxLat = ll.lat(); 
     153            maxLat = roundToOsmPrecision(ll.lat()); 
    154154        } 
    155155        if (ll.lon() > maxLon) { 
    156             maxLon = ll.lon(); 
     156            maxLon = roundToOsmPrecision(ll.lon()); 
    157157        } 
    158158    } 
     
    172172        return true; 
    173173    } 
    174      
     174 
    175175    /** 
    176176     * The two bounds intersect? Compared to java Shape.intersects, if does not use 
     
    178178     */ 
    179179    public boolean intersects(Bounds b) { 
    180             return b.getMax().lat() >= minLat && 
    181                     b.getMax().lon() >= minLon && 
    182                     b.getMin().lat() <= maxLat && 
    183                     b.getMin().lon() <= maxLon; 
    184     } 
    185      
     180        return b.getMax().lat() >= minLat && 
     181        b.getMax().lon() >= minLon && 
     182        b.getMin().lat() <= maxLat && 
     183        b.getMin().lon() <= maxLon; 
     184    } 
     185 
    186186 
    187187    /** 
     
    242242 
    243243    /** 
    244      * Returns a clone of this Bounds, rounded to OSM precisions, i.e. to 
     244     * Returns the value rounded to OSM precisions, i.e. to 
    245245     * LatLon.MAX_SERVER_PRECISION 
    246246     * 
    247      * @return a clone of this Bounds 
    248      */ 
    249     public Bounds getRoundedToOsmPrecision() { 
    250         return new Bounds( 
    251                 Math.round(minLat / LatLon.MAX_SERVER_PRECISION) * LatLon.MAX_SERVER_PRECISION, 
    252                 Math.round(minLon / LatLon.MAX_SERVER_PRECISION) * LatLon.MAX_SERVER_PRECISION, 
    253                 Math.round(maxLat / LatLon.MAX_SERVER_PRECISION) * LatLon.MAX_SERVER_PRECISION, 
    254                 Math.round(maxLon / LatLon.MAX_SERVER_PRECISION) * LatLon.MAX_SERVER_PRECISION 
    255         ); 
     247     * @return rounded value 
     248     */ 
     249    private double roundToOsmPrecision(double value) { 
     250        return Math.round(value / LatLon.MAX_SERVER_PRECISION) * LatLon.MAX_SERVER_PRECISION; 
    256251    } 
    257252} 
Note: See TracChangeset for help on using the changeset viewer.