summaryrefslogtreecommitdiff
path: root/builtin/common/vector.lua
diff options
context:
space:
mode:
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)