Merge pull request #8430 from osmandapp/Fix_8266

Fix_8266
This commit is contained in:
vshcherb 2020-02-11 17:39:47 +01:00 committed by GitHub
commit 74bd9a002d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -35,6 +35,7 @@ public class RouteCalculationResult {
private static double distanceClosestToIntermediate = 3000; private static double distanceClosestToIntermediate = 3000;
private static double distanceThresholdToIntermediate = 25; private static double distanceThresholdToIntermediate = 25;
private static double DISTANCE_THRESHOLD_TO_INTRODUCE_FIRST_AND_LAST_POINTS = 50;
// could not be null and immodifiable! // could not be null and immodifiable!
private final List<Location> locations; private final List<Location> locations;
private final List<RouteDirectionInfo> directions; private final List<RouteDirectionInfo> directions;
@ -692,22 +693,9 @@ public class RouteCalculationResult {
private static void introduceFirstPointAndLastPoint(List<Location> locations, List<RouteDirectionInfo> directions, private static void introduceFirstPointAndLastPoint(List<Location> locations, List<RouteDirectionInfo> directions,
List<RouteSegmentResult> segs, Location start, LatLon end, List<RouteSegmentResult> segs, Location start, LatLon end,
OsmandApplication ctx) { OsmandApplication ctx) {
if (!locations.isEmpty() && locations.get(0).distanceTo(start) > 50) { boolean firstPointIntroduced = introduceFirstPoint(locations, directions, segs, start);
// add start point boolean lastPointIntroduced = introduceLastPoint(locations, directions, segs, end);
locations.add(0, start); if (firstPointIntroduced || lastPointIntroduced) {
if(segs != null) {
segs.add(0, segs.get(0));
}
if (directions != null && !directions.isEmpty()) {
for (RouteDirectionInfo i : directions) {
i.routePointOffset++;
}
RouteDirectionInfo info = new RouteDirectionInfo(directions.get(0).getAverageSpeed(),
TurnType.straight());
info.routePointOffset = 0;
// info.setDescriptionRoute(ctx.getString( R.string.route_head));//; //$NON-NLS-1$
directions.add(0, info);
}
checkForDuplicatePoints(locations, directions); checkForDuplicatePoints(locations, directions);
} }
RouteDirectionInfo lastDirInf = directions.size() > 0 ? directions.get(directions.size() - 1) : null; RouteDirectionInfo lastDirInf = directions.size() > 0 ? directions.get(directions.size() - 1) : null;
@ -742,6 +730,70 @@ public class RouteCalculationResult {
} }
} }
private static boolean introduceFirstPoint(List<Location> locations, List<RouteDirectionInfo> directions,
List<RouteSegmentResult> segs, Location start) {
if (!locations.isEmpty() && locations.get(0).distanceTo(start) > DISTANCE_THRESHOLD_TO_INTRODUCE_FIRST_AND_LAST_POINTS) {
// add start point
locations.add(0, start);
if (segs != null) {
segs.add(0, segs.get(0));
}
if (directions != null && !directions.isEmpty()) {
for (RouteDirectionInfo i : directions) {
i.routePointOffset++;
}
RouteDirectionInfo info = new RouteDirectionInfo(directions.get(0).getAverageSpeed(), TurnType.straight());
info.routePointOffset = 0;
// info.setDescriptionRoute(ctx.getString( R.string.route_head));//; //$NON-NLS-1$
directions.add(0, info);
}
return true;
}
return false;
}
private static boolean introduceLastPoint(List<Location> locations, List<RouteDirectionInfo> directions,
List<RouteSegmentResult> segs, LatLon end) {
if (!locations.isEmpty()) {
Location lastFoundLocation = locations.get(locations.size() - 1);
Location endLocation = new Location(lastFoundLocation.getProvider());
endLocation.setLatitude(end.getLatitude());
endLocation.setLongitude(end.getLongitude());
if (lastFoundLocation.distanceTo(endLocation) > DISTANCE_THRESHOLD_TO_INTRODUCE_FIRST_AND_LAST_POINTS) {
if (directions != null && !directions.isEmpty()) {
if (locations.size() > 2) {
int type = TurnType.C;
Location prevLast = locations.get(locations.size() - 2);
float lastBearing = prevLast.bearingTo(lastFoundLocation);
float bearingToEnd = lastFoundLocation.bearingTo(endLocation);
double diff = MapUtils.degreesDiff(lastBearing, bearingToEnd);
if (Math.abs(diff) > 10) {
if (Math.abs(diff) < 60) {
type = diff > 0 ? TurnType.TSLL : TurnType.TSLR;
} else {
type = diff > 0 ? TurnType.TL : TurnType.TR;
}
}
RouteDirectionInfo lastDirInf = directions.get(directions.size() - 1);
RouteDirectionInfo info = new RouteDirectionInfo(lastDirInf != null ? lastDirInf.getAverageSpeed() : 1, TurnType.valueOf(type, false));
info.routePointOffset = locations.size() - 1;
directions.add(info);
}
}
// add end point
locations.add(endLocation);
if (segs != null) {
segs.add(segs.get(segs.size() - 1));
}
return true;
}
}
return false;
}
/** /**
* PREPARATION * PREPARATION
* At the end always update listDistance local vars and time * At the end always update listDistance local vars and time