Ignore:
Timestamp:
2006-03-25T16:21:09+01:00 (18 years ago)
Author:
imi
Message:
  • refactored GpsPoint to be immutable and added LatLon and NorthEast
  • refactored Bounding Box calculations
  • various other renames
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r66 r71  
    88
    99import org.openstreetmap.josm.Main;
    10 import org.openstreetmap.josm.data.GeoPoint;
     10import org.openstreetmap.josm.data.coor.LatLon;
     11import org.openstreetmap.josm.data.coor.EastNorth;
    1112import org.openstreetmap.josm.data.osm.LineSegment;
    1213import org.openstreetmap.josm.data.osm.Node;
     
    3233         * Center n/e coordinate of the desired screen center.
    3334         */
    34         protected GeoPoint center;
     35        protected EastNorth center;
    3536
    3637        /**
     
    4647         *              change the center by accessing the return value. Use zoomTo instead.
    4748         */
    48         public GeoPoint getCenter() {
    49                 return center.clone();
    50         }
    51 
    52         /**
    53          * Get geographic coordinates from a specific pixel coordination
    54          * on the screen.
    55          *
    56          * If you don't need it, provide false at third parameter to speed
    57          * up the calculation.
    58          * 
     49        public EastNorth getCenter() {
     50                return center;
     51        }
     52
     53        /**
    5954         * @param x X-Pixelposition to get coordinate from
    6055         * @param y Y-Pixelposition to get coordinate from
    61          * @param latlon If set, the return value will also have the
    62          *                               latitude/longitude filled.
    63          *
    64          * @return The geographic coordinate, filled with x/y (northing/easting)
    65          *              settings and, if requested with latitude/longitude.
    66          */
    67         public GeoPoint getPoint(int x, int y, boolean latlon) {
    68                 GeoPoint p = new GeoPoint();
    69                 p.x = center.x + (x - getWidth()/2.0)*scale;
    70                 p.y = center.y - (y - getHeight()/2.0)*scale;
    71                 if (latlon)
    72                         getProjection().xy2latlon(p);
    73                 return p;
    74         }
    75 
    76         /**
    77          * Return the point on the screen where this GeoPoint would be.
     56         *
     57         * @return Geographic coordinates from a specific pixel coordination
     58         *              on the screen.
     59         */
     60        public EastNorth getEastNorth(int x, int y) {
     61                return new EastNorth(
     62                                center.east() + (x - getWidth()/2.0)*scale,
     63                                center.north() - (y - getHeight()/2.0)*scale);
     64        }
     65
     66        /**
     67         * @param x X-Pixelposition to get coordinate from
     68         * @param y Y-Pixelposition to get coordinate from
     69         *
     70         * @return Geographic unprojected coordinates from a specific pixel coordination
     71         *              on the screen.
     72         */
     73        public LatLon getLatLon(int x, int y) {
     74                EastNorth eastNorth = new EastNorth(
     75                                center.east() + (x - getWidth()/2.0)*scale,
     76                                center.north() - (y - getHeight()/2.0)*scale);
     77                return Main.pref.getProjection().eastNorth2latlon(eastNorth);
     78        }
     79
     80        /**
     81         * Return the point on the screen where this Coordinate would be.
    7882         * @param point The point, where this geopoint would be drawn.
    7983         * @return The point on screen where "point" would be drawn, relative
    8084         *              to the own top/left.
    8185         */
    82         public Point getScreenPoint(GeoPoint point) {
    83                 GeoPoint p;
    84                 if (!Double.isNaN(point.x) && !Double.isNaN(point.y))
    85                         p = point;
    86                 else {
    87                         if (Double.isNaN(point.lat) || Double.isNaN(point.lon))
    88                                 throw new IllegalArgumentException("point: Either lat/lon or x/y must be set.");
    89                         p = point.clone();
    90                         getProjection().latlon2xy(p);
    91                 }
    92                 double x = (p.x-center.x)/scale + getWidth()/2;
    93                 double y = (center.y-p.y)/scale + getHeight()/2;
     86        public Point getPoint(EastNorth p) {
     87                double x = (p.east()-center.east())/scale + getWidth()/2;
     88                double y = (center.north()-p.north())/scale + getHeight()/2;
    9489                return new Point((int)x,(int)y);
    9590        }
     
    10196         * @param scale The scale to use.
    10297         */
    103         public void zoomTo(GeoPoint newCenter, double scale) {
    104                 center = newCenter.clone();
    105                 getProjection().xy2latlon(center);
     98        public void zoomTo(EastNorth newCenter, double scale) {
     99                center = newCenter;
     100                getProjection().eastNorth2latlon(center);
    106101                this.scale = scale;
    107102                repaint();
     
    127122         *
    128123         * @param p                              The point on screen.
    129          * @param lsInsteadWay Whether the line segment (true) or only the whole
     124         * @param segmentInsteadWay Whether the line segment (true) or only the whole
    130125         *                                               way should be returned.
    131126         * @return      The primitive, that is nearest to the point p.
    132127         */
    133         public OsmPrimitive getNearest(Point p, boolean lsInsteadWay) {
     128        public OsmPrimitive getNearest(Point p, boolean segmentInsteadWay) {
    134129                double minDistanceSq = Double.MAX_VALUE;
    135130                OsmPrimitive minPrimitive = null;
     
    139134                        if (n.isDeleted())
    140135                                continue;
    141                         Point sp = getScreenPoint(n.coor);
     136                        Point sp = getPoint(n.eastNorth);
    142137                        double dist = p.distanceSq(sp);
    143138                        if (minDistanceSq > dist && dist < 100) {
     
    151146                // for whole ways, try the ways first
    152147                minDistanceSq = Double.MAX_VALUE;
    153                 if (!lsInsteadWay) {
    154                         for (Way w : Main.main.ds.waies) {
     148                if (!segmentInsteadWay) {
     149                        for (Way w : Main.main.ds.ways) {
    155150                                if (w.isDeleted())
    156151                                        continue;
     
    158153                                        if (ls.isDeleted() || ls.incomplete)
    159154                                                continue;
    160                                         Point A = getScreenPoint(ls.from.coor);
    161                                         Point B = getScreenPoint(ls.to.coor);
     155                                        Point A = getPoint(ls.from.eastNorth);
     156                                        Point B = getPoint(ls.to.eastNorth);
    162157                                        double c = A.distanceSq(B);
    163158                                        double a = p.distanceSq(B);
     
    179174                        if (ls.isDeleted() || ls.incomplete)
    180175                                continue;
    181                         Point A = getScreenPoint(ls.from.coor);
    182                         Point B = getScreenPoint(ls.to.coor);
     176                        Point A = getPoint(ls.from.eastNorth);
     177                        Point B = getPoint(ls.to.eastNorth);
    183178                        double c = A.distanceSq(B);
    184179                        double a = p.distanceSq(B);
     
    201196         * If its a node, return all line segments and
    202197         * streets the node is part of, as well as all nodes
    203          * (with their line segments and waies) with the same
     198         * (with their line segments and ways) with the same
    204199         * location.
    205200         *
    206          * If its a line segment, return all waies this segment
     201         * If its a line segment, return all ways this segment
    207202         * belongs to as well as all line segments that are between
    208          * the same nodes (in both direction) with all their waies.
     203         * the same nodes (in both direction) with all their ways.
    209204         *
    210205         * @return A collection of all items or <code>null</code>
     
    221216                        Node node = (Node)osm;
    222217                        for (Node n : Main.main.ds.nodes)
    223                                 if (!n.isDeleted() && n.coor.equalsLatLon(node.coor))
     218                                if (!n.isDeleted() && n.coor.equals(node.coor))
    224219                                        c.add(n);
    225220                        for (LineSegment ls : Main.main.ds.lineSegments)
     
    235230                }
    236231                if (osm instanceof Node || osm instanceof LineSegment) {
    237                         for (Way t : Main.main.ds.waies) {
     232                        for (Way t : Main.main.ds.ways) {
    238233                                if (t.isDeleted())
    239234                                        continue;
Note: See TracChangeset for help on using the changeset viewer.