From 2dba3fd29525a5b82badcd9a0b953b2961d03ddf Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Fri, 5 Dec 2014 23:18:52 +0100 Subject: [PATCH] Add Lua helper functions vector.apply(v) math.sign(x, tolerance) --- builtin/common/misc_helpers.lua | 11 +++++++++++ builtin/common/vector.lua | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index 0b60812..e1dc289 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -212,6 +212,17 @@ function math.hypot(x, y) return x * math.sqrt(1 + t * t) 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) local parts = text:split(DIR_DELIM) diff --git a/builtin/common/vector.lua b/builtin/common/vector.lua index 88ccfe6..e9ed3aa 100644 --- a/builtin/common/vector.lua +++ b/builtin/common/vector.lua @@ -39,6 +39,14 @@ function vector.round(v) } 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) local x = a.x - b.x local y = a.y - b.y