1 /*! ========================================================================
2 ** Extended Template and Library Test Suite
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === H E A D E R S ======================================================= */
26 #include <ETL/fastangle>
29 #include <ETL/hermite>
31 /* === M A C R O S ========================================================= */
38 /* === C L A S S E S ======================================================= */
40 int fastangle_test(void)
52 theta=angle::degrees(0),theta2=fastangle::degrees(0);
53 theta<=angle::degrees(360);
54 theta+=angle::degrees(10),theta2+=fastangle::degrees(10)
57 error=(float)angle::sin(theta).get() -(float)fastangle::sin(theta2).get();
59 fprintf(stderr,"angle: sin(%d)=%f ;\tfastangle: sin(%d)=%f ;\t diff: %f\n",
60 (int)angle::degrees(theta),
61 (float)angle::sin(theta),
62 (int)fastangle::degrees(theta2),
63 (float)fastangle::sin(theta2),
67 if(error > largest_error)
69 if(error < -largest_error)
74 printf("fastangle: Largest SIN error: (+/-)%f\n",largest_error);
75 if(largest_error>0.075)ret++;
84 theta=angle::degrees(0),theta2=fastangle::degrees(0);
85 theta<=angle::degrees(360);
86 theta+=angle::degrees(10),theta2+=fastangle::degrees(10)
89 error=(float)angle::cos(theta).get() -(float)fastangle::cos(theta2).get();
91 fprintf(stderr,"angle: cos(%d)=%f ;\tfastangle: cos(%d)=%f ;\t diff: %f\n",
92 (int)angle::degrees(theta),
93 (float)angle::cos(theta),
94 (int)fastangle::degrees(theta2),
95 (float)fastangle::cos(theta2),
99 if(error > largest_error)
101 if(error < -largest_error)
102 largest_error=-error;
106 printf("fastangle: Largest COS error: (+/-)%f\n",largest_error);
107 if(largest_error>0.075)ret++;
120 error=angle::radians(angle::sin(val)).get() -fastangle::radians(fastangle::sin(val)).get();
122 fprintf(stderr,"angle: asin(%f)=%frad ;\tfastangle: asin(%f)=%frad ;\t diff: %f\n",
124 (float)(angle::radians)angle::sin(val),
126 (float)(fastangle::radians)fastangle::sin(val),
130 if(error > largest_error)
132 if(error < -largest_error)
133 largest_error=-error;
137 printf("fastangle: Largest ASIN error: (+/-)%frad\n",largest_error);
138 if(largest_error>0.075)ret++;
152 error=angle::radians(angle::cos(val)).get() -fastangle::radians(fastangle::cos(val)).get();
154 fprintf(stderr,"angle: acos(%f)=%frad ;\tfastangle: acos(%f)=%frad ;\t diff: %f\n",
156 (float)(angle::radians)angle::cos(val),
158 (float)(fastangle::radians)fastangle::cos(val),
162 if(error > largest_error)
164 if(error < -largest_error)
165 largest_error=-error;
169 printf("fastangle: Largest ACOS error: (+/-)%frad\n",largest_error);
170 if(largest_error>0.075)ret++;
180 theta=angle::degrees(0),theta2=fastangle::degrees(0);
181 theta<angle::degrees(360);
182 theta+=angle::degrees(38),theta2+=fastangle::degrees(38)
185 error=angle::tan(theta).get() - fastangle::tan(theta2).get();
187 fprintf(stderr,"angle: tan(%d)=%f ;\tfastangle: tan(%d)=%f ;\t diff: %f\n",
188 (int)angle::degrees(theta),
189 (float)angle::tan(theta),
190 (int)fastangle::degrees(theta2),
191 (float)fastangle::tan(theta2),
195 if(error > largest_error)
197 if(error < -largest_error)
198 largest_error=-error;
202 printf("fastangle: Largest TAN error: (+/-)%f\n",largest_error);
203 if(largest_error>0.75)ret++;
216 error=angle::radians(angle::tan(val)).get() -fastangle::radians(fastangle::tan(val)).get();
218 fprintf(stderr,"angle: atan(%f)=%frad ;\tfastangle: atan(%f)=%frad ;\t diff: %f\n",
220 (float)(angle::radians)angle::tan(val),
222 (float)(fastangle::radians)fastangle::tan(val),
226 if(error > largest_error)
228 if(error < -largest_error)
229 largest_error=-error;
233 printf("fastangle: Largest ATAN error: (+/-)%frad\n",largest_error);
234 if(largest_error>0.075)ret++;
243 theta=angle::degrees(-179);
244 theta<angle::degrees(180);
245 theta+=angle::degrees(5)
248 error=angle::radians(theta).get()-fastangle::radians(fastangle::tan(angle::sin(theta).get(),angle::cos(theta).get())).get();
250 fprintf(stderr,"\tfastangle: atan2(%f, %f)=%fdeg (%f) ;\t diff: %frad\n",
251 (float)angle::sin(theta),
252 (float)angle::cos(theta),
253 (float)(fastangle::degrees)fastangle::tan(angle::sin(theta),angle::cos(theta)),
254 (float)(fastangle::degrees)fastangle::tan((float)angle::sin(theta)/(float)angle::cos(theta)),
258 if(error > largest_error)
260 if(error < -largest_error)
261 largest_error=-error;
265 printf("fastangle: Largest ATAN2 error: (+/-)%frad\n",largest_error);
266 if(largest_error>0.075)ret++;
268 printf("constant tests: %f==%f\n",
269 (float)angle::degrees(angle::tan(1.01)).get(),
270 (float)fastangle::degrees(fastangle::tan(1.01)).get());
271 printf("constant tests: %f==%f\n",
272 (float)angle::degrees(angle::tan(-1.0)).get(),
273 (float)fastangle::degrees(fastangle::tan(-1.0)).get());
278 template <class Angle>
279 void angle_cos_speed_test(void)
284 for(tmp=-1.0;tmp<1.0;tmp+=0.000002)
286 a=(typename Angle::cos)(tmp);
287 b=(typename Angle::cos)(tmp);
288 c=(typename Angle::cos)(tmp);
289 d=(typename Angle::cos)(tmp);
290 tmp2=((typename Angle::cos)(a)).get();
291 tmp2=((typename Angle::cos)(b)).get();
292 tmp2=((typename Angle::cos)(c)).get();
293 tmp2=((typename Angle::cos)(d)).get();
296 template <class Angle>
297 void angle_sin_speed_test(void)
302 for(tmp=-1.0;tmp<1.0;tmp+=0.000002)
304 a=(typename Angle::sin)(tmp);
305 b=(typename Angle::sin)(tmp);
306 c=(typename Angle::sin)(tmp);
307 d=(typename Angle::sin)(tmp);
308 tmp2=((typename Angle::sin)(a)).get();
309 tmp2=((typename Angle::sin)(b)).get();
310 tmp2=((typename Angle::sin)(c)).get();
311 tmp2=((typename Angle::sin)(d)).get();
314 template <class Angle>
315 void angle_tan_speed_test(void)
320 for(tmp=-1.0;tmp<1.0;tmp+=0.000002)
322 a=(typename Angle::tan)(tmp);
323 b=(typename Angle::tan)(tmp);
324 c=(typename Angle::tan)(tmp);
325 d=(typename Angle::tan)(tmp);
326 tmp2=((typename Angle::tan)(a)).get();
327 tmp2=((typename Angle::tan)(b)).get();
328 tmp2=((typename Angle::tan)(c)).get();
329 tmp2=((typename Angle::tan)(d)).get();
332 template <class Angle, class mytan>
333 void angle_atan2_speed_test(void)
338 for(y=-10.0;y<10.0;y+=0.05)
339 for(x=-10.0;x<10.0;x+=0.05)
356 int fastangle_speed_test(void)
365 fastangle_atan2_time,
372 angle_cos_speed_test<angle>();
373 angle_cos_time=MyTimer();
374 printf("angle: Cosine test: %f seconds\n",angle_cos_time);
377 angle_cos_speed_test<fastangle>();
378 fastangle_cos_time=MyTimer();
379 printf("fastangle: Cosine test: %f seconds\n",fastangle_cos_time);
380 printf("fastangle is %.02f%% faster\n",(angle_cos_time/fastangle_cos_time)*100.0-100.0);
383 angle_sin_speed_test<angle>();
384 angle_sin_time=MyTimer();
385 printf("angle: Sine test: %f seconds\n",angle_sin_time);
388 angle_sin_speed_test<fastangle>();
389 fastangle_sin_time=MyTimer();
390 printf("fastangle: Sine test: %f seconds\n",fastangle_sin_time);
391 printf("fastangle is %.02f%% faster\n",(angle_sin_time/fastangle_sin_time)*100.0-100.0);
394 angle_tan_speed_test<angle>();
395 angle_tan_time=MyTimer();
396 printf("angle: Tangent test: %f seconds\n",angle_tan_time);
399 angle_tan_speed_test<fastangle>();
400 fastangle_tan_time=MyTimer();
401 printf("fastangle: Tangent test: %f seconds\n",fastangle_tan_time);
402 printf("fastangle is %.02f%% faster\n",(angle_tan_time/fastangle_tan_time)*100.0-100.0);
405 angle_atan2_speed_test<angle,angle::tan>();
406 angle_atan2_time=MyTimer();
407 printf("angle: arcTangent2 test: %f seconds\n",angle_atan2_time);
410 angle_atan2_speed_test<fastangle,fastangle::tan>();
411 fastangle_atan2_time=MyTimer();
412 printf("fastangle: arcTangent2 test: %f seconds\n",fastangle_atan2_time);
413 printf("fastangle is %.02f%% faster\n",(angle_atan2_time/fastangle_atan2_time)*100.0-100.0);
423 dist=angle::deg(angle::deg(330).dist(angle::deg(30))).get();
424 printf("angle: angular difference between 330deg and 30deg is %0.1fdeg\n",dist);
425 if(floor(dist+0.5)!=-60)
427 printf("angle: error: should be -60deg!\n");
431 dist=angle::deg(angle::deg(30).dist(angle::deg(330))).get();
432 printf("angle: angular difference between 30deg and 330deg is %0.1fdeg\n",dist);
433 if(floor(dist+0.5)!=60)
435 printf("angle: error: should be 60deg!\n");
439 dist=angle::deg(angle::deg(30).dist(angle::deg(-30))).get();
440 printf("angle: angular difference between 30deg and -30deg is %0.1fdeg\n",dist);
441 if(floor(dist+0.5)!=60)
443 printf("angle: error: should be 60deg!\n");
447 dist=angle::deg(angle::deg(-30).dist(angle::deg(30))).get();
448 printf("angle: angular difference between -30deg and 30deg is %0.1fdeg\n",dist);
449 if(floor(dist+0.5)!=-60)
451 printf("angle: error: should be -60deg!\n");
455 dist=angle::deg(angle::deg(20).dist(angle::deg(195))).get();
456 printf("angle: angular difference between 20deg and 195deg is %0.1fdeg\n",dist);
457 if(floor(dist+0.5)!=-175)
459 printf("angle: error: should be -175deg!\n");
463 dist=angle::deg(angle::deg(20).dist(angle::deg(205))).get();
464 printf("angle: angular difference between 20deg and 205deg is %0.1fdeg\n",dist);
465 if(floor(dist+0.5)!=175)
467 printf("angle: error: should be 175deg!\n");
473 for(i=-1000;i<1000;i++)
475 dist=angle::deg(angle::deg(20+i+360).dist(angle::deg(205+i-360))).get();
476 if(floor(dist+0.5)!=175)
478 printf("angle: error: Badness at %d!\n",i);
484 for(i=-1000;i<1000;i++)
486 dist=angle::deg(angle::deg(20+i-360).dist(angle::deg(195+i+360))).get();
487 if(floor(dist+0.5)!=-175)
489 printf("angle: error: Badness at %d!\n",i);
499 angle a(angle::deg(-2005));
500 angle b(angle::deg(200));
502 affine_combo<angle> combo;
504 hermite<angle> hermie(a,b,b.dist(a),b.dist(a));
506 for(f=0;f<1.001;f+=0.1)
508 printf("@%f--affine_combo: %f hermie: %f\n",angle::deg(f).get(),angle::deg(combo(a,b,f)).get(),angle::deg(hermie(f)).get());
516 /* === E N T R Y P O I N T ================================================= */
522 error+=fastangle_test();
523 error+=fastangle_speed_test();