You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug summary
If I two paths has a common segment, the result of a.intersects_path(b) is inconsistent. I think it should return True every time in this case.
Code for reproduction
frommatplotlib.pathimportPatha=Path([(0,1),(0,3)])
b=Path([(0,0),(0,4)]) # larger than ac=Path([(0,0),(0,2)]) # ends in ad=Path([(0,1),(0,2),(0,3)]) # same as a, but has an extra point in ae=Path([(0,0),(0,2),(0,4)]) # same as b, but has an extra point in af=Path([(0,0),(0,1),(0,3),(0,4)]) # contains a as a segmentg=Path([(0,1),(0,3),(1,3)]) # a and a non-collinear pointpaths= [a,b,c,d,e,f, g]
foriinpaths:
print([1ifp.intersects_path(i) else0forpinpaths])
I am not sure what the convention for 'intersection' with co-linear lines is. If by "intersect" you mean "some points fall on one side and some points fall on the other" then there is a case that everything but 'g' should not be considered intersecting.
What does shapely do in these cases? We should probably do the same thing as I trust that there are experts in computational geometry working on that project.
I expect that if two paths have at least one common point, intersects_path() should return True. It looks like shapely thinks the same:
fromshapely.geometryimportLineStringa=LineString([(0,1),(0,3)])
b=LineString([(0,0),(0,4)]) # larger than ac=LineString([(0,0),(0,2)]) # ends in ad=LineString([(0,1),(0,2),(0,3)]) # same as a, but has an extra point in ae=LineString([(0,0),(0,2),(0,4)]) # same as b, but has an extra point in af=LineString([(0,0),(0,1),(0,3),(0,4)]) # contains a as a segmentg=LineString([(0,1),(0,3),(1,3)]) # a and a not co-linear pointpaths= [a,b,c,d,e,f, g]
foriinpaths:
print([1ifp.intersects(i) else0forpinpaths])
Activity
tacaswell commentedon Jun 28, 2018
That is interesting.
I am not sure what the convention for 'intersection' with co-linear lines is. If by "intersect" you mean "some points fall on one side and some points fall on the other" then there is a case that everything but 'g' should not be considered intersecting.
tacaswell commentedon Jun 28, 2018
What does shapely do in these cases? We should probably do the same thing as I trust that there are experts in computational geometry working on that project.
firesharker commentedon Jun 28, 2018
I expect that if two paths have at least one common point, intersects_path() should return True. It looks like shapely thinks the same:
returns
I can accept that if by "intersect" we mean two lines crossing each other in exactly one point, but this is seriously wrong:
tacaswell commentedon Jun 28, 2018
Thanks for doing the legwork on getting those answers!
I suspect the bug lies someplace in https://github.com/matplotlib/matplotlib/blob/master/src/_path_wrapper.cpp or https://github.com/matplotlib/matplotlib/blob/master/src/_path.h
attn @mdboom @QuLogic
TarasKuzyo commentedon Jul 2, 2018
It looks the issue is caused by the early exit condition in
segments_intersecthttps://github.com/matplotlib/matplotlib/blob/master/src/_path.h#L825
basically, it returns
falseif two segments have the same slopes, yet it doesn't take into account the case when segments overlap.