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
L.Util.formatNum round #6586
Comments
That error between -1.4837191022531273 and -1.4837191022531275 is roughly equal to... checks notes... one tenth of an atom. I know that cadastre applications rely on precision, but I don't think one needs that much precision. In all seriousness now: I acknowledge that it can lead to misdetection of features with the same coordinates. If you could make that suggestion into a pull request, and see it all the unit tests still pass nicely, I don't think there should be any problem making the change. |
Sure ! But maths dont lie : Geos & Postgis are really sensible. Pull request in progress. |
Just for completeness: #6587 was reverted because of performance issues, but there also was reported more serious flow with numbers in scientific notation: var line = L.polyline([[0,-7.993322e-10],[10,20],[20,30]]);
L.geoJson(line.toGeoJSON());//errors on NaN
L.Util.formatNum(-7.993322e-10); //Returns NaN But you may consider "2nd best" approach with epsilon: #7129 With this function we get almost same precision as in your original PR: L.Util.formatNum(1.005, 2) === 1.01
L.Util.formatNum(-1.005, 2) === -1.01
L.Util.formatNum(1.555, 2) === 1.56
L.Util.formatNum(-1.555, 2) === -1.56
L.Util.formatNum(-7.993322e-10, 16) === -7.993322e-10
L.Util.formatNum(-1.4837191022531273, 18) === -1.4837191022531275 // Round-off error Performance is great: https://jsperf.com/leaflet-issue-6668/2 |
Environment
To reproduce
The way
formatNum
performs rounding can result in unexpected changes to coordinates.For example :
The precision argument for
latLngToCoords
is not documented, but it may be.I play with french cadastre, and such approximation leads to various mistakes.
Solution
According to this article on stackoverflow, this rounding method should be better :
The text was updated successfully, but these errors were encountered: