Merge pull request #968 from saiarcot895/remove-verifications

Remove one verification of lanes and turn:lanes
This commit is contained in:
vshcherb 2014-11-23 17:16:28 +01:00
commit 087506c795

View file

@ -463,10 +463,7 @@ public class RouteResultPreparation {
} }
private void assignLanesInfo(RouteSegmentResult prevSegm, TurnType t, boolean leftSide) { private void assignLanesInfo(RouteSegmentResult prevSegm, TurnType t, boolean leftSide) {
int lanes = prevSegm.getObject().getLanes(); int lanes = countLanes(prevSegm);
if (prevSegm.getObject().getOneway() == 0) {
lanes = countLanes(prevSegm, lanes);
}
if (lanes <= 0) { if (lanes <= 0) {
return; return;
} }
@ -574,10 +571,7 @@ public class RouteResultPreparation {
if (rsSpeakPriority != MAX_SPEAK_PRIORITY || speakPriority == MAX_SPEAK_PRIORITY) { if (rsSpeakPriority != MAX_SPEAK_PRIORITY || speakPriority == MAX_SPEAK_PRIORITY) {
if ((ex < TURN_DEGREE_MIN || mpi < TURN_DEGREE_MIN) && ex >= 0) { if ((ex < TURN_DEGREE_MIN || mpi < TURN_DEGREE_MIN) && ex >= 0) {
kl = true; kl = true;
int lns = attached.getObject().getLanes(); int lns = countLanes(attached);
if(attached.getObject().getOneway() == 0) {
lns = countLanes(attached, lns);
}
if (lns <= 0) { if (lns <= 0) {
right += 1; right += 1;
} else { } else {
@ -586,10 +580,7 @@ public class RouteResultPreparation {
speak = speak || rsSpeakPriority <= speakPriority; speak = speak || rsSpeakPriority <= speakPriority;
} else if ((ex > -TURN_DEGREE_MIN || mpi < TURN_DEGREE_MIN) && ex <= 0) { } else if ((ex > -TURN_DEGREE_MIN || mpi < TURN_DEGREE_MIN) && ex <= 0) {
kr = true; kr = true;
int lns = attached.getObject().getLanes(); int lns = countLanes(attached);
if(attached.getObject().getOneway() == 0) {
lns = countLanes(attached, lns);
}
if (lns <= 0) { if (lns <= 0) {
left += 1; left += 1;
} else { } else {
@ -605,11 +596,8 @@ public class RouteResultPreparation {
} else if(kl && right == 0) { } else if(kl && right == 0) {
right = 1; right = 1;
} }
int current = currentSegm.getObject().getLanes(); int current = countLanes(currentSegm);
// attachedRoutes covers all allowed outbound routes at that point except currentSegm. // attachedRoutes covers all allowed outbound routes at that point except currentSegm.
if (currentSegm.getObject().getOneway() == 0) {
current = countLanes(currentSegm, current);
}
if (current <= 0) { if (current <= 0) {
current = 1; current = 1;
} }
@ -647,17 +635,23 @@ public class RouteResultPreparation {
return t; return t;
} }
protected int countLanes(RouteSegmentResult attached, int lns) { protected int countLanes(RouteSegmentResult attached) {
if (attached.getObject().getOneway() == 0) {
try { try {
if (attached.isForwardDirection() && attached.getObject().getValue("lanes:forward") != null) { if (attached.isForwardDirection() && attached.getObject().getValue("lanes:forward") != null) {
return Integer.parseInt(attached.getObject().getValue("lanes:forward")); return Integer.parseInt(attached.getObject().getValue("lanes:forward"));
} else if (!attached.isForwardDirection() && attached.getObject().getValue("lanes:backward") != null) { } else if (!attached.isForwardDirection() && attached.getObject().getValue("lanes:backward") != null) {
return Integer.parseInt(attached.getObject().getValue("lanes:backward")); return Integer.parseInt(attached.getObject().getValue("lanes:backward"));
} else {
return -1;
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
e.printStackTrace(); e.printStackTrace();
return -1;
}
} else {
return attached.getObject().getLanes();
} }
return (lns + 1) / 2;
} }
protected String getTurnLanesString(RouteSegmentResult segment) { protected String getTurnLanesString(RouteSegmentResult segment) {
@ -673,7 +667,7 @@ public class RouteResultPreparation {
} }
private TurnType attachTurnLanesData(boolean leftSide, RouteSegmentResult prevSegm, TurnType t) { private TurnType attachTurnLanesData(boolean leftSide, RouteSegmentResult prevSegm, TurnType t) {
int lanes = prevSegm.getObject().getLanes(); int lanes = countLanes(prevSegm);
String turnLanes = getTurnLanesString(prevSegm); String turnLanes = getTurnLanesString(prevSegm);
if (turnLanes == null) { if (turnLanes == null) {
@ -681,19 +675,42 @@ public class RouteResultPreparation {
} }
String[] splitLaneOptions = turnLanes.split("\\|", -1); String[] splitLaneOptions = turnLanes.split("\\|", -1);
if (splitLaneOptions.length != lanes) { if (splitLaneOptions.length != lanes) {
// Error in data or missing data log.warn("Number of lanes in lanes key (" + lanes + ") does not match number of lanes from turn:lanes key (" + splitLaneOptions.length + "). Errors may occur.");
return t;
int leftLanes = 0;
int rightLanes = 0;
boolean processingLeft = true;
for (int i = 0; i < t.getLanes().length; i++) {
if (t.getLanes()[i] == 0) {
if (processingLeft) {
leftLanes++;
} else {
rightLanes++;
}
} else {
processingLeft = false;
}
}
int[] adjustedLanes = new int[lanes + leftLanes + rightLanes];
for (int i = leftLanes; i < leftLanes + lanes; i++) {
adjustedLanes[i] = 1;
}
t.setLanes(adjustedLanes);
} }
if (t.getLanes().length != lanes) { if (t.getLanes().length != lanes) {
// The turn:lanes don't easily match up to the target road. // The lanes from prevSegm don't easily match up to the target roads (it's not one-to-one).
List<Integer> sourceLanes = new ArrayList<Integer>(); List<Integer> sourceLanes = new ArrayList<Integer>();
int outgoingLanesIndex = 0; int outgoingLanesIndex = 0;
int sourceLanesIndex = 0; int sourceLanesIndex = 0;
while (outgoingLanesIndex < t.getLanes().length && sourceLanesIndex < lanes) { while (outgoingLanesIndex < t.getLanes().length && sourceLanesIndex < splitLaneOptions.length) {
if (splitLaneOptions[sourceLanesIndex].contains(";")) { if (splitLaneOptions[sourceLanesIndex].contains(";")) {
// Two or more allowed turns for this lane // Two or more allowed turns for this lane
int options = countOccurrences(splitLaneOptions[sourceLanesIndex], ';'); int options = countOccurrences(splitLaneOptions[sourceLanesIndex], ';');