Skip to content

Commit

Permalink
made roundabout instructions working for CH too, #185
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter committed Feb 25, 2015
1 parent 772414d commit 414937e
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 158 deletions.
24 changes: 13 additions & 11 deletions core/src/main/java/com/graphhopper/routing/Path.java
Expand Up @@ -252,7 +252,7 @@ private void forEveryEdge( EdgeVisitor visitor )
int len = edgeIds.size();
for (int i = 0; i < len; i++)
{
EdgeIteratorState edgeBase = graph.getBaseGraph().getEdgeProps(edgeIds.get(i), tmpNode);
EdgeIteratorState edgeBase = graph.getEdgeProps(edgeIds.get(i), tmpNode);
if (edgeBase == null)
throw new IllegalStateException("Edge " + edgeIds.get(i) + " was empty when requested with node " + tmpNode
+ ", array index:" + i + ", edges:" + edgeIds.size());
Expand Down Expand Up @@ -434,13 +434,13 @@ public void next( EdgeIteratorState edge, int index )
} else
{
if (isRoundabout)
// remark: names and annotations within roundabout are ignored
// remark: names and annotations within roundabout are ignored
{
if (!prevInRoundabout) //just entered roundabout
{
int sign = Instruction.USE_ROUNDABOUT;
RoundaboutInstruction roundaboutInstruction = new RoundaboutInstruction(sign, name,
annotation, new PointList(10, nodeAccess.is3D()));
annotation, new PointList(10, nodeAccess.is3D()));
if (prevName != null)
{
// previous orientation is last orientation before entering roundabout
Expand Down Expand Up @@ -468,7 +468,10 @@ public void next( EdgeIteratorState edge, int index )
// This could lead to problems if there are non-complete roundabouts!
EdgeIterator edgeIter = outEdgeExplorer.setBaseNode(adjNode);
edgeIter.next();
if (edgeIter.next()) {((RoundaboutInstruction) prevInstruction).increaseExitNumber();}
if (edgeIter.next())
{
((RoundaboutInstruction) prevInstruction).increaseExitNumber();
}

} else if (prevInRoundabout) //previously in roundabout but not anymore
{
Expand All @@ -487,9 +490,9 @@ public void next( EdgeIteratorState edge, int index )
double deltaOut = (orientation - recentOrientation);

prevInstruction = ((RoundaboutInstruction) prevInstruction)
.setRadian(deltaInOut)
.setDirOfRotation(deltaOut)
.setExited();
.setRadian(deltaInOut)
.setDirOfRotation(deltaOut)
.setExited();

prevName = name;
prevAnnotation = annotation;
Expand Down Expand Up @@ -532,7 +535,7 @@ public void next( EdgeIteratorState edge, int index )
sign = Instruction.TURN_SHARP_RIGHT;

}
prevInstruction = new Instruction(sign, name, annotation, new PointList(10, nodeAccess.is3D()) );
prevInstruction = new Instruction(sign, name, annotation, new PointList(10, nodeAccess.is3D()));
ways.add(prevInstruction);
prevName = name;
prevAnnotation = annotation;
Expand All @@ -545,12 +548,11 @@ public void next( EdgeIteratorState edge, int index )
{
doublePrevLat = prevLat;
doublePrevLong = prevLon;
}
else
} else
{
int beforeLast = wayGeo.getSize() - 2;
doublePrevLat = wayGeo.getLatitude(beforeLast);
doublePrevLong = wayGeo.getLongitude(beforeLast);
doublePrevLong = wayGeo.getLongitude(beforeLast);
}
prevInRoundabout = isRoundabout;
prevLat = adjLat;
Expand Down
28 changes: 15 additions & 13 deletions core/src/main/java/com/graphhopper/routing/ch/Path4CH.java
Expand Up @@ -20,7 +20,6 @@
import com.graphhopper.routing.PathBidirRef;
import com.graphhopper.routing.util.FlagEncoder;
import com.graphhopper.storage.Graph;
import com.graphhopper.storage.LevelGraph;
import com.graphhopper.util.EdgeSkipIterState;

/**
Expand All @@ -31,17 +30,20 @@
*/
public class Path4CH extends PathBidirRef
{
public Path4CH( Graph g, FlagEncoder encoder )
private final Graph routingGraph;

public Path4CH( Graph routingGraph, Graph baseGraph, FlagEncoder encoder )
{
super(g, encoder);
super(baseGraph, encoder);
this.routingGraph = routingGraph;
}

@Override
protected final void processEdge( int tmpEdge, int endNode )
{
// Shortcuts do only contain valid weight so first expand before adding
// to distance and time
expandEdge((EdgeSkipIterState) graph.getEdgeProps(tmpEdge, endNode), false);
expandEdge((EdgeSkipIterState) routingGraph.getEdgeProps(tmpEdge, endNode), false);
}

private void expandEdge( EdgeSkipIterState mainEdgeState, boolean reverse )
Expand Down Expand Up @@ -71,32 +73,32 @@ private void expandEdge( EdgeSkipIterState mainEdgeState, boolean reverse )
// getEdgeProps could possibly return an empty edge if the shortcut is available for both directions
if (reverseOrder)
{
EdgeSkipIterState edgeState = (EdgeSkipIterState) graph.getEdgeProps(skippedEdge1, to);
EdgeSkipIterState edgeState = (EdgeSkipIterState) routingGraph.getEdgeProps(skippedEdge1, to);
boolean empty = edgeState == null;
if (empty)
edgeState = (EdgeSkipIterState) graph.getEdgeProps(skippedEdge2, to);
edgeState = (EdgeSkipIterState) routingGraph.getEdgeProps(skippedEdge2, to);

expandEdge(edgeState, false);

if (empty)
edgeState = (EdgeSkipIterState) graph.getEdgeProps(skippedEdge1, from);
edgeState = (EdgeSkipIterState) routingGraph.getEdgeProps(skippedEdge1, from);
else
edgeState = (EdgeSkipIterState) graph.getEdgeProps(skippedEdge2, from);
edgeState = (EdgeSkipIterState) routingGraph.getEdgeProps(skippedEdge2, from);

expandEdge(edgeState, true);
} else
{
EdgeSkipIterState iter = (EdgeSkipIterState) graph.getEdgeProps(skippedEdge1, from);
EdgeSkipIterState iter = (EdgeSkipIterState) routingGraph.getEdgeProps(skippedEdge1, from);
boolean empty = iter == null;
if (empty)
iter = (EdgeSkipIterState) graph.getEdgeProps(skippedEdge2, from);
iter = (EdgeSkipIterState) routingGraph.getEdgeProps(skippedEdge2, from);

expandEdge(iter, true);

if (empty)
iter = (EdgeSkipIterState) graph.getEdgeProps(skippedEdge1, to);
iter = (EdgeSkipIterState) routingGraph.getEdgeProps(skippedEdge1, to);
else
iter = (EdgeSkipIterState) graph.getEdgeProps(skippedEdge2, to);
iter = (EdgeSkipIterState) routingGraph.getEdgeProps(skippedEdge2, to);

expandEdge(iter, false);
}
Expand Down
Expand Up @@ -803,7 +803,7 @@ protected boolean finished()

protected Path createAndInitPath()
{
bestPath = new Path4CH(graph, flagEncoder);
bestPath = new Path4CH(graph, graph.getBaseGraph(), flagEncoder);
return bestPath;
}

Expand Down Expand Up @@ -849,7 +849,7 @@ public boolean finished()
@Override
protected Path createAndInitPath()
{
bestPath = new Path4CH(graph, flagEncoder);
bestPath = new Path4CH(graph, graph.getBaseGraph(), flagEncoder);
return bestPath;
}

Expand Down

0 comments on commit 414937e

Please sign in to comment.