1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
//$Id$
#ifndef __osgAL_math_h__
#define __osgAL_math_h__
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
namespace osgAL {
/// Lineary interpolate from a to b using s = {0,..1}
template<typename T>
inline T const mix(T const& a, T const& b, float s)
{
if (s > 1)
return b;
if (s <=0)
return a;
return ((1-s)*a + s*b);
}
/// Return the smallest item of a and b
template<typename T>
inline T const& min(T const& a, T const& b)
{
return (a < b ? a : b);
}
/// Return the greatest item of a and b
template<typename T>
inline T const& max(T const& a, T const& b)
{
return (a > b ? a : b);
}
/// Return the greatest item of a and b
template<typename T>
inline T const& clamp(T const& x, T const& min, T const& max)
{
return ( ((x) > (max)) ? (max) : ( ((x) < (min)) ? (min) : (x) ));
}
}
#endif
|