aboutsummaryrefslogtreecommitdiff
path: root/builtin/common/vector.lua
diff options
context:
space:
mode:
authorDS <vorunbekannt75@web.de>2021-09-10 23:16:16 +0200
committerGitHub <noreply@github.com>2021-09-10 23:16:16 +0200
commit2cefe51d3b9bc4f3ae18854e171a06ea83e9cb25 (patch)
treec80c7a13df16eb1a8db02dad5c39ddffb71c206a /builtin/common/vector.lua
parentbbfae0cc673d3abdc21224c53e09b209ee4688a2 (diff)
downloadminetest-2cefe51d3b9bc4f3ae18854e171a06ea83e9cb25.tar.gz
minetest-2cefe51d3b9bc4f3ae18854e171a06ea83e9cb25.tar.bz2
minetest-2cefe51d3b9bc4f3ae18854e171a06ea83e9cb25.zip
Split vector.new into 3 constructors
Diffstat (limited to 'builtin/common/vector.lua')
-rw-r--r--builtin/common/vector.lua22
1 files changed, 17 insertions, 5 deletions
diff --git a/builtin/common/vector.lua b/builtin/common/vector.lua
index 752167a63..02fc1bdee 100644
--- a/builtin/common/vector.lua
+++ b/builtin/common/vector.lua
@@ -30,16 +30,28 @@ local function fast_new(x, y, z)
end
function vector.new(a, b, c)
- if type(a) == "table" then
- assert(a.x and a.y and a.z, "Invalid vector passed to vector.new()")
- return fast_new(a.x, a.y, a.z)
- elseif a then
- assert(b and c, "Invalid arguments for vector.new()")
+ if a and b and c then
return fast_new(a, b, c)
end
+
+ -- deprecated, use vector.copy and vector.zero directly
+ if type(a) == "table" then
+ return vector.copy(a)
+ else
+ assert(not a, "Invalid arguments for vector.new()")
+ return vector.zero()
+ end
+end
+
+function vector.zero()
return fast_new(0, 0, 0)
end
+function vector.copy(v)
+ assert(v.x and v.y and v.z, "Invalid vector passed to vector.copy()")
+ return fast_new(v.x, v.y, v.z)
+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)