From c8e3c5a420d1f46ced8c0a8987315b13091d4420 Mon Sep 17 00:00:00 2001 From: Anuj Verma Date: Tue, 30 Jun 2020 19:30:43 +0530 Subject: [PATCH] * src/sdf/ftsdf.c: Refactored the code. --- [GSoC]ChangeLog | 5 +++++ src/sdf/ftsdf.c | 20 +++++--------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/[GSoC]ChangeLog b/[GSoC]ChangeLog index 74fa792be..7a5171edc 100644 --- a/[GSoC]ChangeLog +++ b/[GSoC]ChangeLog @@ -1,3 +1,8 @@ +2020-06-30 Anuj Verma + + * src/sdf/ftsdf.c: Avoid parentheses if there is only + one statement inside a control-flow statement. + 2020-06-30 Anuj Verma [sdf] Added functions to solve polynomial equations. diff --git a/src/sdf/ftsdf.c b/src/sdf/ftsdf.c index 5691643f6..a95ae231f 100644 --- a/src/sdf/ftsdf.c +++ b/src/sdf/ftsdf.c @@ -635,7 +635,8 @@ cube_root( FT_16D16 val ) { /* [IMPORTANT]: This function is not good as it may */ - /* not break, so use a lookup table instead. */ + /* not break, so use a lookup table instead. Or we */ + /* can use algorithm similar to `square_root'. */ FT_Int v, g, c; @@ -703,9 +704,7 @@ if ( a == 0 ) { if ( b == 0 ) - { return 0; - } else { out[0] = FT_DivFix( -c, b ); @@ -716,9 +715,7 @@ discriminant = FT_MulFix( b, b ) - 4 * FT_MulFix( a, c ); if ( discriminant < 0 ) - { return 0; - } else if ( discriminant == 0 ) { out[0] = FT_DivFix( -b, 2 * a ); @@ -736,10 +733,10 @@ } /* The function compute the roots of a cubic polynomial */ - /* assigns it to `out' and returns the umber of real */ + /* assigns it to `out' and returns the number of real */ /* roots of the equation. */ /* The procedure can be found at: */ - /* https://mathworld.wolfram.com/QuadraticFormula.html */ + /* https://mathworld.wolfram.com/CubicFormula.html */ static FT_UShort solve_cubic_equation( FT_26D6 a, FT_26D6 b, @@ -761,12 +758,9 @@ FT_16D16 a1x2 = 0; - /* cutoff value for `a' to be a cubic */ + /* cutoff value for `a' to be a cubic otherwise solve quadratic*/ if ( a == 0 || FT_ABS( a ) < 16 ) - { - /* quadratic equation */ return solve_quadratic_equation( b, c, d, out ); - } if ( d == 0 ) { out[0] = 0; @@ -832,13 +826,9 @@ if ( q3 == 0 ) - { dis = FT_ABS( r ); - } else - { dis = square_root( q3 + r2 ); - } s = cube_root( r + dis ); t = cube_root( r - dis );