From 1bdc2135d7d669b2b8b034eb180afa8c4cefb826 Mon Sep 17 00:00:00 2001 From: tidwall Date: Sun, 11 Nov 2018 09:33:58 -0700 Subject: [PATCH] Update geojson vendor --- Gopkg.lock | 4 +- vendor/github.com/tidwall/geojson/circle.go | 82 ++------------------- 2 files changed, 9 insertions(+), 77 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 6eb3854d..3a60493c 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -243,7 +243,7 @@ [[projects]] branch = "master" - digest = "1:145703130ac1de36086ab350337777161f9c1d791e81a73659ac1f569e15b5e5" + digest = "1:3307384a763736cbcfa625076939fe9a240e5f5c9d6ace507fa4fd1f4f6944d6" name = "github.com/tidwall/geojson" packages = [ ".", @@ -251,7 +251,7 @@ "geometry", ] pruneopts = "" - revision = "dbcb73c57c65ff784ce2ccaad3f062c9787d6f81" + revision = "553da6f08f84f544b5482743fe73c3989facc578" [[projects]] digest = "1:3ddca2bd5496c6922a2a9e636530e178a43c2a534ea6634211acdc7d10222794" diff --git a/vendor/github.com/tidwall/geojson/circle.go b/vendor/github.com/tidwall/geojson/circle.go index 50bac786..fb34e882 100644 --- a/vendor/github.com/tidwall/geojson/circle.go +++ b/vendor/github.com/tidwall/geojson/circle.go @@ -3,7 +3,6 @@ package geojson import ( "math" "strconv" - "sync" "github.com/tidwall/geojson/geo" "github.com/tidwall/geojson/geometry" @@ -212,10 +211,7 @@ func (g *Circle) getObject() Object { return makeCircleObject(g.center, g.meters, g.steps) } -var llmu sync.RWMutex -var llobj Object - -func makeCircleObjectA(center geometry.Point, meters float64, steps int) Object { +func makeCircleObject(center geometry.Point, meters float64, steps int) Object { if meters <= 0 { return NewPoint(center) } @@ -227,9 +223,15 @@ func makeCircleObjectA(center geometry.Point, meters float64, steps int) Object _, maxX := geo.DestinationPoint(center.Y, center.X, meters, 90) minY, _ := geo.DestinationPoint(center.Y, center.X, meters, 180) _, minX := geo.DestinationPoint(center.Y, center.X, meters, 270) + + // TODO: detect of pole and antimeridian crossing and generate a + // valid multigeometry + + // use the half width of the lat and lon lons := (maxX - minX) / 2 lats := (maxY - minY) / 2 + // generate the for th := 0.0; th <= 360.0; th += 360.0 / float64(steps) { radians := (math.Pi / 180) * th x := center.X + lats*math.Cos(radians) @@ -245,73 +247,3 @@ func makeCircleObjectA(center geometry.Point, meters float64, steps int) Object }), ) } -func makeCircleObjectB(center geometry.Point, meters float64, steps int) Object { - if meters <= 0 { - return NewPoint(center) - } - meters = geo.NormalizeDistance(meters) - points := make([]geometry.Point, 0, steps+1) - - step := 360.0 / float64(steps) - i := 0 - for deg := 360.0; deg > 0; deg -= step { - lat, lon := geo.DestinationPoint(center.Y, center.X, meters, deg) - points = append(points, geometry.Point{X: lon, Y: lat}) - i++ - } - // add last connecting point, make a total of steps+1 - points = append(points, points[0]) - - return NewPolygon( - geometry.NewPoly(points, nil, &geometry.IndexOptions{ - Kind: geometry.None, - }), - ) -} - -func makeCircleObject(center geometry.Point, meters float64, steps int) Object { - if meters <= 0 { - return NewPoint(center) - } - - meters = geo.NormalizeDistance(meters) - points := make([]geometry.Point, 0, steps+1) - return makeCircleObjectA(center, meters, steps) - - llmu.RLock() - if llobj != nil { - llmu.RUnlock() - return llobj - } - llmu.RUnlock() - llmu.Lock() - if llobj != nil { - llmu.Unlock() - return llobj - } - defer llmu.Unlock() - - step := 360.0 / float64(steps) - i := 0 - for deg := 360.0; deg > 0; deg -= step { - lat, lon := geo.DestinationPoint(center.Y, center.X, meters, deg) - points = append(points, geometry.Point{X: lon, Y: lat}) - i++ - } - // add last connecting point, make a total of steps+1 - points = append(points, points[0]) - - // for i := 0; i < steps; i++ { - // fmt.Printf("%d: %v\n", i, points[i].X) - // } - - // TODO: account for the pole and antimerdian. In most cases only a - // polygon is needed, but when the circle bounds passes the 90/180 - // lines, we need to create a multipolygon - - llobj = NewPolygon( - geometry.NewPoly(points, nil, geometry.DefaultIndexOptions), - ) - // println(llobj.String()) - return llobj -}