-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Average Speed as PathDetails to Response #1091
Changes from 45 commits
d38aa5c
887cbf4
f10da8a
6082c39
b16205f
3d87388
dfa6e34
e281e9b
75660e9
7b95358
66754f5
b72e5c1
e722752
3153e10
c7768bf
fede463
e969263
bf0f96e
fe28658
f926402
02e89ad
43a4c2c
92d351a
746aff1
85d1e55
2a384fd
8d08821
f135c46
7f5b936
1c211b4
b2a09d8
9c4ad54
5e20f04
28b71d5
73c6b73
30eec76
87a9a51
618967f
009c887
db89861
bbbd403
f398ab2
871c675
0894a03
e96cf3e
89ea614
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,13 +18,13 @@ | |
package com.graphhopper; | ||
|
||
import com.graphhopper.util.InstructionList; | ||
import com.graphhopper.util.PathMerger; | ||
import com.graphhopper.util.PointList; | ||
import com.graphhopper.util.details.PathDetail; | ||
import com.graphhopper.util.shapes.BBox; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.*; | ||
|
||
/** | ||
* This class holds the data like points and instructions of a Path. | ||
|
@@ -46,6 +46,7 @@ public class PathWrapper { | |
private PointList pointList = PointList.EMPTY; | ||
private int numChanges; | ||
private final List<Trip.Leg> legs = new ArrayList<>(); | ||
private Map<String, List<PathDetail>> pathDetails = new HashMap<>(); | ||
private BigDecimal fare; | ||
|
||
/** | ||
|
@@ -242,6 +243,30 @@ public void setInstructions(InstructionList instructions) { | |
this.instructions = instructions; | ||
} | ||
|
||
/** | ||
* Adds the given PathDetails to the existing ones. If there are already PathDetails set, the number | ||
* details has to be equal to <code>details</code>. | ||
* | ||
* @param details The PathDetails to add | ||
*/ | ||
public void addPathDetails(Map<String, List<PathDetail>> details) { | ||
if (!this.pathDetails.isEmpty() && !details.isEmpty() && this.pathDetails.size() != details.size()) { | ||
throw new IllegalStateException("Details have to be the same size"); | ||
} | ||
for (Map.Entry<String, List<PathDetail>> detailEntry : details.entrySet()) { | ||
if (this.pathDetails.containsKey(detailEntry.getKey())) { | ||
List<PathDetail> pd = this.pathDetails.get(detailEntry.getKey()); | ||
PathMerger.merge(pd, detailEntry.getValue()); | ||
} else { | ||
this.pathDetails.put(detailEntry.getKey(), detailEntry.getValue()); | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See below: what is a 'merge'? And why not just adding PathDetails like the method says it? Also instead of EMPTY_LIST and if+else I would prefer without the if and always do the same. |
||
|
||
public Map<String, List<PathDetail>> getPathDetails() { | ||
return this.pathDetails; | ||
} | ||
|
||
private void check(String method) { | ||
if (hasErrors()) { | ||
throw new RuntimeException("You cannot call " + method + " if response contains errors. Check this with ghResponse.hasErrors(). " | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ public class Instruction { | |
public static final int PT_TRANSFER = 102; | ||
public static final int PT_END_TRIP = 103; | ||
private static final AngleCalc AC = Helper.ANGLE_CALC; | ||
protected final PointList points; | ||
protected PointList points; | ||
protected final InstructionAnnotation annotation; | ||
protected boolean rawName; | ||
protected int sign; | ||
|
@@ -137,14 +137,20 @@ public Instruction setTime(long time) { | |
return points.getElevation(0); | ||
} | ||
|
||
/* This method returns the points associated to this instruction. Please note that it will not include the last point, | ||
* i.e. the first point of the next instruction object. | ||
*/ | ||
public PointList getPoints() { | ||
return points; | ||
} | ||
|
||
public void setPoints(PointList points) { | ||
this.points = points; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we avoid this setter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not easily. The issue is that we have to change the points, once the instruction is created. Changing this might be complicated, but not necessarily impossible. Once the instructions and PathDetails are calculated, we do the simplification. When simplifying, we need to change the points. I think changing this would require quite a lot overhead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood. So the setter is more explicit ... it might be uglier but more efficient to do an inplace modification of the PointList - we have to compare to understand how much this would be |
||
} | ||
|
||
/** | ||
* This method returns a list of gpx entries where the time (in time) is relative to the first | ||
* which is 0. It does NOT contain the last point which is the first of the next instruction. | ||
* <p> | ||
* | ||
* @return the time offset to add for the next instruction | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we should ensure that this happens only for i==0 (?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would this be the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ups no, forget about it :) but I think there will be either all merge or all put operations?
BTW: here is also no need to call pathDetails.put for the merge case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, if the element does not exist, we have to put it. If it exists, then we have to merge it? I removed the unnecessary put for the merge case.