Ticket #22115: 22115.patch

File 22115.patch, 30.4 KB (added by taylor.smock, 4 years ago)
  • src/org/openstreetmap/josm/actions/CreateCircleAction.java

    diff --git a/src/org/openstreetmap/josm/actions/CreateCircleAction.java b/src/org/openstreetmap/josm/actions/CreateCircleAction.java
    index a8488ae92e..6ecbefdf72 100644
    a b public final class CreateCircleAction extends JosmAction {  
    191191        double r = n1.distance(center);
    192192
    193193        // see #10777
    194         LatLon ll1 = ProjectionRegistry.getProjection().eastNorth2latlon(n1);
    195194        LatLon ll2 = ProjectionRegistry.getProjection().eastNorth2latlon(center);
    196195
    197         double radiusInMeters = ll1.greatCircleDistance(ll2);
     196        double radiusInMeters = nodes.get(0).greatCircleDistance(ll2);
    198197
    199198        int numberOfNodesInCircle = (int) Math.ceil(6.0 * Math.pow(radiusInMeters, 0.5));
    200199        // an odd number of nodes makes the distribution uneven
  • src/org/openstreetmap/josm/actions/mapmode/DrawSnapHelper.java

    diff --git a/src/org/openstreetmap/josm/actions/mapmode/DrawSnapHelper.java b/src/org/openstreetmap/josm/actions/mapmode/DrawSnapHelper.java
    index 59992ac1eb..f09960ebbd 100644
    a b class DrawSnapHelper {  
    388388
    389389        // find out the distance, in metres, between the base point and projected point
    390390        LatLon mouseLatLon = mapView.getProjection().eastNorth2latlon(snapPoint);
    391         double distance = this.drawAction.getCurrentBaseNode().getCoor().greatCircleDistance(mouseLatLon);
     391        double distance = this.drawAction.getCurrentBaseNode().greatCircleDistance(mouseLatLon);
    392392        double hdg = Utils.toDegrees(p0.heading(snapPoint));
    393393        // heading of segment from current to calculated point, not to mouse position
    394394
  • src/org/openstreetmap/josm/command/MoveCommand.java

    diff --git a/src/org/openstreetmap/josm/command/MoveCommand.java b/src/org/openstreetmap/josm/command/MoveCommand.java
    index b2bf3a2d02..9d8a333627 100644
    a b import java.util.function.Predicate;  
    1515import javax.swing.Icon;
    1616
    1717import org.openstreetmap.josm.data.coor.EastNorth;
     18import org.openstreetmap.josm.data.coor.ILatLon;
    1819import org.openstreetmap.josm.data.coor.LatLon;
    1920import org.openstreetmap.josm.data.osm.DataSet;
    2021import org.openstreetmap.josm.data.osm.Node;
    public class MoveCommand extends Command {  
    313314    public double getDistance(Predicate<Node> predicate) {
    314315        return nodes.stream()
    315316                .filter(predicate)
    316                 .filter(node -> node.getCoor() != null && node.getEastNorth() != null)
     317                .filter(ILatLon::isLatLonKnown /* If the node latlon is known, then the eastnorth cannot be null */)
    317318                .findFirst()
    318319                .map(node -> {
    319320                    final Node old = new Node(node);
    320321                    old.setEastNorth(old.getEastNorth().add(-x, -y));
    321                     return node.getCoor().greatCircleDistance(old.getCoor());
     322                    return node.greatCircleDistance(old);
    322323                }).orElse(Double.NaN);
    323324    }
    324325
  • src/org/openstreetmap/josm/data/coor/ILatLon.java

    diff --git a/src/org/openstreetmap/josm/data/coor/ILatLon.java b/src/org/openstreetmap/josm/data/coor/ILatLon.java
    index 45498b5cf6..3891ad57b7 100644
    a b  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.coor;
    33
     4import static java.lang.Math.PI;
     5import static java.lang.Math.asin;
     6import static java.lang.Math.atan2;
     7import static java.lang.Math.cos;
     8import static java.lang.Math.sin;
     9import static java.lang.Math.sqrt;
     10import static org.openstreetmap.josm.data.projection.Ellipsoid.WGS84;
     11import static org.openstreetmap.josm.tools.Utils.toRadians;
     12
    413import org.openstreetmap.josm.data.projection.Projecting;
     14import org.openstreetmap.josm.tools.Logging;
    515
    616/**
    717 * This interface represents a coordinate in LatLon space.
    public interface ILatLon {  
    8090        double p = precision / 2;
    8191        return Math.abs(lat() - other.lat()) <= p && Math.abs(lon() - other.lon()) <= p;
    8292    }
     93
     94    /**
     95     * Computes the distance between this lat/lon and another point on the earth.
     96     * Uses <a href="https://en.wikipedia.org/wiki/Haversine_formula">Haversine formula</a>.
     97     * @param other the other point.
     98     * @return distance in metres.
     99     * @since xxx (extracted from {@link LatLon})
     100     */
     101    default double greatCircleDistance(ILatLon other) {
     102        double sinHalfLat = sin(toRadians(other.lat() - this.lat()) / 2);
     103        double sinHalfLon = sin(toRadians(other.lon() - this.lon()) / 2);
     104        double d = 2 * WGS84.a * asin(
     105                sqrt(sinHalfLat*sinHalfLat +
     106                        cos(toRadians(this.lat()))*cos(toRadians(other.lat()))*sinHalfLon*sinHalfLon));
     107        // For points opposite to each other on the sphere,
     108        // rounding errors could make the argument of asin greater than 1
     109        // (This should almost never happen.)
     110        if (Double.isNaN(d)) {
     111            Logging.error("NaN in greatCircleDistance: {0} {1}", this, other);
     112            d = PI * WGS84.a;
     113        }
     114        return d;
     115    }
     116
     117    /**
     118     * Returns bearing from this point to another.
     119     *
     120     * Angle starts from north and increases clockwise, PI/2 means east.
     121     *
     122     * Please note that reverse bearing (from other point to this point) should NOT be
     123     * calculated from return value of this method, because great circle path
     124     * between the two points have different bearings at each position.
     125     *
     126     * To get bearing from another point to this point call other.bearing(this)
     127     *
     128     * @param other the "destination" position
     129     * @return heading in radians in the range 0 &lt;= hd &lt; 2*PI
     130     * @since xxx (extracted from {@link LatLon}, added in 9796)
     131     */
     132    default double bearing(ILatLon other) {
     133        double lat1 = toRadians(this.lat());
     134        double lat2 = toRadians(other.lat());
     135        double dlon = toRadians(other.lon() - this.lon());
     136        double bearing = atan2(
     137                sin(dlon) * cos(lat2),
     138                cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dlon)
     139        );
     140        bearing %= 2 * PI;
     141        if (bearing < 0) {
     142            bearing += 2 * PI;
     143        }
     144        return bearing;
     145    }
    83146}
  • src/org/openstreetmap/josm/data/coor/LatLon.java

    diff --git a/src/org/openstreetmap/josm/data/coor/LatLon.java b/src/org/openstreetmap/josm/data/coor/LatLon.java
    index 43d12f6336..3d7fafdf55 100644
    a b  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.coor;
    33
    4 import static java.lang.Math.PI;
    5 import static java.lang.Math.asin;
    6 import static java.lang.Math.atan2;
    7 import static java.lang.Math.cos;
    8 import static java.lang.Math.sin;
    9 import static java.lang.Math.sqrt;
    10 import static org.openstreetmap.josm.data.projection.Ellipsoid.WGS84;
    11 import static org.openstreetmap.josm.tools.Utils.toRadians;
    12 
    134import java.awt.geom.Area;
    145import java.text.DecimalFormat;
    156import java.text.NumberFormat;
    import java.util.Objects;  
    1910import org.openstreetmap.josm.data.Bounds;
    2011import org.openstreetmap.josm.data.osm.Node;
    2112import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    22 import org.openstreetmap.josm.tools.Logging;
    2313import org.openstreetmap.josm.tools.Utils;
    2414
    2515/**
    public class LatLon extends Coordinate implements ILatLon {  
    228218     * Uses <a href="https://en.wikipedia.org/wiki/Haversine_formula">Haversine formula</a>.
    229219     * @param other the other point.
    230220     * @return distance in metres.
     221     * @deprecated since xxx (use {@link ILatLon#greatCircleDistance(ILatLon)} instead)
    231222     */
     223    @Deprecated
    232224    public double greatCircleDistance(LatLon other) {
    233         double sinHalfLat = sin(toRadians(other.lat() - this.lat()) / 2);
    234         double sinHalfLon = sin(toRadians(other.lon() - this.lon()) / 2);
    235         double d = 2 * WGS84.a * asin(
    236                 sqrt(sinHalfLat*sinHalfLat +
    237                         cos(toRadians(this.lat()))*cos(toRadians(other.lat()))*sinHalfLon*sinHalfLon));
    238         // For points opposite to each other on the sphere,
    239         // rounding errors could make the argument of asin greater than 1
    240         // (This should almost never happen.)
    241         if (Double.isNaN(d)) {
    242             Logging.error("NaN in greatCircleDistance: {0} {1}", this, other);
    243             d = PI * WGS84.a;
    244         }
    245         return d;
     225        return ILatLon.super.greatCircleDistance(other);
    246226    }
    247227
    248228    /**
    public class LatLon extends Coordinate implements ILatLon {  
    259239     * @param other the "destination" position
    260240     * @return heading in radians in the range 0 &lt;= hd &lt; 2*PI
    261241     * @since 9796
     242     * @deprecated since xxx (use {@link ILatLon#bearing(ILatLon)} instead)
    262243     */
     244    @Deprecated
    263245    public double bearing(LatLon other) {
    264         double lat1 = toRadians(this.lat());
    265         double lat2 = toRadians(other.lat());
    266         double dlon = toRadians(other.lon() - this.lon());
    267         double bearing = atan2(
    268             sin(dlon) * cos(lat2),
    269             cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dlon)
    270         );
    271         bearing %= 2 * PI;
    272         if (bearing < 0) {
    273             bearing += 2 * PI;
    274         }
    275         return bearing;
     246        return ILatLon.super.bearing(other);
    276247    }
    277248
    278249    /**
  • src/org/openstreetmap/josm/data/gpx/GpxImageCorrelation.java

    diff --git a/src/org/openstreetmap/josm/data/gpx/GpxImageCorrelation.java b/src/org/openstreetmap/josm/data/gpx/GpxImageCorrelation.java
    index c3ede940b6..bcd175ecf0 100644
    a b public final class GpxImageCorrelation {  
    9191                            double totalDist = 0;
    9292                            List<Pair<Double, WayPoint>> nextWps = new ArrayList<>();
    9393                            for (int j = i; j < size; j++) {
    94                                 totalDist += wps.get(j - 1).getCoor().greatCircleDistance(wps.get(j).getCoor());
     94                                totalDist += wps.get(j - 1).greatCircleDistance(wps.get(j));
    9595                                nextWps.add(new Pair<>(totalDist, wps.get(j)));
    9696                                if (wps.get(j).hasDate()) {
    9797                                    // ...if yes, interpolate everything in between
    public final class GpxImageCorrelation {  
    120120                            firstSegment = false;
    121121                            if (!trkInt || isFirst || prevWp == null ||
    122122                                    Math.abs(curWpTime - prevWpTime) > TimeUnit.MINUTES.toMillis(trkTime) ||
    123                                     prevWp.getCoor().greatCircleDistance(curWp.getCoor()) > trkDist) {
     123                                    prevWp.greatCircleDistance(curWp) > trkDist) {
    124124                                isFirst = false;
    125125                                interpolate = false;
    126126                                if (trkTag) {
    public final class GpxImageCorrelation {  
    131131                            // Apply settings for segments
    132132                            if (!segInt || prevWp == null ||
    133133                                    Math.abs(curWpTime - prevWpTime) > TimeUnit.MINUTES.toMillis(segTime) ||
    134                                     prevWp.getCoor().greatCircleDistance(curWp.getCoor()) > segDist) {
     134                                    prevWp.greatCircleDistance(curWp) > segDist) {
    135135                                interpolate = false;
    136136                                if (segTag) {
    137137                                    tagTime = segTagTime;
    public final class GpxImageCorrelation {  
    237237        Double prevElevation = null;
    238238
    239239        if (prevWp != null && interpolate) {
    240             double distance = prevWp.getCoor().greatCircleDistance(curWp.getCoor());
     240            double distance = prevWp.greatCircleDistance(curWp);
    241241            // This is in km/h, 3.6 * m/s
    242242            if (curWpTime > prevWpTime) {
    243243                speed = 3600 * distance / (curWpTime - prevWpTime);
    public final class GpxImageCorrelation {  
    266266                        curTmp.setPos(curWp.getCoor());
    267267                    }
    268268                    if (nextWp != null && dirpos.isSetImageDirection()) {
    269                         double direction = curWp.getCoor().bearing(nextWp.getCoor());
     269                        double direction = curWp.bearing(nextWp);
    270270                        curTmp.setExifImgDir(computeDirection(direction, dirpos.getImageDirectionAngleOffset()));
    271271                    }
    272272                    curTmp.setGpsTime(curImg.getExifInstant().minusMillis(offset));
  • src/org/openstreetmap/josm/data/gpx/GpxTrackSegment.java

    diff --git a/src/org/openstreetmap/josm/data/gpx/GpxTrackSegment.java b/src/org/openstreetmap/josm/data/gpx/GpxTrackSegment.java
    index 02fa8f12c3..df0993eda5 100644
    a b public class GpxTrackSegment extends WithAttributes implements IGpxTrackSegment  
    4646        WayPoint last = null;
    4747        for (WayPoint tpt : wayPoints) {
    4848            if (last != null) {
    49                 Double d = last.getCoor().greatCircleDistance(tpt.getCoor());
     49                Double d = last.greatCircleDistance(tpt);
    5050                if (!d.isNaN() && !d.isInfinite()) {
    5151                    result += d;
    5252                }
  • src/org/openstreetmap/josm/data/osm/Way.java

    diff --git a/src/org/openstreetmap/josm/data/osm/Way.java b/src/org/openstreetmap/josm/data/osm/Way.java
    index b746a98891..ebea83125e 100644
    a b import java.util.Set;  
    1212import java.util.stream.Collectors;
    1313import java.util.stream.IntStream;
    1414
    15 import org.openstreetmap.josm.data.coor.LatLon;
     15import org.openstreetmap.josm.data.coor.ILatLon;
    1616import org.openstreetmap.josm.data.osm.visitor.OsmPrimitiveVisitor;
    1717import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
    1818import org.openstreetmap.josm.spi.preferences.Config;
    public final class Way extends OsmPrimitive implements IWay<Node> {  
    630630    }
    631631
    632632    /**
    633      * Replies the length of the way, in metres, as computed by {@link LatLon#greatCircleDistance}.
     633     * Replies the length of the way, in metres, as computed by {@link ILatLon#greatCircleDistance}.
    634634     * @return The length of the way, in metres
    635635     * @since 4138
    636636     */
    public final class Way extends OsmPrimitive implements IWay<Node> {  
    638638        double length = 0;
    639639        Node lastN = null;
    640640        for (Node n:nodes) {
    641             if (lastN != null) {
    642                 LatLon lastNcoor = lastN.getCoor();
    643                 LatLon coor = n.getCoor();
    644                 if (lastNcoor != null && coor != null) {
    645                     length += coor.greatCircleDistance(lastNcoor);
    646                 }
     641            if (lastN != null && lastN.isLatLonKnown() && n.isLatLonKnown()) {
     642                length += n.greatCircleDistance(lastN);
    647643            }
    648644            lastN = n;
    649645        }
    public final class Way extends OsmPrimitive implements IWay<Node> {  
    651647    }
    652648
    653649    /**
    654      * Replies the length of the longest segment of the way, in metres, as computed by {@link LatLon#greatCircleDistance}.
     650     * Replies the length of the longest segment of the way, in metres, as computed by {@link ILatLon#greatCircleDistance}.
    655651     * @return The length of the segment, in metres
    656652     * @since 8320
    657653     */
    public final class Way extends OsmPrimitive implements IWay<Node> {  
    659655        double length = 0;
    660656        Node lastN = null;
    661657        for (Node n:nodes) {
    662             if (lastN != null) {
    663                 LatLon lastNcoor = lastN.getCoor();
    664                 LatLon coor = n.getCoor();
    665                 if (lastNcoor != null && coor != null) {
    666                     double l = coor.greatCircleDistance(lastNcoor);
    667                     if (l > length) {
    668                         length = l;
    669                     }
     658            if (lastN != null && lastN.isLatLonKnown() && n.isLatLonKnown()) {
     659                double l = n.greatCircleDistance(lastN);
     660                if (l > length) {
     661                    length = l;
    670662                }
    671663            }
    672664            lastN = n;
  • src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java

    diff --git a/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java b/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java
    index 0e6612d0d7..60da76e165 100644
    a b import java.util.regex.PatternSyntaxException;  
    2828import java.util.stream.Collectors;
    2929
    3030import org.openstreetmap.josm.data.Bounds;
    31 import org.openstreetmap.josm.data.coor.LatLon;
    3231import org.openstreetmap.josm.data.osm.Node;
    3332import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3433import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    public class SearchCompiler {  
    18081807            if (!osm.isUsable())
    18091808                return false;
    18101809            else if (osm instanceof Node) {
    1811                 LatLon coordinate = ((Node) osm).getCoor();
    18121810                Collection<Bounds> allBounds = getBounds(osm);
    1813                 return coordinate != null && allBounds != null && allBounds.stream().anyMatch(bounds -> bounds.contains(coordinate));
     1811                return ((Node) osm).isLatLonKnown() && allBounds != null && allBounds.stream().anyMatch(bounds -> bounds.contains((Node) osm));
    18141812            } else if (osm instanceof Way) {
    18151813                Collection<Node> nodes = ((Way) osm).getNodes();
    18161814                return all ? nodes.stream().allMatch(this) : nodes.stream().anyMatch(this);
  • src/org/openstreetmap/josm/data/validation/tests/Addresses.java

    diff --git a/src/org/openstreetmap/josm/data/validation/tests/Addresses.java b/src/org/openstreetmap/josm/data/validation/tests/Addresses.java
    index 11170dee89..98a3fbc25c 100644
    a b import java.util.stream.Stream;  
    2222import org.openstreetmap.josm.command.Command;
    2323import org.openstreetmap.josm.command.DeleteCommand;
    2424import org.openstreetmap.josm.data.coor.EastNorth;
     25import org.openstreetmap.josm.data.coor.ILatLon;
    2526import org.openstreetmap.josm.data.coor.LatLon;
    2627import org.openstreetmap.josm.data.osm.Node;
    2728import org.openstreetmap.josm.data.osm.OsmPrimitive;
    public class Addresses extends Test {  
    361362     * @return distance of center of bounding boxes in meters
    362363     */
    363364    static double getDistance(OsmPrimitive a, OsmPrimitive b) {
     365        if (a instanceof ILatLon && b instanceof ILatLon) {
     366            return ((ILatLon) a).greatCircleDistance((ILatLon) b);
     367        }
    364368        LatLon centerA = a.getBBox().getCenter();
    365369        LatLon centerB = b.getBBox().getCenter();
    366370        return centerA.greatCircleDistance(centerB);
  • src/org/openstreetmap/josm/data/validation/tests/LongSegment.java

    diff --git a/src/org/openstreetmap/josm/data/validation/tests/LongSegment.java b/src/org/openstreetmap/josm/data/validation/tests/LongSegment.java
    index cac2453184..d09f1a0f40 100644
    a b import java.util.Collections;  
    88import java.util.HashSet;
    99import java.util.Set;
    1010
    11 import org.openstreetmap.josm.data.coor.LatLon;
    1211import org.openstreetmap.josm.data.osm.Node;
    1312import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1413import org.openstreetmap.josm.data.osm.Way;
    public class LongSegment extends Test {  
    9190    }
    9291
    9392    private void visitWaySegment(Way w, int i) {
    94         LatLon coor1 = w.getNode(i).getCoor();
    95         LatLon coor2 = w.getNode(i + 1).getCoor();
     93        Node oneI = w.getNode(i);
     94        Node twoI = w.getNode(i + 1);
    9695
    97         if (coor1 != null && coor2 != null) {
    98             Double length = coor1.greatCircleDistance(coor2);
     96        if (oneI.isLatLonKnown() && twoI.isLatLonKnown()) {
     97            double length = oneI.greatCircleDistance(twoI);
    9998            if (length > maxlength) {
    10099                addErrorForSegment(new WaySegment(w, i), length / 1000.0);
    101100            }
  • src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java

    diff --git a/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java b/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
    index 007eba11bf..5665106a1a 100644
    a b public abstract class UnconnectedWays extends Test {  
    468468                Node uncon = visited.iterator().next();
    469469                LatLon cl = ProjectionRegistry.getProjection().eastNorth2latlon(calcClosest(uncon));
    470470                // calculate real detour length, closest point might be somewhere between n1 and n2
    471                 double detourLen = len + node.getCoor().greatCircleDistance(cl);
     471                double detourLen = len + node.greatCircleDistance(cl);
    472472                if (detourLen > maxLen)
    473473                    return false;
    474474                // see #17914: flag also nodes which are very close
    public abstract class UnconnectedWays extends Test {  
    500500                        final boolean containsN = visited.contains(next);
    501501                        visited.add(next);
    502502                        if (!containsN && isConnectedTo(next, visited,
    503                                 len + node.getCoor().greatCircleDistance(next.getCoor()), way)) {
     503                                len + node.greatCircleDistance(next), way)) {
    504504                            return true;
    505505                        }
    506506                    }
    public abstract class UnconnectedWays extends Test {  
    515515
    516516        double getDist(Node n) {
    517517            EastNorth closest = calcClosest(n);
    518             return n.getCoor().greatCircleDistance(ProjectionRegistry.getProjection().eastNorth2latlon(closest));
     518            return n.greatCircleDistance(ProjectionRegistry.getProjection().eastNorth2latlon(closest));
    519519        }
    520520
    521521        private boolean nearby(Node n, double dist) {
    public abstract class UnconnectedWays extends Test {  
    526526        }
    527527
    528528        private BBox getBounds(double fudge) {
    529             double x1 = n1.getCoor().lon();
    530             double x2 = n2.getCoor().lon();
     529            double x1 = n1.lon();
     530            double x2 = n2.lon();
    531531            if (x1 > x2) {
    532532                double tmpx = x1;
    533533                x1 = x2;
    534534                x2 = tmpx;
    535535            }
    536             double y1 = n1.getCoor().lat();
    537             double y2 = n2.getCoor().lat();
     536            double y1 = n1.lat();
     537            double y2 = n2.lat();
    538538            if (y1 > y2) {
    539539                double tmpy = y1;
    540540                y1 = y2;
  • src/org/openstreetmap/josm/gui/MapStatus.java

    diff --git a/src/org/openstreetmap/josm/gui/MapStatus.java b/src/org/openstreetmap/josm/gui/MapStatus.java
    index e7d71b7df8..83ba6364bc 100644
    a b import javax.swing.event.PopupMenuListener;  
    6161
    6262import org.openstreetmap.josm.data.SystemOfMeasurement;
    6363import org.openstreetmap.josm.data.SystemOfMeasurement.SoMChangeListener;
     64import org.openstreetmap.josm.data.coor.ILatLon;
    6465import org.openstreetmap.josm.data.coor.LatLon;
    6566import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager;
    6667import org.openstreetmap.josm.data.coor.conversion.DMSCoordinateFormat;
    import org.openstreetmap.josm.data.osm.DataSelectionListener;  
    7071import org.openstreetmap.josm.data.osm.DataSet;
    7172import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    7273import org.openstreetmap.josm.data.osm.IPrimitive;
    73 import org.openstreetmap.josm.data.osm.Node;
    7474import org.openstreetmap.josm.data.osm.OsmPrimitive;
    7575import org.openstreetmap.josm.data.osm.Way;
    7676import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
    public final class MapStatus extends JPanel implements  
    12201220            OsmPrimitive n1 = it.next();
    12211221            OsmPrimitive n2 = it.next();
    12221222            // show distance between two selected nodes with coordinates
    1223             if (n1 instanceof Node && n2 instanceof Node) {
    1224                 LatLon c1 = ((Node) n1).getCoor();
    1225                 LatLon c2 = ((Node) n2).getCoor();
    1226                 if (c1 != null && c2 != null) {
    1227                     setDist(c1.greatCircleDistance(c2));
    1228                     return;
    1229                 }
     1223            if (n1 instanceof ILatLon && n2 instanceof ILatLon && ((ILatLon) n1).isLatLonKnown() && ((ILatLon) n2).isLatLonKnown()) {
     1224                setDist(((ILatLon) n1).greatCircleDistance((ILatLon) n2));
     1225                return;
    12301226            }
    12311227        }
    12321228        setDist(new SubclassFilteredCollection<OsmPrimitive, Way>(newSelection, Way.class::isInstance));
  • src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

    diff --git a/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java b/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
    index 60292441a8..c2854f9a7c 100644
    a b public class GpxDrawHelper implements SoMChangeListener, MapViewPaintable.LayerP  
    566566                            continue;
    567567                        }
    568568                        if (oldWp != null && trkPnt.getTimeInMillis() > oldWp.getTimeInMillis()) {
    569                             double vel = trkPnt.getCoor().greatCircleDistance(oldWp.getCoor())
     569                            double vel = trkPnt.greatCircleDistance(oldWp)
    570570                                    / (trkPnt.getTime() - oldWp.getTime());
    571571                            velocities.add(vel);
    572572                        }
    public class GpxDrawHelper implements SoMChangeListener, MapViewPaintable.LayerP  
    623623                oldWp = null;
    624624            }
    625625            for (WayPoint trkPnt : segment) {
    626                 LatLon c = trkPnt.getCoor();
    627626                trkPnt.customColoring = segment.getColor();
    628                 if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) {
     627                if (Double.isNaN(trkPnt.lat()) || Double.isNaN(trkPnt.lon())) {
    629628                    continue;
    630629                }
    631630                // now we are sure some color will be assigned
    public class GpxDrawHelper implements SoMChangeListener, MapViewPaintable.LayerP  
    645644                    }
    646645                }
    647646                if (oldWp != null) { // other coloring modes need segment for calcuation
    648                     double dist = c.greatCircleDistance(oldWp.getCoor());
     647                    double dist = trkPnt.greatCircleDistance(oldWp);
    649648                    boolean noDraw = false;
    650649                    switch (colored) {
    651650                    case VELOCITY:
    public class GpxDrawHelper implements SoMChangeListener, MapViewPaintable.LayerP  
    657656                        }
    658657                        break;
    659658                    case DIRECTION:
    660                         double dirColor = oldWp.getCoor().bearing(trkPnt.getCoor());
     659                        double dirColor = oldWp.bearing(trkPnt);
    661660                        color = directionScale.getColor(dirColor);
    662661                        break;
    663662                    case TIME:
    public class GpxDrawHelper implements SoMChangeListener, MapViewPaintable.LayerP  
    673672                    }
    674673                    if (!noDraw && (!segment.isUnordered() || !data.fromServer) && (maxLineLength == -1 || dist <= maxLineLength)) {
    675674                        trkPnt.drawLine = true;
    676                         double bearing = oldWp.getCoor().bearing(trkPnt.getCoor());
     675                        double bearing = oldWp.bearing(trkPnt);
    677676                        trkPnt.dir = ((int) (bearing / Math.PI * 4 + 1.5)) % 8;
    678677                    } else {
    679678                        trkPnt.drawLine = false;
  • src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java

    diff --git a/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java b/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java
    index 632e9db390..e05361a7d7 100644
    a b public class AddNodeHandler extends RequestHandler {  
    9191            MapView mapView = MainApplication.getMap().mapView;
    9292            Point p = mapView.getPoint(ll);
    9393            node = mapView.getNearestNode(p, OsmPrimitive::isUsable);
    94             if (node != null && node.getCoor().greatCircleDistance(ll) > Config.getPref().getDouble("remotecontrol.tolerance", 0.1)) {
     94            if (node != null && node.greatCircleDistance(ll) > Config.getPref().getDouble("remotecontrol.tolerance", 0.1)) {
    9595                node = null; // node is too far
    9696            }
    9797        }
  • src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java

    diff --git a/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java b/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java
    index f2b54f02d9..dbd27e0e91 100644
    a b public class AddWayHandler extends RequestHandler {  
    128128        if (MainApplication.isDisplayingMapView()) {
    129129            MapView mapView = MainApplication.getMap().mapView;
    130130            nd = mapView.getNearestNode(mapView.getPoint(ll), OsmPrimitive::isUsable);
    131             if (nd != null && nd.getCoor().greatCircleDistance(ll) > Config.getPref().getDouble("remote.tolerance", 0.1)) {
     131            if (nd != null && nd.greatCircleDistance(ll) > Config.getPref().getDouble("remote.tolerance", 0.1)) {
    132132                nd = null; // node is too far
    133133            }
    134134        }
  • src/org/openstreetmap/josm/tools/Geometry.java

    diff --git a/src/org/openstreetmap/josm/tools/Geometry.java b/src/org/openstreetmap/josm/tools/Geometry.java
    index 6eca937e72..ad7eeb5016 100644
    a b public final class Geometry {  
    14001400        double rValue = Double.MAX_VALUE;
    14011401        if (one == null || two == null || one.isIncomplete()
    14021402                || two.isIncomplete()) return Double.NaN;
    1403         if (one instanceof Node && two instanceof Node) {
    1404             rValue = ((Node) one).getCoor().greatCircleDistance(((Node) two).getCoor());
     1403        if (one instanceof ILatLon && two instanceof ILatLon) {
     1404            rValue = ((ILatLon) one).greatCircleDistance(((ILatLon) two));
    14051405        } else if (one instanceof Node && two instanceof Way) {
    14061406            rValue = getDistanceWayNode((Way) two, (Node) one);
    14071407        } else if (one instanceof Way && two instanceof Node) {