diff --git a/common/coords.go b/common/coords.go index 9b9bb72..ae6e92b 100644 --- a/common/coords.go +++ b/common/coords.go @@ -59,6 +59,23 @@ func maxComponent(a, b int16) int16 { return b } +func clipComponent(x int16) int16 { + if x < minValue { + return minValue + } + if x > maxValue { + return maxValue + } + return x +} + +func ClipCoord(c Coord) Coord { + return Coord{ + X: clipComponent(c.X), + Y: clipComponent(c.Y), + Z: clipComponent(c.Z)} +} + func MinCoord(a, b Coord) Coord { return Coord{ X: minComponent(a.X, b.X), diff --git a/leveldb.go b/leveldb.go index 63a5530..a85d8da 100644 --- a/leveldb.go +++ b/leveldb.go @@ -309,8 +309,8 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c if secondKey, err = common.DecodeStringFromBytes(second); err != nil { return } - c1 := common.PlainToCoord(firstKey) - c2 := common.PlainToCoord(secondKey) + c1 := common.ClipCoord(common.PlainToCoord(firstKey)) + c2 := common.ClipCoord(common.PlainToCoord(secondKey)) c1, c2 = common.MinCoord(c1, c2), common.MaxCoord(c1, c2) blocks = make(chan Block) @@ -336,6 +336,7 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c encodedKey []byte ) + //log.Printf("seeking to: %d", zmin) it.Seek(common.ToBigEndian(zmin)) for it.Valid() { zcode := common.FromBigEndian(it.Key()) @@ -356,9 +357,13 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c } it.Next() } else { - it.Seek(common.ToBigEndian(common.BigMin(zmin, zmax, zcode))) + next := common.BigMin(zmin, zmax, zcode) + //log.Printf("seeking to: %d", next) + it.Seek(common.ToBigEndian(next)) + //log.Printf("seeking done: %d", next) } } + //log.Println("iterating done") if err = it.GetError(); err != nil { log.Printf("error while iterating: %s", err) return diff --git a/sqlite.go b/sqlite.go index bc6c5cf..be1c9ac 100644 --- a/sqlite.go +++ b/sqlite.go @@ -303,8 +303,8 @@ func (ss *SqliteSession) interleavedSpatialQuery(first, second []byte, done chan if secondKey, err = common.DecodeStringFromBytes(second); err != nil { return } - c1 := common.PlainToCoord(firstKey) - c2 := common.PlainToCoord(secondKey) + c1 := common.ClipCoord(common.PlainToCoord(firstKey)) + c2 := common.ClipCoord(common.PlainToCoord(secondKey)) c1, c2 = common.MinCoord(c1, c2), common.MaxCoord(c1, c2) blocks = make(chan Block) diff --git a/tilemapper/tilemapper b/tilemapper/tilemapper index 4545440..aa2bef1 100755 Binary files a/tilemapper/tilemapper and b/tilemapper/tilemapper differ