]> git.mxchange.org Git - simgear.git/blob - simgear/props/easing_functions_test.cxx
cppbind: automatic conversion of SGReferenced derived pointers.
[simgear.git] / simgear / props / easing_functions_test.cxx
1 /*
2  * easing_functions_test.cxx
3  *
4  * Output values of all easing functions for plotting and some simple tests.
5  *
6  *  Created on: 15.03.2013
7  *      Author: tom
8  */
9
10 #include "easing_functions.hxx"
11 #include <cmath>
12 #include <iostream>
13
14 #define VERIFY_CLOSE(a, b) \
15   if( std::fabs(a - b) > 1e-5 ) \
16   { \
17     std::cerr << "failed: line " << __LINE__ << ": "\
18               << a << " != " << b\
19               << std::endl; \
20     return 1; \
21   }
22
23 int main(int argc, char* argv[])
24 {
25   using simgear::easing_functions;
26
27   for( double t = 0; t <= 1; t += 1/32. )
28   {
29     if( t == 0 )
30     {
31       for( size_t i = 0; easing_functions[i].name; ++i )
32         std::cout << easing_functions[i].name << " ";
33       std::cout << '\n';
34     }
35
36     for( size_t i = 0; easing_functions[i].name; ++i )
37     {
38       double val = (*easing_functions[i].func)(t);
39       std::cout << val << " ";
40
41       if( t == 0 )
42       {
43         VERIFY_CLOSE(val, 0)
44       }
45       else if( t == 1 )
46       {
47         VERIFY_CLOSE(val, 1)
48       }
49     }
50     std::cout << '\n';
51   }
52
53   return 0;
54 }