csgeom/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 00032 template<class T> 00033 const T& csMax (const T& a, const T& b) 00034 { 00035 if (a >= b) return a; 00036 return b; 00037 } 00038 00042 template<class T> 00043 const T& csMin (const T& a, const T& b) 00044 { 00045 if (a < b) return a; 00046 return b; 00047 } 00048 00049 00053 template<class T> 00054 T csClamp (const T& a, T max, T min) 00055 { 00056 return csMin (csMax (a, min), max); 00057 } 00058 00064 template<class T> 00065 T csSmoothStep (const T& a, T max, T min) 00066 { 00067 T tmp, tmp2; 00068 if (a <= min) 00069 tmp = 0.0f; 00070 else if (a >= max) 00071 tmp = 1.0f; 00072 else 00073 { 00074 tmp2 = (a - min) / (max-min); 00075 tmp = tmp2*tmp2 * (3.0 - 2.0*tmp2); 00076 } 00077 return tmp; 00078 } 00079 00083 template<class T> 00084 T csSquare (const T& x) 00085 { 00086 return x * x; 00087 } 00088 00091 #endif //__CS_MATH_H__
Generated for Crystal Space by doxygen 1.4.6