Fix roam fence missing

This commit is contained in:
tidwall 2019-01-06 10:23:57 -07:00
parent 35dbb0cd6f
commit d7d0baa954
1 changed files with 10 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import (
"time" "time"
"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/gjson" "github.com/tidwall/gjson"
"github.com/tidwall/tile38/internal/glob" "github.com/tidwall/tile38/internal/glob"
@ -356,15 +357,20 @@ func fenceMatchRoam(
c *Server, fence *liveFenceSwitches, c *Server, fence *liveFenceSwitches,
tkey, tid string, obj geojson.Object, tkey, tid string, obj geojson.Object,
) (nearbys, faraways []roamMatch) { ) (nearbys, faraways []roamMatch) {
col := c.getCol(fence.roam.key) col := c.getCol(fence.roam.key)
if col == nil { if col == nil {
return return
} }
prevNearbys := fence.roam.nearbys[tid] prevNearbys := fence.roam.nearbys[tid]
var newNearbys map[string]bool var newNearbys map[string]bool
center := obj.Center()
col.Intersects(obj, 0, nil, func( minLat, minLon, maxLat, maxLon :=
geo.RectFromCenter(center.Y, center.X, fence.roam.meters)
rect := geometry.Rect{
Min: geometry.Point{X: minLon, Y: minLat},
Max: geometry.Point{X: maxLon, Y: maxLat},
}
col.Intersects(geojson.NewRect(rect), 0, nil, func(
id string, obj2 geojson.Object, fields []float64, id string, obj2 geojson.Object, fields []float64,
) bool { ) bool {
if c.hasExpired(fence.roam.key, id) { if c.hasExpired(fence.roam.key, id) {
@ -395,6 +401,7 @@ func fenceMatchRoam(
obj: obj2, obj: obj2,
meters: obj.Distance(obj2), meters: obj.Distance(obj2),
} }
if !prev || !fence.nodwell { if !prev || !fence.nodwell {
// brand new "nearby" // brand new "nearby"
nearbys = append(nearbys, match) nearbys = append(nearbys, match)