From 6f3716a0cf1f5cca2056275da19238d1b67eaab4 Mon Sep 17 00:00:00 2001 From: tidwall Date: Thu, 28 Nov 2019 10:13:00 -0700 Subject: [PATCH] Fixes a false negative for intersecting rings https://github.com/tidwall/geojson/commit/ac08098 --- go.mod | 2 +- go.sum | 4 ++-- scripts/build.sh | 7 ++++-- scripts/test.sh | 7 ++++-- vendor/github.com/tidwall/geojson/circle.go | 5 +++++ vendor/github.com/tidwall/geojson/geo/geo.go | 6 +---- .../tidwall/geojson/geometry/ring.go | 22 +++++-------------- vendor/modules.txt | 2 +- 8 files changed, 25 insertions(+), 30 deletions(-) diff --git a/go.mod b/go.mod index d32000cc..77b55b9b 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/tidwall/buntdb v1.1.0 github.com/tidwall/cities v0.0.0-20190730194520-dbe1ae0b862c // indirect github.com/tidwall/geoindex v1.1.0 - github.com/tidwall/geojson v1.1.7 + github.com/tidwall/geojson v1.1.8 github.com/tidwall/gjson v1.3.2 github.com/tidwall/grect v0.0.0-20161006141115-ba9a043346eb // indirect github.com/tidwall/lotsa v0.0.0-20180225195211-a03631ac7f1c // indirect diff --git a/go.sum b/go.sum index 0e09a769..9de4ede9 100644 --- a/go.sum +++ b/go.sum @@ -59,8 +59,8 @@ github.com/tidwall/cities v0.0.0-20190730194520-dbe1ae0b862c h1:K/6v4woP8qym96ZK github.com/tidwall/cities v0.0.0-20190730194520-dbe1ae0b862c/go.mod h1:lV/HDp2gCcRcHJWqgt6Di54GiDrTZwh1aG2ZUPNbqa4= github.com/tidwall/geoindex v1.1.0 h1:d/pGCgKUonfQINd1235kKqx9gWBU4N7GjDS9WvbPvLY= github.com/tidwall/geoindex v1.1.0/go.mod h1:3gTa91BW+eiVIipuR6aU1Y9Sa0q75b1teE/NP2vfsTc= -github.com/tidwall/geojson v1.1.7 h1:uNeIRbzYzGpFw88CLajyrN3d0To5GcMW5YJSmPqkhH0= -github.com/tidwall/geojson v1.1.7/go.mod h1:tBjfxeALRFLc25LLpjtWzy2nIrNmW1ze1EAhLtd8+QQ= +github.com/tidwall/geojson v1.1.8 h1:n/WT/PG0OEHrxUJQoeqkupWDt3pwbHMynl6OF9xKIM0= +github.com/tidwall/geojson v1.1.8/go.mod h1:tBjfxeALRFLc25LLpjtWzy2nIrNmW1ze1EAhLtd8+QQ= github.com/tidwall/gjson v1.3.2 h1:+7p3qQFaH3fOMXAJSrdZwGKcOO/lYdGS0HqGhPqDdTI= github.com/tidwall/gjson v1.3.2/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= github.com/tidwall/grect v0.0.0-20161006141115-ba9a043346eb h1:5NSYaAdrnblKByzd7XByQEJVT8+9v0W/tIY0Oo4OwrE= diff --git a/scripts/build.sh b/scripts/build.sh index c9726b2c..97203e1e 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -30,8 +30,11 @@ core/gen.sh # Set final Go environment options LDFLAGS="$LDFLAGS -extldflags '-static'" export CGO_ENABLED=0 -export GO111MODULE=on -export GOFLAGS=-mod=vendor + +if [ "$NOMODULES" != "1" ]; then + export GO111MODULE=on + export GOFLAGS=-mod=vendor +fi # Build and store objects into original directory. go build -ldflags "$LDFLAGS" -o $1 cmd/$1/*.go diff --git a/scripts/test.sh b/scripts/test.sh index e6375c3a..a91e516a 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -4,8 +4,11 @@ set -e cd $(dirname "${BASH_SOURCE[0]}")/.. export CGO_ENABLED=0 -export GO111MODULE=on -export GOFLAGS=-mod=vendor + +if [ "$NOMODULES" != "1" ]; then + export GO111MODULE=on + export GOFLAGS=-mod=vendor +fi cd tests && go test && cd .. go test $(go list ./... | grep -v /vendor/ | grep -v /tests) diff --git a/vendor/github.com/tidwall/geojson/circle.go b/vendor/github.com/tidwall/geojson/circle.go index 0d8ca6d1..5dd3a724 100644 --- a/vendor/github.com/tidwall/geojson/circle.go +++ b/vendor/github.com/tidwall/geojson/circle.go @@ -216,6 +216,11 @@ func (g *Circle) Spatial() Spatial { return g.getObject().Spatial() } +// Primative returns a primative GeoJSON object. Either a Polygon or Point. +func (g *Circle) Primative() Object { + return g.getObject() +} + func (g *Circle) getObject() Object { if g.object != nil { return g.object diff --git a/vendor/github.com/tidwall/geojson/geo/geo.go b/vendor/github.com/tidwall/geojson/geo/geo.go index 36863b0a..e92435f4 100644 --- a/vendor/github.com/tidwall/geojson/geo/geo.go +++ b/vendor/github.com/tidwall/geojson/geo/geo.go @@ -31,11 +31,7 @@ func Haversine(latA, lonA, latB, lonB float64) float64 { // NormalizeDistance ... func NormalizeDistance(meters float64) float64 { - m1 := math.Mod(meters, twoPiR) - if m1 <= piR { - return m1 - } - return twoPiR - m1 + return math.Mod(meters, twoPiR) } // DistanceToHaversine ... diff --git a/vendor/github.com/tidwall/geojson/geometry/ring.go b/vendor/github.com/tidwall/geojson/geometry/ring.go index dae70149..4affa962 100644 --- a/vendor/github.com/tidwall/geojson/geometry/ring.go +++ b/vendor/github.com/tidwall/geojson/geometry/ring.go @@ -301,23 +301,11 @@ func ringIntersectsRing(ring, other Ring, allowOnEdge bool) bool { // swap the rings so that the inner ring is smaller than the outer ring ring, other = other, ring } - if ring.Convex() && allowOnEdge { - // outer ring is convex so test that any inner points are inside of - // the outer ring - otherNumPoints := other.NumPoints() - for i := 0; i < otherNumPoints; i++ { - if ringContainsPoint(ring, other.PointAt(i), allowOnEdge).hit { - return true - } - } - } else { - // outer ring is concave so let's make sure that all inner segments are - // fully contained inside of the outer ring. - otherNumSegments := other.NumSegments() - for i := 0; i < otherNumSegments; i++ { - if ringIntersectsSegment(ring, other.SegmentAt(i), allowOnEdge) { - return true - } + + otherNumSegments := other.NumSegments() + for i := 0; i < otherNumSegments; i++ { + if ringIntersectsSegment(ring, other.SegmentAt(i), allowOnEdge) { + return true } } return false diff --git a/vendor/modules.txt b/vendor/modules.txt index b2818b69..562e844a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -81,7 +81,7 @@ github.com/tidwall/buntdb # github.com/tidwall/geoindex v1.1.0 github.com/tidwall/geoindex github.com/tidwall/geoindex/child -# github.com/tidwall/geojson v1.1.7 +# github.com/tidwall/geojson v1.1.8 github.com/tidwall/geojson github.com/tidwall/geojson/geo github.com/tidwall/geojson/geometry