mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-01-25 15:40:22 +01:00
Clip coordinates in interleaved spatial queries to world boundaries.
This commit is contained in:
parent
6b717e41fb
commit
eb9cfb9959
@ -59,6 +59,23 @@ func maxComponent(a, b int16) int16 {
|
|||||||
return b
|
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 {
|
func MinCoord(a, b Coord) Coord {
|
||||||
return Coord{
|
return Coord{
|
||||||
X: minComponent(a.X, b.X),
|
X: minComponent(a.X, b.X),
|
||||||
|
11
leveldb.go
11
leveldb.go
@ -309,8 +309,8 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c
|
|||||||
if secondKey, err = common.DecodeStringFromBytes(second); err != nil {
|
if secondKey, err = common.DecodeStringFromBytes(second); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c1 := common.PlainToCoord(firstKey)
|
c1 := common.ClipCoord(common.PlainToCoord(firstKey))
|
||||||
c2 := common.PlainToCoord(secondKey)
|
c2 := common.ClipCoord(common.PlainToCoord(secondKey))
|
||||||
c1, c2 = common.MinCoord(c1, c2), common.MaxCoord(c1, c2)
|
c1, c2 = common.MinCoord(c1, c2), common.MaxCoord(c1, c2)
|
||||||
|
|
||||||
blocks = make(chan Block)
|
blocks = make(chan Block)
|
||||||
@ -336,6 +336,7 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c
|
|||||||
encodedKey []byte
|
encodedKey []byte
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//log.Printf("seeking to: %d", zmin)
|
||||||
it.Seek(common.ToBigEndian(zmin))
|
it.Seek(common.ToBigEndian(zmin))
|
||||||
for it.Valid() {
|
for it.Valid() {
|
||||||
zcode := common.FromBigEndian(it.Key())
|
zcode := common.FromBigEndian(it.Key())
|
||||||
@ -356,9 +357,13 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c
|
|||||||
}
|
}
|
||||||
it.Next()
|
it.Next()
|
||||||
} else {
|
} 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 {
|
if err = it.GetError(); err != nil {
|
||||||
log.Printf("error while iterating: %s", err)
|
log.Printf("error while iterating: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -303,8 +303,8 @@ func (ss *SqliteSession) interleavedSpatialQuery(first, second []byte, done chan
|
|||||||
if secondKey, err = common.DecodeStringFromBytes(second); err != nil {
|
if secondKey, err = common.DecodeStringFromBytes(second); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c1 := common.PlainToCoord(firstKey)
|
c1 := common.ClipCoord(common.PlainToCoord(firstKey))
|
||||||
c2 := common.PlainToCoord(secondKey)
|
c2 := common.ClipCoord(common.PlainToCoord(secondKey))
|
||||||
c1, c2 = common.MinCoord(c1, c2), common.MaxCoord(c1, c2)
|
c1, c2 = common.MinCoord(c1, c2), common.MaxCoord(c1, c2)
|
||||||
|
|
||||||
blocks = make(chan Block)
|
blocks = make(chan Block)
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user