Changeset 8181 in josm for trunk/src


Ignore:
Timestamp:
2015-04-09T22:17:16+02:00 (5 years ago)
Author:
stoecker
Message:

fix #5880 - reverse new ways in favour of existing ones

File:
1 edited

Legend:

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

    r8061 r8181  
    9595
    9696    /**
    97      * @param ways
     97     * Combine multiple ways into one.
     98     * @param ways the way to combine to one way
    9899     * @return null if ways cannot be combined. Otherwise returns the combined
    99100     *              ways and the commands to combine
     
    114115        // ways
    115116        //
    116         NodeGraph graph = NodeGraph.createUndirectedGraphFromNodeWays(ways);
     117        NodeGraph graph = NodeGraph.createNearlyUndirectedGraphFromNodeWays(ways);
    117118        List<Node> path = graph.buildSpanningPath();
    118119        if (path == null) {
     
    421422        }
    422423
     424        /**
     425         * Create an undirected graph from the given ways.
     426         * @param ways Ways to build the graph from
     427         * @return node graph structure
     428         */
    423429        public static NodeGraph createUndirectedGraphFromNodeList(List<NodePair> pairs) {
    424430            NodeGraph graph = new NodeGraph();
     
    430436        }
    431437
     438        /**
     439         * Create an undirected graph from the given ways, but prevent reversing of all
     440         * non-new ways by fix one direction.
     441         * @param ways Ways to build the graph from
     442         * @return node graph structure
     443         * @since 8181
     444         */
    432445        public static NodeGraph createUndirectedGraphFromNodeWays(Collection<Way> ways) {
     446            boolean dir = true;
    433447            NodeGraph graph = new NodeGraph();
    434448            for (Way w: ways) {
    435449                graph.add(buildNodePairs(w, false /* undirected */));
     450            }
     451            return graph;
     452        }
     453
     454        public static NodeGraph createNearlyUndirectedGraphFromNodeWays(Collection<Way> ways) {
     455            boolean dir = true;
     456            NodeGraph graph = new NodeGraph();
     457            for (Way w: ways) {
     458                if(!w.isNew()) {
     459                    /* let the first non-new way give the direction (see #5880) */
     460                    graph.add(buildNodePairs(w, dir));
     461                    dir = false;
     462                } else {
     463                    graph.add(buildNodePairs(w, false /* undirected */));
     464                }
    436465            }
    437466            return graph;
     
    604633        /**
    605634         * Tries to find a path through the graph which visits each edge (i.e.
    606          * the segment of a way) exactly one.
     635         * the segment of a way) exactly once.
    607636         *
    608637         * @return the path; null, if no path was found
Note: See TracChangeset for help on using the changeset viewer.