ReactOS 0.4.15-dev-7942-gd23573b
test_trig.c File Reference
#include <ft2build.h>
#include <math.h>
#include <stdio.h>
Include dependency graph for test_trig.c:

Go to the source code of this file.

Macros

#define PI   3.14159265358979323846
 
#define SPI   (PI/FT_ANGLE_PI)
 
#define THRESHOLD   64
 

Functions

static void test_cos (void)
 
static void test_sin (void)
 
static void test_tan (void)
 
static void test_atan2 (void)
 
static void test_unit (void)
 
static void test_length (void)
 
static void test_rotate (void)
 
int main (void)
 

Variables

static error = 0
 

Macro Definition Documentation

◆ PI

#define PI   3.14159265358979323846

Definition at line 8 of file test_trig.c.

◆ SPI

#define SPI   (PI/FT_ANGLE_PI)

Definition at line 9 of file test_trig.c.

◆ THRESHOLD

#define THRESHOLD   64

Definition at line 13 of file test_trig.c.

Function Documentation

◆ main()

int main ( void  )

Definition at line 244 of file test_trig.c.

245 {
246 test_cos();
247 test_sin();
248 test_tan();
249 test_atan2();
250 test_unit();
251 test_length();
252 test_rotate();
253
254 if (!error)
255 printf( "trigonometry test ok !\n" );
256
257 return !error;
258 }
#define printf
Definition: freeldr.h:97
static void test_cos(void)
Definition: test_trig.c:18
static void test_rotate(void)
Definition: test_trig.c:191
static void test_length(void)
Definition: test_trig.c:164
static void test_sin(void)
Definition: test_trig.c:44
static void test_atan2(void)
Definition: test_trig.c:96
static void test_unit(void)
Definition: test_trig.c:131
static error
Definition: test_trig.c:15
static void test_tan(void)
Definition: test_trig.c:70

◆ test_atan2()

static void test_atan2 ( void  )
static

Definition at line 96 of file test_trig.c.

97 {
98 int i;
99
100
101 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000L )
102 {
103 FT_Fixed c2, s2;
104 double l, a, c1, s1;
105 int j;
106
107
108 l = 5.0;
109 a = i*SPI;
110
111 c1 = l * cos(a);
112 s1 = l * sin(a);
113
114 c2 = (FT_Fixed)(c1*65536.0);
115 s2 = (FT_Fixed)(s1*65536.0);
116
117 j = FT_Atan2( c2, s2 );
118 if ( j < 0 )
119 j += FT_ANGLE_2PI;
120
121 if ( abs( i - j ) > 1 )
122 {
123 printf( "FT_Atan2( %.7f, %.7f ) = %.5f, atan = %.5f\n",
124 c2/65536.0, s2/65536.0, j/65536.0, i/65536.0 );
125 }
126 }
127 }
_STLP_DECLSPEC complex< float > _STLP_CALL cos(const complex< float > &)
_STLP_DECLSPEC complex< float > _STLP_CALL sin(const complex< float > &)
r l[0]
Definition: byte_order.h:168
#define abs(i)
Definition: fconv.c:206
FT_Atan2(FT_Fixed x, FT_Fixed y)
Definition: fttrigon.c:340
#define FT_ANGLE_2PI
Definition: fttrigon.h:76
signed long FT_Fixed
Definition: fttypes.h:288
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define a
Definition: ke_i.h:78
struct S1 s1
struct S2 s2
#define SPI
Definition: test_trig.c:9

Referenced by main().

◆ test_cos()

static void test_cos ( void  )
static

Definition at line 18 of file test_trig.c.

19 {
20 int i;
21
22
23 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000L )
24 {
25 FT_Fixed f1, f2;
26 double d2;
27
28
29 f1 = FT_Cos(i);
30 d2 = cos( i*SPI );
31 f2 = (FT_Fixed)(d2*65536.0);
32
33 if ( abs( f2-f1 ) > THRESHOLD )
34 {
35 error = 1;
36 printf( "FT_Cos[%3d] = %.7f cos[%3d] = %.7f\n",
37 (i >> 16), f1/65536.0, (i >> 16), d2 );
38 }
39 }
40 }
FT_Cos(FT_Angle angle)
Definition: fttrigon.c:298
#define f2(x, y, z)
Definition: sha1.c:31
#define f1(x, y, z)
Definition: sha1.c:30
#define THRESHOLD
Definition: test_trig.c:13

Referenced by main().

◆ test_length()

static void test_length ( void  )
static

Definition at line 164 of file test_trig.c.

165 {
166 int i;
167
168
169 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000L )
170 {
171 FT_Vector v;
172 FT_Fixed l, l2;
173
174
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 );
179
180 if ( abs( l2-l ) > THRESHOLD )
181 {
182 error = 1;
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 );
185 }
186 }
187 }
FT_Vector_Length(FT_Vector *vec)
Definition: fttrigon.c:426
const GLdouble * v
Definition: gl.h:2040

Referenced by main().

◆ test_rotate()

