ol.format.Polyline fixes#16955
Merged
Merged
Conversation
Doing the addition with the last number as integer prevents subtle rounding errors, i. e. 0.3 instead of 0.30000000000000004
Rounding the number instead of the delta stops rounding errors to accumulate. Deltas that individually round to zero should be encoded to the polyline once their sum is big enough.
Google's polyline algorithm uses rounding from python 2 which this now mimics. Round -0.5 away from zero instead of towards zero.
|
📦 Preview the website for this branch here: https://deploy-preview-16955--ol-site.netlify.app/. |
ahocevar
reviewed
Jul 3, 2025
ahocevar
left a comment
Member
There was a problem hiding this comment.
Thanks, @M393. Would it be possible to only make the accuracy improvements you mentioned, without the API changes? If not, we'll mark this as breaking change, you'll have to add upgrade instructions in upgrade-notes.md, and we'll merge this when we release v11.
Contributor
Author
|
@ahocevar I re-added the |
ahocevar
approved these changes
Jul 3, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes a few subtle bugs with Polyline encoding and decoding.
The methods
encodeFloatsanddecodeFloatsare part of the api, and now no longer used. I'm not sure why they were in the api in the first place as they don't seem to be useful on their own. They are now marked as deprecated, but maybe they could be removed.Clue for the python2 rounding mode:
https://github.com/mapbox/polyline/blob/5e797bf9cdf46db94bc3290b0e4d39e6db5a51c9/src/polyline.js#L15
Can be tested here:
https://developers.google.com/maps/documentation/utilities/polylineutility