From d7d0baa954477424e1519f89219ff1e61d8e2664 Mon Sep 17 00:00:00 2001 From: tidwall Date: Sun, 6 Jan 2019 10:23:57 -0700 Subject: [PATCH] Fix roam fence missing --- internal/server/fence.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/server/fence.go b/internal/server/fence.go index 93545e01..67c041a0 100644 --- a/internal/server/fence.go +++ b/internal/server/fence.go @@ -6,6 +6,7 @@ import ( "time" "github.com/tidwall/geojson" + "github.com/tidwall/geojson/geo" "github.com/tidwall/geojson/geometry" "github.com/tidwall/gjson" "github.com/tidwall/tile38/internal/glob" @@ -356,15 +357,20 @@ func fenceMatchRoam( c *Server, fence *liveFenceSwitches, tkey, tid string, obj geojson.Object, ) (nearbys, faraways []roamMatch) { - col := c.getCol(fence.roam.key) if col == nil { return } prevNearbys := fence.roam.nearbys[tid] var newNearbys map[string]bool - - col.Intersects(obj, 0, nil, func( + center := obj.Center() + 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, ) bool { if c.hasExpired(fence.roam.key, id) { @@ -395,6 +401,7 @@ func fenceMatchRoam( obj: obj2, meters: obj.Distance(obj2), } + if !prev || !fence.nodwell { // brand new "nearby" nearbys = append(nearbys, match)