[FontTools-checkins] CVS: fonttools/Lib/fontTools/misc bezierTools.py,1.3,1.4

 [FontTools-checkins] CVS: fonttools/Lib/fontTools/misc bezierTools.py,1.3,1.4 From: Just van Rossum - 2003-08-26 19:33:43 ```Update of /cvsroot/fonttools/fonttools/Lib/fontTools/misc In directory sc8-pr-cvs1:/tmp/cvs-serv14162/misc Modified Files: bezierTools.py Log Message: - Fixed ZeroDivisionError in solveCubic(). The solution is mathematically dubious (I don't think 0.0/0.0 == 0.0...) but the result seems to be correct. - Documented that soleCubic() and solveQuadratic() are not guaranteed to return the roots in order, and nor that they are guaranteed to not return duplicate roots. Index: bezierTools.py =================================================================== RCS file: /cvsroot/fonttools/fonttools/Lib/fontTools/misc/bezierTools.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** bezierTools.py 29 Jun 2003 19:25:05 -0000 1.3 --- bezierTools.py 26 Aug 2003 19:20:33 -0000 1.4 *************** *** 160,164 **** """Solve a quadratic equation where a, b and c are real. a*x*x + b*x + c = 0 ! This function returns a list of roots. """ if a == 0.0: --- 160,165 ---- """Solve a quadratic equation where a, b and c are real. a*x*x + b*x + c = 0 ! This function returns a list of roots. Note that the returned list ! is neither guaranteed to be sorted nor to contain unique values! """ if a == 0.0: *************** *** 185,189 **** """Solve a cubic equation where a, b, c and d are real. a*x*x*x + b*x*x + c*x + d = 0 ! This function returns a list of roots. """ # --- 186,191 ---- """Solve a cubic equation where a, b, c and d are real. a*x*x*x + b*x*x + c*x + d = 0 ! This function returns a list of roots. Note that the returned list ! is neither guaranteed to be sorted nor to contain unique values! """ # *************** *** 206,210 **** R2_Q3 = R*R - Q*Q*Q ! if R2_Q3 <= 0: theta = acos(R/sqrt(Q*Q*Q)) rQ2 = -2.0*sqrt(Q) --- 208,212 ---- R2_Q3 = R*R - Q*Q*Q ! if R2_Q3 < 0: theta = acos(R/sqrt(Q*Q*Q)) rQ2 = -2.0*sqrt(Q) *************** *** 214,219 **** return [x0, x1, x2] else: ! x = pow(sqrt(R2_Q3)+abs(R), 1/3.0) ! x = x + Q/x if R >= 0.0: x = -x --- 216,224 ---- return [x0, x1, x2] else: ! if Q == 0 and R == 0: ! x = 0 ! else: ! x = pow(sqrt(R2_Q3)+abs(R), 1/3.0) ! x = x + Q/x if R >= 0.0: x = -x ```

 [FontTools-checkins] CVS: fonttools/Lib/fontTools/misc bezierTools.py,1.3,1.4 From: Just van Rossum - 2003-08-26 19:33:43 ```Update of /cvsroot/fonttools/fonttools/Lib/fontTools/misc In directory sc8-pr-cvs1:/tmp/cvs-serv14162/misc Modified Files: bezierTools.py Log Message: - Fixed ZeroDivisionError in solveCubic(). The solution is mathematically dubious (I don't think 0.0/0.0 == 0.0...) but the result seems to be correct. - Documented that soleCubic() and solveQuadratic() are not guaranteed to return the roots in order, and nor that they are guaranteed to not return duplicate roots. Index: bezierTools.py =================================================================== RCS file: /cvsroot/fonttools/fonttools/Lib/fontTools/misc/bezierTools.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** bezierTools.py 29 Jun 2003 19:25:05 -0000 1.3 --- bezierTools.py 26 Aug 2003 19:20:33 -0000 1.4 *************** *** 160,164 **** """Solve a quadratic equation where a, b and c are real. a*x*x + b*x + c = 0 ! This function returns a list of roots. """ if a == 0.0: --- 160,165 ---- """Solve a quadratic equation where a, b and c are real. a*x*x + b*x + c = 0 ! This function returns a list of roots. Note that the returned list ! is neither guaranteed to be sorted nor to contain unique values! """ if a == 0.0: *************** *** 185,189 **** """Solve a cubic equation where a, b, c and d are real. a*x*x*x + b*x*x + c*x + d = 0 ! This function returns a list of roots. """ # --- 186,191 ---- """Solve a cubic equation where a, b, c and d are real. a*x*x*x + b*x*x + c*x + d = 0 ! This function returns a list of roots. Note that the returned list ! is neither guaranteed to be sorted nor to contain unique values! """ # *************** *** 206,210 **** R2_Q3 = R*R - Q*Q*Q ! if R2_Q3 <= 0: theta = acos(R/sqrt(Q*Q*Q)) rQ2 = -2.0*sqrt(Q) --- 208,212 ---- R2_Q3 = R*R - Q*Q*Q ! if R2_Q3 < 0: theta = acos(R/sqrt(Q*Q*Q)) rQ2 = -2.0*sqrt(Q) *************** *** 214,219 **** return [x0, x1, x2] else: ! x = pow(sqrt(R2_Q3)+abs(R), 1/3.0) ! x = x + Q/x if R >= 0.0: x = -x --- 216,224 ---- return [x0, x1, x2] else: ! if Q == 0 and R == 0: ! x = 0 ! else: ! x = pow(sqrt(R2_Q3)+abs(R), 1/3.0) ! x = x + Q/x if R >= 0.0: x = -x ```