Move math.hypot() to misc_helpers.lua and fix zero-division error

stable-0.4
ShadowNinja 2013-07-07 12:02:11 -04:00 committed by kwolekr
parent 9dcd21911a
commit a75afb85ca
2 changed files with 10 additions and 10 deletions

View File

@ -106,13 +106,3 @@ function minetest.formspec_escape(str)
return str return str
end 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)
t = t / x
return x * math.sqrt(1 + t * t)
end

View File

@ -91,4 +91,14 @@ function minetest.pos_to_string(pos)
return "(" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")" return "(" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")"
end 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