Ignore:
Timestamp:
2017-07-20T17:37:19+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] roundabout splitter - handle routes with ways in reverse order

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/SplitRoundaboutAction.java

    r33429 r33463  
    189189                    return;
    190190
     191                if (needSwap(entryNode, entryWay, exitNode, exitWay)) {
     192                    Node temp = entryNode;
     193                    entryNode = exitNode;
     194                    exitNode = temp;
     195                }
     196
    191197                //starting from the entry node, add split ways until the
    192198                //exit node is reached
    193                 List<Way> parents = entryNode.getParentWays();
    194                 parents.removeIf(w -> !w.firstNode().equals(entryNode));
    195                 parents.removeIf(w -> w.equals(entryWay));
     199                List<Way> parents = filterParents(entryNode.getParentWays(),
     200                        entryWay, entryNode);
    196201
    197202                Way curr = parents.get(0);
     
    208213            }));
    209214        return changingRelation;
     215    }
     216
     217    private List<Way> filterParents(List<Way> parentWays, Way entryWay, Node entryNode) {
     218        List<Way> ret = new ArrayList<>();
     219        for (Way w : parentWays) {
     220            if (!w.equals(entryWay) && w.firstNode().equals(entryNode))
     221                ret.add(w);
     222        }
     223        return ret;
     224    }
     225
     226    //check whether the ways were in reverse order and need to be split
     227    private boolean needSwap(Node entryNode, Way entryWay, Node exitNode, Way exitWay) {
     228        boolean entryReversed = false;
     229        boolean exitReversed = false;
     230
     231        if (entryWay.firstNode().equals(entryNode)
     232                && !entryWay.hasTag("oneway", "-1"))
     233            entryReversed = true;
     234
     235        if (exitWay.lastNode().equals(exitNode)
     236                && !exitWay.hasTag("oneway", "-1"))
     237            exitReversed = true;
     238
     239        return entryReversed && exitReversed;
    210240    }
    211241
Note: See TracChangeset for help on using the changeset viewer.