Changeset 8276 in josm for trunk/src/org


Ignore:
Timestamp:
2015-04-26T15:33:50+02:00 (10 years ago)
Author:
Balaitous
Message:

fix #11184 - "split way" is splitting an other way instead of the selected.
The case where the selected node is both one end and an intermediate node of the selected way was not taken into account.
Add test case.

File:
1 edited

Legend:

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

    r7534 r8276  
    125125        List<Node> selectedNodes = OsmPrimitive.getFilteredList(selection, Node.class);
    126126        List<Way> selectedWays = OsmPrimitive.getFilteredList(selection, Way.class);
    127         List<Relation> selectedRelations = OsmPrimitive.getFilteredList(selection, Relation.class);
     127        List<Relation> selectedRelations =
     128            OsmPrimitive.getFilteredList( selection, Relation.class);
    128129        List<Way> applicableWays = getApplicableWays(selectedWays, selectedNodes);
    129130
     
    142143        }
    143144
    144         // If several ways have been found, remove ways that doesn't have selected node in the middle
     145        // If several ways have been found, remove ways that doesn't have selected
     146        // node in the middle
    145147        if (applicableWays.size() > 1) {
    146             WAY_LOOP:
    147                 for (Iterator<Way> it = applicableWays.iterator(); it.hasNext();) {
    148                     Way w = it.next();
    149                     for (Node n : selectedNodes) {
    150                         if (!w.isInnerNode(n)) {
    151                             it.remove();
    152                             continue WAY_LOOP;
    153                         }
     148            for (Iterator<Way> it = applicableWays.iterator(); it.hasNext();) {
     149                Way w = it.next();
     150                for (Node n : selectedNodes) {
     151                    if (!w.isInnerNode(n)) {
     152                        it.remove();
     153                        break;
    154154                    }
    155155                }
     156            }
    156157        }
    157158
     
    188189    }
    189190
     191    /**
     192     * Determine witch ways to split.
     193     * @param selectedWays List of user selected ways.
     194     * @param selectedNodes List of user selected nodes.
     195     * @return List of ways to split
     196     */
    190197    private List<Way> getApplicableWays(List<Way> selectedWays, List<Node> selectedNodes) {
    191198        if (selectedNodes.isEmpty())
    192199            return null;
    193200
    194         // Special case - one of the selected ways touches (not cross) way that we want to split
     201        // Special case - one of the selected ways touches (not cross) way that we
     202        // want to split
    195203        if (selectedNodes.size() == 1) {
    196204            Node n = selectedNodes.get(0);
    197             List<Way> referedWays = OsmPrimitive.getFilteredList(n.getReferrers(), Way.class);
     205            List<Way> referedWays =
     206                OsmPrimitive.getFilteredList(n.getReferrers(), Way.class);
    198207            Way inTheMiddle = null;
    199             boolean foundSelected = false;
    200208            for (Way w: referedWays) {
    201                 if (selectedWays.contains(w)) {
    202                     foundSelected = true;
    203                 }
    204                 if (w.getNode(0) != n && w.getNode(w.getNodesCount() - 1) != n) {
     209                // Need to look at all nodes see #11184 for a case where node n is
     210                // firstNode, lastNode and also in the middle
     211                if (selectedWays.contains(w) && w.isInnerNode(n)) {
    205212                    if (inTheMiddle == null) {
    206213                        inTheMiddle = w;
     
    211218                }
    212219            }
    213             if (foundSelected && inTheMiddle != null)
     220            if (inTheMiddle != null)
    214221                return Collections.singletonList(inTheMiddle);
    215222        }
    216223
    217224        // List of ways shared by all nodes
    218         List<Way> result = new ArrayList<>(OsmPrimitive.getFilteredList(selectedNodes.get(0).getReferrers(), Way.class));
     225        List<Way> result =
     226            new ArrayList<>(OsmPrimitive.getFilteredList(selectedNodes.get(0).getReferrers(),
     227                                                         Way.class));
    219228        for (int i=1; i<selectedNodes.size(); i++) {
    220229            List<OsmPrimitive> ref = selectedNodes.get(i).getReferrers();
Note: See TracChangeset for help on using the changeset viewer.