add interp()

This commit is contained in:
Glenn Maynard
2006-01-20 06:21:07 +00:00
parent e39f1499e2
commit 02bae15b84
+7
View File
@@ -41,6 +41,13 @@ inline unsigned long max( unsigned long a, unsigned int b ) { return a > b? a:b;
// Do the multiply before the divide to that integer scales have more precision.
#define SCALE(x, l1, h1, l2, h2) (((x) - (l1)) * ((h2) - (l2)) / ((h1) - (l1)) + (l2))
// Like SCALE(x, 0, 1, L, H); interpolate between L and H.
template<typename T, typename U>
inline U interp( T x, U l, U h )
{
return U(x * (h - l) + l);
}
inline bool CLAMP( int &x, int l, int h )
{
if (x > h) { x = h; return true; }