mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-04 19:41:26 -05:00
33 lines
957 B
Go
33 lines
957 B
Go
package common
|
|
|
|
import "github.com/attic-labs/noms/datas"
|
|
|
|
func (qt *SQuadTree) Query(p GeopositionDef, kilometers float64, ds datas.DataStore) (GeorectangleDef, []Incident) {
|
|
r := BoundingRectangle(p, kilometers)
|
|
nodes := qt.Search(r, p, float32(kilometers), ds)
|
|
return r, nodes
|
|
}
|
|
|
|
func (qt *SQuadTree) Search(r GeorectangleDef, p GeopositionDef, kilometers float32, ds datas.DataStore) []Incident {
|
|
nodes := []Incident{}
|
|
if qt.Tiles().Len() > 0 {
|
|
for _, q := range quadrants {
|
|
tile := qt.Tiles().Get(q).TargetValue(ds)
|
|
if IntersectsRect(tile.Georectangle().Def(), r) {
|
|
tnodes := tile.Search(r, p, kilometers, ds)
|
|
nodes = append(nodes, tnodes...)
|
|
}
|
|
}
|
|
} else if qt.Nodes().Len() > 0 {
|
|
qt.Nodes().Iter(func(r RefOfValue, i uint64) bool {
|
|
incident := r.TargetValue(ds).(Incident)
|
|
if DistanceTo(p, incident.Geoposition().Def()) < kilometers {
|
|
nodes = append(nodes, incident)
|
|
}
|
|
return false
|
|
})
|
|
}
|
|
|
|
return nodes
|
|
}
|