99ac1cf174d98cc4553cb389f58ce79d4e072f62
3 #include FT_TRIGONOMETRY_H
8 #define PI 3.14159265358979323846
9 #define SPI (PI/FT_ANGLE_PI)
11 /* the precision in 16.16 fixed-point checks. Expect between 2 and 5 */
12 /* noise LSB bits during operations, due to rounding errors.. */
23 for ( i
= 0; i
< FT_ANGLE_2PI
; i
+= 0x10000L
)
31 f2
= (FT_Fixed
)(d2
*65536.0);
33 if ( abs( f2
-f1
) > THRESHOLD
)
36 printf( "FT_Cos[%3d] = %.7f cos[%3d] = %.7f\n",
37 (i
>> 16), f1
/65536.0, (i
>> 16), d2
);
49 for ( i
= 0; i
< FT_ANGLE_2PI
; i
+= 0x10000L
)
57 f2
= (FT_Fixed
)(d2
*65536.0);
59 if ( abs( f2
-f1
) > THRESHOLD
)
62 printf( "FT_Sin[%3d] = %.7f sin[%3d] = %.7f\n",
63 (i
>> 16), f1
/65536.0, (i
>> 16), d2
);
75 for ( i
= 0; i
< FT_ANGLE_PI2
- 0x2000000L
; i
+= 0x10000L
)
83 f2
= (FT_Fixed
)(d2
*65536.0);
85 if ( abs( f2
-f1
) > THRESHOLD
)
88 printf( "FT_Tan[%3d] = %.7f tan[%3d] = %.7f\n",
89 (i
>> 16), f1
/65536.0, (i
>> 16), d2
);
101 for ( i
= 0; i
< FT_ANGLE_2PI
; i
+= 0x10000L
)
114 c2
= (FT_Fixed
)(c1
*65536.0);
115 s2
= (FT_Fixed
)(s1
*65536.0);
117 j
= FT_Atan2( c2
, s2
);
121 if ( abs( i
- j
) > 1 )
123 printf( "FT_Atan2( %.7f, %.7f ) = %.5f, atan = %.5f\n",
124 c2
/65536.0, s2
/65536.0, j
/65536.0, i
/65536.0 );
136 for ( i
= 0; i
< FT_ANGLE_2PI
; i
+= 0x10000L
)
143 FT_Vector_Unit( &v
, i
);
147 c2
= (FT_Fixed
)(c1
*65536.0);
148 s2
= (FT_Fixed
)(s1
*65536.0);
150 if ( abs( v
.x
-c2
) > THRESHOLD
||
151 abs( v
.y
-s2
) > THRESHOLD
)
154 printf( "FT_Vector_Unit[%3d] = ( %.7f, %.7f ) vec = ( %.7f, %.7f )\n",
156 v
.x
/65536.0, v
.y
/65536.0,
169 for ( i
= 0; i
< FT_ANGLE_2PI
; i
+= 0x10000L
)
175 l
= (FT_Fixed
)(500.0*65536.0);
176 v
.x
= (FT_Fixed
)( l
* cos( i
*SPI
) );
177 v
.y
= (FT_Fixed
)( l
* sin( i
*SPI
) );
178 l2
= FT_Vector_Length( &v
);
180 if ( abs( l2
-l
) > THRESHOLD
)
183 printf( "FT_Length( %.7f, %.7f ) = %.5f, length = %.5f\n",
184 v
.x
/65536.0, v
.y
/65536.0, l2
/65536.0, l
/65536.0 );
196 for ( rotate
= 0; rotate
< FT_ANGLE_2PI
; rotate
+= 0x10000L
)
206 for ( i
= 0; i
< FT_ANGLE_2PI
; i
+= 0x10000L
)
208 FT_Fixed c2
, s2
, c4
, s4
;
210 double l
, a
, c1
, s1
, c3
, s3
;
219 v
.x
= c2
= (FT_Fixed
)(c1
*65536.0);
220 v
.y
= s2
= (FT_Fixed
)(s1
*65536.0);
222 FT_Vector_Rotate( &v
, rotate
);
224 c3
= c1
* cra
- s1
* sra
;
225 s3
= c1
* sra
+ s1
* cra
;
227 c4
= (FT_Fixed
)(c3
*65536.0);
228 s4
= (FT_Fixed
)(s3
*65536.0);
230 if ( abs( c4
- v
.x
) > THRESHOLD
||
231 abs( s4
- v
.y
) > THRESHOLD
)
234 printf( "FT_Rotate( (%.7f,%.7f), %.5f ) = ( %.7f, %.7f ), rot = ( %.7f, %.7f )\n",
236 c2
/65536.0, s2
/65536.0,
237 c4
/65536.0, s4
/65536.0 );
255 printf( "trigonometry test ok !\n" );