Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
math.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2005 by Marten Svanfeldt 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_MATH_H__ 00020 #define __CS_MATH_H__ 00021 00031 template<class T> 00032 const T& csMax (const T& a, const T& b) 00033 { 00034 if (a >= b) return a; 00035 return b; 00036 } 00037 00041 template<class T> 00042 const T& csMin (const T& a, const T& b) 00043 { 00044 if (a < b) return a; 00045 return b; 00046 } 00047 00048 00052 template<class T> 00053 T csClamp (const T& a, T max, T min) 00054 { 00055 return csMin (csMax (a, min), max); 00056 } 00057 00063 template<class T> 00064 T csSmoothStep (const T& a, T max, T min) 00065 { 00066 T tmp, tmp2; 00067 if (a <= min) 00068 tmp = 0.0f; 00069 else if (a >= max) 00070 tmp = 1.0f; 00071 else 00072 { 00073 tmp2 = (a - min) / (max-min); 00074 tmp = tmp2*tmp2 * (3.0 - 2.0*tmp2); 00075 } 00076 return tmp; 00077 } 00078 00082 template<class T> 00083 T csSquare (const T& x) 00084 { 00085 return x * x; 00086 } 00087 00090 #endif //__CS_MATH_H__
Generated for Crystal Space by doxygen 1.4.4