Check for speeds smaller than we can store


I am currently looking into #1116 (ferry speeds). In the AbstractFlagEncoder we check a couple of times if the speed we are trying to store for an edge is smaller than the speed we can store in the speedEncoder. We do this with this check:

speed < speedEncoder.factor / 2

Right now I wonder where the / 2 comes from. To clarify the / 2 is not wrong, but why don’t we simply check if the speed < speedEncoder.factor?

When reading a value from the flags in the EncodedDoubleValue, we do this:

flags &= mask;
flags >>>= shift;
return flags * factor;

Which means that we cannot store anything smaller than the factor (excluding 0, obviously).

Do I miss something?


I think this is due to the rounding. So if it is bigger than factor/2 we can still store it as it will be rounded to ‘factor’.

Ok, this is what I thought, I was just wondering, as I couldn’t see a benefit of this approach compared to simply using the factor, but I think I just came up with one.

If for some reason we want to manipulate the speed, before storing it, the manipulated speed will be closer to the intended speed. But I am not sure if this is a common scenario :).