add interp()
This commit is contained in:
@@ -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.
|
// 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))
|
#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 )
|
inline bool CLAMP( int &x, int l, int h )
|
||||||
{
|
{
|
||||||
if (x > h) { x = h; return true; }
|
if (x > h) { x = h; return true; }
|
||||||
|
|||||||
Reference in New Issue
Block a user