Fix invisible zigzags

This commit is contained in:
vshcherb 2013-11-26 16:23:05 +01:00
parent 050b48274b
commit 3bf2ded7a4
3 changed files with 42 additions and 4 deletions

View file

@ -7,6 +7,7 @@ import java.text.MessageFormat;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
import net.osmand.util.MapUtils;
public class RouteDataObject {
/*private */static final int RESTRICTION_SHIFT = 3;
@ -250,6 +251,24 @@ public class RouteDataObject {
// So it should be fix in both places
return directionRoute(startPoint, plus, 5);
}
public double distance(int startPoint, int endPoint) {
if(startPoint > endPoint) {
int k = endPoint;
endPoint = startPoint;
startPoint = k;
}
double d = 0;
for(int k = startPoint; k < endPoint && k < getPointsLength() -1; k++) {
int x = getPoint31XTile(k);
int y = getPoint31YTile(k);
int kx = getPoint31XTile(k + 1);
int ky = getPoint31YTile(k + 1);
d += simplifyDistance(kx, ky, x, y);
}
return d;
}
// Gives route direction of EAST degrees from NORTH ]-PI, PI]
public double directionRoute(int startPoint, boolean plus, float dist) {
@ -274,10 +293,14 @@ public class RouteDataObject {
px = getPoint31XTile(nx);
py = getPoint31YTile(nx);
// translate into meters
total += Math.abs(px - x) * 0.011d + Math.abs(py - y) * 0.01863d;
total += simplifyDistance(x, y, px, py);
} while (total < dist);
return -Math.atan2( x - px, y - py );
}
private double simplifyDistance(int x, int y, int px, int py) {
return Math.abs(px - x) * 0.011d + Math.abs(py - y) * 0.01863d;
}
@Override
public String toString() {

View file

@ -95,9 +95,20 @@ public class RouteResultPreparation {
attachRoadSegments(ctx, result, i, next, plus);
}
List<RouteSegmentResult> attachedRoutes = rr.getAttachedRoutes(next);
if (next != rr.getEndPointIndex() && !rr.getObject().roundabout() && attachedRoutes != null) {
boolean tryToSplit = next != rr.getEndPointIndex() && !rr.getObject().roundabout() && attachedRoutes != null;
if(rr.getDistance(next, plus ) == 0) {
// same point will be processed next step
tryToSplit = false;
}
if (tryToSplit) {
// avoid small zigzags
float before = rr.getBearing(next, !plus);
float after = rr.getBearing(next, plus);
if(rr.getDistance(next, plus ) < 5) {
after = before + 180;
} else if(rr.getDistance(next, !plus ) < 5) {
before = after - 180;
}
boolean straight = Math.abs(MapUtils.degreesDiff(before + 180, after)) < TURN_DEGREE_MIN;
boolean isSplit = false;
// split if needed
@ -483,11 +494,11 @@ public class RouteResultPreparation {
double devation = Math.abs(MapUtils.degreesDiff(prevSegm.getBearingEnd(), currentSegm.getBearingBegin()));
boolean makeSlightTurn = devation > 5 && (!isMotorway(prevSegm) || !isMotorway(currentSegm));
if (kl) {
t = TurnType.valueOf(devation > 5 ? TurnType.TSLL : TurnType.KL, leftSide);
t = TurnType.valueOf(makeSlightTurn ? TurnType.TSLL : TurnType.KL, leftSide);
t.setSkipToSpeak(!speak);
}
if (kr) {
t = TurnType.valueOf(devation > 5 ? TurnType.TSLR : TurnType.KR, leftSide);
t = TurnType.valueOf(makeSlightTurn ? TurnType.TSLR : TurnType.KR, leftSide);
t.setSkipToSpeak(!speak);
}
if (t != null && lanes != null) {

View file

@ -99,6 +99,10 @@ public class RouteSegmentResult {
return (float) (object.directionRoute(point, plus) / Math.PI * 180);
}
public float getDistance(int point, boolean plus) {
return (float) (plus? object.distance(point, endPointIndex): object.distance(startPointIndex, point));
}
public float getBearingEnd() {
return (float) (MapUtils.alignAngleDifference(object.directionRoute(endPointIndex, startPointIndex > endPointIndex) - Math.PI) / Math.PI * 180);
}