geo icon indicating copy to clipboard operation
geo copied to clipboard

CellId.AllNeighbors has documented but unchecked precondition

Open ymofen opened this issue 2 years ago • 3 comments

ll1 := s2.LatLngFromDegrees(30.755702, 114.127656) c1 := s2.CellIDFromLatLng(ll1) neighbors := c1.AllNeighbors(8)

image

ymofen avatar Dec 15 '23 14:12 ymofen

Can you put this in the form of a test case we can add to latlng_test.go?

jmr avatar Apr 01 '25 07:04 jmr

c1 is level 30. You can't get level 8 neighbors from that.

https://github.com/golang/geo/blob/dc45a1002b836666a1af4fffedca3220ba59d03c/s2/cellid.go#L271

You can try c1 := s2.CellIDFromLatLng(ll1).Parent(8).

@rsned Apparently go has no assert / DCHECK. Should this also return an ok bool? There must be many more examples of unchecked preconditions waiting to bite someone and waste time.

jmr avatar Apr 03 '25 07:04 jmr

It is possible to set up a dcheck equivalent using go build tags. e.g. https://github.com/golang/geo/pull/141. There are a couple places where I noted the c++ checks something here, but not too many of the DCHECKs are directly referenced in the code.

rsned avatar Apr 03 '25 17:04 rsned