1 /* Copyright (C) 2010 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_MATHUTIL
19 #define INCLUDED_MATHUTIL
20 
21 #define DEGTORAD(a)					((a) * ((float)M_PI/180.0f))
22 #define RADTODEG(a)					((a) * (180.0f/(float)M_PI))
23 #define SQR(x)						((x) * (x))
24 
25 template <typename T>
Interpolate(const T & a,const T & b,float l)26 inline T Interpolate(const T& a, const T& b, float l)
27 {
28 	return a + (b - a) * l;
29 }
30 
31 template <typename T>
clamp(T value,T min,T max)32 inline T clamp(T value, T min, T max)
33 {
34 	if (value <= min) return min;
35 	else if (value >= max) return max;
36 	else return value;
37 }
38 
sgn(float a)39 inline float sgn(float a)
40 {
41     if (a > 0.0f) return 1.0f;
42     if (a < 0.0f) return -1.0f;
43     return 0.0f;
44 }
45 
46 #endif
47