Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix floating point precision issues with new algorithm for Encode() and Decode() #9

Merged
merged 4 commits into from
Jul 6, 2019

Conversation

JonMcPherson
Copy link
Owner

@JonMcPherson JonMcPherson commented Jul 6, 2019

The original algorithm used floating point arithmetic which caused precision issues as discussed in Issue google/open-location-code#307.
The new algorithm implemented in this PR uses 64-bit integer arithmetic to avoid the precision errors and was ported from the Java implementation google/open-location-code#347.

The CodeArea class was improved without any breaking changes to add the CodeLength property and to extend a new publicly accessible GeoArea class which contains the generic area properties and methods. The CodeArea constructor is still not publicly accessible to ensure that all CodeArea instances represent a valid OLC area.

The unit tests were improved to read and parse the test_data CSV files from the original open-location-code project. The encoding.csv and decoding.csv TestData files also include new test cases for these changes. No unit tests or test cases were removed (only added).

The Encode() and Decode() algorithms were changed in the canonical project to properly handle floating point errors by doing arithmetic on 64-bit integers (long).  This commit applies those changes ported from the Java implementation.
Additionally, the unit tests were improved to read and parse test data CSV files coppied from the original open-location-code project.
@JonMcPherson JonMcPherson changed the title Fix floating point precision issues with new algorithms for Encode() and Decode() Fix floating point precision issues with new algorithm for Encode() and Decode() Jul 6, 2019
@JonMcPherson JonMcPherson merged commit a2bcf65 into master Jul 6, 2019
@JonMcPherson JonMcPherson deleted the float-handling branch July 6, 2019 20:27
@ujvalak
Copy link

ujvalak commented Jul 10, 2019

Hello, Is there any function/interface that allows to extract the city from a respective PlusCode? Thanks

@JonMcPherson
Copy link
Owner Author

@ujvalak There is not. Open Location Code (Plus Codes) is a totally separate geocode system. You would need to use a reverse geocoding service like with Google Maps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants