Changeset 2296 in josm


Ignore:
Timestamp:
2009-10-17T15:40:11+02:00 (15 years ago)
Author:
stoecker
Message:

see #3703 - patch by Daeron - deleting way segment cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r2273 r2296  
    427427
    428428    public static Command deleteWaySegment(OsmDataLayer layer, WaySegment ws) {
     429        if (ws.way.getNodesCount() < 3) {
     430            // If the way contains less than three nodes, it can't have more
     431            // than one segment, so the way should be deleted.
     432
     433            return new DeleteCommand(layer, Collections.singleton(ws.way));
     434        }
     435
     436        if (ws.way.firstNode() == ws.way.lastNode()) {
     437            // If the way is circular (first and last nodes are the same),
     438            // the way shouldn't be splitted
     439
     440            List<Node> n = new ArrayList<Node>();
     441
     442            n.addAll(ws.way.getNodes().subList(ws.lowerIndex + 1, ws.way.getNodesCount() - 1));
     443            n.addAll(ws.way.getNodes().subList(0, ws.lowerIndex + 1));
     444
     445            Way wnew = new Way(ws.way);
     446            wnew.setNodes(n);
     447
     448            return new ChangeCommand(ws.way, wnew);
     449        }
     450
    429451        List<Node> n1 = new ArrayList<Node>(), n2 = new ArrayList<Node>();
    430452
    431453        n1.addAll(ws.way.getNodes().subList(0, ws.lowerIndex + 1));
    432454        n2.addAll(ws.way.getNodes().subList(ws.lowerIndex + 1, ws.way.getNodesCount()));
    433 
    434         if (n1.size() < 2 && n2.size() < 2)
    435             return new DeleteCommand(layer, Collections.singleton(ws.way));
    436455
    437456        Way wnew = new Way(ws.way);
     
    453472            wnew2.setNodes(n2);
    454473            cmds.add(new AddCommand(wnew2));
     474
     475            // FIXME: relation memberships are not handled
    455476
    456477            return new SequenceCommand(tr("Split way segment"), cmds);
Note: See TracChangeset for help on using the changeset viewer.