Merge branch 'r3.3'

This commit is contained in:
Victor Shcherb 2019-03-13 16:43:11 +01:00
commit bd5ab069d3
2 changed files with 58 additions and 41 deletions

View file

@ -1,18 +1,17 @@
package net.osmand.data; package net.osmand.data;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
public class TransportRoute extends MapObject { public class TransportRoute extends MapObject {
private List<TransportStop> forwardStops = new ArrayList<TransportStop>(); private List<TransportStop> forwardStops = new ArrayList<TransportStop>();
private String ref; private String ref;
@ -53,52 +52,61 @@ public class TransportRoute extends MapObject {
// combine as many ways as possible // combine as many ways as possible
while (changed) { while (changed) {
changed = false; changed = false;
Iterator<Way> it = forwardWays.iterator(); for(int k = 0; k < forwardWays.size(); ) {
while (it.hasNext() && !changed) {
// scan to merge with the next segment // scan to merge with the next segment
Way first = forwardWays.get(k);
double d = SAME_STOP; double d = SAME_STOP;
Way w = it.next(); boolean reverseSecond = false;
Way toCombine = null; boolean reverseFirst = false;
boolean reverseOriginal = false; int secondInd = -1;
boolean reverseCombine = false; for (int i = k + 1; i < forwardWays.size(); i++) {
for (int i = 0; i < forwardWays.size(); i++) { Way w = forwardWays.get(i);
Way combine = forwardWays.get(i); double distAttachAfter = MapUtils.getDistance(first.getLastNode().getLatLon(), w.getFirstNode().getLatLon());
if (combine == w) { double distReverseAttach = MapUtils.getDistance(first.getLastNode().getLatLon(), w.getLastNode().getLatLon());
continue; double distAttachAfterReverse = MapUtils.getDistance(first.getFirstNode().getLatLon(), w.getFirstNode().getLatLon());
} double distReverseAttachReverse = MapUtils.getDistance(first.getFirstNode().getLatLon(), w.getLastNode().getLatLon());
double distAttachAfter = MapUtils.getDistance(w.getFirstNode().getLatLon(), combine.getLastNode().getLatLon());
double distReverseAttachAfter = MapUtils.getDistance(w.getLastNode().getLatLon(), combine.getLastNode()
.getLatLon());
double distAttachAfterReverse = MapUtils.getDistance(w.getFirstNode().getLatLon(), combine.getFirstNode().getLatLon());
if (distAttachAfter < d) { if (distAttachAfter < d) {
toCombine = combine; reverseSecond = false;
reverseOriginal = false; reverseFirst = false;
reverseCombine = false;
d = distAttachAfter; d = distAttachAfter;
} else if (distReverseAttachAfter < d) { secondInd = i;
toCombine = combine; }
reverseOriginal = true; if (distReverseAttach < d) {
reverseCombine = false; reverseSecond = true;
d = distReverseAttachAfter; reverseFirst = false;
} else if (distAttachAfterReverse < d) { d = distReverseAttach;
toCombine = combine; secondInd = i;
reverseOriginal = false; }
reverseCombine = true; if (distAttachAfterReverse < d) {
reverseSecond = false;
reverseFirst = true;
d = distAttachAfterReverse; d = distAttachAfterReverse;
secondInd = i;
}
if (distReverseAttachReverse < d) {
reverseSecond = true;
reverseFirst = true;
d = distReverseAttachReverse;
secondInd = i;
}
if (d == 0) {
break;
} }
} }
if (toCombine != null) { if (secondInd != -1) {
if(reverseCombine) { Way second = forwardWays.remove(secondInd);
toCombine.reverseNodes(); if(reverseFirst) {
first.reverseNodes();
} }
if(reverseOriginal) { if(reverseSecond) {
w.reverseNodes(); second.reverseNodes();
} }
for (int i = 1; i < w.getNodes().size(); i++) { for (int i = 1; i < second.getNodes().size(); i++) {
toCombine.addNode(w.getNodes().get(i)); first.addNode(second.getNodes().get(i));
} }
it.remove();
changed = true; changed = true;
} else {
k++;
} }
} }
} }

View file

@ -273,6 +273,8 @@ public class TransportRoutePlanner {
public static class TransportRouteResultSegment { public static class TransportRouteResultSegment {
private static final boolean DISPLAY_FULL_SEGMENT_ROUTE = false;
private static final int DISPLAY_SEGMENT_IND = 0;
public final TransportRoute route; public final TransportRoute route;
public final int start; public final int start;
public final int end; public final int end;
@ -329,6 +331,13 @@ public class TransportRoutePlanner {
public List<Way> getGeometry() { public List<Way> getGeometry() {
List<Way> list = new ArrayList<Way>(); List<Way> list = new ArrayList<Way>();
route.mergeForwardWays(); route.mergeForwardWays();
if(DISPLAY_FULL_SEGMENT_ROUTE) {
System.out.println("TOTAL SEGMENTS: " + route.getForwardWays().size());
if(route.getForwardWays().size() > DISPLAY_SEGMENT_IND) {
return Collections.singletonList(route.getForwardWays().get(DISPLAY_SEGMENT_IND));
}
return route.getForwardWays();
}
List<Way> fw = route.getForwardWays(); List<Way> fw = route.getForwardWays();
double minStart = 150; double minStart = 150;
double minEnd = 150; double minEnd = 150;