Changeset 15555 in josm
- Timestamp:
- 2019-12-03T16:28:41+01:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r14397 r15555 124 124 // try to build a new way which includes all the combined ways 125 125 NodeGraph graph = NodeGraph.createNearlyUndirectedGraphFromNodeWays(ways); 126 List<Node> path = graph.buildSpanningPath(); 126 List<Node> path = graph.buildSpanningPathNoRemove(); 127 127 if (path == null) { 128 128 warnCombiningImpossible(); -
trunk/src/org/openstreetmap/josm/data/osm/NodeGraph.java
r15554 r15555 139 139 private final Set<NodePair> edges; 140 140 private int numUndirectedEges; 141 /** counts the number of edges that were added */ 142 private int addedEdges; 141 143 private final Map<Node, List<NodePair>> successors = new LinkedHashMap<>(); 142 144 private final Map<Node, List<NodePair>> predecessors = new LinkedHashMap<>(); … … 195 197 */ 196 198 public void add(NodePair pair) { 197 if (!edges.contains(pair)) { 198 edges.add(pair); 199 } 199 addedEdges++; 200 edges.add(pair); 200 201 } 201 202 … … 290 291 public List<Node> buildSpanningPath() { 291 292 prepare(); 292 if(numUndirectedEges > 0 && isConnected()) { 293 if (numUndirectedEges > 0 && isConnected()) { 293 294 // try to find a path from each "terminal node", i.e. from a 294 295 // node which is connected by exactly one undirected edges (or … … 311 312 312 313 /** 314 * Tries to find a path through the graph which visits each edge (i.e. 315 * the segment of a way) exactly once. If the graph was build from overlapping 316 * ways duplicate edges were removed already. This method will return null if 317 * any duplicated edge was removed. 318 * 319 * @return the path; null, if no path was found or duplicated edges were found 320 * @since xxx 321 */ 322 public List<Node> buildSpanningPathNoRemove() { 323 if (edges.size() != addedEdges) 324 return null; 325 return buildSpanningPath(); 326 } 327 328 /** 313 329 * Find out if the graph is connected. 314 330 * @return true if it is connected. … … 321 337 HashSet<Node> visited = new HashSet<>(); 322 338 toVisit.add(nodes.iterator().next()); 323 while(!toVisit.isEmpty()) { 339 while (!toVisit.isEmpty()) { 324 340 Node n = toVisit.pop(); 325 341 if (!visited.contains(n)) { -
trunk/test/unit/org/openstreetmap/josm/actions/CombineWayActionTest.java
r14604 r15555 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertNull; 5 6 6 7 import java.io.IOException; … … 46 47 DataSet ds = OsmReader.parseDataSet(is, null); 47 48 NodeGraph graph = NodeGraph.createNearlyUndirectedGraphFromNodeWays(ds.getWays()); 48 List<Node> path = graph.buildSpanningPath(); 49 List<Node> path = graph.buildSpanningPathNoRemove(); 49 50 assertEquals(10, path.size()); 50 51 Set<Long> firstAndLastObtained = new HashSet<>(); … … 55 56 firstAndLastExpected.add(35213705L); 56 57 assertEquals(firstAndLastExpected, firstAndLastObtained); 58 } 59 } 60 61 /** 62 * Non-regression test for bug #1835 (combine way with overlapping ways) 63 * @throws IOException if any I/O error occurs 64 * @throws IllegalDataException if OSM parsing fails 65 */ 66 @Test 67 public void testTicket18385() throws IOException, IllegalDataException { 68 try (InputStream is = TestUtils.getRegressionDataStream(18385, "data.osm")) { 69 DataSet ds = OsmReader.parseDataSet(is, null); 70 NodeGraph graph = NodeGraph.createNearlyUndirectedGraphFromNodeWays(ds.getWays()); 71 List<Node> path = graph.buildSpanningPathNoRemove(); 72 assertNull(path); 57 73 } 58 74 }
Note:
See TracChangeset
for help on using the changeset viewer.