diff --git a/modules/vec2.lua b/modules/vec2.lua index c7f2adc..4dd570e 100644 --- a/modules/vec2.lua +++ b/modules/vec2.lua @@ -68,7 +68,7 @@ function vector.__add(a,b) if type(a) == "number" then return new(a+b.x, a+b.y) elseif type(b) == "number" then - return new(b+a.x, b+a.y) + return new(a.x+b, a.y+b) else assert(isvector(a) and isvector(b), "Add: wrong argument types ( expected)") return new(a.x+b.x, a.y+b.y) @@ -79,7 +79,7 @@ function vector.__sub(a,b) if type(a) == "number" then return new(a-b.x, a-b.y) elseif type(b) == "number" then - return new(b-a.x, b-a.y) + return new(a.x-b, a.y-b) else assert(isvector(a) and isvector(b), "Sub: wrong argument types ( expected)") return new(a.x-b.x, a.y-b.y) diff --git a/modules/vec3.lua b/modules/vec3.lua index eff511c..43e1b92 100644 --- a/modules/vec3.lua +++ b/modules/vec3.lua @@ -85,7 +85,7 @@ function vector.__add(a,b) if type(a) == "number" then return new(a+b.x, a+b.y, a+b.z) elseif type(b) == "number" then - return new(b+a.x, b+a.y, b+a.z) + return new(a.x+b, a.y+b, a.z+b) else assert(isvector(a) and isvector(b), "Add: wrong argument types ( expected)") return new(a.x+b.x, a.y+b.y, a.z+b.z) @@ -96,7 +96,7 @@ function vector.__sub(a,b) if type(a) == "number" then return new(a-b.x, a-b.y, a-b.z) elseif type(b) == "number" then - return new(b-a.x, b-a.y, b-a.z) + return new(a.x-b, a.y-b, a.z-b) else assert(isvector(a) and isvector(b), "Sub: wrong argument types ( expected)") return new(a.x-b.x, a.y-b.y, a.z-b.z)