spherely
spherely copied to clipboard
Issue with exact equality and roundtrip of lat/lng coordinates
Something I ran into while testing https://github.com/benbovy/spherely/pull/20 (xref https://github.com/benbovy/spherely/pull/20#discussion_r1141150124), is that it is not that easy to pass an exact equality test with equals()
.
Illustration:
# construct a point through centroid to get something that is not exactly Point(1, 0)
>>> point = spherely.centroid(spherely.LineString([(0, 0), (0, 2)]))
>>> point
POINT (0.9999999999999998 0)
# reconstruct this point through its lat/long coordinates
>>> point2 = spherely.Point(spherely.get_y(point), spherely.get_x(point))
>>> point2
POINT (0.9999999999999998 0)
# those two points (with the same WKT repr and equal coordinates in degrees) are not considered equal
>>> spherely.equals(point, point2)
False
What I assume is happening here is that the roundtrip from S2Point
to S2LatLng
and back is not exact (the conversion from S2Point to LatLng essentially happens in the WKT repr or in get_x/get_y, and the conversion from S2LatLng to S2Point is essentially happening in the Point(..)
constructor.
While that might be expected based on knowledge of the S2 internals (how a S2Point is stored, which is not as its lon/lat coords), I suppose this will not be expected in general by users? And it also gives some usability issues (also when testing)
For equals()
specifically, it might be possible to have an option there to snap round coordinates while checking equality.