Changeset 15728 in josm


Ignore:
Timestamp:
2020-01-19T10:54:23+01:00 (3 months ago)
Author:
simon04
Message:

fix #18477 - Split Way: smart way selection

If only one highway/railway/waterway is applicable, use that one.

Location:
trunk
Files:
2 edited

Legend:

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

    r15727 r15728  
    1616import java.util.List;
    1717import java.util.concurrent.atomic.AtomicInteger;
     18import java.util.stream.Collectors;
    1819
    1920import javax.swing.DefaultListCellRenderer;
     
    103104        if (applicableWays.size() > 1) {
    104105             applicableWays.removeIf(w -> selectedNodes.stream().noneMatch(w::isInnerNode));
     106        }
     107
     108        // Smart way selection: if only one highway/railway/waterway is applicable, use that one
     109        if (applicableWays.size() > 1) {
     110            final List<Way> mainWays = applicableWays.stream()
     111                    .filter(w -> w.hasKey("highway", "railway", "waterway"))
     112                    .collect(Collectors.toList());
     113            if (mainWays.size() == 1) {
     114                applicableWays = mainWays;
     115            }
    105116        }
    106117
  • trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java

    r15186 r15728  
    77import java.util.Arrays;
    88
     9import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    910import org.junit.Assert;
    1011import org.junit.Rule;
     
    2021import org.openstreetmap.josm.testutils.JOSMTestRules;
    2122
    22 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    23 
    2423/**
    2524 * Unit tests for class {@link SplitWayAction}.
     
    3332    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3433    public JOSMTestRules test = new JOSMTestRules().projection();
     34    private final DataSet dataSet = new DataSet();
     35
     36    private Node addNode(int east, int north) {
     37        final Node node = new Node(new EastNorth(east, north));
     38        dataSet.addPrimitive(node);
     39        return node;
     40    }
    3541
    3642    /**
     
    4046    @Test
    4147    public void testTicket11184() {
    42         DataSet dataSet = new DataSet();
    43 
    44         Node n1 = new Node(new EastNorth(0, 0));
    45         Node n2 = new Node(new EastNorth(-1, 1));
    46         Node n3 = new Node(new EastNorth(1, 1));
    47         Node n4 = new Node(new EastNorth(-1, -1));
    48         Node n5 = new Node(new EastNorth(1, -1));
    49         Node n6 = new Node(new EastNorth(-1, 0));
    50         Node n7 = new Node(new EastNorth(1, 0));
    51         dataSet.addPrimitive(n1);
    52         dataSet.addPrimitive(n2);
    53         dataSet.addPrimitive(n3);
    54         dataSet.addPrimitive(n4);
    55         dataSet.addPrimitive(n5);
    56         dataSet.addPrimitive(n6);
    57         dataSet.addPrimitive(n7);
     48        Node n1 = addNode(0, 0);
     49        Node n2 = addNode(-1, 1);
     50        Node n3 = addNode(1, 1);
     51        Node n4 = addNode(-1, -1);
     52        Node n5 = addNode(1, -1);
     53        Node n6 = addNode(-1, 0);
     54        Node n7 = addNode(1, 0);
    5855
    5956        Way w1 = new Way();
     
    9693                new Node(new LatLon(0.00033, 0.00033)), new Node(new LatLon(0.00066, 0.00066)),
    9794                new Node(new LatLon(0.001, 0.001)));
    98         from.getNodes().forEach(node -> dataSet.addPrimitive(node));
     95        from.getNodes().forEach(dataSet::addPrimitive);
    9996        dataSet.addPrimitive(from);
    10097        Node via = from.lastNode();
     
    119116        }
    120117    }
     118
     119    /**
     120     * Test case: smart way selection
     121     * see #18477
     122     */
     123    @Test
     124    public void testTicket18477() {
     125        final Node n10 = addNode(1, 0);
     126        final Node n21 = addNode(2, 1);
     127        final Way highway = TestUtils.newWay("highway=residential",
     128                addNode(0, 0), n10, n21, addNode(3, 1));
     129        final Way bridge = TestUtils.newWay("man_made=bridge",
     130                n10, addNode(2, 0), n21, addNode(1, 1), n10);
     131        dataSet.addPrimitive(highway);
     132        dataSet.addPrimitive(bridge);
     133        dataSet.setSelected(n10, n21);
     134        SplitWayAction.runOn(dataSet);
     135        assertSame(String.format("Found %d ways after split action instead of 4.", dataSet.getWays().size()),
     136                dataSet.getWays().size(), 4);
     137    }
    121138}
Note: See TracChangeset for help on using the changeset viewer.