Changeset 14960 in josm


Ignore:
Timestamp:
2019-04-04T11:34:48+02:00 (6 years ago)
Author:
GerdP
Message:

see #13538:

  • Add new method isOutSideWorld() to class Node and use the method where LatLon.isOutSideWorld() was used before
  • Add a check in MoveNodeAction to make sure that rounding errors near 180 longitude don't move the node from east to west or vice versa

(I've removed the changes to reactions implemented in 13538-v2.patch, they would be too confusing.)

TODO: Plugins should use the new method in Node

Location:
trunk
Files:
8 edited

Legend:

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

    r14659 r14960  
    214214                double y = center.north() + r*Math.sin(alpha);
    215215                LatLon ll = ProjectionRegistry.getProjection().eastNorth2latlon(new EastNorth(x, y));
    216                 if (ll.isOutSideWorld()) {
     216                if (new Node(new EastNorth(x, y)).isOutSideWorld()) {
    217217                    notifyNodesNotOnCircle();
    218218                    return;
  • trunk/src/org/openstreetmap/josm/actions/MoveAction.java

    r14397 r14960  
    152152
    153153        for (Node n : affectedNodes) {
    154             if (n.isLatLonKnown() && n.getCoor().isOutSideWorld()) {
     154            if (n.isLatLonKnown() && n.isOutSideWorld()) {
    155155                // Revert move
    156156                ((MoveCommand) c).moveAgain(-distx, -disty);
  • trunk/src/org/openstreetmap/josm/actions/MoveNodeAction.java

    r14397 r14960  
    5252        // move the node
    5353        UndoRedoHandler.getInstance().add(new MoveCommand(n, coordinates));
     54        if (n.getCoor().distance(coordinates) > 1) {
     55            // see #13538: Avoid rounding error near 180 longitude which moves nodes too far
     56            if (coordinates.lon() >= 180.0) {
     57                coordinates = new LatLon(coordinates.lat(), Math.nextDown(180.0));
     58            } else if (coordinates.lon() <= -180.0) {
     59                coordinates = new LatLon(coordinates.lat(), Math.nextUp(-180.0));
     60            }
     61            UndoRedoHandler.getInstance().undo(1);
     62            UndoRedoHandler.getInstance().add(new MoveCommand(n, coordinates));
     63        }
    5464        MainApplication.getMap().mapView.repaint();
    5565    }
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r14654 r14960  
    530530
    531531        if (newNode) {
    532             if (n.getCoor().isOutSideWorld()) {
     532            if (n.isOutSideWorld()) {
    533533                JOptionPane.showMessageDialog(
    534534                        MainApplication.getMainFrame(),
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java

    r14670 r14960  
    416416        } else if (state == State.IMPROVING) {
    417417            // Checking if the new coordinate is outside of the world
    418             if (mv.getLatLon(mousePos.x, mousePos.y).isOutSideWorld()) {
     418            if (new Node(mv.getEastNorth(mousePos.x, mousePos.y)).isOutSideWorld()) {
    419419                JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
    420420                        tr("Cannot add a node outside of the world."),
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r14654 r14960  
    3232import org.openstreetmap.josm.data.UndoRedoHandler;
    3333import org.openstreetmap.josm.data.coor.EastNorth;
    34 import org.openstreetmap.josm.data.coor.LatLon;
    3534import org.openstreetmap.josm.data.osm.DataSet;
    3635import org.openstreetmap.josm.data.osm.Node;
     
    723722                }
    724723                for (Node n : affectedNodes) {
    725                     LatLon ll = n.getCoor();
    726                     if (ll != null && ll.isOutSideWorld()) {
     724                    if (n.isOutSideWorld()) {
    727725                        // Revert move
    728726                        if (c instanceof MoveCommand) {
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r14654 r14960  
    403403        return referrers(Way.class).collect(Collectors.toList());
    404404    }
     405
     406    /**
     407     * Determines if this node is outside of the world. See also #13538.
     408     * @return <code>true</code>, if the coordinate is outside the world, compared by using lat/lon and east/north
     409     * @since 14960
     410     */
     411    public boolean isOutSideWorld() {
     412        LatLon ll = getCoor();
     413        if (ll != null) {
     414            if (ll.isOutSideWorld())
     415                return true;
     416            if (!new Node(ll).getEastNorth().equalsEpsilon(getEastNorth(), 1.0)) {
     417                // we get here if a node was moved or created left from -180 or right from +180
     418                return true;
     419            }
     420        }
     421        return false;
     422    }
    405423}
  • trunk/test/unit/org/openstreetmap/josm/data/osm/NodeTest.java

    r11630 r14960  
    1212import org.openstreetmap.josm.data.Bounds;
    1313import org.openstreetmap.josm.data.DataSource;
     14import org.openstreetmap.josm.data.coor.EastNorth;
    1415import org.openstreetmap.josm.data.coor.LatLon;
    1516import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    2728    @Rule
    2829    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    29     public JOSMTestRules test = new JOSMTestRules();
     30    public JOSMTestRules test = new JOSMTestRules().projection();
    3031
    3132    /**
     
    104105        new Node().load(new WayData());
    105106    }
     107
     108    /**
     109     * Test that {@link Node#isOutSideWorld} works as expected.
     110     */
     111    @Test
     112    public void testOutsideWorld() {
     113        Node n = new Node(1, 1);
     114        n.setCoor(LatLon.ZERO);
     115        assertFalse(n.isOutSideWorld());
     116        n.setCoor(null);
     117        assertFalse(n.isOutSideWorld());
     118        n.setCoor(LatLon.NORTH_POLE);
     119        assertTrue(n.isOutSideWorld());
     120        n.setCoor(new LatLon(0, 180.0));
     121        assertFalse(n.isOutSideWorld());
     122        // simulate a small move east
     123        n.setEastNorth(new EastNorth(n.getEastNorth().getX() + 0.1, n.getEastNorth().getY()));
     124        assertTrue(n.isOutSideWorld());
     125        n.setCoor(new LatLon(0, -180.0));
     126        assertFalse(n.isOutSideWorld());
     127        // simulate a small move west
     128        n.setEastNorth(new EastNorth(n.getEastNorth().getX() - 0.1, n.getEastNorth().getY()));
     129        assertTrue(n.isOutSideWorld());
     130    }
     131
    106132}
Note: See TracChangeset for help on using the changeset viewer.