Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / tools / GenerateSineTables.cpp
blob050299bddc59e498e71c7d77ad09b105e3975fa7
1 #ifndef FIXED_MATH
2 #define FIXED_MATH
3 #endif
5 #include "Math/Constants.h"
6 #include "Math/fixed.hpp"
7 #include "Computer/ThermalLocator.hpp"
9 #include <math.h>
10 #include <stdio.h>
12 static inline double
13 thermal_fn(int x)
15 return exp((-0.2/ThermalLocator::TLOCATOR_NMAX)*pow((double)x, 1.5));
18 static inline double
19 INT_TO_DEG(int x)
21 return DEG_TO_RAD * ((double)x * 360) / 4096;
24 int
25 main(int argc, char **argv)
27 (void)argc;
28 (void)argv;
30 puts("#ifdef FIXED_MATH");
31 puts("const int SINETABLE[4096] = {");
32 for (unsigned i = 0; i < 4096; i++)
33 printf(" %d,\n",
34 (int)(sin(INT_TO_DEG(i)) * (double)fixed::resolution));
35 puts("#else");
36 puts("const fixed SINETABLE[4096] = {");
37 for (unsigned i = 0; i < 4096; i++)
38 printf(" fixed(%.20e),\n", sin(INT_TO_DEG(i)));
39 puts("#endif");
40 puts("};");
42 puts("const short ISINETABLE[4096] = {");
43 for (unsigned i = 0; i < 4096; i++)
44 printf(" %d,\n", (int)lround(sin(INT_TO_DEG(i)) * 1024));
45 puts("};");
47 puts("#ifdef FIXED_MATH");
48 puts("const fixed::value_t INVCOSINETABLE[4096] = {");
49 for (unsigned i = 0; i < 4096; i++) {
50 double x = cos(INT_TO_DEG(i));
51 if ((x >= 0) && (x < 1.0e-8))
52 x = 1.0e-8;
54 if ((x < 0) && (x > -1.0e-8))
55 x = -1.0e-8;
57 #if defined(HAVE_MSVCRT) && !defined(__CYGWIN__)
58 // Due to non-standard behavior of the microsoft implementation
59 // this hack is needed to compile on windows machines
60 printf(" %I64dLL,\n",
61 #else
62 printf(" %lldLL,\n",
63 #endif
64 (long long)((double)fixed::resolution / x));
66 puts("#else");
67 puts("const fixed INVCOSINETABLE[4096] = {");
68 for (unsigned i = 0; i < 4096; i++) {
69 double x = cos(INT_TO_DEG(i));
70 if ((x >= 0) && (x < 1.0e-8))
71 x = 1.0e-8;
73 if ((x < 0) && (x > -1.0e-8))
74 x = -1.0e-8;
76 printf(" fixed(%.20e),\n", 1.0 / x);
78 puts("#endif");
79 puts("};");
81 printf("#define THERMALRECENCY_SIZE %d\n", ThermalLocator::TLOCATOR_NMAX);
82 puts("#ifdef FIXED_MATH");
83 printf("const unsigned THERMALRECENCY[] = {\n");
84 for (unsigned i = 0; i < ThermalLocator::TLOCATOR_NMAX; i++)
85 printf(" %u,\n", (unsigned)(thermal_fn(i) * (double)fixed::resolution));
86 puts("#else");
87 printf("const fixed THERMALRECENCY[%d] = {", ThermalLocator::TLOCATOR_NMAX);
88 for (unsigned i = 0; i < ThermalLocator::TLOCATOR_NMAX; i++)
89 printf(" fixed(%.20e),\n", thermal_fn(i));
90 puts("#endif");
91 puts("};");
93 return 0;