Changeset 32710 in osm for applications/editors/josm/plugins/pt_assistant
- Timestamp:
- 2016-07-24T15:43:24+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTRouteDataManager.java
r32707 r32710 2 2 3 3 import java.util.ArrayList; 4 import java.util.HashSet; 4 5 import java.util.List; 5 6 … … 182 183 return this.failedMembers; 183 184 } 184 185 185 186 /** 186 187 * Returns the route relation for which this manager was created: 188 * 187 189 * @return 188 190 */ … … 324 326 */ 325 327 public List<PTWay> getPTWaysBetween(Way start, Way end) { 326 328 327 329 List<Integer> potentialStartIndices = new ArrayList<>(); 328 330 List<Integer> potentialEndIndices = new ArrayList<>(); 329 331 330 332 for (int i = 0; i < ptways.size(); i++) { 331 333 if (ptways.get(i).getWays().contains(start)) { … … 336 338 } 337 339 } 338 340 339 341 List<int[]> pairList = new ArrayList<>(); 340 for (Integer potentialStartIndex: potentialStartIndices) { 341 for (Integer potentialEndIndex: potentialEndIndices) { 342 for (Integer potentialStartIndex : potentialStartIndices) { 343 for (Integer potentialEndIndex : potentialEndIndices) { 342 344 if (potentialStartIndex <= potentialEndIndex) { 343 int[] pair = {potentialStartIndex, potentialEndIndex}; 345 int[] pair = { potentialStartIndex, potentialEndIndex }; 344 346 pairList.add(pair); 345 347 } 346 348 } 347 349 } 348 350 349 351 int minDifference = Integer.MAX_VALUE; 350 int[] mostSuitablePair = { 0, 0};351 for (int[] pair: pairList) { 352 int[] mostSuitablePair = { 0, 0 }; 353 for (int[] pair : pairList) { 352 354 int diff = pair[1] - pair[0]; 353 355 if (diff < minDifference) { … … 356 358 } 357 359 } 358 360 359 361 List<PTWay> result = new ArrayList<>(); 360 362 for (int i = mostSuitablePair[0]; i <= mostSuitablePair[1]; i++) { … … 363 365 return result; 364 366 } 365 366 /** 367 * Returns the common Node of two PTWays or null if there is no common Node 367 368 /** 369 * Returns the common Node of two PTWays or null if there is no common Node. 370 * If there is more than one common Node, only the first found is returned. 371 * 368 372 * @param way1 369 373 * @param way2 … … 371 375 */ 372 376 public Node getCommonNode(PTWay way1, PTWay way2) { 373 377 374 378 List<Way> wayList1 = way1.getWays(); 375 379 List<Way> wayList2 = way2.getWays(); 376 377 for (int i = 0; i < wayList1.size(); i++) { 378 for (int j = 0; j < wayList2.size(); j++) { 379 if (wayList1.get(i).firstNode() == wayList2.get(j).firstNode() || wayList1.get(i).firstNode() == wayList2.get(j).lastNode()) { 380 return wayList1.get(i).firstNode(); 381 } 382 if (wayList1.get(i).lastNode() == wayList2.get(j).firstNode() || wayList1.get(i).lastNode() == wayList2.get(j).lastNode()) { 383 return wayList1.get(i).lastNode(); 384 } 385 } 386 } 380 381 HashSet<Node> nodeSet1 = new HashSet<>(); 382 for (Way w : wayList1) { 383 nodeSet1.addAll(w.getNodes()); 384 } 385 HashSet<Node> nodeSet2 = new HashSet<>(); 386 for (Way w : wayList2) { 387 nodeSet2.addAll(w.getNodes()); 388 } 389 390 for (Node n : nodeSet1) { 391 if (nodeSet2.contains(n)) { 392 return n; 393 } 394 } 395 387 396 return null; 388 397 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTWay.java
r32707 r32710 118 118 return endNodes; 119 119 } 120 121 public boolean containsUnsplitRoundabout() { 122 123 List<Way> ways = this.getWays(); 124 for (Way way: ways) { 125 if (way.hasTag("junction", "roundabout") && way.firstNode() == way.lastNode()) { 126 return true; 127 } 128 } 129 return false; 130 } 120 131 121 132 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r32707 r32710 342 342 // matter which of the geometrically equal PTWays it finds 343 343 344 // find the next node in direction of travel (which is part of the345 // PTWay start):346 firstNodeOfRouteSegmentInDirectionOfTravel = getOppositeEndNode(current,347 firstNodeOfRouteSegmentInDirectionOfTravel);348 349 List<PTWay> nextWaysInDirectionOfTravel = this.findNextPTWaysInDirectionOfTravel(current,350 firstNodeOfRouteSegmentInDirectionOfTravel);351 352 344 PTWay nextPTWayAccortingToExistingSorting = manager.getNextPTWay(current); 353 if (!nextWaysInDirectionOfTravel.contains(nextPTWayAccortingToExistingSorting)) { 354 List<Relation> primitives = new ArrayList<>(1); 355 primitives.add(relation); 356 List<OsmPrimitive> highlighted = new ArrayList<>(); 357 358 highlighted.addAll(current.getWays()); 359 highlighted.add(firstNodeOfRouteSegmentInDirectionOfTravel); 360 361 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Problem in the route segment"), 362 PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP, primitives, highlighted); 363 this.errors.add(e); 364 this.firstNodeOfRouteSegmentInDirectionOfTravel = null; 365 return false; 345 346 // if current contains an unsplit roundabout: 347 if (current.containsUnsplitRoundabout()) { 348 firstNodeOfRouteSegmentInDirectionOfTravel = manager.getCommonNode(current, 349 nextPTWayAccortingToExistingSorting); 350 if (firstNodeOfRouteSegmentInDirectionOfTravel == null) { 351 List<Relation> primitives = new ArrayList<>(1); 352 primitives.add(relation); 353 List<OsmPrimitive> highlighted = new ArrayList<>(); 354 highlighted.addAll(current.getWays()); 355 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Problem in the route segment"), 356 PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP, primitives, highlighted); 357 this.errors.add(e); 358 return false; 359 } 360 } else { 361 // if this is a regular way, not an unsplit roundabout 362 363 // find the next node in direction of travel (which is part of 364 // the PTWay start): 365 firstNodeOfRouteSegmentInDirectionOfTravel = getOppositeEndNode(current, 366 firstNodeOfRouteSegmentInDirectionOfTravel); 367 368 List<PTWay> nextWaysInDirectionOfTravel = this.findNextPTWaysInDirectionOfTravel(current, 369 firstNodeOfRouteSegmentInDirectionOfTravel); 370 371 if (!nextWaysInDirectionOfTravel.contains(nextPTWayAccortingToExistingSorting)) { 372 List<Relation> primitives = new ArrayList<>(1); 373 primitives.add(relation); 374 List<OsmPrimitive> highlighted = new ArrayList<>(); 375 376 highlighted.addAll(current.getWays()); 377 highlighted.add(firstNodeOfRouteSegmentInDirectionOfTravel); 378 379 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Problem in the route segment"), 380 PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP, primitives, highlighted); 381 this.errors.add(e); 382 this.firstNodeOfRouteSegmentInDirectionOfTravel = null; 383 return false; 384 385 } 366 386 } 367 387 … … 373 393 } 374 394 395 /** 396 * Will return the same node if the way is an unsplit roundabout 397 * @param way 398 * @param node 399 * @return 400 */ 375 401 private Node getOppositeEndNode(Way way, Node node) { 376 402 … … 386 412 } 387 413 414 /** 415 * Does not work correctly for unsplit roundabouts 416 * @param ptway 417 * @param node 418 * @return 419 */ 388 420 private Node getOppositeEndNode(PTWay ptway, Node node) { 389 421 if (ptway.isWay()) { … … 425 457 426 458 if (ptway != currentWay) { 427 Node[] endNodes = ptway.getEndNodes(); 428 if (endNodes[0] == nextNodeInDirectionOfTravel || endNodes[1] == nextNodeInDirectionOfTravel) { 429 nextPtways.add(ptway); 459 for (Way way: ptway.getWays()) { 460 if (way.containsNode(nextNodeInDirectionOfTravel)) { 461 nextPtways.add(ptway); 462 } 430 463 } 431 464 }
Note:
See TracChangeset
for help on using the changeset viewer.