Changeset 2456 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-11-15T11:33:47+01:00 (14 years ago)
Author:
Gubaer
Message:

Additional constructor for Bounds. Going to need this in waydownloader plugin shortly.

File:
1 edited

Legend:

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

    r2327 r2456  
    22package org.openstreetmap.josm.data;
    33
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
    46import java.awt.geom.Rectangle2D;
    57
    6 import org.openstreetmap.josm.Main;
    78import org.openstreetmap.josm.data.coor.LatLon;
    8 import static org.openstreetmap.josm.tools.I18n.tr;
    99
    1010/**
     
    1919     */
    2020    private LatLon min, max;
    21    
     21
    2222    public LatLon getMin() {
    2323        return min;
     
    4040        this.max = b;
    4141    }
    42    
     42
    4343    public Bounds(double minlat, double minlon, double maxlat, double maxlon) {
    4444        this.min = new LatLon(minlat, minlon);
    4545        this.max = new LatLon(maxlat, maxlon);
    4646    }
    47    
     47
    4848    public Bounds(double [] coords) {
    4949        if (coords == null)
     
    5454        this.max = new LatLon(coords[2], coords[3]);
    5555    }
    56    
     56
    5757    public Bounds(String asString, String separator) throws IllegalArgumentException {
    5858        if (asString == null)
    5959            throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "asString"));
    6060        String[] components = asString.split(separator);
    61         if (components.length != 4) {
     61        if (components.length != 4)
    6262            throw new IllegalArgumentException(tr("Exactly four doubles excpected in string, got {0}", components.length));
    63         }
    6463        double[] values = new double[4];
    6564        for (int i=0; i<4; i++) {
     
    7372        this.max = new LatLon(values[2], values[3]);
    7473    }
    75    
     74
    7675    public Bounds(Bounds other) {
    7776        this.min = new LatLon(other.min);
     
    8382        this.max = new LatLon(rect.getMaxY(), rect.getMaxX());
    8483    }
    85    
     84
     85    /**
     86     * Creates new bounds around a coordinate pair <code>center</code>. The
     87     * new bounds shall have an extension in latitude direction of <code>latExtent</code>,
     88     * and in longitude direction of <code>lonExtent</code>.
     89     *
     90     * @param center  the center coordinate pair. Must not be null.
     91     * @param latExtent the latitude extent. > 0 required.
     92     * @param lonExtent the longitude extent. > 0 required.
     93     * @throws IllegalArgumentException thrown if center is null
     94     * @throws IllegalArgumentException thrown if latExtent <= 0
     95     * @throws IllegalArgumentException thrown if lonExtent <= 0
     96     */
     97    public Bounds(LatLon center, double latExtent, double lonExtent) {
     98        if (center == null)
     99            throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "center"));
     100        if (latExtent <= 0.0)
     101            throw new IllegalArgumentException(tr("Parameter ''{0}'' > 0.0 exptected, got {1}", "latExtent", latExtent));
     102        if (lonExtent <= 0.0)
     103            throw new IllegalArgumentException(tr("Parameter ''{0}'' > 0.0 exptected, got {1}", "lonExtent", lonExtent));
     104
     105        this.min = new LatLon(
     106                center.lat() - latExtent / 2,
     107                center.lon() - lonExtent / 2
     108        );
     109        this.max = new LatLon(
     110                center.lat() + latExtent / 2,
     111                center.lon() + lonExtent / 2
     112        );
     113    }
     114
    86115    @Override public String toString() {
    87116        return "Bounds["+min.lat()+","+min.lon()+","+max.lat()+","+max.lon()+"]";
     
    100129     */
    101130    public void extend(LatLon ll) {
    102         if (ll.lat() < min.lat() || ll.lon() < min.lon())
     131        if (ll.lat() < min.lat() || ll.lon() < min.lon()) {
    103132            min = new LatLon(Math.min(ll.lat(), min.lat()), Math.min(ll.lon(), min.lon()));
    104         if (ll.lat() > max.lat() || ll.lon() > max.lon())
     133        }
     134        if (ll.lat() > max.lat() || ll.lon() > max.lon()) {
    105135            max = new LatLon(Math.max(ll.lat(), max.lat()), Math.max(ll.lon(), max.lon()));
     136        }
    106137    }
    107138    /**
     
    123154        return new Rectangle2D.Double(min.lon(), min.lat(), max.lon()-min.lon(), max.lat()-min.lat());
    124155    }
    125    
     156
    126157    public double getArea() {
    127158        return (max.lon() - min.lon()) * (max.lat() - min.lat());
     
    135166        return sb.toString();
    136167    }
    137    
     168
    138169    @Override
    139170    public int hashCode() {
Note: See TracChangeset for help on using the changeset viewer.