Changeset 18494 in josm for trunk


Ignore:
Timestamp:
2022-06-15T19:27:05+02:00 (2 years ago)
Author:
taylor.smock
Message:

Fix #22115: Extract methods from LatLon into ILatLon where they are generally applicable

This also removes calls to Node#getCoor where possible, which reduces
the number of memory allocations in SearchCompiler#match, and overall
allocations due to Node#getCoor

Location:
trunk
Files:
37 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java

    r17188 r18494  
    7575            ds.setSelected(nnew);
    7676            MapView mapView = MainApplication.getMap().mapView;
    77             if (mapView != null && !mapView.getRealBounds().contains(nnew.getCoor())) {
     77            if (mapView != null && !mapView.getRealBounds().contains(nnew)) {
    7878                AutoScaleAction.zoomTo(Collections.<OsmPrimitive>singleton(nnew));
    7979            }
  • trunk/src/org/openstreetmap/josm/actions/CopyCoordinatesAction.java

    r17036 r18494  
    4040        ICoordinateFormat coordinateFormat = CoordinateFormatManager.getDefaultFormat();
    4141        String string = getSelectedNodes().stream()
    42                 .map(Node::getCoor)
    4342                .filter(Objects::nonNull)
    4443                .map(c -> coordinateFormat.toString(c, ", "))
  • trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java

    r18217 r18494  
    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));
  • trunk/src/org/openstreetmap/josm/actions/DownloadAlongAction.java

    r17419 r18494  
    2323
    2424import org.openstreetmap.josm.actions.downloadtasks.DownloadTaskList;
     25import org.openstreetmap.josm.data.coor.ILatLon;
    2526import org.openstreetmap.josm.data.coor.LatLon;
    2627import org.openstreetmap.josm.data.osm.DataSet;
     
    161162        ArrayList<LatLon> intermediateNodes = new ArrayList<>();
    162163        intermediateNodes.add(p2);
    163         if (p1 != null && p2.greatCircleDistance(p1) > bufferDist) {
    164             double d = p2.greatCircleDistance(p1) / bufferDist;
     164        if (p1 != null && p2.greatCircleDistance((ILatLon) p1) > bufferDist) {
     165            double d = p2.greatCircleDistance((ILatLon) p1) / bufferDist;
    165166            int nbNodes = (int) d;
    166167            if (Logging.isDebugEnabled()) {
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawSnapHelper.java

    r17632 r18494  
    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
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    r18332 r18494  
    3838import org.openstreetmap.josm.data.UndoRedoHandler;
    3939import org.openstreetmap.josm.data.coor.EastNorth;
     40import org.openstreetmap.josm.data.coor.ILatLon;
    4041import org.openstreetmap.josm.data.osm.DataIntegrityProblemException;
    4142import org.openstreetmap.josm.data.osm.DataSet;
     
    938939        // find out the movement distance, in metres
    939940        double distance = ProjectionRegistry.getProjection().eastNorth2latlon(initialN1en).greatCircleDistance(
    940                 ProjectionRegistry.getProjection().eastNorth2latlon(n1movedEn));
     941                (ILatLon) ProjectionRegistry.getProjection().eastNorth2latlon(n1movedEn));
    941942        MainApplication.getMap().statusLine.setDist(distance);
    942943        updateStatusLine();
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java

    r18129 r18494  
    2828import org.openstreetmap.josm.data.SystemOfMeasurement;
    2929import org.openstreetmap.josm.data.coor.EastNorth;
     30import org.openstreetmap.josm.data.coor.ILatLon;
    3031import org.openstreetmap.josm.data.osm.Node;
    3132import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    392393        // Note: d is the distance in _projected units_
    393394        double d = enp.distance(nearestPointOnRefLine);
    394         double realD = mv.getProjection().eastNorth2latlon(enp).greatCircleDistance(mv.getProjection().eastNorth2latlon(nearestPointOnRefLine));
     395        double realD = mv.getProjection().eastNorth2latlon(enp).greatCircleDistance(
     396                (ILatLon) mv.getProjection().eastNorth2latlon(nearestPointOnRefLine));
    395397        double snappedRealD = realD;
    396398
  • trunk/src/org/openstreetmap/josm/command/MoveCommand.java

    r17093 r18494  
    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;
     
    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    }
  • trunk/src/org/openstreetmap/josm/data/coor/ILatLon.java

    r18464 r18494  
    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/**
     
    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}
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r18464 r18494  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.coor;
    3 
    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;
    123
    134import java.awt.geom.Area;
     
    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
     
    229219     * @param other the other point.
    230220     * @return distance in metres.
    231      */
     221     * @deprecated since xxx (use {@link ILatLon#greatCircleDistance(ILatLon)} instead)
     222     */
     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
     
    260240     * @return heading in radians in the range 0 &lt;= hd &lt; 2*PI
    261241     * @since 9796
    262      */
     242     * @deprecated since xxx (use {@link ILatLon#bearing(ILatLon)} instead)
     243     */
     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
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxImageCorrelation.java

    r18243 r18494  
    77import java.util.concurrent.TimeUnit;
    88
     9import org.openstreetmap.josm.data.coor.ILatLon;
    910import org.openstreetmap.josm.data.coor.LatLon;
    1011import org.openstreetmap.josm.data.projection.Projection;
     
    9293                            List<Pair<Double, WayPoint>> nextWps = new ArrayList<>();
    9394                            for (int j = i; j < size; j++) {
    94                                 totalDist += wps.get(j - 1).getCoor().greatCircleDistance(wps.get(j).getCoor());
     95                                totalDist += wps.get(j - 1).greatCircleDistance(wps.get(j));
    9596                                nextWps.add(new Pair<>(totalDist, wps.get(j)));
    9697                                if (wps.get(j).hasDate()) {
     
    121122                            if (!trkInt || isFirst || prevWp == null ||
    122123                                    Math.abs(curWpTime - prevWpTime) > TimeUnit.MINUTES.toMillis(trkTime) ||
    123                                     prevWp.getCoor().greatCircleDistance(curWp.getCoor()) > trkDist) {
     124                                    prevWp.greatCircleDistance(curWp) > trkDist) {
    124125                                isFirst = false;
    125126                                interpolate = false;
     
    132133                            if (!segInt || prevWp == null ||
    133134                                    Math.abs(curWpTime - prevWpTime) > TimeUnit.MINUTES.toMillis(segTime) ||
    134                                     prevWp.getCoor().greatCircleDistance(curWp.getCoor()) > segDist) {
     135                                    prevWp.greatCircleDistance(curWp) > segDist) {
    135136                                interpolate = false;
    136137                                if (segTag) {
     
    238239
    239240        if (prevWp != null && interpolate) {
    240             double distance = prevWp.getCoor().greatCircleDistance(curWp.getCoor());
     241            double distance = prevWp.greatCircleDistance(curWp);
    241242            // This is in km/h, 3.6 * m/s
    242243            if (curWpTime > prevWpTime) {
     
    267268                    }
    268269                    if (nextWp != null && dirpos.isSetImageDirection()) {
    269                         double direction = curWp.getCoor().bearing(nextWp.getCoor());
     270                        double direction = curWp.bearing(nextWp);
    270271                        curTmp.setExifImgDir(computeDirection(direction, dirpos.getImageDirectionAngleOffset()));
    271272                    }
     
    298299                    LatLon position = prevCoor.interpolate(curCoor, timeDiff);
    299300                    if (nextCoorForDirection != null && (shiftXY || dirpos.isSetImageDirection())) {
    300                         double direction = position.bearing(nextCoorForDirection);
     301                        double direction = position.bearing((ILatLon) nextCoorForDirection);
    301302                        if (dirpos.isSetImageDirection()) {
    302303                            curTmp.setExifImgDir(computeDirection(direction, dirpos.getImageDirectionAngleOffset()));
     
    307308                            final double offsetY = dirpos.getShiftImageY();
    308309                            final double r = Math.sqrt(offsetX * offsetX + offsetY * offsetY);
    309                             final double orientation = (direction + LatLon.ZERO.bearing(new LatLon(offsetX, offsetY))) % (2 * Math.PI);
     310                            final double orientation = (direction + LatLon.ZERO.bearing((ILatLon) new LatLon(offsetX, offsetY))) % (2 * Math.PI);
    310311                            position = proj.eastNorth2latlon(proj.latlon2eastNorth(position)
    311312                                    .add(r * Math.sin(orientation), r * Math.cos(orientation)));
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxTrackSegment.java

    r16488 r18494  
    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;
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r18464 r18494  
    373373     */
    374374    public boolean isOutSideWorld() {
    375         LatLon ll = getCoor();
    376         if (ll != null) {
     375        if (this.isLatLonKnown()) {
    377376            Bounds b = ProjectionRegistry.getProjection().getWorldBoundsLatLon();
    378377            if (lat() < b.getMinLat() || lat() > b.getMaxLat() || lon() < b.getMinLon() || lon() > b.getMaxLon()) {
    379378                return true;
    380379            }
    381             if (!ProjectionRegistry.getProjection().latlon2eastNorth(ll).equalsEpsilon(getEastNorth(), 1.0)) {
     380            if (!ProjectionRegistry.getProjection().latlon2eastNorth(this).equalsEpsilon(getEastNorth(), 1.0)) {
    382381                // we get here if a node was moved or created left from -180 or right from +180
    383382                return true;
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r18470 r18494  
    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;
     
    632632
    633633    /**
    634      * Replies the length of the way, in metres, as computed by {@link LatLon#greatCircleDistance}.
     634     * Replies the length of the way, in metres, as computed by {@link ILatLon#greatCircleDistance}.
    635635     * @return The length of the way, in metres
    636636     * @since 4138
     
    640640        Node lastN = null;
    641641        for (Node n:nodes) {
    642             if (lastN != null) {
    643                 LatLon lastNcoor = lastN.getCoor();
    644                 LatLon coor = n.getCoor();
    645                 if (lastNcoor != null && coor != null) {
    646                     length += coor.greatCircleDistance(lastNcoor);
    647                 }
     642            if (lastN != null && lastN.isLatLonKnown() && n.isLatLonKnown()) {
     643                length += n.greatCircleDistance(lastN);
    648644            }
    649645            lastN = n;
     
    653649
    654650    /**
    655      * Replies the length of the longest segment of the way, in metres, as computed by {@link LatLon#greatCircleDistance}.
     651     * Replies the length of the longest segment of the way, in metres, as computed by {@link ILatLon#greatCircleDistance}.
    656652     * @return The length of the segment, in metres
    657653     * @since 8320
     
    661657        Node lastN = null;
    662658        for (Node n:nodes) {
    663             if (lastN != null) {
    664                 LatLon lastNcoor = lastN.getCoor();
    665                 LatLon coor = n.getCoor();
    666                 if (lastNcoor != null && coor != null) {
    667                     double l = coor.greatCircleDistance(lastNcoor);
    668                     if (l > length) {
    669                         length = l;
    670                     }
     659            if (lastN != null && lastN.isLatLonKnown() && n.isLatLonKnown()) {
     660                double l = n.greatCircleDistance(lastN);
     661                if (l > length) {
     662                    length = l;
    671663                }
    672664            }
  • trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java

    r18291 r18494  
    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;
     
    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();
  • trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java

    r16643 r18494  
    1919import org.openstreetmap.josm.data.ProjectionBounds;
    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.coor.conversion.LatLonParser;
     
    808809                        // project back and check if the result is somewhat reasonable
    809810                        LatLon llBack = eastNorth2latlon(enPole);
    810                         if (llBack.isValid() && ll.greatCircleDistance(llBack) < 1000) {
     811                        if (llBack.isValid() && ll.greatCircleDistance((ILatLon) llBack) < 1000) {
    811812                            polesEN.put(p, enPole);
    812813                        }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Addresses.java

    r18332 r18494  
    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;
     
    362363     */
    363364    static double getDistance(OsmPrimitive a, OsmPrimitive b) {
    364         LatLon centerA = a.getBBox().getCenter();
    365         LatLon centerB = b.getBBox().getCenter();
     365        if (a instanceof ILatLon && b instanceof ILatLon) {
     366            return ((ILatLon) a).greatCircleDistance((ILatLon) b);
     367        }
     368        ILatLon centerA = a.getBBox().getCenter();
     369        ILatLon centerB = b.getBBox().getCenter();
    366370        return centerA.greatCircleDistance(centerB);
    367371    }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/LongSegment.java

    r17896 r18494  
    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;
     
    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);
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java

    r18272 r18494  
    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;
     
    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                        }
     
    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
     
    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;
     
    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;
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r18211 r18494  
    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;
     
    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;
     
    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        }
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r18211 r18494  
    399399        int w = getWidth()/2;
    400400        int h = getHeight()/2;
    401         LatLon ll1 = getLatLon(w-50, h);
    402         LatLon ll2 = getLatLon(w+50, h);
     401        ILatLon ll1 = getLatLon(w-50, h);
     402        ILatLon ll2 = getLatLon(w+50, h);
    403403        double gcd = ll1.greatCircleDistance(ll2);
    404404        if (alwaysPositive && gcd <= 0)
     
    649649        LatLon ll2 = getLatLon(width / 2 + 50, height / 2);
    650650        if (ll1.isValid() && ll2.isValid() && b.contains(ll1) && b.contains(ll2)) {
    651             double dm = ll1.greatCircleDistance(ll2);
     651            double dm = ll1.greatCircleDistance((ILatLon) ll2);
    652652            double den = 100 * getScale();
    653653            double scaleMin = 0.01 * den / dm / 100;
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java

    r17333 r18494  
    2929import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    3030import org.openstreetmap.josm.data.Bounds;
     31import org.openstreetmap.josm.data.coor.ILatLon;
    3132import org.openstreetmap.josm.data.coor.LatLon;
    3233import org.openstreetmap.josm.data.osm.BBox;
     
    168169        ICoordinate c1 = getPosition(w - 50, h);
    169170        ICoordinate c2 = getPosition(w + 50, h);
    170         final LatLon ll1 = new LatLon(c1.getLat(), c1.getLon());
    171         final LatLon ll2 = new LatLon(c2.getLat(), c2.getLon());
     171        final ILatLon ll1 = new LatLon(c1.getLat(), c1.getLon());
     172        final ILatLon ll2 = new LatLon(c2.getLat(), c2.getLon());
    172173        double gcd = ll1.greatCircleDistance(ll2);
    173174        return gcd <= 0 ? 0.1 : gcd;
  • trunk/src/org/openstreetmap/josm/gui/history/CoordinateInfoViewer.java

    r17684 r18494  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.history;
     3
    34import static org.openstreetmap.josm.tools.I18n.tr;
    45
     
    2425import org.openstreetmap.josm.command.MoveCommand;
    2526import org.openstreetmap.josm.data.UndoRedoHandler;
     27import org.openstreetmap.josm.data.coor.ILatLon;
    2628import org.openstreetmap.josm.data.coor.LatLon;
    2729import org.openstreetmap.josm.data.coor.conversion.DecimalDegreesCoordinateFormat;
     
    408410            final Pair<LatLon, LatLon> coordinates = updater.getCoordinates();
    409411            if (coordinates == null) return;
    410             final LatLon coord = coordinates.a;
    411             final LatLon oppositeCoord = coordinates.b;
     412            final ILatLon coord = coordinates.a;
     413            final ILatLon oppositeCoord = coordinates.b;
    412414
    413415            // update distance
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

    r18396 r18494  
    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);
     
    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                }
     
    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) {
     
    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;
     
    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 {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java

    r18366 r18494  
    2727import org.openstreetmap.josm.data.ProjectionBounds;
    2828import org.openstreetmap.josm.data.coor.EastNorth;
     29import org.openstreetmap.josm.data.coor.ILatLon;
    2930import org.openstreetmap.josm.data.coor.LatLon;
    3031import org.openstreetmap.josm.data.coor.conversion.LatLonParser;
     
    491492                    EastNorth projAnchorShifted = projAnchor.add(shiftMeter / proj.getMetersPerUnit(),
    492493                            shiftMeter / proj.getMetersPerUnit());
    493                     LatLon anchorShifted = proj.eastNorth2latlon(projAnchorShifted);
     494                    ILatLon anchorShifted = proj.eastNorth2latlon(projAnchorShifted);
    494495                    return projAnchor.distance(projAnchorShifted) / argAnchor.greatCircleDistance(anchorShifted);
    495496                };
     
    559560            if (argScale != null) {
    560561                double enPerMeter = pb.getMin().distance(pb.getMax())
    561                         / bounds.getMin().greatCircleDistance(bounds.getMax());
     562                        / bounds.getMin().greatCircleDistance((ILatLon) bounds.getMax());
    562563                scale = argScale * enPerMeter / PIXEL_PER_METER;
    563564            } else if (argWidthPx != null) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r18275 r18494  
    546546            } else if (ChildOrParentSelectorType.SUPERSET_OR_EQUAL == type || ChildOrParentSelectorType.NOT_SUPERSET_OR_EQUAL == type) {
    547547
    548                 if (e.osm.getDataSet() == null || (e.osm instanceof INode && ((INode) e.osm).getCoor() == null)
     548                if (e.osm.getDataSet() == null || (e.osm instanceof INode && !((INode) e.osm).isLatLonKnown())
    549549                        || (!(e.osm instanceof INode) && !isArea(e.osm))) {
    550550                    return ChildOrParentSelectorType.NOT_SUPERSET_OR_EQUAL == type;
  • trunk/src/org/openstreetmap/josm/io/GeoJSONWriter.java

    r18365 r18494  
    3333import org.openstreetmap.josm.data.Bounds;
    3434import org.openstreetmap.josm.data.coor.EastNorth;
     35import org.openstreetmap.josm.data.coor.ILatLon;
    3536import org.openstreetmap.josm.data.coor.LatLon;
    3637import org.openstreetmap.josm.data.osm.DataSet;
     
    240241            final JsonArrayBuilder multiPoint = Json.createArrayBuilder();
    241242            r.getMembers().stream().map(RelationMember::getMember).filter(Node.class::isInstance).map(Node.class::cast)
    242                     .map(Node::getCoor).map(latLon -> getCoorArray(null, latLon))
     243                    .map(latLon -> getCoorArray(null, latLon))
    243244                    .forEach(multiPoint::add);
    244245            geomObj.add("type", "MultiPoint");
     
    255256                    .map(Way::getNodes).map(p -> {
    256257                JsonArrayBuilder array = getCoorsArray(p);
    257                 LatLon ll = p.get(0).getCoor();
     258                ILatLon ll = p.get(0);
    258259                // since first node is not duplicated as last node
    259                 return ll != null ? array.add(getCoorArray(null, ll)) : array;
     260                return ll.isLatLonKnown() ? array.add(getCoorArray(null, ll)) : array;
    260261            }).forEach(multiLine::add);
    261262            geomObj.add("type", "MultiLineString");
     
    297298                        .map(p -> {
    298299                            JsonArrayBuilder array = getCoorsArray(p);
    299                             LatLon ll = p.get(0).getCoor();
     300                            ILatLon ll = p.get(0);
    300301                            // since first node is not duplicated as last node
    301                             return ll != null ? array.add(getCoorArray(null, ll)) : array;
     302                            return ll.isLatLonKnown() ? array.add(getCoorArray(null, ll)) : array;
    302303                        })
    303304                        .forEach(polygon::add);
     
    311312            final JsonArrayBuilder builder = Json.createArrayBuilder();
    312313            for (Node n : nodes) {
    313                 LatLon ll = n.getCoor();
    314                 if (ll != null) {
    315                     builder.add(getCoorArray(null, ll));
     314                if (n.isLatLonKnown()) {
     315                    builder.add(getCoorArray(null, n));
    316316                }
    317317            }
     
    320320    }
    321321
    322     private JsonArrayBuilder getCoorArray(JsonArrayBuilder builder, LatLon c) {
     322    private JsonArrayBuilder getCoorArray(JsonArrayBuilder builder, ILatLon c) {
    323323        return getCoorArray(builder, projection.latlon2eastNorth(c));
    324324    }
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java

    r18134 r18494  
    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            }
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java

    r18134 r18494  
    1919import org.openstreetmap.josm.command.SequenceCommand;
    2020import org.openstreetmap.josm.data.UndoRedoHandler;
     21import org.openstreetmap.josm.data.coor.ILatLon;
    2122import org.openstreetmap.josm.data.coor.LatLon;
    2223import org.openstreetmap.josm.data.osm.DataSet;
     
    129130            MapView mapView = MainApplication.getMap().mapView;
    130131            nd = mapView.getNearestNode(mapView.getPoint(ll), OsmPrimitive::isUsable);
    131             if (nd != null && nd.getCoor().greatCircleDistance(ll) > Config.getPref().getDouble("remote.tolerance", 0.1)) {
     132            if (nd != null && nd.greatCircleDistance(ll) > Config.getPref().getDouble("remote.tolerance", 0.1)) {
    132133                nd = null; // node is too far
    133134            }
     
    136137        Node prev = null;
    137138        for (Entry<LatLon, Node> entry : addedNodes.entrySet()) {
    138             LatLon lOld = entry.getKey();
     139            ILatLon lOld = entry.getKey();
    139140            if (lOld.greatCircleDistance(ll) < Config.getPref().getDouble("remotecontrol.tolerance", 0.1)) {
    140141                prev = entry.getValue();
  • trunk/src/org/openstreetmap/josm/io/session/SessionReader.java

    r18466 r18494  
    3737import org.openstreetmap.josm.data.ViewportData;
    3838import org.openstreetmap.josm.data.coor.EastNorth;
     39import org.openstreetmap.josm.data.coor.ILatLon;
    3940import org.openstreetmap.josm.data.coor.LatLon;
    4041import org.openstreetmap.josm.data.projection.Projection;
     
    144145            // not too small to avoid rounding errors.
    145146            double dist = 0.01 * proj.getDefaultZoomInPPD();
    146             LatLon ll1 = proj.eastNorth2latlon(new EastNorth(centerEN.east() - dist, centerEN.north()));
    147             LatLon ll2 = proj.eastNorth2latlon(new EastNorth(centerEN.east() + dist, centerEN.north()));
     147            ILatLon ll1 = proj.eastNorth2latlon(new EastNorth(centerEN.east() - dist, centerEN.north()));
     148            ILatLon ll2 = proj.eastNorth2latlon(new EastNorth(centerEN.east() + dist, centerEN.north()));
    148149            double meterPerEasting = ll1.greatCircleDistance(ll2) / dist / 2;
    149150            double scale = meterPerPixel / meterPerEasting; // unit: easting per pixel
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r18109 r18494  
    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);
  • trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCacheManagerTest.java

    r18037 r18494  
    99import java.util.logging.Logger;
    1010
    11 import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    12 
    13 import net.trajano.commons.testing.UtilityClassTestUtil;
    1411import org.apache.commons.jcs3.access.CacheAccess;
    1512import org.apache.commons.jcs3.auxiliary.disk.block.BlockDiskCacheAttributes;
    1613import org.junit.jupiter.api.Test;
    1714import org.junit.jupiter.api.Timeout;
     15import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     16
     17import net.trajano.commons.testing.UtilityClassTestUtil;
    1818
    1919/**
     
    5959            CacheAccess<Object, Object> cache = JCSCacheManager.getCache("testUseBigDiskFile", 1, 100, "foobar");
    6060            assertEquals(10*1024,
    61                     ((BlockDiskCacheAttributes) cache.getCacheControl().getAuxCaches()[0].getAuxiliaryCacheAttributes()).getMaxKeySize(),
     61                    ((BlockDiskCacheAttributes) cache.getCacheControl().getAuxCacheList().get(0).getAuxiliaryCacheAttributes()).getMaxKeySize(),
    6262                    "BlockDiskCache use file size to calculate its size");
    6363        }
  • trunk/test/unit/org/openstreetmap/josm/data/coor/LatLonTest.java

    r17275 r18494  
    170170    @Test
    171171    void testBearing() {
    172         LatLon c = new LatLon(47.000000, 19.000000);
    173         LatLon e = new LatLon(47.000000, 19.000001);
    174         LatLon n = new LatLon(47.000001, 19.000000);
     172        ILatLon c = new LatLon(47.000000, 19.000000);
     173        ILatLon e = new LatLon(47.000000, 19.000001);
     174        ILatLon n = new LatLon(47.000001, 19.000000);
    175175        assertEquals(0, Math.toDegrees(c.bearing(n)), EPSILON);
    176176        assertEquals(90, Math.toDegrees(c.bearing(e)), EPSILON);
  • trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxDataTest.java

    r18287 r18494  
    2626import org.openstreetmap.josm.data.DataSource;
    2727import org.openstreetmap.josm.data.coor.EastNorth;
     28import org.openstreetmap.josm.data.coor.ILatLon;
    2829import org.openstreetmap.josm.data.coor.LatLon;
    2930import org.openstreetmap.josm.data.gpx.GpxData.GpxDataChangeEvent;
     
    322323        data.addTrack(track1);
    323324        data.addTrack(track2);
    324         assertEquals(3 * new LatLon(0, 0).greatCircleDistance(new LatLon(1, 1)), data.length(), 1);
     325        assertEquals(3 * new LatLon(0, 0).greatCircleDistance((ILatLon) new LatLon(1, 1)), data.length(), 1);
    325326    }
    326327
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionTest.java

    r17275 r18494  
    1414import org.openstreetmap.josm.data.Bounds;
    1515import org.openstreetmap.josm.data.coor.EastNorth;
     16import org.openstreetmap.josm.data.coor.ILatLon;
    1617import org.openstreetmap.josm.data.coor.LatLon;
    1718
     
    171172            LatLon ll2 = p.eastNorth2latlon(en);
    172173            assertTrue(ll2.isValid(), p.toCode() + " at " + ll1 + " is " + ll2);
    173             double dist = ll1.greatCircleDistance(ll2);
     174            double dist = ll1.greatCircleDistance((ILatLon) ll2);
    174175            if (dist > eps) {
    175176                error2 = true;
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/RenderingCLIAreaTest.java

    r17276 r18494  
    1616import org.junit.jupiter.params.provider.MethodSource;
    1717import org.openstreetmap.josm.data.Bounds;
     18import org.openstreetmap.josm.data.coor.ILatLon;
    1819import org.openstreetmap.josm.data.coor.LatLon;
    1920import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    6465                CoreMatchers.is(bFeldberg)});
    6566
    66         LatLon aFeldberg = bFeldberg.getMin();
    67         LatLon aFeldberg200mRight = new LatLon(aFeldberg.lat(), 13.433008399004041);
    68         LatLon aFeldberg150mUp = new LatLon(53.33134745249311, aFeldberg.lon());
     67        ILatLon aFeldberg = bFeldberg.getMin();
     68        ILatLon aFeldberg200mRight = new LatLon(aFeldberg.lat(), 13.433008399004041);
     69        ILatLon aFeldberg150mUp = new LatLon(53.33134745249311, aFeldberg.lon());
    6970        assertThat(aFeldberg.greatCircleDistance(aFeldberg200mRight), isFP(200.0, 0.01));
    7071        assertThat(aFeldberg.greatCircleDistance(aFeldberg150mUp), isFP(150.0, 0.01));
     
    142143    }
    143144
    144     private static String param(LatLon ll) {
     145    private static String param(ILatLon ll) {
    145146        return ll.lon() + "," + ll.lat();
    146147    }
  • trunk/test/unit/org/openstreetmap/josm/tools/GeometryTest.java

    r18109 r18494  
    2424import org.openstreetmap.josm.TestUtils;
    2525import org.openstreetmap.josm.data.coor.EastNorth;
     26import org.openstreetmap.josm.data.coor.ILatLon;
    2627import org.openstreetmap.josm.data.coor.LatLon;
    2728import org.openstreetmap.josm.data.osm.DataSet;
     
    503504        ProjectionRegistry.setProjection(projection);
    504505        final double offset = offsetInMeters / projection.getMetersPerUnit();
    505         final LatLon original = new LatLon(lat, lon);
    506 
    507         final LatLon actual = (LatLon) Geometry.getLatLonFrom(original, Math.toRadians(angle), offset);
     506        final ILatLon original = new LatLon(lat, lon);
     507
     508        final ILatLon actual = Geometry.getLatLonFrom(original, Math.toRadians(angle), offset);
    508509        // Due to degree -> radian -> degree conversion, there is a limit to how precise it can be
    509510        assertEquals(offsetInMeters, original.greatCircleDistance(actual), 0.000_000_1);
Note: See TracChangeset for help on using the changeset viewer.