Changeset 12167 in josm


Ignore:
Timestamp:
2017-05-15T17:13:11+02:00 (8 years ago)
Author:
michael2402
Message:

Make WayPoint implement ILatLon.

Location:
trunk
Files:
5 edited

Legend:

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

    r11893 r12167  
    66import java.util.Date;
    77import java.util.List;
     8import java.util.Objects;
    89
    910import org.openstreetmap.josm.Main;
    1011import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
    1112import org.openstreetmap.josm.data.coor.EastNorth;
     13import org.openstreetmap.josm.data.coor.ILatLon;
    1214import org.openstreetmap.josm.data.coor.LatLon;
    13 import org.openstreetmap.josm.data.projection.Projections;
     15import org.openstreetmap.josm.data.projection.Projecting;
    1416import org.openstreetmap.josm.tools.UncheckedParseException;
    1517import org.openstreetmap.josm.tools.date.DateUtils;
    1618import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
    1719
    18 public class WayPoint extends WithAttributes implements Comparable<WayPoint>, TemplateEngineDataProvider {
     20/**
     21 * A point in the GPX data
     22 * @since 12167 implements ILatLon
     23 */
     24public class WayPoint extends WithAttributes implements Comparable<WayPoint>, TemplateEngineDataProvider, ILatLon {
    1925
    2026    /**
     
    3642        east = p.east;
    3743        north = p.north;
     44        eastNorthCacheKey = p.eastNorthCacheKey;
    3845        time = p.time;
    3946        customColoring = p.customColoring;
     
    6370    private double east = Double.NaN;
    6471    private double north = Double.NaN;
     72    private Object eastNorthCacheKey = null;
    6573
    6674    /**
     
    8088    }
    8189
    82     /**
    83      * <p>Replies the projected east/north coordinates.</p>
    84      *
    85      * <p>Uses the {@link Main#getProjection() global projection} to project the lan/lon-coordinates.
    86      * Internally caches the projected coordinates.</p>
    87      *
    88      * <p><strong>Caveat:</strong> doesn't listen to projection changes. Clients must
    89      * {@link #invalidateEastNorthCache() invalidate the internal cache}.</p>
    90      *
    91      * @return the east north coordinates or {@code null}
    92      * @see #invalidateEastNorthCache()
    93      */
    94     public final EastNorth getEastNorth() {
    95         if (Double.isNaN(east) || Double.isNaN(north)) {
     90    @Override
     91    public double lon() {
     92        return lat;
     93    }
     94
     95    @Override
     96    public double lat() {
     97        return lon;
     98    }
     99
     100    @Override
     101    public final EastNorth getEastNorth(Projecting projecting) {
     102        Object newCacheKey = projecting.getCacheKey();
     103        if (Double.isNaN(east) || Double.isNaN(north) || !Objects.equals(newCacheKey, this.eastNorthCacheKey)) {
    96104            // projected coordinates haven't been calculated yet,
    97105            // so fill the cache of the projected waypoint coordinates
    98             EastNorth en = Projections.project(new LatLon(lat, lon));
     106            EastNorth en = projecting.latlon2eastNorth(this);
    99107            this.east = en.east();
    100108            this.north = en.north();
     109            this.eastNorthCacheKey = newCacheKey;
    101110        }
    102111        return new EastNorth(east, north);
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r12161 r12167  
    107107            // projected coordinates haven't been calculated yet,
    108108            // so fill the cache of the projected node coordinates
    109             EastNorth en = Projections.project(new LatLon(lat, lon));
     109            EastNorth en = projection.latlon2eastNorth(this);
    110110            this.east = en.east();
    111111            this.north = en.north();
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongTrackAction.java

    r12131 r12167  
    7171                for (GpxTrackSegment segment : trk.getSegments()) {
    7272                    for (WayPoint p : segment.getWayPoints()) {
    73                         latsum += p.getCoor().lat();
     73                        latsum += p.lat();
    7474                        latcnt++;
    7575                    }
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

    r12157 r12167  
    478478                    }
    479479                    for (WayPoint trkPnt : segment) {
    480                         LatLon c = trkPnt.getCoor();
    481                         if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
     480                        if (!trkPnt.isLatLonKnown()) {
    482481                            continue;
    483482                        }
    484483                        if (oldWp != null && trkPnt.time > oldWp.time) {
    485                             double vel = c.greatCircleDistance(oldWp.getCoor())
     484                            double vel = trkPnt.getCoor().greatCircleDistance(oldWp.getCoor())
    486485                                    / (trkPnt.time - oldWp.time);
    487486                            velocities.add(vel);
     
    624623            Point old = null;
    625624            for (WayPoint trkPnt : visibleSegments) {
    626                 LatLon c = trkPnt.getCoor();
    627                 if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
     625                if (!trkPnt.isLatLonKnown()) {
    628626                    continue;
    629627                }
     
    653651            Point oldA = null; // last arrow painted
    654652            for (WayPoint trkPnt : visibleSegments) {
    655                 LatLon c = trkPnt.getCoor();
    656                 if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
     653                if (!trkPnt.isLatLonKnown()) {
    657654                    continue;
    658655                }
  • trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxDataTest.java

    r12166 r12167  
    325325        data.addTrack(new ImmutableGpxTrack(Arrays.asList(points), Collections.emptyMap()));
    326326
    327         assertEquals(points.get(1), data.nearestPointOnTrack(new EastNorth(10, 0), 10));
     327        WayPoint closeToMiddle = data.nearestPointOnTrack(new EastNorth(10, 0), 10);
     328        assertEquals(points.get(1).lat(), closeToMiddle.lat(), 1e-4);
     329        assertEquals(points.get(1).lon(), closeToMiddle.lon(), 1e-4);
    328330
    329331        WayPoint close = data.nearestPointOnTrack(new EastNorth(5, 5), 10);
Note: See TracChangeset for help on using the changeset viewer.