Skip to content

Commit

Permalink
Fix dtype error on calling ..._inside_poly with lists
Browse files Browse the repository at this point in the history
  • Loading branch information
dhomeier committed May 19, 2022
1 parent bf50213 commit 0047ff5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion glue/core/roi.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ def contains(self, x, y):
if not isinstance(y, np.ndarray):
y = np.asarray(y)

result = points_inside_poly(x, y, self.vx, self.vy)
result = points_inside_poly(x, y, np.asarray(self.vx), np.asarray(self.vy))
return result

# There are several possible definitions of the centre; `mean()` is
Expand Down
15 changes: 15 additions & 0 deletions glue/utils/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ def rotation_matrix_2d(alpha):


def points_inside_poly(x, y, vx, vy):
"""
Test if coordinates ``x``, ``y`` fall inside polygon of vertices ``vx``, ``vy``.
Parameters
----------
x, y : `~numpy.ndarray`
Coordinates of the points to test
vx, vy : `~numpy.ndarray`
The vertices of the polygon
Returns
-------
contains : `~numpy.ndarray` of bool
Array indicating whether each coordinate pair is inside the polygon.
"""

if x.dtype.kind == 'M' and vx.dtype.kind == 'M':
vx = vx.astype(x.dtype).astype(float)
Expand Down

0 comments on commit 0047ff5

Please # to comment.