Changeset 12478 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/NodeGraph.java
r12463 r12478 21 21 */ 22 22 public class NodeGraph { 23 24 /** 25 * Builds a list of pair of nodes from the given way. 26 * @param way way 27 * @param directed if {@code true} each pair of nodes will occur once, in the way nodes order. 28 * if {@code false} each pair of nodes will occur twice (the pair and its inversed copy) 29 * @return a list of pair of nodes from the given way 30 */ 23 31 public static List<NodePair> buildNodePairs(Way way, boolean directed) { 24 32 List<NodePair> pairs = new ArrayList<>(); … … 32 40 } 33 41 42 /** 43 * Builds a list of pair of nodes from the given ways. 44 * @param ways ways 45 * @param directed if {@code true} each pair of nodes will occur once, in the way nodes order. 46 * if {@code false} each pair of nodes will occur twice (the pair and its inversed copy) 47 * @return a list of pair of nodes from the given ways 48 */ 34 49 public static List<NodePair> buildNodePairs(List<Way> ways, boolean directed) { 35 50 List<NodePair> pairs = new ArrayList<>(); … … 40 55 } 41 56 57 /** 58 * Builds a new list of pair nodes without the duplicated pairs (including inversed copies). 59 * @param pairs existing list of pairs 60 * @return a new list of pair nodes without the duplicated pairs 61 */ 42 62 public static List<NodePair> eliminateDuplicateNodePairs(List<NodePair> pairs) { 43 63 List<NodePair> cleaned = new ArrayList<>(); … … 242 262 */ 243 263 protected List<Node> buildSpanningPath(Node startNode) { 244 if (startNode == null) 245 return null; 246 Stack<NodePair> path = new Stack<>(); 247 Stack<NodePair> nextPairs = new Stack<>(); 248 nextPairs.addAll(getOutboundPairs(startNode)); 249 while (!nextPairs.isEmpty()) { 250 NodePair cur = nextPairs.pop(); 251 if (!path.contains(cur) && !path.contains(cur.swap())) { 252 while (!path.isEmpty() && !path.peek().isPredecessorOf(cur)) { 253 path.pop(); 264 if (startNode != null) { 265 Stack<NodePair> path = new Stack<>(); 266 Stack<NodePair> nextPairs = new Stack<>(); 267 nextPairs.addAll(getOutboundPairs(startNode)); 268 while (!nextPairs.isEmpty()) { 269 NodePair cur = nextPairs.pop(); 270 if (!path.contains(cur) && !path.contains(cur.swap())) { 271 while (!path.isEmpty() && !path.peek().isPredecessorOf(cur)) { 272 path.pop(); 273 } 274 path.push(cur); 275 if (isSpanningWay(path)) return buildPathFromNodePairs(path); 276 nextPairs.addAll(getOutboundPairs(path.peek())); 254 277 } 255 path.push(cur); 256 if (isSpanningWay(path)) return buildPathFromNodePairs(path); 257 nextPairs.addAll(getOutboundPairs(path.peek())); 258 } 259 } 260 return null; 278 } 279 } 280 return Collections.emptyList(); 261 281 } 262 282 … … 280 300 for (Node n: nodes) { 281 301 List<Node> path = buildSpanningPath(n); 282 if ( path != null)302 if (!path.isEmpty()) 283 303 return path; 284 304 }
Note:
See TracChangeset
for help on using the changeset viewer.