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 ======================================================= */
24 #include <ETL/hermite>
27 #include <ETL/calculus>
30 /* === M A C R O S ========================================================= */
34 /* === C L A S S E S ======================================================= */
37 /* === P R O C E D U R E S ================================================= */
44 hermite<float> Hermie;
55 integral<hermite<float> > inte(Hermie);
58 fprintf(stderr,"integral of curve() on [0,1] = %f\n",inte(0,1.0));
59 fprintf(stderr,"integral of curve() on [-1,3] = %f\n",inte(-1.0,3.0));
60 Hermie.set_rs(-1.0,7.0);
61 inte=integral<hermite<float> >(Hermie);
62 fprintf(stderr,"integral of curve()[%f,%f] on [-1,7] = %f\n",Hermie.get_r(),Hermie.get_s(),inte(-1.0,7.0));
63 fprintf(stderr,"integral of curve()[%f,%f] on [0,1] = %f\n",Hermie.get_r(),Hermie.get_s(),inte(0,1.0));
64 Hermie.set_rs(0.0,1.0);
67 for(f=0.0f,timer.reset();f<1.001f;f+=0.000005f)
69 t+=Hermie(f)+Hermie(f+0.1f);
70 t+=Hermie(f)+Hermie(f+0.1f);
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);
84 fprintf(stderr,"time=%f milliseconds\n",t*1000);
93 hermite<angle> Hermie;
98 Hermie.p1()=angle::degrees(0);
99 Hermie.t1()=angle::degrees(45);
101 Hermie.p2()=angle::degrees(-45);
102 Hermie.t2()=angle::degrees(180);
107 for(f=0.0f,timer.reset();f<1.001f;f+=0.000005f)
109 tmp+=Hermie(f)+Hermie(f+0.1f);
110 tmp+=Hermie(f)+Hermie(f+0.1f);
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);
124 fprintf(stderr,"angle time=%f milliseconds\n",t*1000);
134 hermite<float,fixed> Hermie;
147 for(f=0.0f,timer.reset();f<1.001f;f+=0.005f)
149 t+=Hermie(f)+Hermie(f+0.1f);
150 t+=Hermie(f)+Hermie(f+0.1f);
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);
164 fprintf(stderr,"time=%f milliseconds\n",t*1000);
169 int anglefixed_test(void)
174 hermite<angle,fixed> Hermie;
179 Hermie.p1()=angle::degrees(0);
180 Hermie.t1()=angle::degrees(45);
182 Hermie.p2()=angle::degrees(-45);
183 Hermie.t2()=angle::degrees(180);
188 for(f=0.0f,timer.reset();f<1.001f;f+=0.0005f)
190 tmp+=Hermie(f)+Hermie(f+0.1f);
191 tmp+=Hermie(f)+Hermie(f+0.1f);
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);
205 fprintf(stderr,"angle fixed time=%f milliseconds\n",t*1000);
210 int float_intersection_test()
214 hermite<float> curve1(0,1,0,1);
215 hermite<float> curve2(-1,2,-1,-2);
219 t1=curve1.intersect(curve2);
220 t2=curve2.intersect(curve1);
222 d=curve1(t1)-curve2(t2);
224 fprintf(stderr,"float:Intersection difference: %f (t1=%f, t2=%f)\n",d,t1,t2);
228 fprintf(stderr,"float:FAILED INTERSECTION TEST.\n");
235 /* === E N T R Y P O I N T ================================================= */
244 error+=float_intersection_test();