mirror of https://github.com/tidwall/tile38.git
Use haversine instead of distance in knn if distance is not required.
This commit is contained in:
parent
81c41a2d3d
commit
2383594048
|
@ -423,10 +423,19 @@ func (server *Server) nearestNeighbors(
|
||||||
if !match {
|
if !match {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
dist := o.Distance(target)
|
var dist float64
|
||||||
|
if s.distance {
|
||||||
|
dist = o.Distance(target)
|
||||||
if target.Meters() > 0 && dist > target.Meters() {
|
if target.Meters() > 0 && dist > target.Meters() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// don't need actual distances, use haversine as proxy for sorting
|
||||||
|
dist = target.HaversineTo(o.Center())
|
||||||
|
if target.Haversine() > 0 && dist > target.Haversine() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
items = append(items, iterItem{id: id, o: o, fields: fields, dist: dist})
|
items = append(items, iterItem{id: id, o: o, fields: fields, dist: dist})
|
||||||
if !keepGoing {
|
if !keepGoing {
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in New Issue