Skip to content

Commit 618bf31

Browse files
committed
Check that we do not exceed the initial calculated maximum speed limit with our boosting.
-> now the previously commented test case can be enabled. Additional a test for exceeding maximum negative boosting added.
1 parent 7ae890e commit 618bf31

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public class BikeFlagEncoder extends AbstractFlagEncoder
4444
private HashSet<String> wheeler = new HashSet<String>();
4545
private HashSet<String> intended = new HashSet<String>();
4646
private HashSet<String> oppositeLanes = new HashSet<String>();
47+
48+
private int maxcyclespeed = 30;
4749

4850
/**
4951
* Should be only instantied via EncodingManager
@@ -95,8 +97,9 @@ public int defineBits( int index, int shift )
9597
{
9698
// first two bits are reserved for route handling in superclass
9799
shift = super.defineBits(index, shift);
100+
maxcyclespeed=relationWeightCodeToSpeed(20, relationMapCode.OUTSTANDING_NICE.getValue());
98101

99-
speedEncoder = new EncodedValue("Speed", shift, 4, 2, HIGHWAY_SPEED.get("cycleway"), relationWeightCodeToSpeed(20, relationMapCode.OUTSTANDING_NICE.getValue()));
102+
speedEncoder = new EncodedValue("Speed", shift, 4, 2, HIGHWAY_SPEED.get("cycleway"), maxcyclespeed);
100103

101104
shift += 4;
102105

@@ -206,7 +209,14 @@ private int relationWeightCodeToSpeed(int highwayspeed, int relationweightcode)
206209
else
207210
speed=highwayspeed;
208211
// Add or remove 3km/h per every relation weight boost point
209-
return speed + 3 * (relationweightcode-unspecifiedRelationWeight);
212+
speed = speed + 3 * (relationweightcode-unspecifiedRelationWeight);
213+
// Make sure that we do not eceed the limits:
214+
if (speed > maxcyclespeed)
215+
speed = maxcyclespeed;
216+
else
217+
if (speed <0)
218+
speed = 0;
219+
return speed ;
210220
}
211221

212222
@Override

core/src/test/java/com/graphhopper/routing/util/BikeFlagEncoderTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,13 @@ public void testhandleWayTags()
286286
flags=encoder.handleWayTags( allowed, way, 7 );
287287
assertEquals(755, flags);
288288

289-
/* This throws an exception, but boosting with 8 is an error as it is higher than OUTSTANDING_NICE
290289
allowed=1;
291-
flags=encoder.handleWayTags( allowed, way, 8 );
292-
assertEquals(127, flags);
293-
*/
290+
flags=encoder.handleWayTags( allowed, way, 18 );
291+
assertEquals(763, flags);
292+
293+
allowed=1;
294+
flags=encoder.handleWayTags( allowed, way, -18 );
295+
assertEquals(707, flags);
294296

295297

296298
}

0 commit comments

Comments
 (0)