diff options
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/common/misc_helpers.lua | 9 | ||||
-rw-r--r-- | builtin/common/vector.lua | 6 |
2 files changed, 12 insertions, 3 deletions
diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index 0f3897f47..d5f25f2fe 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -244,6 +244,15 @@ function math.factorial(x) return v end + +function math.round(x) + if x >= 0 then + return math.floor(x + 0.5) + end + return math.ceil(x - 0.5) +end + + function core.formspec_escape(text) if text ~= nil then text = string.gsub(text,"\\","\\\\") diff --git a/builtin/common/vector.lua b/builtin/common/vector.lua index d6437deda..b04c12610 100644 --- a/builtin/common/vector.lua +++ b/builtin/common/vector.lua @@ -41,9 +41,9 @@ end function vector.round(v) return { - x = math.floor(v.x + 0.5), - y = math.floor(v.y + 0.5), - z = math.floor(v.z + 0.5) + x = math.round(v.x), + y = math.round(v.y), + z = math.round(v.z) } end |