From 1980aebdc32392f4975f6d1f8ecd9050f27e475f Mon Sep 17 00:00:00 2001 From: jussi Date: Thu, 9 May 2024 22:05:24 +0300 Subject: Matrix lib clone fix. --- examples/resources/lib/matrix.lua | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'examples/resources/lib') diff --git a/examples/resources/lib/matrix.lua b/examples/resources/lib/matrix.lua index 28d4305..1dc128f 100644 --- a/examples/resources/lib/matrix.lua +++ b/examples/resources/lib/matrix.lua @@ -3,23 +3,20 @@ if table.unpack == nil then table.unpack = unpack end -local function deepCopy( orig ) - local copy +local function copyMatrix( orig ) + local copy = RL.MatrixIdentity() - if type( orig ) == "table" then - copy = {} + if orig ~= nil then + for y = 1, 4 do + for x = 1, 4 do + if orig[x][y] ~= nil then + copy[x][y] = orig[x][y] + end + end + end + end - for origKey, origValue in next, orig, nil do - -- If object has clone method, use that. - copy[ deepCopy( origKey ) ] = deepCopy( origValue ) - end - - -- setmetatable( copy, utillib.deepCopy( getmetatable( orig ) ) ) - else -- number, string, boolean, etc. - copy = orig - end - - return copy + return copy end local Matrix = {} @@ -50,17 +47,17 @@ Matrix.meta = { function Matrix:new( m ) local object = setmetatable( {}, Matrix.meta ) - object.m = deepCopy( m ) + object.m = copyMatrix( m ) return object end function Matrix:set( m ) - self.m = deepCopy( m ) + self.m = copyMatrix( m ) end function Matrix:clone() - return Matrix:new( self ) + return Matrix:new( self.m ) end function Matrix:determinant() -- cgit v1.2.3