Ticket #15229: deprecate_ILatLon#getEastNorth().patch

File deprecate_ILatLon#getEastNorth().patch, 25.2 KB (added by bastiK, 2 weeks ago)
  • src/org/openstreetmap/josm/data/coor/ILatLon.java

     
    4343     * <p>Uses the {@link Main#getProjection() global projection} to project the lan/lon-coordinates.</p>
    4444     *
    4545     * @return the east north coordinates or {@code null} if #is
     46     * @deprecated use {@link #getEastNorth(org.openstreetmap.josm.data.projection.Projecting)}
    4647     */
     48    @Deprecated
    4749    default EastNorth getEastNorth() {
    4850        return getEastNorth(Main.getProjection());
    4951    }
  • src/org/openstreetmap/josm/data/coor/LatLon.java

     
    307307        case DECIMAL_DEGREES: return cDdFormatter.format(y);
    308308        case DEGREES_MINUTES_SECONDS: return degreesMinutesSeconds(y) + ((y < 0) ? SOUTH : NORTH);
    309309        case NAUTICAL: return degreesMinutes(y) + ((y < 0) ? SOUTH : NORTH);
    310         case EAST_NORTH: return cDdFormatter.format(this.getEastNorth().north());
     310        case EAST_NORTH: return cDdFormatter.format(this.getEastNorth(Main.getProjection()).north());
    311311        default: return "ERR";
    312312        }
    313313    }
     
    327327        case DECIMAL_DEGREES: return cDdFormatter.format(x);
    328328        case DEGREES_MINUTES_SECONDS: return degreesMinutesSeconds(x) + ((x < 0) ? WEST : EAST);
    329329        case NAUTICAL: return degreesMinutes(x) + ((x < 0) ? WEST : EAST);
    330         case EAST_NORTH: return cDdFormatter.format(this.getEastNorth().east());
     330        case EAST_NORTH: return cDdFormatter.format(this.getEastNorth(Main.getProjection()).east());
    331331        default: return "ERR";
    332332        }
    333333    }
  • src/org/openstreetmap/josm/data/gpx/GpxData.java

     
    416416        for (GpxTrack track : getTracks()) {
    417417            for (GpxTrackSegment seg : track.getSegments()) {
    418418                WayPoint r = null;
    419                 for (WayPoint S : seg.getWayPoints()) {
    420                     EastNorth en = S.getEastNorth();
     419                for (WayPoint wpSeg : seg.getWayPoints()) {
     420                    EastNorth en = wpSeg.getEastNorth(Main.getProjection());
    421421                    if (r == null) {
    422                         r = S;
     422                        r = wpSeg;
    423423                        rx = en.east();
    424424                        ry = en.north();
    425425                        x = px - rx;
     
    454454                                double nx = rx - rnoverRS * b;
    455455                                double ny = ry + rnoverRS * a;
    456456                                bestEN = new EastNorth(nx, ny);
    457                                 bestTime = r.time + rnoverRS * (S.time - r.time);
     457                                bestTime = r.time + rnoverRS * (wpSeg.time - r.time);
    458458                                pnminsq = pnsq;
    459459                            }
    460460                        }
    461                         r = S;
     461                        r = wpSeg;
    462462                        rx = sx;
    463463                        ry = sy;
    464464                    }
    465465                }
    466466                if (r != null) {
    467                     EastNorth c = r.getEastNorth();
     467                    EastNorth c = r.getEastNorth(Main.getProjection());
    468468                    /* if there is only one point in the seg, it will do this twice, but no matter */
    469469                    rx = c.east();
    470470                    ry = c.north();
  • src/org/openstreetmap/josm/data/osm/Node.java

     
    9999        return lon;
    100100    }
    101101
     102    /**
     103     * Replies the projected east/north coordinates.
     104     * <p>
     105     * Uses the {@link Main#getProjection() global projection} to project the lan/lon-coordinates.
     106     * @return the east north coordinates or {@code null} if #is
     107     */
     108    public EastNorth getEastNorth() {
     109        return getEastNorth(Main.getProjection());
     110    }
     111
    102112    @Override
    103113    public EastNorth getEastNorth(Projecting projection) {
    104114        if (!isLatLonKnown()) return null;
  • src/org/openstreetmap/josm/data/osm/NodeData.java

     
    7575    }
    7676
    7777    @Override
     78    @Deprecated
    7879    public EastNorth getEastNorth() {
    7980        // No internal caching of projected coordinates needed. In contrast to getEastNorth()
    8081        // on Node, this method is rarely used. Caching would be overkill.
  • src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

     
    7373    /**
    7474     * Visiting call for lat/lon.
    7575     * @param latlon lat/lon
     76     * @since xxx (public for ILatLon parameter)
    7677     */
    77     public void visit(LatLon latlon) {
     78    public void visit(ILatLon latlon) {
    7879        if (latlon != null) {
    79             visit((ILatLon) latlon);
     80            visit(latlon.getEastNorth(Main.getProjection()));
    8081        }
    8182    }
    8283
    83     private void visit(ILatLon latlon) {
    84         visit(latlon.getEastNorth());
     84    /**
     85     * Visiting call for lat/lon.
     86     * @param latlon lat/lon
     87     */
     88    public void visit(LatLon latlon) {
     89        visit((ILatLon) latlon);
    8590    }
    8691
    8792    /**
     
    137142        LatLon maxLatlon = Main.getProjection().eastNorth2latlon(bounds.getMax());
    138143        bounds = new ProjectionBounds(new LatLon(
    139144                        Math.max(-90, minLatlon.lat() - enlargeDegree),
    140                         Math.max(-180, minLatlon.lon() - enlargeDegree)).getEastNorth(),
     145                        Math.max(-180, minLatlon.lon() - enlargeDegree)).getEastNorth(Main.getProjection()),
    141146                new LatLon(
    142147                        Math.min(90, maxLatlon.lat() + enlargeDegree),
    143                         Math.min(180, maxLatlon.lon() + enlargeDegree)).getEastNorth());
     148                        Math.min(180, maxLatlon.lon() + enlargeDegree)).getEastNorth(Main.getProjection()));
    144149    }
    145150
    146151    /**
  • src/org/openstreetmap/josm/data/projection/Projections.java

     
    1818
    1919import org.openstreetmap.josm.Main;
    2020import org.openstreetmap.josm.data.coor.EastNorth;
     21import org.openstreetmap.josm.data.coor.ILatLon;
    2122import org.openstreetmap.josm.data.coor.LatLon;
    2223import org.openstreetmap.josm.data.projection.datum.Datum;
    2324import org.openstreetmap.josm.data.projection.datum.GRS80Datum;
     
    191192     *
    192193     * @param ll the geographical point to convert (in WGS84 lat/lon)
    193194     * @return the corresponding east/north coordinates
     195     * @since xxx
    194196     */
    195     public static EastNorth project(LatLon ll) {
     197    public static EastNorth project(ILatLon ll) {
    196198        if (ll == null) return null;
    197199        return Main.getProjection().latlon2eastNorth(ll);
    198200    }
    199201
    200202    /**
     203     * Convert from lat/lon to easting/northing using the current projection.
     204     *
     205     * @param ll the geographical point to convert (in WGS84 lat/lon)
     206     * @return the corresponding east/north coordinates
     207     */
     208    public static EastNorth project(LatLon ll) {
     209        return project((ILatLon) ll);
     210    }
     211
     212    /**
    201213     * Convert from easting/norting to lat/lon using the current projection.
    202214     *
    203215     * @param en the geographical point to convert (in projected coordinates)
  • src/org/openstreetmap/josm/gui/MapViewState.java

     
    394394    private static EastNorth calculateDefaultCenter() {
    395395        Bounds b = Optional.ofNullable(DownloadDialog.getSavedDownloadBounds()).orElseGet(
    396396                () -> Main.getProjection().getWorldBoundsLatLon());
    397         return b.getCenter().getEastNorth();
     397        return b.getCenter().getEastNorth(Main.getProjection());
    398398    }
    399399
    400400    /**
  • src/org/openstreetmap/josm/gui/NavigatableComponent.java

     
    515515     * @param latlon The point, where this geopoint would be drawn.
    516516     * @return The point on screen where "point" would be drawn, relative to the own top/left.
    517517     */
    518     public Point2D getPoint2D(LatLon latlon) {
     518    public Point2D getPoint2D(ILatLon latlon) {
    519519        if (latlon == null) {
    520520            return new Point();
    521521        } else {
    522             return getPoint2D(latlon.getEastNorth());
     522            return getPoint2D(latlon.getEastNorth(Main.getProjection()));
    523523        }
    524524    }
    525525
    526526    /**
     527     * Return the point on the screen where this Coordinate would be.
     528     *
     529     * Alternative: {@link #getState()}, then {@link MapViewState#getPointFor(ILatLon)}
     530     * @param latlon The point, where this geopoint would be drawn.
     531     * @return The point on screen where "point" would be drawn, relative to the own top/left.
     532     */
     533    public Point2D getPoint2D(LatLon latlon) {
     534        return getPoint2D((ILatLon) latlon);
     535    }
     536
     537    /**
    527538     * Return the point on the screen where this Node would be.
    528539     *
    529540     * Alternative: {@link #getState()}, then {@link MapViewState#getPointFor(ILatLon)}
     
    550561     * @param latlon lat/lon
    551562     * @return point
    552563     * @see #getPoint2D(LatLon)
     564     * @since xxx
    553565     */
    554     public Point getPoint(LatLon latlon) {
     566    public Point getPoint(ILatLon latlon) {
    555567        Point2D d = getPoint2D(latlon);
    556568        return new Point((int) d.getX(), (int) d.getY());
    557569    }
     
    558570
    559571    /**
    560572     * looses precision, may overflow (depends on p and current scale)
     573     * @param latlon lat/lon
     574     * @return point
     575     * @see #getPoint2D(LatLon)
     576     */
     577    public Point getPoint(LatLon latlon) {
     578        return getPoint((ILatLon) latlon);
     579    }
     580
     581    /**
     582     * looses precision, may overflow (depends on p and current scale)
    561583     * @param n node
    562584     * @return point
    563585     * @see #getPoint2D(Node)
     
    689711    /**
    690712     * Zoom to given lat/lon.
    691713     * @param newCenter new center coordinates
     714     * @since xxx
    692715     */
    693     public void zoomTo(LatLon newCenter) {
     716    public void zoomTo(ILatLon newCenter) {
    694717        zoomTo(Projections.project(newCenter));
    695718    }
    696719
    697720    /**
     721     * Zoom to given lat/lon.
     722     * @param newCenter new center coordinates
     723     */
     724    public void zoomTo(LatLon newCenter) {
     725        zoomTo((ILatLon) newCenter);
     726    }
     727
     728    /**
    698729     * Create a thread that moves the viewport to the given center in an animated fashion.
    699730     * @param newCenter new east/north center
    700731     */
  • src/org/openstreetmap/josm/gui/datatransfer/data/PrimitiveTransferData.java

     
    131131        BoundingXYVisitor visitor = new BoundingXYVisitor();
    132132        for (PrimitiveData pd : getAll()) {
    133133            if (pd instanceof NodeData && !pd.isIncomplete()) {
    134                 visitor.visit(((NodeData) pd).getEastNorth());
     134                visitor.visit(((NodeData) pd));
    135135            }
    136136        }
    137137        ProjectionBounds bounds = visitor.getBounds();
  • src/org/openstreetmap/josm/gui/datatransfer/importers/PrimitiveDataPaster.java

     
    7272            try {
    7373                if (data instanceof NodeData) {
    7474                    NodeData nodeData = (NodeData) data;
    75                     nodeData.setEastNorth(nodeData.getEastNorth().add(offset));
     75                    nodeData.setEastNorth(nodeData.getEastNorth(Main.getProjection()).add(offset));
    7676                } else if (data instanceof WayData) {
    7777                    updateNodes(newIds.get(OsmPrimitiveType.NODE), data);
    7878                } else if (data instanceof RelationData) {
  • src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDataText.java

     
    190190        BBox bbox = o.getBBox();
    191191        if (bbox != null) {
    192192            add(tr("Bounding box: "), bbox.toStringCSV(", "));
    193             EastNorth bottomRigth = bbox.getBottomRight().getEastNorth();
    194             EastNorth topLeft = bbox.getTopLeft().getEastNorth();
     193            EastNorth bottomRigth = bbox.getBottomRight().getEastNorth(Main.getProjection());
     194            EastNorth topLeft = bbox.getTopLeft().getEastNorth(Main.getProjection());
    195195            add(tr("Bounding box (projected): "),
    196196                    Double.toString(topLeft.east()), ", ",
    197197                    Double.toString(bottomRigth.north()), ", ",
  • src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

     
    650650                    old = null;
    651651                    continue;
    652652                }
    653                 Point screen = mv.getPoint(trkPnt.getEastNorth());
     653                Point screen = mv.getPoint(trkPnt);
    654654                // skip points that are on the same screenposition
    655655                if (trkPnt.drawLine && old != null && ((old.x != screen.x) || (old.y != screen.y))) {
    656656                    g.setColor(trkPnt.customColoring);
     
    680680                    continue;
    681681                }
    682682                if (trkPnt.drawLine) {
    683                     Point screen = mv.getPoint(trkPnt.getEastNorth());
     683                    Point screen = mv.getPoint(trkPnt);
    684684                    // skip points that are on the same screenposition
    685685                    if (old != null
    686686                            && (oldA == null || screen.x < oldA.x - delta || screen.x > oldA.x + delta
     
    710710                    continue;
    711711                }
    712712                if (trkPnt.drawLine) {
    713                     Point screen = mv.getPoint(trkPnt.getEastNorth());
     713                    Point screen = mv.getPoint(trkPnt);
    714714                    // skip points that are on the same screenposition
    715715                    if (old != null
    716716                            && (oldA == null || screen.x < oldA.x - delta || screen.x > oldA.x + delta
     
    745745                if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
    746746                    continue;
    747747                }
    748                 Point screen = mv.getPoint(trkPnt.getEastNorth());
     748                Point screen = mv.getPoint(trkPnt);
    749749
    750750                if (hdopCircle && trkPnt.get(GpxConstants.PT_HDOP) != null) {
    751751                    // hdop value
     
    786786                    continue;
    787787                }
    788788                if (!trkPnt.drawLine) {
    789                     Point screen = mv.getPoint(trkPnt.getEastNorth());
     789                    Point screen = mv.getPoint(trkPnt);
    790790                    g.drawRect(screen.x, screen.y, 0, 0);
    791791                }
    792792            } // end for trkpnt
     
    802802                if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
    803803                    continue;
    804804                }
    805                 Point screen = mv.getPoint(trkPnt.getEastNorth());
     805                Point screen = mv.getPoint(trkPnt);
    806806                g.setColor(trkPnt.customColoring);
    807807                g.drawRect(screen.x, screen.y, 0, 0);
    808808            } // end for trkpnt
     
    852852        for (WayPoint trkPnt : visibleSegments) {
    853853
    854854            // transform coordinates
    855             final Point paintPnt = mv.getPoint(trkPnt.getEastNorth());
     855            final Point paintPnt = mv.getPoint(trkPnt);
    856856
    857857            // skip single points
    858858            if (lastPaintPnt != null && trkPnt.drawLine && !lastPaintPnt.equals(paintPnt)) {
     
    11111111        for (WayPoint trkPnt : listSegm) {
    11121112
    11131113            // get transformed coordinates
    1114             final Point paintPnt = mv.getPoint(trkPnt.getEastNorth());
     1114            final Point paintPnt = mv.getPoint(trkPnt);
    11151115
    11161116            // end of line segment or end of list reached
    11171117            if (!trkPnt.drawLine || (lastPnt == trkPnt)) {
     
    13611361        for (WayPoint trkPnt : listSegm) {
    13621362
    13631363            // get transformed coordinates
    1364             final Point paintPnt = mv.getPoint(trkPnt.getEastNorth());
     1364            final Point paintPnt = mv.getPoint(trkPnt);
    13651365
    13661366            // end of line segment or end of list reached
    13671367            if (trkPnt.drawLine && null != lastPnt) {
  • src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java

     
    186186                if (waypoints.contains(w)) {
    187187                    continue;
    188188                }
    189                 WayPoint wNear = layer.data.nearestPointOnTrack(w.getEastNorth(), snapDistance);
     189                WayPoint wNear = layer.data.nearestPointOnTrack(w.getEastNorth(Main.getProjection()), snapDistance);
    190190                if (wNear != null) {
    191191                    WayPoint wc = new WayPoint(w.getCoor());
    192192                    wc.time = wNear.time;
  • src/org/openstreetmap/josm/gui/layer/markerlayer/ButtonMarker.java

     
    3838    }
    3939
    4040    @Override public boolean containsPoint(Point p) {
    41         Point screen = MainApplication.getMap().mapView.getPoint(getEastNorth());
     41        Point screen = MainApplication.getMap().mapView.getPoint(this);
    4242        buttonRectangle.setLocation(screen.x+4, screen.y+2);
    4343        return buttonRectangle.contains(p);
    4444    }
     
    4848            super.paint(g, mv, mousePressed, showTextOrIcon);
    4949            return;
    5050        }
    51         Point screen = mv.getPoint(getEastNorth());
     51        Point screen = mv.getPoint(this);
    5252        buttonRectangle.setLocation(screen.x+4, screen.y+2);
    5353        paintIcon(mv, g, screen.x+4, screen.y+2);
    5454        Border b;
  • src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

     
    2222
    2323import javax.swing.ImageIcon;
    2424
     25import org.openstreetmap.josm.Main;
    2526import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    2627import org.openstreetmap.josm.data.coor.CachedLatLon;
    2728import org.openstreetmap.josm.data.coor.EastNorth;
     29import org.openstreetmap.josm.data.coor.ILatLon;
    2830import org.openstreetmap.josm.data.coor.LatLon;
    2931import org.openstreetmap.josm.data.gpx.GpxConstants;
    3032import org.openstreetmap.josm.data.gpx.WayPoint;
     
    7476 *
    7577 * @author Frederik Ramm
    7678 */
    77 public class Marker implements TemplateEngineDataProvider {
     79public class Marker implements TemplateEngineDataProvider, ILatLon {
    7880
    7981    public static final class TemplateEntryProperty extends CachedProperty<TemplateEntry> {
    8082        // This class is a bit complicated because it supports both global and per layer settings. I've added per layer settings because
     
    317319    }
    318320
    319321    /**
     322     * @since xxx
     323     */
     324    @Override
     325    public double lon() {
     326        return coor == null ? Double.NaN : coor.lon();
     327    }
     328
     329    /**
     330     * @since xxx
     331     */
     332    @Override
     333    public double lat() {
     334        return coor == null ? Double.NaN : coor.lat();
     335    }
     336
     337    /**
    320338     * Returns the marker's projected coordinates.
    321339     * @return The marker's projected coordinates (easting/northing)
     340     * @deprecated use {@link #getEastNorth(org.openstreetmap.josm.data.projection.Projecting)}
    322341     */
     342    @Deprecated
    323343    public final EastNorth getEastNorth() {
    324         return coor.getEastNorth();
     344        return coor.getEastNorth(Main.getProjection());
    325345    }
    326346
    327347    /**
     
    353373     * @param showTextOrIcon true if text and icon shall be drawn
    354374     */
    355375    public void paint(Graphics g, MapView mv, boolean mousePressed, boolean showTextOrIcon) {
    356         Point screen = mv.getPoint(getEastNorth());
     376        Point screen = mv.getPoint(this);
    357377        if (symbol != null && showTextOrIcon) {
    358378            paintIcon(mv, g, screen.x-symbol.getIconWidth()/2, screen.y-symbol.getIconHeight()/2);
    359379        } else {
  • src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

     
    210210
    211211    @Override public void visitBoundingBox(BoundingXYVisitor v) {
    212212        for (Marker mkr : data) {
    213             v.visit(mkr.getEastNorth());
     213            v.visit(mkr);
    214214        }
    215215    }
    216216
     
    351351                }
    352352            }
    353353        }
    354         MainApplication.getMap().mapView.zoomTo(currentMarker.getEastNorth());
     354        MainApplication.getMap().mapView.zoomTo(currentMarker);
    355355    }
    356356
    357357    @Override
     
    370370                }
    371371            }
    372372        }
    373         MainApplication.getMap().mapView.zoomTo(currentMarker.getEastNorth());
     373        MainApplication.getMap().mapView.zoomTo(currentMarker);
    374374    }
    375375
    376376    public static void playAudio() {
  • src/org/openstreetmap/josm/gui/layer/markerlayer/PlayHeadMarker.java

     
    8484
    8585    @Override
    8686    public boolean containsPoint(Point p) {
    87         Point screen = MainApplication.getMap().mapView.getPoint(getEastNorth());
     87        Point screen = MainApplication.getMap().mapView.getPoint(this);
    8888        Rectangle r = new Rectangle(screen.x, screen.y, symbol.getIconWidth(),
    8989                symbol.getIconHeight());
    9090        return r.contains(p);
     
    213213            double closestAudioMarkerDistanceSquared = 1.0E100;
    214214            for (Marker m : recent.parentLayer.data) {
    215215                if (m instanceof AudioMarker) {
    216                     double distanceSquared = m.getEastNorth().distanceSq(en);
     216                    double distanceSquared = m.getEastNorth(Main.getProjection()).distanceSq(en);
    217217                    if (distanceSquared < closestAudioMarkerDistanceSquared) {
    218218                        ca = (AudioMarker) m;
    219219                        closestAudioMarkerDistanceSquared = distanceSquared;
     
    282282     */
    283283    public void paint(Graphics g, MapView mv) {
    284284        if (time < 0.0) return;
    285         Point screen = mv.getPoint(getEastNorth());
     285        Point screen = mv.getPoint(this);
    286286        paintIcon(mv, g, screen.x, screen.y);
    287287    }
    288288
     
    346346        if (w1 == null)
    347347            return;
    348348        setEastNorth(w2 == null ?
    349                 w1.getEastNorth() :
    350                     w1.getEastNorth().interpolate(w2.getEastNorth(),
     349                w1.getEastNorth(Main.getProjection()) :
     350                    w1.getEastNorth(Main.getProjection()).interpolate(w2.getEastNorth(Main.getProjection()),
    351351                            (audioTime - w1.time)/(w2.time - w1.time)));
    352352        time = audioTime;
    353353        MapView mapView = MainApplication.getMap().mapView;
    354354        if (jumpToMarker) {
    355355            jumpToMarker = false;
    356             mapView.zoomTo(w1.getEastNorth());
     356            mapView.zoomTo(w1);
    357357        }
    358358        mapView.repaint();
    359359    }