Skip to content

Commit 999697e

Browse files
committed
allow intersection/contain tests to test sets of points/polygons
1 parent b905689 commit 999697e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

spatialmath/geom2d.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def contains(self, p, radius=0.0):
186186
# https://stackoverflow.com/questions/45957229/matplotlib-path-contains-points-radius-parameter-defined-inconsistently
187187
# edges are included but the corners are not
188188

189-
if p.ndim == 1:
189+
if isinstance(p, (list, tuple)) or (isinstance(p, np.ndarray) and p.ndim == 1):
190190
return self.path.contains_point(tuple(p), radius=radius)
191191
else:
192192
return self.path.contains_points(p.T, radius=radius)
@@ -254,6 +254,11 @@ def intersects(self, other):
254254
if other.intersect_segment(p1, p2):
255255
return True
256256
return False
257+
elif isinstance(other, (list, tuple)):
258+
for polygon in other:
259+
if self.path.intersects_path(polygon.path, filled=True):
260+
return True
261+
return False
257262

258263
def transformed(self, T):
259264
"""

0 commit comments

Comments
 (0)