aboutsummaryrefslogtreecommitdiff
path: root/builtin/common/vector.lua
diff options
context:
space:
mode:
authorMinetest-j45 <55553015+Minetest-j45@users.noreply.github.com>2021-08-30 15:22:40 +0100
committerGitHub <noreply@github.com>2021-08-30 15:22:40 +0100
commit7824a4956bf489b4e2cc35e0c97272eee06be6ba (patch)
tree70243765dc1743a83596f9c6eec122fb417ef92c /builtin/common/vector.lua
parent607add326feb44e078b843464ce4a8de09f28743 (diff)
parent35445d24f425c6291a0580b468919ca83de716fd (diff)
downloaddragonfireclient-7824a4956bf489b4e2cc35e0c97272eee06be6ba.tar.xz
Merge pull request #1 from EliasFleckenstein03/master
update
Diffstat (limited to 'builtin/common/vector.lua')
-rw-r--r--builtin/common/vector.lua22
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