-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Round latitude/longitude values #6800
Comments
Using 10 decimals results in precision of:
|
It seems that using 10 decimals is not ideal. For example take a LatLngBounds with corners equal to In this case we should round with 3 decimals, which results in a precision of 111m at equator... update this mistake in rounding is not coming from core but comes from our own calculations when trying to determine the center of the bounds for the camera update. |
Capturing from internal discussions this is expected behaviour from doubles and we/endusers should take this in account when working with the core api. Eg. when comparing two doubles we should always take in account a delta. Closing for now and will fix up tests #6803 following these guidelines. |
The imprecision described here occurs when you take a |
I have been looking into this issue is more depth by reading up on it and debugging core. I was able to verify the following statement:
This is the output produced by java vs c++: Zoom
Latitude
Longitude
Bearing
I'm now thinking about rounding the values coming from core to the same decimal amount as what I'm seeing with logging. update: |
That’s an apples-to-oranges comparison of the default string conversion formats for floating-point numbers: by default, C/C++ APIs like printf("%g", M_PI);
// => 3.14159
printf("%f", M_PI);
// => 3.141593
printf("%.15f", M_PI);
// => 3.141592653589793 What you care about is not the way these numbers get converted to strings but rather how they’re represented in memory. |
I’m suspicious of lines like this that appear to reinterpret a |
Thank you for 👀, was able to verify that they are the same if I increased the decimals while logging. I have now a setup to do some more testes while consecutive zooming isn't resulting in rounded zoom levels.
Yes, this is could definitely be an issue, but not the issue for which I reopened this ticket as the code shown there is only used at map startup. I have commented this code out to do additional test on this issue. Will pick this up in a follow up. |
First thing I'm noticing is that a map that is initialised with zoom level 0 is set to 0.236014191900084796538195064386 Second thing I noticed is that if you zoom in by 1 using the on screen zoom control you get: |
That could be due to mbgl::TransformState constraining the map so that we don't show anything beyond ±180° latitude don't show more than 180° of longitude at the same time (avoiding "world copying"). |
Figured this one out, it's not related to floating point, our camera change listener was not hooked into the correct MapChange events. |
While writing some instrumentation tests on the Camera API. I noticed that latitude/longitude coming from core needs to be rounded. Eg. setting a camera position at latitude = 1.0 results in getting core values equal to 1.0000000000000142. I'm suggesting to round this value to 10 decimals.
The text was updated successfully, but these errors were encountered: