From 64f69b10972cb6f6d329837b8142bd1f5d93fe88 Mon Sep 17 00:00:00 2001 From: skyler Date: Sat, 21 Jan 2012 18:13:15 -0500 Subject: [PATCH] Fixed division by zero in straighten mode. --- misc_funcs.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/misc_funcs.py b/misc_funcs.py index fb4be2f..95f7b9f 100644 --- a/misc_funcs.py +++ b/misc_funcs.py @@ -143,13 +143,21 @@ def simplify_shape(shape,mode,iterations): cax=pcx-pax; cay=pcy-pay; ca=math.sqrt(cax*cax+cay*cay); - cosB=-(ca*ca-bc*bc-ab*ab)/(2*bc*ab); + try: + cosB=-(ca*ca-bc*bc-ab*ab)/(2*bc*ab); + except ZeroDivisionError: + cosB=-1 # Two of the points overlap; the best thing to do is delete one. try: acosB=math.acos(cosB)*180/math.pi; except ValueError: acosB=0 - if acosB>(165-500/(ab+bc)): # at least 15 degrees away from straight angle - del shape[j] + try: + if acosB>(165-500/(ab+bc)): # at least 15 degrees away from straight angle + del shape[j] + except ZeroDivisionError: + # Either both points overlap or one is imaginary. Kudos to you if you manage + # to create a point with an imaginary coordinate in Lightningbeam. + del shape[j] if mode=="smooth": shape = catmullRom2bezier([shape[0]]*2+shape+[shape[-1]]) print shape