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>
31 /* === M A C R O S ========================================================= */
35 /* === C L A S S E S ======================================================= */
38 /* === P R O C E D U R E S ================================================= */
45 hermite<float> Hermie;
56 integral<hermite<float> > inte(Hermie);
59 fprintf(stderr,"integral of curve() on [0,1] = %f\n",inte(0,1.0));
60 fprintf(stderr,"integral of curve() on [-1,3] = %f\n",inte(-1.0,3.0));
61 Hermie.set_rs(-1.0,7.0);
62 inte=integral<hermite<float> >(Hermie);
63 fprintf(stderr,"integral of curve()[%f,%f] on [-1,7] = %f\n",Hermie.get_r(),Hermie.get_s(),inte(-1.0,7.0));
64 fprintf(stderr,"integral of curve()[%f,%f] on [0,1] = %f\n",Hermie.get_r(),Hermie.get_s(),inte(0,1.0));
65 Hermie.set_rs(0.0,1.0);
68 for(f=0.0f,timer.reset();f<1.001f;f+=0.000005f)
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);
81 t+=Hermie(f)+Hermie(f+0.1f);
85 fprintf(stderr,"time=%f milliseconds\n",t*1000);
94 hermite<angle> Hermie;
99 Hermie.p1()=angle::degrees(0);
100 Hermie.t1()=angle::degrees(45);
102 Hermie.p2()=angle::degrees(-45);
103 Hermie.t2()=angle::degrees(180);
108 for(f=0.0f,timer.reset();f<1.001f;f+=0.000005f)
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);
121 tmp+=Hermie(f)+Hermie(f+0.1f);
125 fprintf(stderr,"angle time=%f milliseconds\n",t*1000);
135 hermite<float,fixed> Hermie;
148 for(f=0.0f,timer.reset();f<1.001f;f+=0.005f)
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);
161 t+=Hermie(f)+Hermie(f+0.1f);
165 fprintf(stderr,"time=%f milliseconds\n",t*1000);
170 int anglefixed_test(void)
175 hermite<angle,fixed> Hermie;
180 Hermie.p1()=angle::degrees(0);
181 Hermie.t1()=angle::degrees(45);
183 Hermie.p2()=angle::degrees(-45);
184 Hermie.t2()=angle::degrees(180);
189 for(f=0.0f,timer.reset();f<1.001f;f+=0.0005f)
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);
202 tmp+=Hermie(f)+Hermie(f+0.1f);
206 fprintf(stderr,"angle fixed time=%f milliseconds\n",t*1000);
211 int float_intersection_test()
215 hermite<float> curve1(0,1,0,1);
216 hermite<float> curve2(-1,2,-1,-2);
220 t1=curve1.intersect(curve2);
221 t2=curve2.intersect(curve1);
223 d=curve1(t1)-curve2(t2);
225 fprintf(stderr,"float:Intersection difference: %f (t1=%f, t2=%f)\n",d,t1,t2);
229 fprintf(stderr,"float:FAILED INTERSECTION TEST.\n");
236 /* === E N T R Y P O I N T ================================================= */
245 error+=float_intersection_test();