Fix bug with road duplication and many times saying same command (keep left or keep right)

This commit is contained in:
Victor Shcherb 2012-09-06 11:12:02 +02:00
parent 6f8956887d
commit df33571d12
2 changed files with 30 additions and 14 deletions

View file

@ -229,8 +229,9 @@ public class RouteDataObject {
} }
px = getPoint31XTile(nx); px = getPoint31XTile(nx);
py = getPoint31YTile(nx); py = getPoint31YTile(nx);
total += Math.abs(px - x) + Math.abs(py - y); // translate into meters
} while (total < 100); total += Math.abs(px - x) * 0.011d + Math.abs(py - y) * 0.01863d;
} while (total < 70);
return -Math.atan2( x - px, y - py ); return -Math.atan2( x - px, y - py );
} }
} }

View file

@ -41,6 +41,7 @@ public class BinaryRoutePlanner {
protected static final Log log = LogUtil.getLog(BinaryRoutePlanner.class); protected static final Log log = LogUtil.getLog(BinaryRoutePlanner.class);
private static final int ROUTE_POINTS = 11; private static final int ROUTE_POINTS = 11;
private static final float TURN_DEGREE_MIN = 45;
public BinaryRoutePlanner(NativeLibrary nativeLib, BinaryMapIndexReader... map) { public BinaryRoutePlanner(NativeLibrary nativeLib, BinaryMapIndexReader... map) {
@ -776,7 +777,6 @@ public class BinaryRoutePlanner {
return false; return false;
} }
private static final float TURN_DEGREE_MIN = 45;
/** /**
* Helper method to prepare final result * Helper method to prepare final result
@ -1079,24 +1079,24 @@ public class BinaryRoutePlanner {
int left = 0; int left = 0;
int right = 0; int right = 0;
boolean speak = highwayLowEnd(prev.getObject().getHighway()) || highwayLowEnd(rr.getObject().getHighway()); boolean speak = highwayLowEnd(prev.getObject().getHighway()) || highwayLowEnd(rr.getObject().getHighway());
if(attachedRoutes != null){ if (attachedRoutes != null) {
for(RouteSegmentResult rs : attachedRoutes){ for (RouteSegmentResult rs : attachedRoutes) {
double ex = MapUtils.degreesDiff(rs.getBearingBegin(), rr.getBearingBegin()); double ex = MapUtils.degreesDiff(rs.getBearingBegin(), rr.getBearingBegin());
double mpi = Math.abs(MapUtils.degreesDiff(prev.getBearingEnd(), rs.getBearingBegin())) ; double mpi = Math.abs(MapUtils.degreesDiff(prev.getBearingEnd(), rs.getBearingBegin()));
if((ex < TURN_DEGREE_MIN || mpi < TURN_DEGREE_MIN) && ex >= 0) { if ((ex < TURN_DEGREE_MIN || mpi < TURN_DEGREE_MIN) && ex >= 0) {
kl = true; kl = true;
int lns = rs.getObject().getLanes(); int lns = rs.getObject().getLanes();
if (lns > 0) { if (lns > 0) {
right += lns; right += lns;
} }
speak = speak || !highwayLowEnd(rs.getObject().getHighway()); speak = speak || !highwayLowEnd(rs.getObject().getHighway());
} else if((ex > -TURN_DEGREE_MIN || mpi < TURN_DEGREE_MIN) && ex <= 0) { } else if ((ex > -TURN_DEGREE_MIN || mpi < TURN_DEGREE_MIN) && ex <= 0) {
kr = true; kr = true;
int lns = rs.getObject().getLanes(); int lns = rs.getObject().getLanes();
if (lns > 0) { if (lns > 0) {
left += lns; left += lns;
} }
speak = speak || !highwayLowEnd(rs.getObject().getHighway()); speak = speak || !highwayLowEnd(rs.getObject().getHighway());
} }
} }
} }
@ -1128,18 +1128,24 @@ public class BinaryRoutePlanner {
t = TurnType.valueOf(TurnType.KR, leftSide); t = TurnType.valueOf(TurnType.KR, leftSide);
t.setSkipToSpeak(!speak); t.setSkipToSpeak(!speak);
} }
if (t!= null && lanes != null) { if (t != null && lanes != null) {
t.setLanes(lanes); t.setLanes(lanes);
} }
return t; return t;
} }
private long getPoint(RouteDataObject road, int pointInd) {
return (((long) road.getPoint31XTile(pointInd)) << 31) + (long) road.getPoint31YTile(pointInd);
}
private void attachRoadSegments(RoutingContext ctx, List<RouteSegmentResult> result, int routeInd, int pointInd, boolean plus) { private void attachRoadSegments(RoutingContext ctx, List<RouteSegmentResult> result, int routeInd, int pointInd, boolean plus) {
RouteSegmentResult rr = result.get(routeInd); RouteSegmentResult rr = result.get(routeInd);
RouteDataObject road = rr.getObject(); RouteDataObject road = rr.getObject();
RoutingTile tl = loadRoutes(ctx, road.getPoint31XTile(pointInd), road.getPoint31YTile(pointInd)); RoutingTile tl = loadRoutes(ctx, road.getPoint31XTile(pointInd), road.getPoint31YTile(pointInd));
long l = (((long) road.getPoint31XTile(pointInd)) << 31) + (long) road.getPoint31YTile(pointInd); long l = getPoint(road, pointInd);
long nextL = pointInd < road.getPointsLength() - 1 ? getPoint(road, pointInd + 1) : 0;
long prevL = pointInd > 0 ? getPoint(road, pointInd - 1) : 0;
// attach additional roads to represent more information about the route // attach additional roads to represent more information about the route
RouteSegmentResult previousResult = null; RouteSegmentResult previousResult = null;
@ -1165,13 +1171,22 @@ public class BinaryRoutePlanner {
while (routeSegment != null) { while (routeSegment != null) {
if (routeSegment.road.getId() != road.getId() && routeSegment.road.getId() != previousRoadId) { if (routeSegment.road.getId() != road.getId() && routeSegment.road.getId() != previousRoadId) {
RouteDataObject addRoad = routeSegment.road; RouteDataObject addRoad = routeSegment.road;
// TODO restrictions can be considered as well // TODO restrictions can be considered as well
int oneWay = ctx.getRouter().isOneWay(addRoad); int oneWay = ctx.getRouter().isOneWay(addRoad);
if (oneWay >= 0 && routeSegment.segmentStart < addRoad.getPointsLength() - 1) { if (oneWay >= 0 && routeSegment.segmentStart < addRoad.getPointsLength() - 1) {
rr.attachRoute(pointInd, new RouteSegmentResult(addRoad, routeSegment.segmentStart, addRoad.getPointsLength() - 1)); long pointL = getPoint(addRoad, routeSegment.segmentStart + 1);
if(pointL != nextL && pointL != prevL) {
// if way contains same segment (nodes) as different way (do not attach it)
rr.attachRoute(pointInd, new RouteSegmentResult(addRoad, routeSegment.segmentStart, addRoad.getPointsLength() - 1));
}
} }
if (oneWay <= 0 && routeSegment.segmentStart > 0) { if (oneWay <= 0 && routeSegment.segmentStart > 0) {
rr.attachRoute(pointInd, new RouteSegmentResult(addRoad, routeSegment.segmentStart, 0)); long pointL = getPoint(addRoad, routeSegment.segmentStart - 1);
// if way contains same segment (nodes) as different way (do not attach it)
if(pointL != nextL && pointL != prevL) {
rr.attachRoute(pointInd, new RouteSegmentResult(addRoad, routeSegment.segmentStart, 0));
}
} }
} }
routeSegment = routeSegment.next; routeSegment = routeSegment.next;