vectors.py: Don't error out when normalizing zero length vectors

This commit is contained in:
Florian Festi 2016-10-12 21:49:28 +02:00
parent 4ae6303053
commit de7a168377
1 changed files with 2 additions and 0 deletions

View File

@ -18,6 +18,8 @@ import math
def normalize(v):
"set lenght of vector to one"
l = (v[0] ** 2 + v[1] ** 2) ** 0.5
if l == 0.0:
return (0.0, 0.0)
return (v[0] / l, v[1] / l)