1 #include <freetype/freetype.h>
2 #include <freetype/fttrigon.h>
7 #define PI 3.14159265358979323846
8 #define SPI (PI/FT_ANGLE_PI)
10 /* the precision in 16.16 fixed-point checks. Expect between 2 and 5 */
11 /* noise LSB bits during operations, due to rounding errors.. */
22 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000L )
30 f2 = (FT_Fixed)(d2*65536.0);
32 if ( abs( f2-f1 ) > THRESHOLD )
35 printf( "FT_Cos[%3d] = %.7f cos[%3d] = %.7f\n",
36 (i >> 16), f1/65536.0, (i >> 16), d2 );
48 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000L )
56 f2 = (FT_Fixed)(d2*65536.0);
58 if ( abs( f2-f1 ) > THRESHOLD )
61 printf( "FT_Sin[%3d] = %.7f sin[%3d] = %.7f\n",
62 (i >> 16), f1/65536.0, (i >> 16), d2 );
74 for ( i = 0; i < FT_ANGLE_PI2 - 0x2000000L; i += 0x10000L )
82 f2 = (FT_Fixed)(d2*65536.0);
84 if ( abs( f2-f1 ) > THRESHOLD )
87 printf( "FT_Tan[%3d] = %.7f tan[%3d] = %.7f\n",
88 (i >> 16), f1/65536.0, (i >> 16), d2 );
100 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000L )
113 c2 = (FT_Fixed)(c1*65536.0);
114 s2 = (FT_Fixed)(s1*65536.0);
116 j = FT_Atan2( c2, s2 );
120 if ( abs( i - j ) > 1 )
122 printf( "FT_Atan2( %.7f, %.7f ) = %.5f, atan = %.5f\n",
123 c2/65536.0, s2/65536.0, j/65536.0, i/65536.0 );
135 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000L )
142 FT_Vector_Unit( &v, i );
146 c2 = (FT_Fixed)(c1*65536.0);
147 s2 = (FT_Fixed)(s1*65536.0);
149 if ( abs( v.x-c2 ) > THRESHOLD ||
150 abs( v.y-s2 ) > THRESHOLD )
153 printf( "FT_Vector_Unit[%3d] = ( %.7f, %.7f ) vec = ( %.7f, %.7f )\n",
155 v.x/65536.0, v.y/65536.0,
168 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000L )
174 l = (FT_Fixed)(500.0*65536.0);
175 v.x = (FT_Fixed)( l * cos( i*SPI ) );
176 v.y = (FT_Fixed)( l * sin( i*SPI ) );
177 l2 = FT_Vector_Length( &v );
179 if ( abs( l2-l ) > THRESHOLD )
182 printf( "FT_Length( %.7f, %.7f ) = %.5f, length = %.5f\n",
183 v.x/65536.0, v.y/65536.0, l2/65536.0, l/65536.0 );
195 for ( rotate = 0; rotate < FT_ANGLE_2PI; rotate += 0x10000L )
205 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000L )
207 FT_Fixed c2, s2, c4, s4;
209 double l, a, c1, s1, c3, s3;
218 v.x = c2 = (FT_Fixed)(c1*65536.0);
219 v.y = s2 = (FT_Fixed)(s1*65536.0);
221 FT_Vector_Rotate( &v, rotate );
223 c3 = c1 * cra - s1 * sra;
224 s3 = c1 * sra + s1 * cra;
226 c4 = (FT_Fixed)(c3*65536.0);
227 s4 = (FT_Fixed)(s3*65536.0);
229 if ( abs( c4 - v.x ) > THRESHOLD ||
230 abs( s4 - v.y ) > THRESHOLD )
233 printf( "FT_Rotate( (%.7f,%.7f), %.5f ) = ( %.7f, %.7f ), rot = ( %.7f, %.7f )\n",
235 c2/65536.0, s2/65536.0,
236 c4/65536.0, s4/65536.0 );
254 printf( "trigonometry test ok !\n" );