Fix invisible zigzags
This commit is contained in:
parent
050b48274b
commit
3bf2ded7a4
3 changed files with 42 additions and 4 deletions
|
@ -7,6 +7,7 @@ import java.text.MessageFormat;
|
||||||
|
|
||||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
|
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
|
||||||
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
|
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
|
||||||
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
public class RouteDataObject {
|
public class RouteDataObject {
|
||||||
/*private */static final int RESTRICTION_SHIFT = 3;
|
/*private */static final int RESTRICTION_SHIFT = 3;
|
||||||
|
@ -251,6 +252,24 @@ public class RouteDataObject {
|
||||||
return directionRoute(startPoint, plus, 5);
|
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]
|
// Gives route direction of EAST degrees from NORTH ]-PI, PI]
|
||||||
public double directionRoute(int startPoint, boolean plus, float dist) {
|
public double directionRoute(int startPoint, boolean plus, float dist) {
|
||||||
int x = getPoint31XTile(startPoint);
|
int x = getPoint31XTile(startPoint);
|
||||||
|
@ -274,11 +293,15 @@ public class RouteDataObject {
|
||||||
px = getPoint31XTile(nx);
|
px = getPoint31XTile(nx);
|
||||||
py = getPoint31YTile(nx);
|
py = getPoint31YTile(nx);
|
||||||
// translate into meters
|
// 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);
|
} while (total < dist);
|
||||||
return -Math.atan2( x - px, y - py );
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String name = getName();
|
String name = getName();
|
||||||
|
|
|
@ -95,9 +95,20 @@ public class RouteResultPreparation {
|
||||||
attachRoadSegments(ctx, result, i, next, plus);
|
attachRoadSegments(ctx, result, i, next, plus);
|
||||||
}
|
}
|
||||||
List<RouteSegmentResult> attachedRoutes = rr.getAttachedRoutes(next);
|
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 before = rr.getBearing(next, !plus);
|
||||||
float after = 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 straight = Math.abs(MapUtils.degreesDiff(before + 180, after)) < TURN_DEGREE_MIN;
|
||||||
boolean isSplit = false;
|
boolean isSplit = false;
|
||||||
// split if needed
|
// split if needed
|
||||||
|
@ -483,11 +494,11 @@ public class RouteResultPreparation {
|
||||||
double devation = Math.abs(MapUtils.degreesDiff(prevSegm.getBearingEnd(), currentSegm.getBearingBegin()));
|
double devation = Math.abs(MapUtils.degreesDiff(prevSegm.getBearingEnd(), currentSegm.getBearingBegin()));
|
||||||
boolean makeSlightTurn = devation > 5 && (!isMotorway(prevSegm) || !isMotorway(currentSegm));
|
boolean makeSlightTurn = devation > 5 && (!isMotorway(prevSegm) || !isMotorway(currentSegm));
|
||||||
if (kl) {
|
if (kl) {
|
||||||
t = TurnType.valueOf(devation > 5 ? TurnType.TSLL : TurnType.KL, leftSide);
|
t = TurnType.valueOf(makeSlightTurn ? TurnType.TSLL : TurnType.KL, leftSide);
|
||||||
t.setSkipToSpeak(!speak);
|
t.setSkipToSpeak(!speak);
|
||||||
}
|
}
|
||||||
if (kr) {
|
if (kr) {
|
||||||
t = TurnType.valueOf(devation > 5 ? TurnType.TSLR : TurnType.KR, leftSide);
|
t = TurnType.valueOf(makeSlightTurn ? TurnType.TSLR : TurnType.KR, leftSide);
|
||||||
t.setSkipToSpeak(!speak);
|
t.setSkipToSpeak(!speak);
|
||||||
}
|
}
|
||||||
if (t != null && lanes != null) {
|
if (t != null && lanes != null) {
|
||||||
|
|
|
@ -99,6 +99,10 @@ public class RouteSegmentResult {
|
||||||
return (float) (object.directionRoute(point, plus) / Math.PI * 180);
|
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() {
|
public float getBearingEnd() {
|
||||||
return (float) (MapUtils.alignAngleDifference(object.directionRoute(endPointIndex, startPointIndex > endPointIndex) - Math.PI) / Math.PI * 180);
|
return (float) (MapUtils.alignAngleDifference(object.directionRoute(endPointIndex, startPointIndex > endPointIndex) - Math.PI) / Math.PI * 180);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue