optimize: implement scale and clamp lua functions in C

This commit is contained in:
Glenn Maynard
2005-08-23 06:14:11 +00:00
parent 49466a567d
commit ba8efe82a0
2 changed files with 8 additions and 14 deletions
@@ -30,16 +30,6 @@ function TableMetricLookup( t, group )
return ret
end
-- Scales x so that l1 corresponds to l2 and h1 corresponds to h2.
function scale( x, l1, h1, l2, h2 )
return (((x) - (l1)) * ((h2) - (l2)) / ((h1) - (l1)) + (l2))
end
-- Scales x so that l1 corresponds to l2 and h1 corresponds to h2.
function scale( x, l1, h1, l2, h2 )
return (((x) - (l1)) * ((h2) - (l2)) / ((h1) - (l1)) + (l2))
end
function split( delimiter, text )
local list = {}
local pos = 1
@@ -64,10 +54,6 @@ function join( delimiter, list )
return ret
end
function clamp(val,low,high)
return math.max( low, math.min(val,high) )
end
function wrap(val,n)
local x = val
Trace( "wrap "..x.." "..n )
+8
View File
@@ -469,6 +469,14 @@ LuaFunction( Trace, Trace(SArg(1)) );
#include "ProductInfo.h"
LuaFunction( ProductVersion, (CString) PRODUCT_VER );
static float scale( float x, float l1, float h1, float l2, float h2 )
{
return SCALE( x, l1, h1, l2, h2 );
}
LuaFunction( scale, scale(FArg(1), FArg(2), FArg(3), FArg(4), FArg(5)) );
LuaFunction( clamp, clamp(FArg(1), FArg(2), FArg(3)) );
/*
* (c) 2004 Glenn Maynard
* All rights reserved.