20
20
import com .graphhopper .routing .util .DataFlagEncoder ;
21
21
import com .graphhopper .routing .util .FlagEncoder ;
22
22
import com .graphhopper .storage .NodeAccess ;
23
- import com .graphhopper .util .*;
23
+ import com .graphhopper .util .EdgeExplorer ;
24
+ import com .graphhopper .util .EdgeIterator ;
25
+ import com .graphhopper .util .EdgeIteratorState ;
24
26
import com .graphhopper .util .shapes .GHPoint ;
25
27
26
28
import java .util .ArrayList ;
27
29
import java .util .List ;
28
30
29
31
/**
30
- * This class maintains the surrounding edges for a single turn instruction.
31
- * <p>
32
- * There a different sets of edges.
33
- * The previous edge is the edge we are comming from.
32
+ * This class handles the outgoing edges for a single turn instruction.
33
+ *
34
+ * There are different sets of edges.
35
+ * The previous edge is the edge we are coming from.
34
36
* The current edge is the edge we turn on.
35
- * The reachable edges are all edges we could turn on, without the prev edge and the current edge.
36
- * The surrounding edges are all edges surrounding the turn, without the prev edge and the current edge.
37
+ * The allowedOutgoingEdges contains all edges that the current vehicle is allowed(*) to turn on to, excluding the prev edge and the current edge.
38
+ * The allOutgoingEdges contains all edges surrounding this turn instruction, without the prev edge and the current edge.
39
+ *
40
+ * (*): This might not consider turn restrictions, but only simple access values.
41
+ *
42
+ * Here is an example:
43
+ *
44
+ * A --> B --> C
45
+ * ^
46
+ * |
47
+ * X
48
+ *
49
+ * For the route from A->B->C and baseNode=B, adjacentNode=C:
50
+ * - the previous edge is A->B
51
+ * - the current edge is B->C
52
+ * - the allowedOutgoingEdges are B->C => return value of {@link #nrOfAllowedOutgoingEdges()} is 1
53
+ * - the allOutgoingEdges are B->X and B->C => return values of {@link #nrOfAllOutgoingEdges()} is 2
37
54
*
38
55
* @author Robin Boldt
39
56
*/
40
- class InstructionsSurroundingEdges {
57
+ class InstructionsOutgoingEdges {
41
58
42
59
final EdgeIteratorState prevEdge ;
43
60
final EdgeIteratorState currentEdge ;
44
61
45
- // Streets that are alternative turns, excluding oneways in the wrong direction
46
- final List <EdgeIteratorState > reachableEdges ;
62
+ // Outgoing edges that we would be allowed to turn on
63
+ final List <EdgeIteratorState > allowedOutgoingEdges ;
47
64
48
- // All Streets surrounding the turn , including oneways in the wrong direction
49
- final List <EdgeIteratorState > surroundingEdges ;
65
+ // All outgoing edges , including oneways in the wrong direction
66
+ final List <EdgeIteratorState > allOutgoingEdges ;
50
67
51
68
final FlagEncoder encoder ;
52
69
final NodeAccess nodeAccess ;
53
70
54
- public InstructionsSurroundingEdges (EdgeIteratorState prevEdge ,
55
- EdgeIteratorState currentEdge ,
56
- FlagEncoder encoder ,
57
- EdgeExplorer crossingExplorer ,
58
- NodeAccess nodeAccess ,
59
- int prevNode ,
60
- int baseNode ,
61
- int adjNode ) {
71
+ public InstructionsOutgoingEdges (EdgeIteratorState prevEdge ,
72
+ EdgeIteratorState currentEdge ,
73
+ FlagEncoder encoder ,
74
+ EdgeExplorer crossingExplorer ,
75
+ NodeAccess nodeAccess ,
76
+ int prevNode ,
77
+ int baseNode ,
78
+ int adjNode ) {
62
79
this .prevEdge = prevEdge ;
63
80
this .currentEdge = currentEdge ;
64
81
this .encoder = encoder ;
65
82
this .nodeAccess = nodeAccess ;
66
83
67
84
EdgeIteratorState tmpEdge ;
68
85
69
- surroundingEdges = new ArrayList <>();
70
- reachableEdges = new ArrayList <>();
86
+ allOutgoingEdges = new ArrayList <>();
87
+ allowedOutgoingEdges = new ArrayList <>();
71
88
EdgeIterator edgeIter = crossingExplorer .setBaseNode (baseNode );
72
89
while (edgeIter .next ()) {
73
90
if (edgeIter .getAdjNode () != prevNode && edgeIter .getAdjNode () != adjNode ) {
74
91
tmpEdge = edgeIter .detach (false );
75
- surroundingEdges .add (tmpEdge );
92
+ allOutgoingEdges .add (tmpEdge );
76
93
if (encoder .isForward (tmpEdge .getFlags ())) {
77
- reachableEdges .add (tmpEdge );
94
+ allowedOutgoingEdges .add (tmpEdge );
78
95
}
79
96
}
80
97
}
81
98
}
82
99
83
100
/**
84
- * Calculates the Number of possible turns, including the current turn.
85
- * If there is only one turn possible, e.g. continue straight on the road is a turn,
86
- * the method will return 1.
101
+ * This method calculates the number of allowed outgoing edges, which could be considered the number of possible
102
+ * roads one might take at the intersection. This excludes the road you are coming from and inaccessible roads.
87
103
*/
88
- public int nrOfPossibleTurns () {
89
- return 1 + reachableEdges .size ();
104
+ public int nrOfAllowedOutgoingEdges () {
105
+ return 1 + allowedOutgoingEdges .size ();
90
106
}
91
107
92
108
/**
93
- * Checks if the surrounding streets are slower. If they are, this indicates, that we are staying
109
+ * This method calculates the number of all outgoing edges, which could be considered the number of roads you see
110
+ * at the intersection. This excludes the road your are coming from.
111
+ */
112
+ public int nrOfAllOutgoingEdges () {
113
+ return 1 + allOutgoingEdges .size ();
114
+ }
115
+
116
+
117
+ /**
118
+ * Checks if the outgoing edges are slower by the provided factor. If they are, this indicates, that we are staying
94
119
* on the prominent street that one would follow anyway.
95
120
*/
96
- public boolean surroundingStreetsAreSlowerByFactor (double factor ) {
121
+ public boolean outgoingEdgesAreSlowerByFactor (double factor ) {
97
122
double tmpSpeed = getSpeed (currentEdge );
98
123
double pathSpeed = getSpeed (prevEdge );
99
124
@@ -104,7 +129,7 @@ public boolean surroundingStreetsAreSlowerByFactor(double factor) {
104
129
105
130
double maxSurroundingSpeed = -1 ;
106
131
107
- for (EdgeIteratorState edge : surroundingEdges ) {
132
+ for (EdgeIteratorState edge : allOutgoingEdges ) {
108
133
tmpSpeed = getSpeed (edge );
109
134
if (tmpSpeed < 1 ) {
110
135
// This might happen for the DataFlagEncoder, might create unnecessary turn instructions
@@ -128,12 +153,13 @@ private double getSpeed(EdgeIteratorState edge) {
128
153
}
129
154
130
155
/**
131
- * Returns an edge that is going into more or less straight compared to the prevEdge.
156
+ * Returns an edge that has more or less in the same orientation as the prevEdge, but is not the currentEdge.
157
+ * If there is one, this indicates that we might need an instruction to help finding the correct edge out of the different choices.
132
158
* If there is none, return null.
133
159
*/
134
160
public EdgeIteratorState getOtherContinue (double prevLat , double prevLon , double prevOrientation ) {
135
161
int tmpSign ;
136
- for (EdgeIteratorState edge : reachableEdges ) {
162
+ for (EdgeIteratorState edge : allowedOutgoingEdges ) {
137
163
GHPoint point = InstructionsHelper .getPointForOrientationCalculation (edge , nodeAccess );
138
164
tmpSign = InstructionsHelper .calculateSign (prevLat , prevLon , point .getLat (), point .getLon (), prevOrientation );
139
165
if (Math .abs (tmpSign ) <= 1 ) {
@@ -155,7 +181,7 @@ public boolean isLeavingCurrentStreet(String prevName, String name) {
155
181
156
182
// If flags are changing, there might be a chance we find these flags on a different edge
157
183
boolean checkFlag = currentEdge .getFlags () != prevEdge .getFlags ();
158
- for (EdgeIteratorState edge : reachableEdges ) {
184
+ for (EdgeIteratorState edge : allowedOutgoingEdges ) {
159
185
String edgeName = edge .getName ();
160
186
long edgeFlag = edge .getFlags ();
161
187
// leave the current street || enter a different street
0 commit comments