static void test_rotate ( void  )
static

Definition at line 191 of file test_trig.c.

192 {
193 int rotate;
194
195
196 for ( rotate = 0; rotate < FT_ANGLE_2PI; rotate += 0x10000L )
197 {
198 double ra, cra, sra;
199 int i;
200
201
202 ra = rotate*SPI;
203 cra = cos( ra );
204 sra = sin( ra );
205
206 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000L )
207 {
208 FT_Fixed c2, s2, c4, s4;
209 FT_Vector v;
210 double l, a, c1, s1, c3, s3;
211
212
213 l = 500.0;
214 a = i*SPI;
215
216 c1 = l * cos(a);
217 s1 = l * sin(a);
218
219 v.x = c2 = (FT_Fixed)(c1*65536.0);
220 v.y = s2 = (FT_Fixed)(s1*65536.0);
221
223
224 c3 = c1 * cra - s1 * sra;
225 s3 = c1 * sra + s1 * cra;
226
227 c4 = (FT_Fixed)(c3*65536.0);
228 s4 = (FT_Fixed)(s3*65536.0);
229
230 if ( abs( c4 - v.x ) > THRESHOLD ||
231 abs( s4 - v.y ) > THRESHOLD )
232 {
233 error = 1;
234 printf( "FT_Rotate( (%.7f,%.7f), %.5f ) = ( %.7f, %.7f ), rot = ( %.7f, %.7f )\n",
235 c1, s1, ra,
236 c2/65536.0, s2/65536.0,
237 c4/65536.0, s4/65536.0 );
238 }
239 }
240 }
241 }
_STLP_MOVE_TO_STD_NAMESPACE void rotate(_ForwardIter __first, _ForwardIter __middle, _ForwardIter __last)
Definition: _algo.c:519
FT_Vector_Rotate(FT_Vector *vec, FT_Angle angle)
Definition: fttrigon.c:386

Referenced by main().

◆ test_sin()

static void test_sin ( void  )
static

Definition at line 44 of file test_trig.c.

45 {
46 int i;
47
48
49 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000L )
50 {
51 FT_Fixed f1, f2;
52 double d2;
53
54
55 f1 = FT_Sin(i);
56 d2 = sin( i*SPI );
57 f2 = (FT_Fixed)(d2*65536.0);
58
59 if ( abs( f2-f1 ) > THRESHOLD )
60 {
61 error = 1;
62 printf( "FT_Sin[%3d] = %.7f sin[%3d] = %.7f\n",
63 (i >> 16), f1/65536.0, (i >> 16), d2 );
64 }
65 }
66 }
FT_Sin(FT_Angle angle)
Definition: fttrigon.c:312

Referenced by main().

◆ test_tan()

static void test_tan ( void  )
static

Definition at line 70 of file test_trig.c.

71 {
72 int i;
73
74
75 for ( i = 0; i < FT_ANGLE_PI2 - 0x2000000L; i += 0x10000L )
76 {
77 FT_Fixed f1, f2;
78 double d2;
79
80
81 f1 = FT_Tan(i);
82 d2 = tan( i*SPI );
83 f2 = (FT_Fixed)(d2*65536.0);
84
85 if ( abs( f2-f1 ) > THRESHOLD )
86 {
87 error = 1;
88 printf( "FT_Tan[%3d] = %.7f tan[%3d] = %.7f\n",
89 (i >> 16), f1/65536.0, (i >> 16), d2 );
90 }
91 }
92 }
_STLP_DECLSPEC complex< float > _STLP_CALL tan(const complex< float > &)
FT_Tan(FT_Angle angle)
Definition: fttrigon.c:326
#define FT_ANGLE_PI2
Definition: fttrigon.h:88

Referenced by main().

◆ test_unit()

static void test_unit ( void  )
static

Definition at line 131 of file test_trig.c.

132 {
133 int i;
134
135
136 for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000L )
137 {
138 FT_Vector v;
139 double a, c1, s1;
140 FT_Fixed c2, s2;
141
142
143 FT_Vector_Unit( &v, i );
144 a = ( i*SPI );
145 c1 = cos(a);
146 s1 = sin(a);
147 c2 = (FT_Fixed)(c1*65536.0);
148 s2 = (FT_Fixed)(s1*65536.0);
149
150 if ( abs( v.x-c2 ) > THRESHOLD ||
151 abs( v.y-s2 ) > THRESHOLD )
152 {
153 error = 1;
154 printf( "FT_Vector_Unit[%3d] = ( %.7f, %.7f ) vec = ( %.7f, %.7f )\n",
155 (i >> 16),
156 v.x/65536.0, v.y/65536.0,
157 c1, s1 );
158 }
159 }
160 }
FT_Vector_Unit(FT_Vector *vec, FT_Angle angle)
Definition: fttrigon.c:361

Referenced by main().

Variable Documentation

◆ error

error = 0
static

Definition at line 15 of file test_trig.c.

Referenced by main(), test_cos(), test_length(), test_rotate(), test_sin(), test_tan(), and test_unit().