1 /*! ========================================================================
2 ** Extended Template and Library Test Suite
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
7 ** Copyright (c) 2007 Chris Moore
9 ** This package is free software; you can redistribute it and/or
10 ** modify it under the terms of the GNU General Public License as
11 ** published by the Free Software Foundation; either version 2 of
12 ** the License, or (at your option) any later version.
14 ** This package is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ** General Public License for more details.
19 ** === N O T E S ===========================================================
21 ** ========================================================================= */
23 /* === H E A D E R S ======================================================= */
25 #include <ETL/hermite>
28 #include <ETL/calculus>
32 /* === M A C R O S ========================================================= */
36 /* === C L A S S E S ======================================================= */
39 /* === P R O C E D U R E S ================================================= */
46 hermite<float> Hermie;
57 integral<hermite<float> > inte(Hermie);
60 fprintf(stderr,"integral of curve() on [0,1] = %f\n",inte(0,1.0));
61 fprintf(stderr,"integral of curve() on [-1,3] = %f\n",inte(-1.0,3.0));
62 Hermie.set_rs(-1.0,7.0);
63 inte=integral<hermite<float> >(Hermie);
64 fprintf(stderr,"integral of curve()[%f,%f] on [-1,7] = %f\n",Hermie.get_r(),Hermie.get_s(),inte(-1.0,7.0));
65 fprintf(stderr,"integral of curve()[%f,%f] on [0,1] = %f\n",Hermie.get_r(),Hermie.get_s(),inte(0,1.0));
66 Hermie.set_rs(0.0,1.0);
69 for(f=0.0f,timer.reset();f<1.001f;f+=0.000005f)
71 t+=Hermie(f)+Hermie(f+0.1f);
72 t+=Hermie(f)+Hermie(f+0.1f);
73 t+=Hermie(f)+Hermie(f+0.1f);
74 t+=Hermie(f)+Hermie(f+0.1f);
75 t+=Hermie(f)+Hermie(f+0.1f);
76 t+=Hermie(f)+Hermie(f+0.1f);
77 t+=Hermie(f)+Hermie(f+0.1f);
78 t+=Hermie(f)+Hermie(f+0.1f);
79 t+=Hermie(f)+Hermie(f+0.1f);
80 t+=Hermie(f)+Hermie(f+0.1f);
81 t+=Hermie(f)+Hermie(f+0.1f);
82 t+=Hermie(f)+Hermie(f+0.1f);
86 fprintf(stderr,"time=%f milliseconds\n",t*1000);
95 hermite<angle> Hermie;
100 Hermie.p1()=angle::degrees(0);
101 Hermie.t1()=angle::degrees(45);
103 Hermie.p2()=angle::degrees(-45);
104 Hermie.t2()=angle::degrees(180);
109 for(f=0.0f,timer.reset();f<1.001f;f+=0.000005f)
111 tmp+=Hermie(f)+Hermie(f+0.1f);
112 tmp+=Hermie(f)+Hermie(f+0.1f);
113 tmp+=Hermie(f)+Hermie(f+0.1f);
114 tmp+=Hermie(f)+Hermie(f+0.1f);
115 tmp+=Hermie(f)+Hermie(f+0.1f);
116 tmp+=Hermie(f)+Hermie(f+0.1f);
117 tmp+=Hermie(f)+Hermie(f+0.1f);
118 tmp+=Hermie(f)+Hermie(f+0.1f);
119 tmp+=Hermie(f)+Hermie(f+0.1f);
120 tmp+=Hermie(f)+Hermie(f+0.1f);
121 tmp+=Hermie(f)+Hermie(f+0.1f);
122 tmp+=Hermie(f)+Hermie(f+0.1f);
126 fprintf(stderr,"angle time=%f milliseconds\n",t*1000);
136 hermite<float,fixed> Hermie;
149 for(f=0.0f,timer.reset();f<1.001f;f+=0.005f)
151 t+=Hermie(f)+Hermie(f+0.1f);
152 t+=Hermie(f)+Hermie(f+0.1f);
153 t+=Hermie(f)+Hermie(f+0.1f);
154 t+=Hermie(f)+Hermie(f+0.1f);
155 t+=Hermie(f)+Hermie(f+0.1f);
156 t+=Hermie(f)+Hermie(f+0.1f);
157 t+=Hermie(f)+Hermie(f+0.1f);
158 t+=Hermie(f)+Hermie(f+0.1f);
159 t+=Hermie(f)+Hermie(f+0.1f);
160 t+=Hermie(f)+Hermie(f+0.1f);
161 t+=Hermie(f)+Hermie(f+0.1f);
162 t+=Hermie(f)+Hermie(f+0.1f);
166 fprintf(stderr,"time=%f milliseconds\n",t*1000);
171 int anglefixed_test(void)
176 hermite<angle,fixed> Hermie;
181 Hermie.p1()=angle::degrees(0);
182 Hermie.t1()=angle::degrees(45);
184 Hermie.p2()=angle::degrees(-45);
185 Hermie.t2()=angle::degrees(180);
190 for(f=0.0f,timer.reset();f<1.001f;f+=0.0005f)
192 tmp+=Hermie(f)+Hermie(f+0.1f);
193 tmp+=Hermie(f)+Hermie(f+0.1f);
194 tmp+=Hermie(f)+Hermie(f+0.1f);
195 tmp+=Hermie(f)+Hermie(f+0.1f);
196 tmp+=Hermie(f)+Hermie(f+0.1f);
197 tmp+=Hermie(f)+Hermie(f+0.1f);
198 tmp+=Hermie(f)+Hermie(f+0.1f);
199 tmp+=Hermie(f)+Hermie(f+0.1f);
200 tmp+=Hermie(f)+Hermie(f+0.1f);
201 tmp+=Hermie(f)+Hermie(f+0.1f);
202 tmp+=Hermie(f)+Hermie(f+0.1f);
203 tmp+=Hermie(f)+Hermie(f+0.1f);
207 fprintf(stderr,"angle fixed time=%f milliseconds\n",t*1000);
212 int float_intersection_test()
216 hermite<float> curve1(0,1,0,1);
217 hermite<float> curve2(-1,2,-1,-2);
221 t1=curve1.intersect(curve2);
222 t2=curve2.intersect(curve1);
224 d=curve1(t1)-curve2(t2);
226 fprintf(stderr,"float:Intersection difference: %f (t1=%f, t2=%f)\n",d,t1,t2);
230 fprintf(stderr,"float:FAILED INTERSECTION TEST.\n");
237 /* === E N T R Y P O I N T ================================================= */
246 error+=float_intersection_test();