mirror of https://github.com/tidwall/tile38.git
linestring nearby search correction, fixes #43
This commit is contained in:
parent
70556ec375
commit
9ab35d91f8
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue