4
* a python script used to generate the following table
14
print "table of arctan( 1/2^n ) for PI = " + repr(units/65536.0) + " units"
21
x = 1.0/(2.0**n) # tangent value
25
angle = math.atan(x) # arctangent
26
angle2 = angle*scale # arctangent in FT_Angle units
28
# determine which integer value for angle gives the best tangent
31
tlo = math.tan(lo/scale)
32
thi = math.tan(hi/scale)
34
errlo = abs( tlo - x )
35
errhi = abs( thi - x )
44
sys.stdout.write( comma + repr( int(angle2) ) )
48
* end of python script
52
/* this table was generated for AF_ANGLE_PI = 256 */
53
#define AF_ANGLE_MAX_ITERS 8
54
#define AF_TRIG_MAX_ITERS 8
57
af_angle_arctan_table[9] =
59
90, 64, 38, 20, 10, 5, 3, 1, 1
64
af_angle_prenorm( FT_Vector* vec )
73
z = ( ( x >= 0 ) ? x : - x ) | ( (y >= 0) ? y : -y );
76
if ( z < ( 1L << 27 ) )
82
} while ( z < ( 1L << 27 ) );
87
else if ( z > ( 1L << 28 ) )
93
} while ( z > ( 1L << 28 ) );
104
af_angle_pseudo_polarize( FT_Vector* vec )
109
const FT_Fixed *arctanptr;
115
/* Get the vector into the right half plane */
127
arctanptr = af_angle_arctan_table;
131
/* Rotate positive */
135
theta -= *arctanptr++; /* Subtract angle */
139
/* Rotate negative */
143
theta += *arctanptr++; /* Add angle */
151
/* Rotate positive */
155
theta -= *arctanptr++;
159
/* Rotate negative */
163
theta += *arctanptr++;
165
} while ( ++i < AF_TRIG_MAX_ITERS );
170
theta = FT_PAD_ROUND( theta, 2 );
172
theta = - FT_PAD_ROUND( -theta, 2 );
180
/* documentation is in fttrigon.h */
182
FT_LOCAL_DEF( AF_Angle )
183
af_angle_atan( FT_Fixed dx,
189
if ( dx == 0 && dy == 0 )
194
af_angle_prenorm( &v );
195
af_angle_pseudo_polarize( &v );
202
FT_LOCAL_DEF( AF_Angle )
203
af_angle_diff( AF_Angle angle1,
206
AF_Angle delta = angle2 - angle1;
208
delta %= AF_ANGLE_2PI;
210
delta += AF_ANGLE_2PI;
212
if ( delta > AF_ANGLE_PI )
213
delta -= AF_ANGLE_2PI;
219
/* well, this needs to be somewhere, right :-)
223
af_sort_pos( FT_UInt count,
230
for ( i = 1; i < count; i++ )
232
for ( j = i; j > 0; j-- )
234
if ( table[j] > table[j - 1] )
238
table[j] = table[j - 1];
246
af_sort_widths( FT_UInt count,
253
for ( i = 1; i < count; i++ )
255
for ( j = i; j > 0; j-- )
257
if ( table[j].org > table[j - 1].org )
261
table[j] = table[j - 1];
277
for ( dist = 100; dist < 1000; dist++ )
279
for ( angle = AF_ANGLE_PI; angle < AF_ANGLE_2PI*4; angle++ )
281
double a = (angle*3.1415926535)/(1.0*AF_ANGLE_PI);
282
int dx, dy, angle1, angle2, delta;
287
angle1 = ((atan2(dy,dx)*AF_ANGLE_PI)/3.1415926535);
288
angle2 = af_angle_atan( dx, dy );
289
delta = (angle2 - angle1) % AF_ANGLE_2PI;
295
printf( "dist:%4d angle:%4d => (%4d,%4d) angle1:%4d angle2:%4d\n",
296
dist, angle, dx, dy, angle1, angle2 );