diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index 2e3c16fb51..f046fa0824 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -705,21 +705,37 @@ public class RouteResultPreparation { active.activeStartIndex = active.activeStartIndex + target.activeStartIndex; changed = true; } else { - // cause the next-turn goes forward exclude left most and right most lane - if(active.activeStartIndex == 0) { - active.activeStartIndex ++; - active.activeLen--; + int straightActiveLen = 0; + int straightActiveBegin = -1; + for(int i = active.activeStartIndex; i <= active.activeEndIndex; i++) { + if(TurnType.hasAnyTurnLane(active.originalLanes[i], TurnType.C)) { + straightActiveLen++; + if(straightActiveBegin == -1) { + straightActiveBegin = i; + } + } } - if(active.activeEndIndex == active.originalLanes.length - 1) { - active.activeEndIndex --; - active.activeLen--; + if(straightActiveLen == target.activeLen) { + active.activeStartIndex = straightActiveBegin; + active.activeEndIndex = straightActiveBegin + target.activeLen - 1; + changed = true; + } else { + // cause the next-turn goes forward exclude left most and right most lane + if (active.activeStartIndex == 0) { + active.activeStartIndex++; + active.activeLen--; + } + if (active.activeEndIndex == active.originalLanes.length - 1) { + active.activeEndIndex--; + active.activeLen--; + } + float ratio = (active.activeLen - target.activeLen) / 2f; + if (ratio > 0) { + active.activeEndIndex = (int) Math.ceil(active.activeEndIndex - ratio); + active.activeStartIndex = (int) Math.floor(active.activeStartIndex + ratio); + } + changed = true; } - float ratio = (active.activeLen - target.activeLen) / 2f; - if(ratio > 0) { - active.activeEndIndex = (int) Math.ceil(active.activeEndIndex - ratio); - active.activeStartIndex = (int) Math.floor(active.activeStartIndex + ratio); - } - changed = true; } } } @@ -1042,8 +1058,17 @@ public class RouteResultPreparation { String[] splitLaneOptions = turnLanes.split("\\|", -1); int activeBeginIndex = findActiveIndex(rawLanes, splitLaneOptions, rs.leftLanes, true, rs.leftLanesInfo, rs.roadsOnLeft, rs.addRoadsOnLeft); + + if(!rs.keepLeft && activeBeginIndex != -1 && + splitLaneOptions.length > 0 && !splitLaneOptions[splitLaneOptions.length - 1].contains(";")) { + activeBeginIndex = Math.max(activeBeginIndex, 1); + } int activeEndIndex = findActiveIndex(rawLanes, splitLaneOptions, rs.rightLanes, false, rs.rightLanesInfo, rs.roadsOnRight, rs.addRoadsOnRight); + if(!rs.keepRight && activeEndIndex != -1 && + splitLaneOptions.length > 0 && !splitLaneOptions[0].contains(";") ) { + activeEndIndex = Math.min(activeEndIndex, rawLanes.length - 1); + } if (activeBeginIndex == -1 || activeEndIndex == -1 || activeBeginIndex > activeEndIndex) { // something went wrong return createSimpleKeepLeftRightTurn(leftSide, prevSegm, currentSegm, rs); @@ -1116,8 +1141,7 @@ public class RouteResultPreparation { for (int i = 0; i < rawLanes.length; i++) { int ind = left ? i : (rawLanes.length - i - 1); if (!lookupSlightTurn || - TurnType.isSlightTurn(TurnType.getPrimaryTurn(rawLanes[ind])) - || TurnType.isSlightTurn(TurnType.getSecondaryTurn(rawLanes[ind]))) { + TurnType.hasAnySlightTurnLane(rawLanes[ind])) { String[] laneTurns = splitLaneOptions[ind].split(";"); int cnt = 0; for(String lTurn : laneTurns) { @@ -1127,14 +1151,8 @@ public class RouteResultPreparation { diffTurnRoads --; } } -// int cnt = countOccurrences(splitLaneOptions[ind], ';') + 1; -// if(cnt > 1) { -// // sometimes slight right turn goes to the road with 2 lanes -// // the better situation to group all the lanes and -// // when ';' we know for sure the lane combines 2 group -// roads --; -// } lanes -= cnt; + //lanes--; // we already found slight turn others are turn in different direction lookupSlightTurn = false; } diff --git a/OsmAnd-java/src/net/osmand/router/TurnType.java b/OsmAnd-java/src/net/osmand/router/TurnType.java index 332ed2a86f..18f7e906b3 100644 --- a/OsmAnd-java/src/net/osmand/router/TurnType.java +++ b/OsmAnd-java/src/net/osmand/router/TurnType.java @@ -357,6 +357,18 @@ public class TurnType { public static boolean isSlightTurn(int type) { return type == TSLL || type == TSLR || type == C || type == KL || type == KR; } + + public static boolean hasAnySlightTurnLane(int type) { + return TurnType.isSlightTurn(TurnType.getPrimaryTurn(type)) + || TurnType.isSlightTurn(TurnType.getSecondaryTurn(type)) + || TurnType.isSlightTurn(TurnType.getTertiaryTurn(type)); + } + + public static boolean hasAnyTurnLane(int type, int turn) { + return TurnType.getPrimaryTurn(type) == turn + || TurnType.getSecondaryTurn(type) == turn + || TurnType.getTertiaryTurn(type) == turn; + } public static void collectTurnTypes(int lane, TIntHashSet set) { int pt = TurnType.getPrimaryTurn(lane); diff --git a/OsmAnd-java/test/resources/test_turn_lanes.json b/OsmAnd-java/test/resources/test_turn_lanes.json index 598f219203..3296a156de 100644 --- a/OsmAnd-java/test/resources/test_turn_lanes.json +++ b/OsmAnd-java/test/resources/test_turn_lanes.json @@ -100,7 +100,7 @@ "longitude": 35.49527125060558 }, "expectedResults": { - "26717": "C:+C,TSLL|C|C", + "26717": "C:C,TSLL|+C|C", "26821": "TSLL:+TSLL,C|C|C", "29088": "C|C|C|C|+C" } @@ -494,6 +494,7 @@ "longitude": 35.5013644695282 }, "expectedResults": { + "61820398":"C|+C|+C|+C|TSLR|TSLR", "4400154": "C|C|+TSLR,C|+TSLR|+TSLR" } }, @@ -583,7 +584,7 @@ } }, { - "testName": "32.Motorway TR South Kent Des Moines Road", + "testName": "32.Motorway TR South Kent Des Moines Road (1st turn incorrect)", "startPoint": { "latitude": 45.64518099200965, "longitude": 35.668448954820605 @@ -593,7 +594,7 @@ "longitude": 35.66181853413579 }, "expectedResults": { - "222244": "TL|TL|+C", + "222244": "TL|+TL|C", "222243": "TL|TL|+C|C|TSLR", "222164": "TL|TL|+C|C" } diff --git a/OsmAnd/res/drawable-mdpi/View_angle_27.png b/OsmAnd/res/drawable-mdpi/View_angle_27.png deleted file mode 100644 index 5b3372e855..0000000000 Binary files a/OsmAnd/res/drawable-mdpi/View_angle_27.png and /dev/null differ