-
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af5cbd9
commit f35d63d
Showing
125 changed files
with
10,500 additions
and
913 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cache | ||
|
||
import ( | ||
"math" | ||
|
||
"github.com/go-spatial/geom/slippy" | ||
) | ||
|
||
// rangeFamilyAt runs the given callback on every related tile at the given zoom. This could include | ||
// the provided tile itself (if the same zoom is provided), the parent (overlapping tile at a lower zoom | ||
// level), or children (overlapping tiles at a higher zoom level). | ||
// | ||
// Copied from go-spatial/geom (dc1d50720ee77122d0) since the function by this name doesn't do | ||
// the same thing anymore. (In geom, it no longer returns ancestors or self, only descendants. | ||
// It's also buggy because grid.ToNative/FromNative are buggy.) | ||
// | ||
// This function should be removed once the one in geom is updated to work as expected. | ||
func rangeFamilyAt(t *slippy.Tile, zoom uint, f func(*slippy.Tile) error) error { | ||
// handle ancestors and self | ||
if zoom <= t.Z { | ||
mag := t.Z - zoom | ||
arg := slippy.NewTile(zoom, t.X>>mag, t.Y>>mag) | ||
return f(arg) | ||
} | ||
|
||
// handle descendants | ||
mag := zoom - t.Z | ||
delta := uint(math.Exp2(float64(mag))) | ||
|
||
leastX := t.X << mag | ||
leastY := t.Y << mag | ||
|
||
for x := leastX; x < leastX+delta; x++ { | ||
for y := leastY; y < leastY+delta; y++ { | ||
err := f(slippy.NewTile(zoom, x, y)) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package cache | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/go-spatial/geom/slippy" | ||
) | ||
|
||
func TestRangeFamilyAt(t *testing.T) { | ||
type coord struct { | ||
z, x, y uint | ||
} | ||
|
||
type tcase struct { | ||
tile *slippy.Tile | ||
zoomAt uint | ||
expected []coord | ||
} | ||
|
||
isIn := func(arr []coord, c coord) bool { | ||
for _, v := range arr { | ||
if v == c { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
fn := func(tc tcase) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
|
||
coordList := make([]coord, 0, len(tc.expected)) | ||
rangeFamilyAt(tc.tile, tc.zoomAt, func(tile *slippy.Tile) error { | ||
z, x, y := tile.ZXY() | ||
c := coord{z, x, y} | ||
|
||
coordList = append(coordList, c) | ||
|
||
return nil | ||
}) | ||
|
||
if len(coordList) != len(tc.expected) { | ||
t.Fatalf("coordinate list length, expected %d, got %d: %v \n\n %v", len(tc.expected), len(coordList), tc.expected, coordList) | ||
} | ||
|
||
for _, v := range tc.expected { | ||
if !isIn(coordList, v) { | ||
t.Logf("coordinates: %v", coordList) | ||
t.Fatalf("coordinate exists, expected %v, got missing", v) | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
testcases := map[string]tcase{ | ||
"children 1": { | ||
tile: slippy.NewTile(0, 0, 0), | ||
zoomAt: 1, | ||
expected: []coord{ | ||
{1, 0, 0}, | ||
{1, 0, 1}, | ||
{1, 1, 0}, | ||
{1, 1, 1}, | ||
}, | ||
}, | ||
"children 2": { | ||
tile: slippy.NewTile(8, 3, 5), | ||
zoomAt: 10, | ||
expected: []coord{ | ||
{10, 12, 20}, | ||
{10, 12, 21}, | ||
{10, 12, 22}, | ||
{10, 12, 23}, | ||
// | ||
{10, 13, 20}, | ||
{10, 13, 21}, | ||
{10, 13, 22}, | ||
{10, 13, 23}, | ||
// | ||
{10, 14, 20}, | ||
{10, 14, 21}, | ||
{10, 14, 22}, | ||
{10, 14, 23}, | ||
// | ||
{10, 15, 20}, | ||
{10, 15, 21}, | ||
{10, 15, 22}, | ||
{10, 15, 23}, | ||
}, | ||
}, | ||
"parent 1": { | ||
tile: slippy.NewTile(1, 0, 0), | ||
zoomAt: 0, | ||
expected: []coord{ | ||
{0, 0, 0}, | ||
}, | ||
}, | ||
"parent 2": { | ||
tile: slippy.NewTile(3, 3, 5), | ||
zoomAt: 1, | ||
expected: []coord{ | ||
{1, 0, 1}, | ||
}, | ||
}, | ||
} | ||
|
||
for name, tc := range testcases { | ||
t.Run(name, fn(tc)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.