Skip to content

fix value expression with encoded value that has defaultIsInfinity==true - #2623

Closed
karussell wants to merge 7 commits into
masterfrom
max_speed_custom_model_fix
Closed

karussell wants to merge 7 commits into
masterfrom
max_speed_custom_model_fix

Conversation

@karussell

@karussell karussell commented Jul 6, 2022 •

Copy link
Copy Markdown
Member

The maximum value of max_speed is Infinity due to defaultIsInfinity==true.

This special case is a bit ugly but we need this for edges without a (known) speed limit.

Or maybe we should move this information into getMaxValue and getMaxStorableDecimal?

@karussell karussell added the bug label Jul 6, 2022
@karussell karussell added this to the 6.0 milestone Jul 6, 2022
@karussell
karussell requested a review from easbar July 18, 2022 08:44
@easbar

easbar commented Jul 18, 2022

Copy link
Copy Markdown
Member

Or maybe we should move this information into getMaxValue and getMaxStorableDecimal?

As long as we do not need it I think it is ok to just throw an error in getMaxValue if defaultIsInfinity=true.
For getMaxStorableDecimal it seems to make sense to return infinity in this case? In DecimalEncodedValue we promise this:

    /**
     * The maximum double value this EncodedValue accepts for setDecimal without throwing an exception.
     */
    double getMaxStorableDecimal();

and set(decEnc, Double.POSITIVE_INFINITY) is actually allowed if defaultIsInfinity=true.

@karussell

karussell commented Jul 18, 2022 •

Copy link
Copy Markdown
Member Author

For getMaxStorableDecimal it seems to make sense to return infinity in this case?

Unfortunately we assume it partially in our code (3 tests fail). I.e. we differentiate between the "last real storable decimal" and infinity it seems.

E.g. OSMMaxAxleLoadParserTest.testSimpleTags will fail when we set 160 and the "last real storable decimal" is 140, because the following will never be true:

if (value > valueEncoder.getMaxStorableDecimal()) value = valueEncoder.getMaxStorableDecimal();

but we could internally (silently) round down to the "last real storable decimal"? (we do this rounding when setting other "unfitting" values too)

Will try this...

Comment on lines 150 to 156
enc.init(new EncodedValue.InitializerConfig());
assertEquals(12, enc.getNextStorableValue(11.2));
assertEquals(45, enc.getNextStorableValue(44.3));
assertEquals(45, enc.getNextStorableValue(45));
assertEquals(42, enc.getNextStorableValue(41.3));
assertEquals(42, enc.getNextStorableValue(42));
assertEquals(Double.POSITIVE_INFINITY, enc.getNextStorableValue(42.1));
assertEquals(Double.POSITIVE_INFINITY, enc.getNextStorableValue(45));
assertEquals(Double.POSITIVE_INFINITY, enc.getNextStorableValue(45.1));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is due to an unrelated bug. See above.

if (!useMaximumAsInfinity && value > getMaxStorableDecimal())
throw new IllegalArgumentException(getName() + ": There is no next storable value for " + value + ". max:" + getMaxStorableDecimal());
else if (useMaximumAsInfinity && value > getMaxStorableDecimal())
else if (useMaximumAsInfinity && value > (maxStorableValue - 1) * factor)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an unrelated bug

Comment on lines +172 to +173
g.getTurnCostStorage().set(turnCostEnc, 0, 4, 7, Double.POSITIVE_INFINITY);
g.getTurnCostStorage().set(turnCostEnc, 0, 4, 9, Double.POSITIVE_INFINITY);

@karussell karussell Jul 18, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO a bug in the test code. But of course this could also happen for production:

only 1 bit was reserved and when the cost=1 was set the (new) behaviour is to use the last possible value below infinity which is 0, which is not the expected outcome here.

@karussell

karussell commented Jul 26, 2022 •

Copy link
Copy Markdown
Member Author

So this is now cleaner than the workaround with isDefaultIsInfinity before, but introduces a small behaviour change, see CHANGELOG. As this change is a bit delicate would you review again :), @easbar ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants