Updated FSF address in all files. Fixes ticket:51
[debian/gnuradio] / ezdop / src / host / hunter / src / util.h
1 /*
2  Copyright 2006 Johnathan Corgan.
3  
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License version 2
6  as published by the Free Software Foundation.
7  
8  This software is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  GNU General Public License for more details.
12  
13  You should have received a copy of the GNU General Public License
14  along with GNU Radio; see the file COPYING.  If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street,
16  Boston, MA 02110-1301, USA.
17 */
18
19 #ifndef __UTIL_H__
20 #define __UTIL_H__
21
22 // System level includes
23 #include <cmath>
24
25 inline double limit(double x, double lower, double upper)
26 {
27     if (x < lower)
28         return lower;
29     else if (x > upper)
30         return upper;
31     else
32         return x;
33 }
34
35 inline int limit(int x, int lower, int upper)
36 {
37     if (x < lower)
38         return lower;
39     else if (x > upper)
40         return upper;
41     else
42         return x;
43 }
44
45 inline double degree_normalize(double degrees)
46 {
47     if (degrees >= 360.0)
48         return degrees - 360.0;
49     else if (degrees < 0.0)
50         return degrees + 360.0;
51     else
52         return degrees;
53 }
54
55 inline int degree_normalize(int degrees)
56 {
57     if (degrees >= 360)
58         return degrees - 360;
59     else if (degrees < 0)
60         return degrees + 360;
61     else
62         return degrees;
63 }
64
65 inline double to_radians(double degrees)
66 {
67     return degrees/180.0*M_PI;
68 }
69
70 inline double to_degrees(double radians)
71 {
72     return radians/M_PI*180.0;
73 }
74
75 #define LOGFUNCTION wxLogDebug("%s", __PRETTY_FUNCTION__)
76 #define LOGFUNCTIONENTRY wxLogDebug("%s: entered", __PRETTY_FUNCTION__)
77 #define LOGFUNCTIONEXIT wxLogDebug("%s: exited", __PRETTY_FUNCTION__)
78
79 #endif // __UTIL_H__