mirror of https://github.com/tidwall/tile38.git
parent
0aa04a1910
commit
cfb1a4c840
|
@ -170,10 +170,10 @@ func (g FeatureCollection) IntersectsBBox(bbox BBox) bool {
|
|||
}
|
||||
for _, g := range g.Features {
|
||||
if g.IntersectsBBox(bbox) {
|
||||
return false
|
||||
return true
|
||||
}
|
||||
}
|
||||
return true
|
||||
return false
|
||||
}
|
||||
|
||||
// Within detects if the object is fully contained inside another object.
|
||||
|
@ -201,6 +201,7 @@ func (g FeatureCollection) Intersects(o Object) bool {
|
|||
return false
|
||||
}
|
||||
for _, f := range g.Features {
|
||||
|
||||
if f.Intersects(o) {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package geojson
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFeatureCollection(t *testing.T) {
|
||||
testJSON(t, `{
|
||||
|
@ -90,3 +92,23 @@ func TestFeatureCollection(t *testing.T) {
|
|||
]
|
||||
}`)
|
||||
}
|
||||
|
||||
func TestPointBounding(t *testing.T) {
|
||||
featureCollectionJSON := `{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-75.1,56.283333]}}]}`
|
||||
polyFeatureJSON := `{"type": "FeatureCollection","features": [{"type": "Feature","properties": {},"geometry": {"type": "Polygon","coordinates": [[
|
||||
[-112.8515625,-29.535229562948444],
|
||||
[85.4296875,-2.535229562948444],
|
||||
[85.4296875,65.36683689226321],
|
||||
[-112.8515625,65.36683689226321],
|
||||
[-112.8515625,-29.535229562948444]
|
||||
]]}}]}`
|
||||
|
||||
featureCollection := testJSON(t, featureCollectionJSON).(FeatureCollection)
|
||||
poly := testJSON(t, polyFeatureJSON).(FeatureCollection)
|
||||
|
||||
r1 := featureCollection.Within(poly)
|
||||
r2 := featureCollection.Intersects(poly)
|
||||
if r1 != r2 || !r1 {
|
||||
t.Fatalf("expected %v/%v, got %v/%v", true, true, r1, r2)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,10 +169,10 @@ func (g GeometryCollection) IntersectsBBox(bbox BBox) bool {
|
|||
}
|
||||
for _, g := range g.Geometries {
|
||||
if g.IntersectsBBox(bbox) {
|
||||
return false
|
||||
return true
|
||||
}
|
||||
}
|
||||
return true
|
||||
return false
|
||||
}
|
||||
|
||||
// Within detects if the object is fully contained inside another object.
|
||||
|
|
|
@ -66,3 +66,20 @@ func TestGeometryCollection(t *testing.T) {
|
|||
]
|
||||
}`)
|
||||
}
|
||||
func TestPointBoundingGeomColl(t *testing.T) {
|
||||
geometryCollectionJSON := `{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[-75.1,56.283333]}]}`
|
||||
polyFeatureJSON := `{"type": "GeometryCollection","geometries": [{"type": "Polygon","coordinates": [[
|
||||
[-112.8515625,-29.535229562948444],
|
||||
[85.4296875,-2.535229562948444],
|
||||
[85.4296875,65.36683689226321],
|
||||
[-112.8515625,65.36683689226321],
|
||||
[-112.8515625,-29.535229562948444]
|
||||
]]}]}`
|
||||
geometryCollection := testJSON(t, geometryCollectionJSON).(GeometryCollection)
|
||||
poly := testJSON(t, polyFeatureJSON).(GeometryCollection)
|
||||
r1 := geometryCollection.Within(poly)
|
||||
r2 := geometryCollection.Intersects(poly)
|
||||
if r1 != r2 || !r1 {
|
||||
t.Fatalf("expected %v/%v, got %v/%v", true, true, r1, r2)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue