Fix #369 poly in hole query

This commit is contained in:
tidwall 2018-10-18 06:28:31 -07:00
parent aba7df1097
commit cc75cf22a8
5 changed files with 69 additions and 7 deletions

4
Gopkg.lock generated
View File

@ -227,7 +227,7 @@
[[projects]]
branch = "master"
digest = "1:62d3906c154a5fd594c51e434c8d38a3f5ae207f0396bf733fcfbe0ea4796430"
digest = "1:c27e7d5bfc68a4ad2166d1ae909917013a985ba4c8b5255b91bd253bf3ab5730"
name = "github.com/tidwall/geojson"
packages = [
".",
@ -235,7 +235,7 @@
"geometry",
]
pruneopts = ""
revision = "996bb585989456cda9c8302e89c2fe6e82cc61bf"
revision = "5302514a34feb71743bf597938742b51831ba289"
[[projects]]
digest = "1:211773b67c5594aa92b1e8389c59558fa4927614507ea38237265e00c0ba6b81"

View File

@ -77,7 +77,6 @@ func keys_WITHIN_test(mc *mockServer) error {
})
}
func keys_INTERSECTS_test(mc *mockServer) error {
return mc.DoBatch([][]interface{}{
{"SET", "mykey", "point1", "POINT", 37.7335, -122.4412}, {"OK"},
@ -114,9 +113,7 @@ func keys_INTERSECTS_test(mc *mockServer) error {
{"SET", "key5", "poly13", "OBJECT", `{"type":"Polygon","coordinates":[[[-122.44073867797852,37.733211601447465],[-122.44011640548705,37.733211601447465],[-122.44011640548705,37.7340516218859],[-122.44073867797852,37.7340516218859],[-122.44073867797852,37.733211601447465]],[[-122.44060993194579,37.73345766902749],[-122.44060993194579,37.73355524732416],[-122.44044363498686,37.73355524732416],[-122.44044363498686,37.73345766902749],[-122.44060993194579,37.73345766902749]],[[-122.44060724973677,37.7336888869566],[-122.44060724973677,37.7339752567853],[-122.4402102828026,37.7339752567853],[-122.4402102828026,37.7336888869566],[-122.44060724973677,37.7336888869566]]]}`}, {"OK"},
{"SET", "key5", "poly14", "OBJECT", `{"type":"Polygon","coordinates":[[[-122.44154334068298,37.73179457567642],[-122.43935465812682,37.73179457567642],[-122.43935465812682,37.7343740514423],[-122.44154334068298,37.7343740514423],[-122.44154334068298,37.73179457567642]],[[-122.44104981422423,37.73286371140448],[-122.44104981422423,37.73424677678513],[-122.43990182876587,37.73424677678513],[-122.43990182876587,37.73286371140448],[-122.44104981422423,37.73286371140448]],[[-122.44109272956847,37.731870943026074],[-122.43976235389708,37.731870943026074],[-122.43976235389708,37.7326855231885],[-122.44109272956847,37.7326855231885],[-122.44109272956847,37.731870943026074]]]}`}, {"OK"},
// THIS FAILS FOR NOW, LOOKS LIKE A BUG.
// https://github.com/tidwall/tile38/issues/369
//{"INTERSECTS", "key5", "IDS", "GET", "mykey", "multipoly5"}, {"[0 [poly13]]"},
{"INTERSECTS", "key5", "IDS", "GET", "mykey", "multipoly5"}, {"[0 [poly13]]"},
{"SET", "key6", "multipoly5", "OBJECT", `{"type":"MultiPolygon","coordinates":[[[[-122.4408378,37.7341129],[-122.4408378,37.733],[-122.44,37.733],[-122.44,37.7341129],[-122.4408378,37.7341129]]],[[[-122.44091033935547,37.731981251280985],[-122.43994474411011,37.731981251280985],[-122.43994474411011,37.73254976045042],[-122.44091033935547,37.73254976045042],[-122.44091033935547,37.731981251280985]]]]}`}, {"OK"},
{"SET", "key6", "poly13", "OBJECT", `{"type":"Polygon","coordinates":[[[-122.44073867797852,37.733211601447465],[-122.44011640548705,37.733211601447465],[-122.44011640548705,37.7340516218859],[-122.44073867797852,37.7340516218859],[-122.44073867797852,37.733211601447465]],[[-122.44060993194579,37.73345766902749],[-122.44060993194579,37.73355524732416],[-122.44044363498686,37.73355524732416],[-122.44044363498686,37.73345766902749],[-122.44060993194579,37.73345766902749]],[[-122.44060724973677,37.7336888869566],[-122.44060724973677,37.7339752567853],[-122.4402102828026,37.7339752567853],[-122.4402102828026,37.7336888869566],[-122.44060724973677,37.7336888869566]]]}`}, {"OK"},
@ -130,7 +127,6 @@ func keys_INTERSECTS_test(mc *mockServer) error {
})
}
func keys_WITHIN_CIRCLE_test(mc *mockServer) error {
return mc.DoBatch([][]interface{}{
{"SET", "mykey", "1", "POINT", 37.7335, -122.4412}, {"OK"},

View File

@ -191,5 +191,10 @@ func (poly *Poly) IntersectsPoly(other *Poly) bool {
return false
}
}
for _, hole := range other.Holes {
if ringContainsRing(hole, poly.Exterior, false) {
return false
}
}
return true
}

View File

@ -188,3 +188,56 @@ func TestPolyClockwise(t *testing.T) {
var poly *Poly
expect(t, !poly.Clockwise())
}
// https://github.com/tidwall/tile38/issues/369
func Test369(t *testing.T) {
polyHoles := NewPoly([]Point{
{-122.44154334068298, 37.73179457567642},
{-122.43935465812682, 37.73179457567642},
{-122.43935465812682, 37.7343740514423},
{-122.44154334068298, 37.7343740514423},
{-122.44154334068298, 37.73179457567642},
}, [][]Point{
[]Point{
{-122.44104981422423, 37.73286371140448},
{-122.44104981422423, 37.73424677678513},
{-122.43990182876587, 37.73424677678513},
{-122.43990182876587, 37.73286371140448},
{-122.44104981422423, 37.73286371140448},
},
[]Point{
{-122.44109272956847, 37.731870943026074},
{-122.43976235389708, 37.731870943026074},
{-122.43976235389708, 37.7326855231885},
{-122.44109272956847, 37.7326855231885},
{-122.44109272956847, 37.731870943026074},
},
}, DefaultIndex)
a := NewPoly([]Point{
{-122.4408378, 37.7341129},
{-122.4408378, 37.733},
{-122.44, 37.733},
{-122.44, 37.7343129},
{-122.4408378, 37.7341129},
}, nil, DefaultIndex)
b := NewPoly([]Point{
{-122.44091033935547, 37.731981251280985},
{-122.43994474411011, 37.731981251280985},
{-122.43994474411011, 37.73254976045042},
{-122.44091033935547, 37.73254976045042},
{-122.44091033935547, 37.731981251280985},
}, nil, DefaultIndex)
c := NewPoly([]Point{
{-122.4408378, 37.7341129},
{-122.4408378, 37.733},
{-122.44, 37.733},
{-122.44, 37.7341129},
{-122.4408378, 37.7341129},
}, nil, DefaultIndex)
expect(t, polyHoles.IntersectsPoly(a))
expect(t, !polyHoles.IntersectsPoly(b))
expect(t, !polyHoles.IntersectsPoly(c))
expect(t, a.IntersectsPoly(polyHoles))
expect(t, !b.IntersectsPoly(polyHoles))
expect(t, !c.IntersectsPoly(polyHoles))
}

View File

@ -39,3 +39,11 @@ func TestMultiPolygonPoly(t *testing.T) {
expect(t, !p.Contains(PO(40, 40)))
expect(t, p.Within(RO(-100, -100, 1000, 1000)))
}
// https://github.com/tidwall/tile38/issues/369
func TestIssue369(t *testing.T) {
poly14 := expectJSON(t, `{"type":"Polygon","coordinates":[[[-122.44154334068298,37.73179457567642],[-122.43935465812682,37.73179457567642],[-122.43935465812682,37.7343740514423],[-122.44154334068298,37.7343740514423],[-122.44154334068298,37.73179457567642]],[[-122.44104981422423,37.73286371140448],[-122.44104981422423,37.73424677678513],[-122.43990182876587,37.73424677678513],[-122.43990182876587,37.73286371140448],[-122.44104981422423,37.73286371140448]],[[-122.44109272956847,37.731870943026074],[-122.43976235389708,37.731870943026074],[-122.43976235389708,37.7326855231885],[-122.44109272956847,37.7326855231885],[-122.44109272956847,37.731870943026074]]]}`, nil)
query := expectJSON(t, `{"type":"MultiPolygon","coordinates":[[[[-122.4408378,37.7341129],[-122.4408378,37.733],[-122.44,37.733],[-122.44,37.7341129],[-122.4408378,37.7341129]]],[[[-122.44091033935547,37.731981251280985],[-122.43994474411011,37.731981251280985],[-122.43994474411011,37.73254976045042],[-122.44091033935547,37.73254976045042],[-122.44091033935547,37.731981251280985]]]]}`, nil)
expect(t, !query.Intersects(poly14))
expect(t, !poly14.Intersects(query))
}