Merge pull request #679 from campagnola/overflow-fix

Fix overflow in Point.length()
This commit is contained in:
Luke Campagnola 2018-04-27 19:27:44 -07:00 committed by GitHub
commit 3ae54bf2c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -105,7 +105,13 @@ class Point(QtCore.QPointF):
def length(self):
"""Returns the vector length of this Point."""
return (self[0]**2 + self[1]**2) ** 0.5
try:
return (self[0]**2 + self[1]**2) ** 0.5
except OverflowError:
try:
return self[1] / np.sin(np.arctan2(self[1], self[0]))
except OverflowError:
return np.inf
def norm(self):
"""Returns a vector in the same direction with unit length."""