Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson committed Oct 21, 2024
1 parent c5a63b6 commit 49667c3
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions gwcs/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

__all__ = ['Region', 'Edge', 'Polygon']

_INTERSECT_ATOL = 1e2 * np.finfo(float).eps

class Region:
"""
Expand Down Expand Up @@ -390,24 +391,30 @@ def intersection(self, edge):
v = edge._stop - edge._start
w = self._start - edge._start

# Find the determinant of the matrix formed by the vectors u and v
# Note: Originally this was computed using a numpy "2D" cross product,
# however, this functionality has been deprecated and slated for
# removal.
D = np.linalg.det([u, v])
D = _det(u, v)

if np.allclose(D, 0, rtol=0, atol=1e2 * np.finfo(float).eps):
if np.allclose(D, 0, rtol=0, atol=_INTERSECT_ATOL):
return np.array(self._start)

# See note above
return np.linalg.det([v, w]) / D * u + self._start
return _det(v, w) / D * u + self._start

def is_parallel(self, edge):
u = self._stop - self._start
v = edge._stop - edge._start
return np.allclose(
np.linalg.det([u, v]), 0, rtol=0, atol=1e2 * np.finfo(float).eps
)
return np.allclose(_det(u, v), 0, rtol=0, atol=_INTERSECT_ATOL)

Check warning on line 404 in gwcs/region.py

View check run for this annotation

Codecov / codecov/patch

gwcs/region.py#L404

Added line #L404 was not covered by tests


def _det(u, v):
"""
Find the determinant of the matrix formed by the vectors u and v
Note: Originally this was computed using a numpy "2D" cross product,
however, this functionality has been deprecated and slated for
removal.
Note: This is marginally faster than using `np.linalg.det([u, v])` by ~10ms
during empirical testing
"""
return u[0] * v[1] - u[1] * v[0]


def _round_vertex(v):
Expand Down

0 comments on commit 49667c3

Please sign in to comment.