File: SinusTable.h

package info (click to toggle)
moagg 0.18-6
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,924 kB
  • ctags: 4,059
  • sloc: cpp: 23,814; sh: 2,652; makefile: 283
file content (39 lines) | stat: -rw-r--r-- 758 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef SINUSTABLE_H
#define SINUSTABLE_H

#include <cassert>

//----------------------------------------------------------------------------
class SinusTable
{
  public:
    SinusTable();
    ~SinusTable();

    static inline double sin(int angle)
    {
        return sm_sinTable[normalize(angle)];
    }

    static inline double cos(int angle)
    {
        return sm_cosTable[normalize(angle)];
    }

    static inline int normalize(int angle)
    {
        while (angle < 0)  angle += 360;
        while (angle >= 360) angle -= 360;

        assert(angle >= 0 && angle < 360);
        return angle;
    }

  private:

    static SinusTable sm_instance;
    static double sm_sinTable[360];
    static double sm_cosTable[360];
};

#endif //SINUSTABLE_H