CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | 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 
00061 template<class T>
00062 T csSmoothStep (const T& a, T max, T min)
00063 {
00064   T tmp;
00065   if (a <= min)
00066     tmp = min;
00067   else if (a >= max)
00068     tmp = max;
00069   else
00070   {
00071     a = (a - min) / (max-min);
00072     tmp = a*a * (3.0 - 2.0*a);
00073   }
00074   return tmp;
00075 }
00076 
00080 template<class T>
00081 T csSquare (const T& x)
00082 {
00083   return x * x;
00084 }
00085 
00088 #endif //__CS_MATH_H__

Generated for Crystal Space by doxygen 1.3.9.1