paleolimbot / s2geography

Simple features (ish) for s2geometry
Apache License 2.0
33 stars 4 forks source link

Coordinate precision problem in S2geometry #12

Closed LemonLiTree closed 1 year ago

LemonLiTree commented 1 year ago

Hi, @paleolimbot I found some precision issues in S2geometry I get S2point first:S2Point point = S2LatLng::FromDegrees(1, 2).ToPoint(); Then I want to get the x coordinate of this point:S2LatLng(*point).lng().degrees(); The result I get is 0.99999999999999978 If I enter a longitude of 56.7, I get 56.699999999999996 I think this is the loss of precision when doing double calculations, is there any way to solve this?

paleolimbot commented 1 year ago

No, sort of!

S2's internal representation of a "point" is an XYZ unit vector, so once you're in "point" land there's no guarantee you'll get back exactly the same value. The main strategy for dealing with this is to minimize the number of times you have to convert back and forth. There are also some places where you can use a "snap" function that will snap to a fixed latitude/longitude precision (e.g., when computing an intersection).

LemonLiTree commented 1 year ago

ths