From 86887ae60f06a8f3a3a25b9af4cd4095422ea2dc Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Thu, 8 Mar 2018 12:16:12 -0700 Subject: [PATCH] use poly bboxes --- geojson/multipolygon.go | 1 + geojson/polygon.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/geojson/multipolygon.go b/geojson/multipolygon.go index 17343974..af2dc96a 100644 --- a/geojson/multipolygon.go +++ b/geojson/multipolygon.go @@ -29,6 +29,7 @@ func fillMultiPolygon(coordinates [][][]Position, bbox *BBox, err error) (MultiP Coordinates: coordinates, BBox: bbox, bboxDefined: bboxDefined, + polygons: polygons, }, err } diff --git a/geojson/polygon.go b/geojson/polygon.go index 4e6db8bf..375b06c3 100644 --- a/geojson/polygon.go +++ b/geojson/polygon.go @@ -103,6 +103,11 @@ func (g Polygon) WithinBBox(bbox BBox) bool { if len(g.Coordinates) == 0 { return false } + if g.BBox != nil { + if !rectBBox(*g.BBox).IntersectsRect(rectBBox(bbox)) { + return false + } + } rbbox := rectBBox(bbox) ext, holes := polyExteriorHoles(g.Coordinates) if len(holes) > 0 { @@ -122,6 +127,11 @@ func (g Polygon) IntersectsBBox(bbox BBox) bool { if len(g.Coordinates) == 0 { return false } + if g.BBox != nil { + if !rectBBox(*g.BBox).IntersectsRect(rectBBox(bbox)) { + return false + } + } rbbox := rectBBox(bbox) ext, holes := polyExteriorHoles(g.Coordinates) if len(holes) > 0 {