Skip to content

Commit e34c1e9

Browse files
boldtrnkarussell
authored andcommitted
Fix PathDetails exception for empty EdgeIdDs list (graphhopper#1240)
* Ignore the tests, reverted memory and some minor improvements * Revert IntelliJ formatting issue * Removed pointList.isEmpty
1 parent c46e093 commit e34c1e9

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

core/src/main/java/com/graphhopper/PathWrapper.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,6 @@ public void addPathDetails(Map<String, List<PathDetail>> details) {
254254
throw new IllegalStateException("Details have to be the same size");
255255
}
256256
for (Map.Entry<String, List<PathDetail>> detailEntry : details.entrySet()) {
257-
if (detailEntry.getValue().isEmpty())
258-
throw new IllegalStateException("PathDetails " + detailEntry.getKey() + " must not be empty");
259-
260257
if (this.pathDetails.containsKey(detailEntry.getKey())) {
261258
List<PathDetail> pd = this.pathDetails.get(detailEntry.getKey());
262259
PathMerger.merge(pd, detailEntry.getValue());

core/src/main/java/com/graphhopper/util/PathSimplification.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public PathSimplification(PathWrapper pathWrapper, DouglasPeucker douglasPeucker
4949
this.pathDetails = pathWrapper.getPathDetails();
5050
for (String name : pathDetails.keySet()) {
5151
List<PathDetail> pathDetailList = pathDetails.get(name);
52-
if (pathDetailList.isEmpty())
52+
// If the pointList only contains one point, PathDetails have to be empty because 1 point => 0 edges
53+
if (pathDetailList.isEmpty() && pointList.size() > 1)
5354
throw new IllegalStateException("PathDetails " + name + " must not be empty");
5455

5556
listsToSimplify.add(pathDetailList);
@@ -58,7 +59,7 @@ public PathSimplification(PathWrapper pathWrapper, DouglasPeucker douglasPeucker
5859
}
5960

6061
public PointList simplify() {
61-
if (listsToSimplify.isEmpty() || pointList.isEmpty())
62+
if (listsToSimplify.isEmpty() || pointList.size() <= 2)
6263
return pointList;
6364

6465
// The offset of already included points

reader-osm/src/test/java/com/graphhopper/GraphHopperIT.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ public void testCircularJunctionInstructionsWithCH() {
730730

731731
assertEquals(2, tmpHopper.getCHFactoryDecorator().getPreparations().size());
732732

733-
GHResponse rsp = tmpHopper.route(new GHRequest(52.513505,13.350443, 52.513505,13.350245)
733+
GHResponse rsp = tmpHopper.route(new GHRequest(52.513505, 13.350443, 52.513505, 13.350245)
734734
.setVehicle(tmpVehicle).setWeighting(tmpWeightCalcStr));
735735

736736
Instruction instr = rsp.getBest().getInstructions().get(1);
@@ -870,6 +870,26 @@ public void testPathDetails1216() {
870870
assertFalse(rsp.hasErrors());
871871
}
872872

873+
@Test
874+
public void testPathDetailsSamePoint() {
875+
GraphHopper tmpHopper = new GraphHopperOSM().
876+
setOSMFile(DIR + "/north-bayreuth.osm.gz").
877+
setCHEnabled(false).
878+
setGraphHopperLocation(tmpGraphFile).
879+
setEncodingManager(new EncodingManager("car"));
880+
tmpHopper.importOrLoad();
881+
882+
GHRequest req = new GHRequest().
883+
addPoint(new GHPoint(49.984352, 11.498802)).
884+
addPoint(new GHPoint(49.984352, 11.498802)).
885+
setVehicle("car").setWeighting("fastest").
886+
setPathDetails(Arrays.asList(Parameters.DETAILS.AVERAGE_SPEED));
887+
888+
GHResponse rsp = tmpHopper.route(req);
889+
890+
assertFalse(rsp.hasErrors());
891+
}
892+
873893
@Test
874894
public void testFlexMode_631() {
875895
String tmpOsmFile = DIR + "/monaco.osm.gz";

web/src/test/java/com/graphhopper/http/GraphHopperServletIT.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ public void testPathDetails() throws Exception {
179179
assertEquals(expectedTime, actualTime);
180180
}
181181

182+
@Test
183+
public void testPathDetailsSamePoint() throws Exception {
184+
GraphHopperAPI hopper = new com.graphhopper.api.GraphHopperWeb();
185+
assertTrue(hopper.load(getTestRouteAPIUrl()));
186+
GHRequest request = new GHRequest(42.554851, 1.536198, 42.554851, 1.536198);
187+
request.setPathDetails(Arrays.asList("average_speed", "edge_id", "time"));
188+
GHResponse rsp = hopper.route(request);
189+
assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
190+
assertTrue(rsp.getErrors().toString(), rsp.getErrors().isEmpty());
191+
}
192+
182193
@Test
183194
public void testPathDetailsNoConnection() throws Exception {
184195
GraphHopperAPI hopper = new com.graphhopper.api.GraphHopperWeb();

0 commit comments

Comments
 (0)