eaae237dfa3772a79eb4fe33e2c38387d1cc4606
[synfig.git] / ETL / test / spline.cpp
1 /*! ========================================================================
2 ** Extended Template and Library Test Suite
3 ** Spline Curve Test
4 ** $Id$
5 **
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
7 **
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.
12 **
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.
17 **
18 ** === N O T E S ===========================================================
19 **
20 ** ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #include <ETL/spline>
25 #include <ETL/angle>
26 #include <ETL/clock>
27 #include <ETL/calculus>
28 #include <stdio.h>
29
30 /* === M A C R O S ========================================================= */
31
32 using namespace etl;
33
34 /* === C L A S S E S ======================================================= */
35
36
37 /* === P R O C E D U R E S ================================================= */
38
39 int bspline_basic_test(void)
40 {
41         int ret=0;
42         float f;
43
44         bspline<float> BSpline;
45         etl::clock timer;
46         double t;
47
48         *BSpline.cpoints().insert(BSpline.cpoints().end())=0;
49         *BSpline.cpoints().insert(BSpline.cpoints().end())=-1;
50         *BSpline.cpoints().insert(BSpline.cpoints().end())=0;
51         *BSpline.cpoints().insert(BSpline.cpoints().end())=1;
52         *BSpline.cpoints().insert(BSpline.cpoints().end())=0;
53
54         BSpline.set_m(4);
55         BSpline.reset_knots();
56
57         integral<bspline<float> > inte(BSpline);
58
59
60         /*
61         for(f=0.0;f<1.001;f+=0.05)
62                 fprintf(stderr,"BSpline(%f)= %f\n",f,BSpline(f));
63         */
64
65         fprintf(stderr,"integral of BSpline() on [0,1] = %f\n",inte(0,1.0));
66
67
68         for(f=0.0f,timer.reset();f<1.001f;f+=0.000005f)
69         {
70                 t+=BSpline(f)+BSpline(f+0.1f);
71                 t+=BSpline(f)+BSpline(f+0.1f);
72                 t+=BSpline(f)+BSpline(f+0.1f);
73                 t+=BSpline(f)+BSpline(f+0.1f);
74                 t+=BSpline(f)+BSpline(f+0.1f);
75                 t+=BSpline(f)+BSpline(f+0.1f);
76                 t+=BSpline(f)+BSpline(f+0.1f);
77                 t+=BSpline(f)+BSpline(f+0.1f);
78                 t+=BSpline(f)+BSpline(f+0.1f);
79                 t+=BSpline(f)+BSpline(f+0.1f);
80                 t+=BSpline(f)+BSpline(f+0.1f);
81                 t+=BSpline(f)+BSpline(f+0.1f);
82         }
83         t=timer();
84
85         fprintf(stderr,"BSpline time=%f milliseconds\n",t*1000);
86         return ret;
87 }
88
89 /* === E N T R Y P O I N T ================================================= */
90
91 int main()
92 {
93         int error=0;
94
95         error+=bspline_basic_test();
96
97         return error;
98 }
99