Update geojson vendor

This commit is contained in:
tidwall 2018-11-11 09:33:58 -07:00
parent 6616b86eda
commit 1bdc2135d7
2 changed files with 9 additions and 77 deletions

4
Gopkg.lock generated
View File

@ -243,7 +243,7 @@
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:145703130ac1de36086ab350337777161f9c1d791e81a73659ac1f569e15b5e5" digest = "1:3307384a763736cbcfa625076939fe9a240e5f5c9d6ace507fa4fd1f4f6944d6"
name = "github.com/tidwall/geojson" name = "github.com/tidwall/geojson"
packages = [ packages = [
".", ".",
@ -251,7 +251,7 @@
"geometry", "geometry",
] ]
pruneopts = "" pruneopts = ""
revision = "dbcb73c57c65ff784ce2ccaad3f062c9787d6f81" revision = "553da6f08f84f544b5482743fe73c3989facc578"
[[projects]] [[projects]]
digest = "1:3ddca2bd5496c6922a2a9e636530e178a43c2a534ea6634211acdc7d10222794" digest = "1:3ddca2bd5496c6922a2a9e636530e178a43c2a534ea6634211acdc7d10222794"

View File

@ -3,7 +3,6 @@ package geojson
import ( import (
"math" "math"
"strconv" "strconv"
"sync"
"github.com/tidwall/geojson/geo" "github.com/tidwall/geojson/geo"
"github.com/tidwall/geojson/geometry" "github.com/tidwall/geojson/geometry"
@ -212,10 +211,7 @@ func (g *Circle) getObject() Object {
return makeCircleObject(g.center, g.meters, g.steps) return makeCircleObject(g.center, g.meters, g.steps)
} }
var llmu sync.RWMutex func makeCircleObject(center geometry.Point, meters float64, steps int) Object {
var llobj Object
func makeCircleObjectA(center geometry.Point, meters float64, steps int) Object {
if meters <= 0 { if meters <= 0 {
return NewPoint(center) 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) _, maxX := geo.DestinationPoint(center.Y, center.X, meters, 90)
minY, _ := geo.DestinationPoint(center.Y, center.X, meters, 180) minY, _ := geo.DestinationPoint(center.Y, center.X, meters, 180)
_, minX := geo.DestinationPoint(center.Y, center.X, meters, 270) _, 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 lons := (maxX - minX) / 2
lats := (maxY - minY) / 2 lats := (maxY - minY) / 2
// generate the
for th := 0.0; th <= 360.0; th += 360.0 / float64(steps) { for th := 0.0; th <= 360.0; th += 360.0 / float64(steps) {
radians := (math.Pi / 180) * th radians := (math.Pi / 180) * th
x := center.X + lats*math.Cos(radians) 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
}