diff --git a/geojson/multipoint.go b/geojson/multipoint.go index 5cbee9c9..3328f7c5 100644 --- a/geojson/multipoint.go +++ b/geojson/multipoint.go @@ -95,7 +95,7 @@ func (g MultiPoint) WithinBBox(bbox BBox) bool { // IntersectsBBox detects if the object intersects a bbox. func (g MultiPoint) IntersectsBBox(bbox BBox) bool { - if g.BBox != nil { + if g.bboxDefined { return rectBBox(g.CalculatedBBox()).IntersectsRect(rectBBox(bbox)) } for _, p := range g.Coordinates { diff --git a/geojson/multipolygon.go b/geojson/multipolygon.go index 29b4891c..5b12d8fb 100644 --- a/geojson/multipolygon.go +++ b/geojson/multipolygon.go @@ -117,7 +117,7 @@ func (g MultiPolygon) WithinBBox(bbox BBox) bool { // IntersectsBBox detects if the object intersects a bbox. func (g MultiPolygon) IntersectsBBox(bbox BBox) bool { - if g.BBox != nil { + if g.bboxDefined { return rectBBox(g.CalculatedBBox()).IntersectsRect(rectBBox(bbox)) } for _, p := range g.Coordinates { diff --git a/geojson/multipolygon_test.go b/geojson/multipolygon_test.go index 4d8fa383..7c5d1f24 100644 --- a/geojson/multipolygon_test.go +++ b/geojson/multipolygon_test.go @@ -239,3 +239,16 @@ func TestIssue244(t *testing.T) { t.Fatal("!") } } + +func TestIssue268(t *testing.T) { + // Simplified geojson of Jersey City from https://github.com/tidwall/tile38/issues/268. + var json = `{"type":"MultiPolygon","coordinates":[[[[-74.116904,40.710477],[-74.103844,40.718665],[-74.103774,40.718694],[-74.094018,40.735138],[-74.093956,40.735199],[-74.080262,40.741407],[-74.077047,40.743248],[-74.075202,40.747395],[-74.078686,40.750601],[-74.075259,40.752693],[-74.075229,40.752748],[-74.076518,40.754725],[-74.076522,40.754807],[-74.074893,40.755611],[-74.074865,40.755663],[-74.074799,40.758149],[-74.074768,40.758186],[-74.065019,40.763723],[-74.06493,40.763755],[-74.060077,40.762508],[-74.06002,40.762542],[-74.060007,40.765648],[-74.05998,40.765723],[-74.057029,40.768911],[-74.056969,40.768987],[-74.052873,40.761349],[-74.05262,40.761053],[-74.044837,40.757022],[-74.04365,40.756586],[-74.042444,40.752501],[-74.042373,40.752416],[-74.038769,40.750888],[-74.037784,40.750317],[-74.043674,40.740008],[-74.043781,40.739849],[-74.042816,40.736036],[-74.042821,40.735952],[-74.038596,40.736322],[-74.038572,40.736322],[-74.022888,40.731061],[-74.020405,40.730321],[-74.02597,40.701624],[-74.026284,40.699902],[-74.048937,40.662702],[-74.049594,40.661622],[-74.065826,40.666881],[-74.097399,40.680376],[-74.098129,40.680685],[-74.102849,40.69536],[-74.102851,40.695424],[-74.114231,40.700944],[-74.114559,40.701072],[-74.113338,40.702477],[-74.112787,40.703102],[-74.116904,40.710477]],[[-74.047285,40.690503],[-74.043556,40.689147],[-74.043513,40.689274],[-74.04586,40.691102],[-74.04607,40.691185],[-74.047285,40.690503]],[[-74.04074,40.700131],[-74.038372,40.698669],[-74.038368,40.698687],[-74.04074,40.700131]]]]}` + g := testJSON(t, json).(MultiPolygon) + p := testJSON(t, `{"type":"Point","coordinates":[-74.03466,40.767623]}`).(SimplePoint) + if p.Intersects(g) { + t.Fatal("expected false") + } + if g.Intersects(p) { + t.Fatal("expected false") + } +}