Add Lua helper functions vector.apply(v) math.sign(x, tolerance)

This commit is contained in:
SmallJoker 2014-12-05 23:18:52 +01:00 committed by Nils Dagsson Moskopp
parent 493521898f
commit 2dba3fd295
Signed by: erle
GPG Key ID: A3BC671C35191080
2 changed files with 19 additions and 0 deletions

View File

@ -212,6 +212,17 @@ function math.hypot(x, y)
return x * math.sqrt(1 + t * t) return x * math.sqrt(1 + t * t)
end end
--------------------------------------------------------------------------------
function math.sign(x, tolerance)
tolerance = tolerance or 0
if x > tolerance then
return 1
elseif x < -tolerance then
return -1
end
return 0
end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function get_last_folder(text,count) function get_last_folder(text,count)
local parts = text:split(DIR_DELIM) local parts = text:split(DIR_DELIM)

View File

@ -39,6 +39,14 @@ function vector.round(v)
} }
end end
function vector.apply(v, func)
return {
x = func(v.x),
y = func(v.y),
z = func(v.z)
}
end
function vector.distance(a, b) function vector.distance(a, b)
local x = a.x - b.x local x = a.x - b.x
local y = a.y - b.y local y = a.y - b.y