This commit is contained in:
Victor Shcherb 2019-06-27 17:16:32 +02:00
parent e027a31176
commit 312b4d7d47

View file

@ -26,7 +26,8 @@ import java.util.List;
import static net.osmand.binary.RouteDataObject.HEIGHT_UNDEFINED; import static net.osmand.binary.RouteDataObject.HEIGHT_UNDEFINED;
public class RouteCalculationResult { public class RouteCalculationResult {
private static double distanceClosestToIntermediate = 400; private static double distanceClosestToIntermediate = 3000;
private static double distanceThresholdToIntermediate = 25;
// 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;
@ -133,27 +134,31 @@ public class RouteCalculationResult {
List<LatLon> intermediates, List<RouteDirectionInfo> localDirections, int[] intermediatePoints) { List<LatLon> intermediates, List<RouteDirectionInfo> localDirections, int[] intermediatePoints) {
if(intermediates != null && localDirections != null) { if(intermediates != null && localDirections != null) {
int[] interLocations = new int[intermediates.size()]; int[] interLocations = new int[intermediates.size()];
int currentIntermediate = 0; for(int currentIntermediate = 0; currentIntermediate < intermediates.size(); currentIntermediate++ ) {
int currentLocation = 0; double setDistance = distanceClosestToIntermediate ;
double distanceThreshold = 25; LatLon currentIntermediatePoint = intermediates.get(currentIntermediate);
double prevDistance = distanceThreshold * 4; int prevLocation = currentIntermediate == 0 ? 0 : interLocations[currentIntermediate - 1];
while((currentIntermediate < intermediates.size() || prevDistance > distanceThreshold) for(int currentLocation = prevLocation; currentLocation < locations.size();
&& currentLocation < locations.size()){ currentLocation++) {
if(currentIntermediate < intermediates.size() && double currentDistance = getDistanceToLocation(locations, currentIntermediatePoint, currentLocation);
getDistanceToLocation(locations, intermediates.get(currentIntermediate), currentLocation) < distanceClosestToIntermediate) { if(currentDistance < setDistance) {
prevDistance = getDistanceToLocation(locations, intermediates.get(currentIntermediate), currentLocation);
interLocations[currentIntermediate] = currentLocation; interLocations[currentIntermediate] = currentLocation;
currentIntermediate++; setDistance = currentDistance;
} else if(currentIntermediate > 0 && prevDistance > distanceThreshold && } else if(currentDistance > distanceThresholdToIntermediate &&
getDistanceToLocation(locations, intermediates.get(currentIntermediate - 1), setDistance < distanceThresholdToIntermediate) {
currentLocation) < prevDistance) { // finish search
prevDistance = getDistanceToLocation(locations, intermediates.get(currentIntermediate - 1), currentLocation); break;
interLocations[currentIntermediate - 1] = currentLocation;
} }
currentLocation ++;
} }
if(setDistance == distanceClosestToIntermediate) {
return;
}
}
int currentDirection = 0; int currentDirection = 0;
currentIntermediate = 0; int currentIntermediate = 0;
while(currentIntermediate < intermediates.size() && currentDirection < localDirections.size()){ while(currentIntermediate < intermediates.size() && currentDirection < localDirections.size()){
int locationIndex = localDirections.get(currentDirection).routePointOffset ; int locationIndex = localDirections.get(currentDirection).routePointOffset ;
if (locationIndex >= interLocations[currentIntermediate]) { if (locationIndex >= interLocations[currentIntermediate]) {