From 2cefe51d3b9bc4f3ae18854e171a06ea83e9cb25 Mon Sep 17 00:00:00 2001 From: DS Date: Fri, 10 Sep 2021 23:16:16 +0200 Subject: Split vector.new into 3 constructors --- builtin/common/vector.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'builtin/common/vector.lua') 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) -- cgit v1.2.3