mirror of https://github.com/tidwall/tile38.git
Fix #369 poly in hole query
This commit is contained in:
parent
aba7df1097
commit
cc75cf22a8
|
@ -227,7 +227,7 @@
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:62d3906c154a5fd594c51e434c8d38a3f5ae207f0396bf733fcfbe0ea4796430"
|
digest = "1:c27e7d5bfc68a4ad2166d1ae909917013a985ba4c8b5255b91bd253bf3ab5730"
|
||||||
name = "github.com/tidwall/geojson"
|
name = "github.com/tidwall/geojson"
|
||||||
packages = [
|
packages = [
|
||||||
".",
|
".",
|
||||||
|
@ -235,7 +235,7 @@
|
||||||
"geometry",
|
"geometry",
|
||||||
]
|
]
|
||||||
pruneopts = ""
|
pruneopts = ""
|
||||||
revision = "996bb585989456cda9c8302e89c2fe6e82cc61bf"
|
revision = "5302514a34feb71743bf597938742b51831ba289"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:211773b67c5594aa92b1e8389c59558fa4927614507ea38237265e00c0ba6b81"
|
digest = "1:211773b67c5594aa92b1e8389c59558fa4927614507ea38237265e00c0ba6b81"
|
||||||
|
|
|
@ -77,7 +77,6 @@ func keys_WITHIN_test(mc *mockServer) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func keys_INTERSECTS_test(mc *mockServer) error {
|
func keys_INTERSECTS_test(mc *mockServer) error {
|
||||||
return mc.DoBatch([][]interface{}{
|
return mc.DoBatch([][]interface{}{
|
||||||
{"SET", "mykey", "point1", "POINT", 37.7335, -122.4412}, {"OK"},
|
{"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", "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"},
|
{"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.
|
{"INTERSECTS", "key5", "IDS", "GET", "mykey", "multipoly5"}, {"[0 [poly13]]"},
|
||||||
// https://github.com/tidwall/tile38/issues/369
|
|
||||||
//{"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", "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"},
|
{"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 {
|
func keys_WITHIN_CIRCLE_test(mc *mockServer) error {
|
||||||
return mc.DoBatch([][]interface{}{
|
return mc.DoBatch([][]interface{}{
|
||||||
{"SET", "mykey", "1", "POINT", 37.7335, -122.4412}, {"OK"},
|
{"SET", "mykey", "1", "POINT", 37.7335, -122.4412}, {"OK"},
|
||||||
|
|
|
@ -191,5 +191,10 @@ func (poly *Poly) IntersectsPoly(other *Poly) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, hole := range other.Holes {
|
||||||
|
if ringContainsRing(hole, poly.Exterior, false) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,3 +188,56 @@ func TestPolyClockwise(t *testing.T) {
|
||||||
var poly *Poly
|
var poly *Poly
|
||||||
expect(t, !poly.Clockwise())
|
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))
|
||||||
|
}
|
||||||
|
|
|
@ -39,3 +39,11 @@ func TestMultiPolygonPoly(t *testing.T) {
|
||||||
expect(t, !p.Contains(PO(40, 40)))
|
expect(t, !p.Contains(PO(40, 40)))
|
||||||
expect(t, p.Within(RO(-100, -100, 1000, 1000)))
|
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))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue