Skip to content

Commit 3844f01

Browse files
author
Peter
committed
added calcEdges method
1 parent fca8fb8 commit 3844f01

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

core/src/main/java/com/graphhopper/reader/OSMInputFile.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,13 @@ private OSMElement getNextXML() throws XMLStreamException
188188
switch (name.charAt(0))
189189
{
190190
case 'n':
191-
id = Long.parseLong(parser.getAttributeValue(null, "id"));
192-
return new OSMNode(id, parser);
191+
// note vs. node
192+
if ("node".equals(name))
193+
{
194+
id = Long.parseLong(parser.getAttributeValue(null, "id"));
195+
return new OSMNode(id, parser);
196+
}
197+
break;
193198

194199
case 'w':
195200
{

core/src/main/java/com/graphhopper/routing/Path.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import gnu.trove.list.array.TDoubleArrayList;
2626
import gnu.trove.list.array.TIntArrayList;
2727
import gnu.trove.list.array.TLongArrayList;
28-
28+
import java.util.ArrayList;
29+
import java.util.List;
2930

3031
/**
3132
* Stores the nodes for the found path of an algorithm. It additionally needs the edgeIds to make
@@ -37,7 +38,7 @@
3738
*/
3839
public class Path
3940
{
40-
private DistanceCalc distCalc = new DistanceCalcEarth();
41+
private final DistanceCalc distCalc = new DistanceCalcEarth();
4142
protected Graph graph;
4243
private FlagEncoder encoder;
4344
protected double distance;
@@ -248,6 +249,23 @@ private void forEveryEdge( EdgeVisitor visitor )
248249
}
249250
}
250251

252+
public List<EdgeIteratorState> calcEdges()
253+
{
254+
final List<EdgeIteratorState> edges = new ArrayList<EdgeIteratorState>(edgeIds.size());
255+
if (edgeIds.isEmpty())
256+
return edges;
257+
258+
forEveryEdge(new EdgeVisitor()
259+
{
260+
@Override
261+
public void next( EdgeIteratorState eb, int i )
262+
{
263+
edges.add(eb);
264+
}
265+
});
266+
return edges;
267+
}
268+
251269
/**
252270
* @return the uncached node indices of the tower nodes in this path.
253271
*/
@@ -448,7 +466,7 @@ public void next( EdgeIteratorState edge, int index )
448466
boolean lastEdge = index == edgeIds.size() - 1;
449467
if (lastEdge)
450468
cachedWays.add(new FinishInstruction(prevLat, prevLon));
451-
}
469+
}
452470

453471
private void add( EdgeIteratorState edge, PointList pl )
454472
{

core/src/main/java/com/graphhopper/routing/util/FastestWeighting.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ public double getMinWeight( double distance )
4242
}
4343

4444
@Override
45-
public double calcWeight( EdgeIteratorState edgeIter )
45+
public double calcWeight( EdgeIteratorState edge )
4646
{
47-
return edgeIter.getDistance() / encoder.getSpeed(edgeIter.getFlags());
47+
return edge.getDistance() / encoder.getSpeed(edge.getFlags());
4848
}
4949

5050
@Override
51-
public double revertWeight( EdgeIteratorState iter, double weight )
51+
public double revertWeight( EdgeIteratorState edge, double weight )
5252
{
53-
return weight * encoder.getSpeed(iter.getFlags());
53+
return weight * encoder.getSpeed(edge.getFlags());
5454
}
5555

5656
@Override

core/src/main/java/com/graphhopper/routing/util/ShortestWeighting.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ public double getMinWeight( double currDistToGoal )
3838
}
3939

4040
@Override
41-
public double calcWeight( EdgeIteratorState iter )
41+
public double calcWeight( EdgeIteratorState edge )
4242
{
43-
return iter.getDistance();
43+
return edge.getDistance();
4444
}
4545

4646
@Override
47-
public double revertWeight( EdgeIteratorState iter, double weight )
47+
public double revertWeight( EdgeIteratorState edge, double weight )
4848
{
4949
return weight;
5050
}

0 commit comments

Comments
 (0)