Ticket #6598: wrong-offset-display-parallel-way-mode.patch

File wrong-offset-display-parallel-way-mode.patch, 2.4 KB (added by olejorgenb, 10 years ago)
  • src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java

    diff --git a/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java b/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java
    index 9ba8be6..964df7c 100644
    a b public class ParallelWayAction extends MapMode implements AWTEventListener, MapV 
    404404        EastNorth nearestPointOnRefLine = Geometry.closestPointToLine(referenceSegment.getFirstNode().getEastNorth(),
    405405                referenceSegment.getSecondNode().getEastNorth(), enp);
    406406
     407        // Note: d is the distance in _projected units_
    407408        double d = enp.distance(nearestPointOnRefLine);
     409        double realD = mv.getProjection().eastNorth2latlon(enp).greatCircleDistance(mv.getProjection().eastNorth2latlon(nearestPointOnRefLine));
     410        double snappedRealD = realD;
     411       
    408412        // TODO: abuse of isToTheRightSideOfLine function.
    409413        boolean toTheRight = Geometry.isToTheRightSideOfLine(referenceSegment.getFirstNode(),
    410414                referenceSegment.getFirstNode(), referenceSegment.getSecondNode(), new Node(enp));
    public class ParallelWayAction extends MapMode implements AWTEventListener, MapV 
    412416        if (snap) {
    413417            // TODO: Very simple snapping
    414418            // - Snap steps and/or threshold relative to the distance?
    415             long closestWholeUnit = Math.round(d);
    416             if (Math.abs(closestWholeUnit - d) < snapThreshold) {
    417                 d = closestWholeUnit;
     419            long closestWholeUnit = Math.round(realD);
     420            if (Math.abs(closestWholeUnit - realD) < snapThreshold) {
     421                snappedRealD = closestWholeUnit;
    418422            } else {
    419                 d = closestWholeUnit + Math.signum(closestWholeUnit - d) * -0.5;
     423                snappedRealD = closestWholeUnit + Math.signum(closestWholeUnit - realD) * -0.5;
    420424            }
    421425        }
     426        d = snappedRealD * (d/realD); // convert back to projected distance. (probably ok on small scales)
    422427        helperLineStart = nearestPointOnRefLine;
    423428        helperLineEnd = enp;
    424429        if (toTheRight) {
    425430            d = -d;
    426431        }
    427432        pWays.changeOffset(d);
    428 
    429         Main.map.statusLine.setDist(Math.abs(d));
     433       
     434        Main.map.statusLine.setDist(Math.abs(snappedRealD));
    430435        Main.map.statusLine.repaint();
    431436        mv.repaint();
    432437    }