mirror of https://github.com/tidwall/tile38.git
Simplification
This commit is contained in:
parent
d2c687d61e
commit
f45d81d692
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/mmcloughlin/geohash"
|
"github.com/mmcloughlin/geohash"
|
||||||
"github.com/tidwall/geojson"
|
"github.com/tidwall/geojson"
|
||||||
|
"github.com/tidwall/geojson/geo"
|
||||||
"github.com/tidwall/geojson/geometry"
|
"github.com/tidwall/geojson/geometry"
|
||||||
"github.com/tidwall/resp"
|
"github.com/tidwall/resp"
|
||||||
"github.com/tidwall/tile38/internal/bing"
|
"github.com/tidwall/tile38/internal/bing"
|
||||||
|
@ -373,7 +374,7 @@ func (server *Server) cmdNearby(msg *Message) (res resp.Value, err error) {
|
||||||
iter := func(id string, o geojson.Object, fields []float64, dist *float64) bool {
|
iter := func(id string, o geojson.Object, fields []float64, dist *float64) bool {
|
||||||
distance := 0.0
|
distance := 0.0
|
||||||
if s.distance {
|
if s.distance {
|
||||||
distance = *dist
|
distance = geo.DistanceFromHaversine(*dist)
|
||||||
}
|
}
|
||||||
return sw.writeObject(ScanWriterParams{
|
return sw.writeObject(ScanWriterParams{
|
||||||
id: id,
|
id: id,
|
||||||
|
@ -406,6 +407,7 @@ func (server *Server) nearestNeighbors(
|
||||||
iter func(id string, o geojson.Object, fields []float64, dist *float64,
|
iter func(id string, o geojson.Object, fields []float64, dist *float64,
|
||||||
) bool) {
|
) bool) {
|
||||||
limit := int(sw.cursor + sw.limit)
|
limit := int(sw.cursor + sw.limit)
|
||||||
|
maxDist := target.Haversine()
|
||||||
var items []iterItem
|
var items []iterItem
|
||||||
sw.col.Nearby(target, func(id string, o geojson.Object, fields []float64) bool {
|
sw.col.Nearby(target, func(id string, o geojson.Object, fields []float64) bool {
|
||||||
if server.hasExpired(s.key, id) {
|
if server.hasExpired(s.key, id) {
|
||||||
|
@ -418,15 +420,7 @@ func (server *Server) nearestNeighbors(
|
||||||
if !match {
|
if !match {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
var dist, maxDist float64
|
dist := target.HaversineTo(o.Center())
|
||||||
if s.distance {
|
|
||||||
dist = o.Distance(target)
|
|
||||||
maxDist = target.Meters()
|
|
||||||
} else {
|
|
||||||
// don't need actual distances, use haversine as proxy for sorting
|
|
||||||
dist = target.HaversineTo(o.Center())
|
|
||||||
maxDist = target.Haversine()
|
|
||||||
}
|
|
||||||
if maxDist > 0 && dist > maxDist {
|
if maxDist > 0 && dist > maxDist {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue