Fixed division by zero in straighten mode.

This commit is contained in:
skyler 2012-01-21 18:13:15 -05:00 committed by Skyler Lehmkuhl
parent ae6753f9ea
commit 64f69b1097
1 changed files with 11 additions and 3 deletions

View File

@ -143,12 +143,20 @@ 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
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]])