//$Id: Math,v 1.1 2004/11/22 07:40:33 andersb Exp $

#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
