diff --git a/geojson/linestring.go b/geojson/linestring.go index 074128bd..816fb2c0 100644 --- a/geojson/linestring.go +++ b/geojson/linestring.go @@ -109,11 +109,11 @@ func (g LineString) Within(o Object) bool { func (g LineString) Intersects(o Object) bool { return intersectsObjectShared(g, o, func(v Polygon) bool { - return polyPositions(g.Coordinates).Intersects(polyExteriorHoles(v.Coordinates)) + return polyPositions(g.Coordinates).LineStringIntersects(polyExteriorHoles(v.Coordinates)) }, func(v MultiPolygon) bool { for _, c := range v.Coordinates { - if polyPositions(g.Coordinates).Intersects(polyExteriorHoles(c)) { + if polyPositions(g.Coordinates).LineStringIntersects(polyExteriorHoles(c)) { return true } } diff --git a/geojson/poly/intersects.go b/geojson/poly/intersects.go index 015f9caa..64fd9a7a 100644 --- a/geojson/poly/intersects.go +++ b/geojson/poly/intersects.go @@ -7,6 +7,12 @@ func (p Point) Intersects(exterior Polygon, holes []Polygon) bool { // Intersects detects if a polygon intersects another polygon func (shape Polygon) Intersects(exterior Polygon, holes []Polygon) bool { + return shape.doesIntersects(false, exterior, holes) +} +func (shape Polygon) LineStringIntersects(exterior Polygon, holes []Polygon) bool { + return shape.doesIntersects(true, exterior, holes) +} +func (shape Polygon) doesIntersects(isLineString bool, exterior Polygon, holes []Polygon) bool { switch len(shape) { case 0: return false @@ -30,7 +36,6 @@ func (shape Polygon) Intersects(exterior Polygon, holes []Polygon) bool { if !shape.Rect().IntersectsRect(exterior.Rect()) { return false } - for i := 0; i < len(shape); i++ { for j := 0; j < len(exterior); j++ { if lineintersects( @@ -49,10 +54,11 @@ func (shape Polygon) Intersects(exterior Polygon, holes []Polygon) bool { if shape.Inside(exterior, nil) { return true } - if exterior.Inside(shape, nil) { - return true + if !isLineString { + if exterior.Inside(shape, nil) { + return true + } } - return false }