Fix complex turns
This commit is contained in:
parent
38c5763337
commit
fc79805bf3
4 changed files with 57 additions and 17 deletions
|
@ -667,17 +667,25 @@ public class RouteResultPreparation {
|
|||
}
|
||||
}
|
||||
}
|
||||
int singleTurn ;
|
||||
int singleTurn = 0;
|
||||
if(turnSet.size() == 1) {
|
||||
singleTurn = turnSet.iterator().next();
|
||||
} else if(currentTurn.goAhead() && nextTurn.goAhead()) {
|
||||
singleTurn = currentTurn.getValue();
|
||||
} else if(currentTurn.goAhead() && turnSet.contains(nextTurn.getValue()) &&
|
||||
(currentTurn.isPossibleLeftTurn() && TurnType.isLeftTurn(nextTurn.getValue()) ) ||
|
||||
(currentTurn.isPossibleRightTurn() && TurnType.isRightTurn(nextTurn.getValue()))
|
||||
) {
|
||||
} else if(currentTurn.goAhead() && turnSet.contains(nextTurn.getValue())) {
|
||||
if(currentTurn.isPossibleLeftTurn() &&
|
||||
TurnType.isLeftTurn(nextTurn.getValue())) {
|
||||
singleTurn = nextTurn.getValue();
|
||||
} else {
|
||||
} else if(currentTurn.isPossibleLeftTurn() &&
|
||||
TurnType.isLeftTurn(nextTurn.getActiveCommonLaneTurn())) {
|
||||
singleTurn = nextTurn.getActiveCommonLaneTurn();
|
||||
} else if(currentTurn.isPossibleRightTurn() &&
|
||||
TurnType.isRightTurn(nextTurn.getValue())) {
|
||||
singleTurn = nextTurn.getValue();
|
||||
} else if(currentTurn.isPossibleRightTurn() &&
|
||||
TurnType.isRightTurn(nextTurn.getActiveCommonLaneTurn())) {
|
||||
singleTurn = nextTurn.getActiveCommonLaneTurn();
|
||||
}
|
||||
}
|
||||
if (singleTurn == 0) {
|
||||
singleTurn = currentTurn.getValue();
|
||||
}
|
||||
for(int i = 0; i < lanes.length; i++) {
|
||||
|
@ -924,6 +932,22 @@ public class RouteResultPreparation {
|
|||
// Maybe going straight at a 90-degree intersection
|
||||
TurnType t = TurnType.valueOf(TurnType.C, leftSide);
|
||||
int[] rawLanes = calculateRawTurnLanes(turnLanes, TurnType.C);
|
||||
boolean possiblyLeftTurn = rs.roadsOnLeft == 0;
|
||||
boolean possiblyRightTurn = rs.roadsOnRight == 0;
|
||||
for (int k = 0; k < rawLanes.length; k++) {
|
||||
int turn = TurnType.getPrimaryTurn(rawLanes[k]);
|
||||
int sturn = TurnType.getSecondaryTurn(rawLanes[k]);
|
||||
int tturn = TurnType.getTertiaryTurn(rawLanes[k]);
|
||||
if (turn == TurnType.TU || sturn == TurnType.TU || tturn == TurnType.TU) {
|
||||
possiblyLeftTurn = true;
|
||||
}
|
||||
if (turn == TurnType.TRU || sturn == TurnType.TRU || sturn == TurnType.TRU) {
|
||||
possiblyRightTurn = true;
|
||||
}
|
||||
}
|
||||
|
||||
t.setPossibleLeftTurn(possiblyLeftTurn);
|
||||
t.setPossibleRightTurn(possiblyRightTurn);
|
||||
if (rs.keepLeft || rs.keepRight) {
|
||||
String[] splitLaneOptions = turnLanes.split("\\|", -1);
|
||||
int activeBeginIndex = findActiveIndex(rawLanes, splitLaneOptions, rs.leftLanes, true,
|
||||
|
@ -944,13 +968,11 @@ public class RouteResultPreparation {
|
|||
t = TurnType.valueOf(tp, leftSide);
|
||||
}
|
||||
} else {
|
||||
boolean possiblyLeftTurn = rs.roadsOnLeft == 0;
|
||||
boolean possiblyRightTurn = rs.roadsOnRight == 0;
|
||||
t.setPossibleLeftTurn(possiblyLeftTurn);
|
||||
t.setPossibleRightTurn(possiblyRightTurn);
|
||||
for (int k = 0; k < rawLanes.length; k++) {
|
||||
int turn = TurnType.getPrimaryTurn(rawLanes[k]);
|
||||
int sturn = TurnType.getSecondaryTurn(rawLanes[k]);
|
||||
int tturn = TurnType.getTertiaryTurn(rawLanes[k]);
|
||||
|
||||
boolean active = false;
|
||||
// some turns go through many segments (to turn right or left)
|
||||
// so on one first segment the lane could be available and may be only 1 possible
|
||||
|
@ -959,8 +981,13 @@ public class RouteResultPreparation {
|
|||
(TurnType.isLeftTurn(sturn) && possiblyLeftTurn)) {
|
||||
// we can't predict here whether it will be a left turn or straight on,
|
||||
// it could be done during 2nd pass
|
||||
// TurnType.setPrimaryTurn(rawLanes, k, sturn);
|
||||
// TurnType.setSecondaryTurn(rawLanes, k, turn);
|
||||
TurnType.setPrimaryTurn(rawLanes, k, sturn);
|
||||
TurnType.setSecondaryTurn(rawLanes, k, turn);
|
||||
active = true;
|
||||
} else if((TurnType.isRightTurn(tturn) && possiblyRightTurn) ||
|
||||
(TurnType.isLeftTurn(tturn) && possiblyLeftTurn)) {
|
||||
TurnType.setPrimaryTurn(rawLanes, k, tturn);
|
||||
TurnType.setTertiaryTurn(rawLanes, k, turn);
|
||||
active = true;
|
||||
} else if((TurnType.isRightTurn(turn) && possiblyRightTurn) ||
|
||||
(TurnType.isLeftTurn(turn) && possiblyLeftTurn)) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.router;
|
||||
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
import gnu.trove.set.hash.TIntHashSet;
|
||||
|
||||
public class TurnType {
|
||||
|
@ -22,6 +23,18 @@ public class TurnType {
|
|||
return valueOf(C, false);
|
||||
}
|
||||
|
||||
public int getActiveCommonLaneTurn() {
|
||||
if(lanes == null || lanes.length == 0) {
|
||||
return C;
|
||||
}
|
||||
for(int i = 0; i < lanes.length; i++) {
|
||||
if(lanes[i] % 2 == 1) {
|
||||
return TurnType.getPrimaryTurn(lanes[i]);
|
||||
}
|
||||
}
|
||||
return C;
|
||||
}
|
||||
|
||||
public String toXmlString() {
|
||||
switch (value) {
|
||||
case C:
|
||||
|
|
|
@ -103,7 +103,7 @@ public class RouteResultPreparationTest {
|
|||
if(!Algorithms.objectEquals(expectedResult, turnLanes) &&
|
||||
!Algorithms.objectEquals(expectedResult, lanes) &&
|
||||
!Algorithms.objectEquals(expectedResult, turn)) {
|
||||
Assert.assertEquals("Segment " + segmentId, turnLanes, expectedResult);
|
||||
Assert.assertEquals("Segment " + segmentId, expectedResult, turnLanes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -324,7 +324,7 @@
|
|||
},
|
||||
"expectedResults": {
|
||||
"96306": null,
|
||||
"96296": "TU:+C|C|C|C|C"
|
||||
"96296": "TU:C|C|C|C|C"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue