]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - builtin/common/misc_helpers.lua
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / builtin / common / misc_helpers.lua
index 324d83b07d483f54d464775c248e628c10c9f6be..e4bc056d9ff424f9b83d9a439bbc5438200cf5dd 100644 (file)
@@ -209,14 +209,7 @@ 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)
+       return math.sqrt(x * x + y * y)
 end
 
 --------------------------------------------------------------------------------
@@ -432,21 +425,19 @@ function core.string_to_pos(value)
                return nil
        end
 
-       local p = {}
-       p.x, p.y, p.z = string.match(value, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
-       if p.x and p.y and p.z then
-               p.x = tonumber(p.x)
-               p.y = tonumber(p.y)
-               p.z = tonumber(p.z)
-               return p
-       end
-       p = {}
-       p.x, p.y, p.z = string.match(value, "^%( *([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) *%)$")
-       if p.x and p.y and p.z then
-               p.x = tonumber(p.x)
-               p.y = tonumber(p.y)
-               p.z = tonumber(p.z)
-               return p
+       local x, y, z = string.match(value, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
+       if x and y and z then
+               x = tonumber(x)
+               y = tonumber(y)
+               z = tonumber(z)
+               return vector.new(x, y, z)
+       end
+       x, y, z = string.match(value, "^%( *([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) *%)$")
+       if x and y and z then
+               x = tonumber(x)
+               y = tonumber(y)
+               z = tonumber(z)
+               return vector.new(x, y, z)
        end
        return nil
 end