optimize: implement scale and clamp lua functions in C
This commit is contained in:
@@ -30,16 +30,6 @@ function TableMetricLookup( t, group )
|
|||||||
return ret
|
return ret
|
||||||
end
|
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 )
|
function split( delimiter, text )
|
||||||
local list = {}
|
local list = {}
|
||||||
local pos = 1
|
local pos = 1
|
||||||
@@ -64,10 +54,6 @@ function join( delimiter, list )
|
|||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
function clamp(val,low,high)
|
|
||||||
return math.max( low, math.min(val,high) )
|
|
||||||
end
|
|
||||||
|
|
||||||
function wrap(val,n)
|
function wrap(val,n)
|
||||||
local x = val
|
local x = val
|
||||||
Trace( "wrap "..x.." "..n )
|
Trace( "wrap "..x.." "..n )
|
||||||
|
|||||||
@@ -469,6 +469,14 @@ LuaFunction( Trace, Trace(SArg(1)) );
|
|||||||
#include "ProductInfo.h"
|
#include "ProductInfo.h"
|
||||||
LuaFunction( ProductVersion, (CString) PRODUCT_VER );
|
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
|
* (c) 2004 Glenn Maynard
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
|||||||
Reference in New Issue
Block a user