From 85b70e0d2675bd562a6cc114b87bd97d82d67020 Mon Sep 17 00:00:00 2001 From: tidwall Date: Fri, 28 Jun 2019 10:01:12 -0700 Subject: [PATCH 1/2] Updated geojson package --- Gopkg.lock | 6 +- Gopkg.toml | 2 +- vendor/github.com/tidwall/geojson/geo/geo.go | 63 +++++++------------ .../tidwall/geojson/geo/geo_test.go | 62 ++++++++++++++++++ 4 files changed, 90 insertions(+), 43 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index a3dcac76..2e241966 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -221,7 +221,8 @@ version = "v1.1.0" [[projects]] - digest = "1:cdab3bce90a53a124ac3982719abde77d779e961d9c180e55c23fb74fc62563a" + branch = "master" + digest = "1:16a87d3d8d3808f3206c4992d1fb50440bb7d5508fbe5bfab7d899b516c7f3b8" name = "github.com/tidwall/geojson" packages = [ ".", @@ -229,8 +230,7 @@ "geometry", ] pruneopts = "" - revision = "eaf6e0a55a79c1e879bbbcc879a3176c720d99cd" - version = "v1.1.3" + revision = "ff8d554639ee72ffa650eca1e02f03ab51193c7f" [[projects]] digest = "1:3ddca2bd5496c6922a2a9e636530e178a43c2a534ea6634211acdc7d10222794" diff --git a/Gopkg.toml b/Gopkg.toml index 7937a2f5..4f51e675 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -34,8 +34,8 @@ required = [ name = "github.com/tidwall/boxtree" [[constraint]] + branch = "master" name = "github.com/tidwall/geojson" - version = "1.1.3" [[constraint]] name = "github.com/Shopify/sarama" diff --git a/vendor/github.com/tidwall/geojson/geo/geo.go b/vendor/github.com/tidwall/geojson/geo/geo.go index fe5c497e..36863b0a 100644 --- a/vendor/github.com/tidwall/geojson/geo/geo.go +++ b/vendor/github.com/tidwall/geojson/geo/geo.go @@ -93,75 +93,60 @@ func BearingTo(latA, lonA, latB, lonB float64) float64 { func RectFromCenter(lat, lon, meters float64) ( minLat, minLon, maxLat, maxLon float64, ) { - - // see http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates#Latitude + // convert degrees to radians lat *= radians lon *= radians - r := meters / earthRadius // angular radius + // Calculate ANGULAR RADIUS + // see http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates#UsingIndex + r := meters / earthRadius + // Calculate LATITUDE min and max + // see http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates#Latitude minLat = lat - r maxLat = lat + r + // Calculate LONGITUDE min and max + // see http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates#Longitude latT := math.Asin(math.Sin(lat) / math.Cos(r)) lonΔ := math.Acos((math.Cos(r) - math.Sin(latT)*math.Sin(lat)) / (math.Cos(latT) * math.Cos(lat))) minLon = lon - lonΔ maxLon = lon + lonΔ - // Adjust for north poll + // ADJUST mins and maxes for edge-of-map cases + // see http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates#PolesAnd180thMeridian + + // adjust for NORTH POLE if maxLat > math.Pi/2 { minLon = -math.Pi maxLat = math.Pi / 2 maxLon = math.Pi } - // Adjust for south poll + // adjust for SOUTH POLE if minLat < -math.Pi/2 { minLat = -math.Pi / 2 minLon = -math.Pi maxLon = math.Pi } - // Adjust for wraparound. Remove this if the commented-out condition below this block is added. + /* adjust for WRAPAROUND + + Creates a bounding box that wraps around the Earth like a belt, which + results in returning false positive candidates (candidates that are + farther away from the center than the distance of the search radius). + + An alternative method, possibly to be implemented in the future, would be + to split the bounding box into two boxes. This would return fewer (or no) + false positives, but will require significant changes to the API's of + geoJSON and any of its dependents. */ if minLon < -math.Pi || maxLon > math.Pi { minLon = -math.Pi maxLon = math.Pi } - /* - // Consider splitting area into two bboxes, using the below checks, and erasing above block for performance. See http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates#PolesAnd180thMeridian - // Adjust for wraparound if minimum longitude is less than -180 degrees. - if lonMin < -math.Pi { - // box 1: - latMin = latMin - latMax = latMax - lonMin += 2*math.Pi - lonMax = math.Pi - // box 2: - latMin = latMin - latMax = latMax - lonMin = -math.Pi - lonMax = lonMax - } - // Adjust for wraparound if maximum longitude is greater than 180 degrees. - if lonMax > math.Pi { - // box 1: - latMin = latMin - latMax = latMax - lonMin = lonMin - lonMax = -math.Pi - // box 2: - latMin = latMin - latMax = latMax - lonMin = -math.Pi - lonMax -= 2*math.Pi - } - */ - - minLon = math.Mod(minLon+3*math.Pi, 2*math.Pi) - math.Pi // normalise to -180..+180° - maxLon = math.Mod(maxLon+3*math.Pi, 2*math.Pi) - math.Pi - + // convert radians to degrees minLat *= degrees minLon *= degrees maxLat *= degrees diff --git a/vendor/github.com/tidwall/geojson/geo/geo_test.go b/vendor/github.com/tidwall/geojson/geo/geo_test.go index 2fd4f522..cf67d9e3 100644 --- a/vendor/github.com/tidwall/geojson/geo/geo_test.go +++ b/vendor/github.com/tidwall/geojson/geo/geo_test.go @@ -41,6 +41,68 @@ func TestGeoCalc(t *testing.T) { if value2 != lonB { t.Fatalf("expected '%v', got '%v'", lonB, value2) } + // RectFromCenter + // expected mins and maxes for wraparound and pole tests + expMinLat := -90.0 + expMinLon := -180.0 + expMaxLat := 90.0 + expMaxLon := 180.0 + + dist1 := 1600000.0 + + wraparoundTests := []struct { + name string + lat, lon, searchRadius float64 + }{ + {name: "Wraparound E", lat: 0.0, lon: 179.0, searchRadius: dist1}, // at equator near 180th meridian East + {name: "Wraparound W", lat: 0.0, lon: -179.0, searchRadius: dist1}, // at equator near 180th meridian West + } + + for _, tt := range wraparoundTests { + t.Run(tt.name, func(t *testing.T) { + _, minLon, _, maxLon := RectFromCenter(tt.lat, tt.lon, tt.searchRadius) + if !(minLon == expMinLon && maxLon == expMaxLon) { + t.Errorf("\nexpected minLon = '%v', maxLon = '%v'"+"\ngot minLon = '%v', maxLon = '%v'\n", + expMinLon, expMaxLon, + minLon, maxLon) + } + }) + } + + northPoleTests := []struct { + name string + lat, lon, searchRadius float64 + }{ + {name: "North Pole", lat: 89.0, lon: 90.0, searchRadius: dist1}, // near North Pole + {name: "North Pole: Tile38 iss422", lat: 13.0257553, lon: 77.6672509, searchRadius: 9000000.0}, + } + for _, tt := range northPoleTests { + t.Run(tt.name, func(t *testing.T) { + _, minLon, maxLat, maxLon := RectFromCenter(tt.lat, tt.lon, tt.searchRadius) + if !(minLon == expMinLon && maxLat == expMaxLat && maxLon == expMaxLon) { + t.Errorf("\nexpected minLon = '%v', maxLat = '%v', maxLon = '%v'"+"\ngot minLon = '%v', maxLat = '%v', maxLon = '%v'", + expMinLon, expMaxLat, expMaxLon, + minLon, maxLat, maxLon) + } + }) + } + + southPoleTests := []struct { + name string + lat, lon, searchRadius float64 + }{ + {name: "South Pole", lat: -89.0, lon: 90.0, searchRadius: dist1}, // near South Pole + } + for _, tt := range southPoleTests { + t.Run(tt.name, func(t *testing.T) { + minLat, minLon, _, maxLon := RectFromCenter(tt.lat, tt.lon, tt.searchRadius) + if !(minLat == expMinLat && minLon == expMinLon && maxLon == expMaxLon) { + t.Errorf("\nexpected minLat = '%v', minLon = '%v', maxLon = '%v'"+"\ngot minLat = '%v', minLon = '%v', maxLon = '%v'", + expMinLat, expMinLon, expMaxLon, + minLat, minLon, maxLon) + } + }) + } } func TestHaversine(t *testing.T) { From 8c9f2f10bdec33c7ebd046169a493d8dc17800a4 Mon Sep 17 00:00:00 2001 From: tidwall Date: Fri, 28 Jun 2019 10:31:49 -0700 Subject: [PATCH 2/2] Updated geojson version --- Gopkg.lock | 2 +- Gopkg.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 2e241966..a074d1b3 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -221,7 +221,6 @@ version = "v1.1.0" [[projects]] - branch = "master" digest = "1:16a87d3d8d3808f3206c4992d1fb50440bb7d5508fbe5bfab7d899b516c7f3b8" name = "github.com/tidwall/geojson" packages = [ @@ -231,6 +230,7 @@ ] pruneopts = "" revision = "ff8d554639ee72ffa650eca1e02f03ab51193c7f" + version = "v1.1.6" [[projects]] digest = "1:3ddca2bd5496c6922a2a9e636530e178a43c2a534ea6634211acdc7d10222794" diff --git a/Gopkg.toml b/Gopkg.toml index 4f51e675..460af89c 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -34,8 +34,8 @@ required = [ name = "github.com/tidwall/boxtree" [[constraint]] - branch = "master" name = "github.com/tidwall/geojson" + version = "1.1.6" [[constraint]] name = "github.com/Shopify/sarama"