diff options
author | ShadowNinja <noreply@gmail.com> | 2013-07-07 12:02:11 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2013-07-07 21:47:38 -0400 |
commit | a75afb85ca6338da847172bbed3cc776d3aced20 (patch) | |
tree | 2f02ef8ea34c6ea30df1ddbc391c792f1c59cbd6 /builtin/misc_helpers.lua | |
parent | 9dcd21911a438fbec5b5aa8cc1f5bb1975a1b98f (diff) | |
download | minetest-a75afb85ca6338da847172bbed3cc776d3aced20.tar.xz |
Move math.hypot() to misc_helpers.lua and fix zero-division error
Diffstat (limited to 'builtin/misc_helpers.lua')
-rw-r--r-- | builtin/misc_helpers.lua | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/builtin/misc_helpers.lua b/builtin/misc_helpers.lua index 743a9cfd3..0439415b1 100644 --- a/builtin/misc_helpers.lua +++ b/builtin/misc_helpers.lua @@ -91,4 +91,14 @@ function minetest.pos_to_string(pos) return "(" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")" end +function math.hypot(x, y) + local t + x = math.abs(x) + y = math.abs(y) + t = math.min(x, y) + x = math.max(x, y) + if x == 0 then return 0 end + t = t / x + return x * math.sqrt(1 + t * t) +end |