summaryrefslogtreecommitdiff
path: root/ezdop/src/host/hunter/src/util.h
blob: 53e0f39d650fe3cfe8fa2ca0f89bb4225f9dc6ff (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 Copyright 2006 Johnathan Corgan.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License version 2
 as published by the Free Software Foundation.
 
 This software is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Radio; see the file COPYING.  If not, write to
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.
*/

#ifndef __UTIL_H__
#define __UTIL_H__

// System level includes
#include <cmath>

inline double limit(double x, double lower, double upper)
{
    if (x < lower)
        return lower;
    else if (x > upper)
        return upper;
    else
        return x;
}

inline int limit(int x, int lower, int upper)
{
    if (x < lower)
        return lower;
    else if (x > upper)
        return upper;
    else
        return x;
}

inline double degree_normalize(double degrees)
{
    if (degrees >= 360.0)
        return degrees - 360.0;
    else if (degrees < 0.0)
        return degrees + 360.0;
    else
        return degrees;
}

inline int degree_normalize(int degrees)
{
    if (degrees >= 360)
        return degrees - 360;
    else if (degrees < 0)
        return degrees + 360;
    else
        return degrees;
}

inline double to_radians(double degrees)
{
    return degrees/180.0*M_PI;
}

inline double to_degrees(double radians)
{
    return radians/M_PI*180.0;
}

#define LOGFUNCTION wxLogDebug("%s", __PRETTY_FUNCTION__)
#define LOGFUNCTIONENTRY wxLogDebug("%s: entered", __PRETTY_FUNCTION__)
#define LOGFUNCTIONEXIT wxLogDebug("%s: exited", __PRETTY_FUNCTION__)

#endif // __UTIL_H__