3 #include FT_TRIGONOMETRY_H
8 #define PI 3.14159265358979323846
9 #define SPI (PI/FT_ANGLE_PI)
11 /* the precision in 16.16 fixed float points of the checks. Expect */
12 /* between 2 and 5 noise LSB bits during operations, due to */
13 /* rounding errors.. */
25 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000 )
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 );
50 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000 )
55 f2 = (FT_Fixed)(d2*65536.0);
57 if ( abs( f2-f1 ) > THRESHOLD )
60 printf( "FT_Sin[%3d] = %.7f sin[%3d] = %.7f\n",
61 (i >> 16), f1/65536.0, (i >> 16), d2 );
74 for ( i = 0; i < FT_ANGLE_PI2-0x2000000; i += 0x10000 )
79 f2 = (FT_Fixed)(d2*65536.0);
81 if ( abs( f2-f1 ) > THRESHOLD )
84 printf( "FT_Tan[%3d] = %.7f tan[%3d] = %.7f\n",
85 (i >> 16), f1/65536.0, (i >> 16), d2 );
98 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000 )
106 c2 = (FT_Fixed)(c1*65536.0);
107 s2 = (FT_Fixed)(s1*65536.0);
109 j = FT_Atan2( c2, s2 );
113 if ( abs( i - j ) > 1 )
115 printf( "FT_Atan2( %.7f, %.7f ) = %.5f, atan = %.5f\n",
116 c2/65536.0, s2/65536.0, j/65536.0, i/65536.0 );
129 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000 )
131 FT_Vector_Unit( &v, i );
135 c2 = (FT_Fixed)(c1*65536.0);
136 s2 = (FT_Fixed)(s1*65536.0);
138 if ( abs( v.x-c2 ) > THRESHOLD ||
139 abs( v.y-s2 ) > THRESHOLD )
142 printf( "FT_Vector_Unit[%3d] = ( %.7f, %.7f ) vec = ( %.7f, %.7f )\n",
144 v.x/65536.0, v.y/65536.0,
158 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000 )
160 l = (FT_Fixed)(500.0*65536.0);
161 v.x = (FT_Fixed)( l * cos( i*SPI ) );
162 v.y = (FT_Fixed)( l * sin( i*SPI ) );
163 l2 = FT_Vector_Length( &v );
165 if ( abs( l2-l ) > THRESHOLD )
168 printf( "FT_Length( %.7f, %.7f ) = %.5f, length = %.5f\n",
169 v.x/65536.0, v.y/65536.0, l2/65536.0, l/65536.0 );
178 FT_Fixed c2, s2, c4, s4;
180 double l, ra, a, c1, s1, cra, sra, c3, s3;
183 for ( rotate = 0; rotate < FT_ANGLE_2PI; rotate += 0x10000 )
189 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000 )
197 v.x = c2 = (FT_Fixed)(c1*65536.0);
198 v.y = s2 = (FT_Fixed)(s1*65536.0);
200 FT_Vector_Rotate( &v, rotate );
202 c3 = c1 * cra - s1 * sra;
203 s3 = c1 * sra + s1 * cra;
205 c4 = (FT_Fixed)(c3*65536.0);
206 s4 = (FT_Fixed)(s3*65536.0);
208 if ( abs( c4 - v.x ) > THRESHOLD ||
209 abs( s4 - v.y ) > THRESHOLD )
212 printf( "FT_Rotate( (%.7f,%.7f), %.5f ) = ( %.7f, %.7f ), rot = ( %.7f, %.7f )\n",
214 c2/65536.0, s2/65536.0,
215 c4/65536.0, s4/65536.0 );
233 printf( "trigonometry test ok !\n" );