File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -268,8 +268,13 @@ func (ci CellID) VertexNeighbors(level int) []CellID {
268
268
// same neighbor may be returned more than once. There could be up to eight
269
269
// neighbors including the diagonal ones that share the vertex.
270
270
//
271
- // This requires level >= ci.Level().
271
+ // Returns nil if level < ci.Level() (cells would not be neighboring) or
272
+ // level > MaxLevel (no such cells exist).
272
273
func (ci CellID ) AllNeighbors (level int ) []CellID {
274
+ if level < ci .Level () || level > MaxLevel {
275
+ return nil
276
+ }
277
+
273
278
var neighbors []CellID
274
279
275
280
face , i , j , _ := ci .faceIJOrientation ()
Original file line number Diff line number Diff line change @@ -323,6 +323,19 @@ func TestCellIDAllNeighbors(t *testing.T) {
323
323
}
324
324
}
325
325
326
+ func TestCellIDAllNeighborsBadLevels (t * testing.T ) {
327
+ ci := CellIDFromLatLng (LatLngFromDegrees (47.38 , 8.54 )).Parent (29 )
328
+ if got := ci .AllNeighbors (- 1 ); got != nil {
329
+ t .Errorf ("AllNeighbors(%v) = %v, want nil" , - 1 , got )
330
+ }
331
+ if got := ci .AllNeighbors (28 ); got != nil {
332
+ t .Errorf ("AllNeighbors(%v) = %v, want nil" , 28 , got )
333
+ }
334
+ if got := ci .AllNeighbors (31 ); got != nil {
335
+ t .Errorf ("AllNeighbors(%v) = %v, want nil" , 31 , got )
336
+ }
337
+ }
338
+
326
339
func TestCellIDTokensNominal (t * testing.T ) {
327
340
tests := []struct {
328
341
token string
You can’t perform that action at this time.
0 commit comments