Improve comments, remove dead code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
diff --git a/include/internal/ftcalc.h b/include/internal/ftcalc.h
index e6bee34..1d83d50 100644
--- a/include/internal/ftcalc.h
+++ b/include/internal/ftcalc.h
@@ -363,11 +363,14 @@ FT_BEGIN_HEADER
/*
- * Approximate sqrt(x*x+y*y) using alpha max plus beta min algorithm.
+ * Approximate sqrt(x*x+y*y) using the `alpha max plus beta min'
+ * algorithm. We use alpha = 1, beta = 3/8, giving us results with a
+ * largest error less than 7% compared to the exact value.
*/
-#define FT_HYPOT( x, y ) \
- ( x = FT_ABS( x ), y = FT_ABS( y ), \
- x > y ? x + ( 3 * y >> 3 ) \
+#define FT_HYPOT( x, y ) \
+ ( x = FT_ABS( x ), \
+ y = FT_ABS( y ), \
+ x > y ? x + ( 3 * y >> 3 ) \
: y + ( 3 * x >> 3 ) )
diff --git a/src/autofit/afangles.c b/src/autofit/afangles.c
index b44a5ba..f8b095b 100644
--- a/src/autofit/afangles.c
+++ b/src/autofit/afangles.c
@@ -20,66 +20,6 @@
#include "aftypes.h"
-#if 0
-
- FT_LOCAL_DEF( FT_Int )
- af_corner_is_flat( FT_Pos x_in,
- FT_Pos y_in,
- FT_Pos x_out,
- FT_Pos y_out )
- {
- FT_Pos ax = x_in;
- FT_Pos ay = y_in;
-
- FT_Pos d_in, d_out, d_corner;
-
-
- if ( ax < 0 )
- ax = -ax;
- if ( ay < 0 )
- ay = -ay;
- d_in = ax + ay;
-
- ax = x_out;
- if ( ax < 0 )
- ax = -ax;
- ay = y_out;
- if ( ay < 0 )
- ay = -ay;
- d_out = ax + ay;
-
- ax = x_out + x_in;
- if ( ax < 0 )
- ax = -ax;
- ay = y_out + y_in;
- if ( ay < 0 )
- ay = -ay;
- d_corner = ax + ay;
-
- return ( d_in + d_out - d_corner ) < ( d_corner >> 4 );
- }
-
-
- FT_LOCAL_DEF( FT_Int )
- af_corner_orientation( FT_Pos x_in,
- FT_Pos y_in,
- FT_Pos x_out,
- FT_Pos y_out )
- {
- FT_Pos delta;
-
-
- delta = x_in * y_out - y_in * x_out;
-
- if ( delta == 0 )
- return 0;
- else
- return 1 - 2 * ( delta < 0 );
- }
-
-#endif /* 0 */
-
-
/*
* We are not using `af_angle_atan' anymore, but we keep the source
* code below just in case...
diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c
index 23c43a7..00071cb 100644
--- a/src/base/ftcalc.c
+++ b/src/base/ftcalc.c
@@ -858,78 +858,40 @@
FT_Pos out_x,
FT_Pos out_y )
{
-#if 0
-
- FT_Pos ax = in_x;
- FT_Pos ay = in_y;
-
- FT_Pos d_in, d_out, d_corner;
-
-
- /* We approximate the Euclidean metric (sqrt(x^2 + y^2)) with */
- /* the Taxicab metric (|x| + |y|), which can be computed much */
- /* faster. If one of the two vectors is much longer than the */
- /* other one, the direction of the shorter vector doesn't */
- /* influence the result any more. */
- /* */
- /* corner */
- /* x---------------------------x */
- /* \ / */
- /* \ / */
- /* in \ / out */
- /* \ / */
- /* o */
- /* Point */
- /* */
-
- if ( ax < 0 )
- ax = -ax;
- if ( ay < 0 )
- ay = -ay;
- d_in = ax + ay; /* d_in = || in || */
-
- ax = out_x;
- if ( ax < 0 )
- ax = -ax;
- ay = out_y;
- if ( ay < 0 )
- ay = -ay;
- d_out = ax + ay; /* d_out = || out || */
-
- ax = out_x + in_x;
- if ( ax < 0 )
- ax = -ax;
- ay = out_y + in_y;
- if ( ay < 0 )
- ay = -ay;
- d_corner = ax + ay; /* d_corner = || in + out || */
-
-#else
-
FT_Pos ax = in_x + out_x;
FT_Pos ay = in_y + out_y;
- FT_Pos d_in, d_out, d_corner;
-
- /* The original implementation always returned TRUE */
- /* for vectors from the same quadrant dues to additivity */
- /* of Taxicab metric there. The alpha max plus beta min */
- /* algorithm used here is additive within each octant, */
- /* so we now reject some near 90-degree corners within */
- /* quadrants, consistently with eliptic definition of */
- /* flat corner. */
-
- d_in = FT_HYPOT( in_x, in_y );
- d_out = FT_HYPOT( out_x, out_y );
- d_corner = FT_HYPOT( ax, ay );
-
-#endif
+ FT_Pos d_in, d_out, d_hypot;
+
+
+ /* The idea of this function is to compare the length of the */
+ /* hypotenuse with the `in' and `out' length. The `corner' */
+ /* represented by `in' and `out' is flat if the hypotenuse's */
+ /* length isn't too large. */
+ /* */
+ /* This approach has the advantage that the angle between */
+ /* `in' and `out' is not checked. In case one of the two */
+ /* vectors is `dominant', this is, much larger than the */
+ /* other vector, we thus always have a flat corner. */
+ /* */
+ /* hypotenuse */
+ /* x---------------------------x */
+ /* \ / */
+ /* \ / */
+ /* in \ / out */
+ /* \ / */
+ /* o */
+ /* Point */
+
+ d_in = FT_HYPOT( in_x, in_y );
+ d_out = FT_HYPOT( out_x, out_y );
+ d_hypot = FT_HYPOT( ax, ay );
/* now do a simple length comparison: */
/* */
- /* d_in + d_out < 17/16 d_corner */
+ /* d_in + d_out < 17/16 d_hypot */
- return ( d_in + d_out - d_corner ) < ( d_corner >> 4 );
+ return ( d_in + d_out - d_hypot ) < ( d_hypot >> 4 );
}