Ignore:
Timestamp:
2013-08-20T18:29:49+02:00 (7 years ago)
Author:
bastiK
Message:

applied #8987 - immutable coordinates (patch by shinigami)

Location:
trunk/src/org/openstreetmap/josm/data/coor
Files:
4 edited

Legend:

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

    r6069 r6162  
    3333    }
    3434
    35     public final void setCoor(LatLon coor) {
    36         setLocation(coor.lon(), coor.lat());
    37         proj = null;
    38     }
    39 
    40     public final void setEastNorth(EastNorth eastNorth) {
    41         proj = Main.getProjection();
    42         this.eastNorth = eastNorth;
    43         LatLon l = proj.eastNorth2latlon(eastNorth);
    44         setLocation(l.lon(), l.lat());
    45     }
    46 
    4735    /**
    4836     * Replies the projected east/north coordinates.
  • trunk/src/org/openstreetmap/josm/data/coor/Coordinate.java

    r6084 r6162  
    22package org.openstreetmap.josm.data.coor;
    33
    4 import java.awt.geom.Point2D;
    54import java.io.Serializable;
    65
     
    1716 * @author imi
    1817 */
    19 abstract class Coordinate extends Point2D implements Serializable {
     18abstract class Coordinate implements Serializable {
    2019
    21     protected double x;
    22     protected double y;
     20    protected final double x;
     21    protected final double y;
    2322
    2423    /**
     
    3231    }
    3332
    34     @Override
    3533    public double getX() {
    3634        return x;
    3735    }
    3836
    39     @Override
    4037    public double getY() {
    4138        return y;
    42     }
    43 
    44     @Override
    45     public void setLocation (double x, double y) {
    46         this.x = x;
    47         this.y = y;
    4839    }
    4940
  • trunk/src/org/openstreetmap/josm/data/coor/EastNorth.java

    r6069 r6162  
    4444    }
    4545
    46     public double distance(EastNorth en2) {
    47         return Math.sqrt((this.x-en2.x)*(this.x-en2.x) + (this.y-en2.y)*(this.y-en2.y));
     46    /**
     47     * Counts euclidean distance between this and other EastNorth.
     48     *
     49     * @param en2 other EastNorth
     50     * @return distance between this and other EastNorth
     51     */
     52    public double distance(final EastNorth en2) {
     53        final double dx = this.x-en2.x;
     54        final double dy = this.y-en2.y;
     55        return Math.sqrt(dx*dx + dy*dy);
    4856    }
    4957
     58    /**
     59     * Counts square of euclidean distance between this and other EastNorth.
     60     *
     61     * @param en2 other EastNorth
     62     * @return square of distance between this and other EastNorth
     63     */
     64    public double distanceSq(final EastNorth en2) {
     65        final double dx = this.x-en2.x;
     66        final double dy = this.y-en2.y;
     67        return dx*dx + dy*dy;
     68    }
     69
     70    /**
     71     * Counts length (distance from [0,0]) of this.
     72     *
     73     * @return length of this
     74     */
     75    public double length(){
     76        return Math.sqrt(x*x + y*y);
     77    }
     78   
    5079    /**
    5180     * Returns the heading, in radians, that you have to use to get from
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r6069 r6162  
    1111import static org.openstreetmap.josm.tools.I18n.trc;
    1212
     13import java.awt.geom.Area;
    1314import java.text.DecimalFormat;
    1415import java.text.NumberFormat;
     
    219220    public boolean isWithin(Bounds b) {
    220221        return b.contains(this);
     222    }
     223
     224    /**
     225     * Check if this is contained in given area or area is null.
     226     *
     227     * @param a Area
     228     * @return <code>true</code> if this is contained in given area or area is null.
     229     */
     230    public boolean isIn(Area a) {
     231        return a == null || a.contains(x, y);
    221232    }
    222233
     
    284295    public LatLon getCenter(LatLon ll2) {
    285296        return new LatLon((this.lat() + ll2.lat())/2.0, (this.lon() + ll2.lon())/2.0);
     297    }
     298
     299    /**
     300     * Counts euclidean distance between this and other LatLon.
     301     *
     302     * @param ll2 other LatLon
     303     * @return distance between this and other LatLon
     304     */
     305   public double distance(final LatLon ll2) {
     306        final double dx = this.x-ll2.x;
     307        final double dy = this.y-ll2.y;
     308        return Math.sqrt(dx*dx + dy*dy);
    286309    }
    287310
Note: See TracChangeset for help on using the changeset viewer.