diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-05-13 18:06:47 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-05-13 18:06:47 +0200 |
commit | f3e741dad1311e0b4057b530386e246f921be52c (patch) | |
tree | 64581e3f0ddfa9d4740eed7b545fe3db87b8c126 /builtin/common/vector.lua | |
parent | 96a37aed31cfb9c131e46eda80bdbe3d2289a546 (diff) | |
parent | 69c70dd319532f7860f211f4a527a902b0386e49 (diff) | |
download | dragonfireclient-f3e741dad1311e0b4057b530386e246f921be52c.tar.xz |
Merge branch 'master' of https://github.com/minetest/minetest
Diffstat (limited to 'builtin/common/vector.lua')
-rw-r--r-- | builtin/common/vector.lua | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/builtin/common/vector.lua b/builtin/common/vector.lua index d6437deda..2ef8fc617 100644 --- a/builtin/common/vector.lua +++ b/builtin/common/vector.lua @@ -12,6 +12,22 @@ function vector.new(a, b, c) return {x=0, y=0, z=0} end +function vector.from_string(s, init) + local x, y, z, np = string.match(s, "^%s*%(%s*([^%s,]+)%s*[,%s]%s*([^%s,]+)%s*[,%s]" .. + "%s*([^%s,]+)%s*[,%s]?%s*%)()", init) + x = tonumber(x) + y = tonumber(y) + z = tonumber(z) + if not (x and y and z) then + return nil + end + return {x = x, y = y, z = z}, np +end + +function vector.to_string(v) + return string.format("(%g, %g, %g)", v.x, v.y, v.z) +end + function vector.equals(a, b) return a.x == b.x and a.y == b.y and @@ -41,9 +57,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 |