use existing methods

This commit is contained in:
Bill Hilbert 2023-12-13 11:10:20 -05:00
parent ce0205b42a
commit 2d0abbd021

View File

@ -455,25 +455,29 @@ end
-- meta functions for mathmatical operations -- meta functions for mathmatical operations
function vec2.__add(a, b) function vec2.__add(a, b)
return vec2(a.x + b.x, a.y + b.y) return a:vector_add_inplace(b)
end end
function vec2.__sub(a, b) function vec2.__sub(a, b)
return vec2(a.x - b.x, a.y - b.y) return a:vector_sub_inplace(b)
end end
function vec2.__mul(a, b) function vec2.__mul(a, b)
if type(a) == "number" then if type(a) == "number" then
return vec2(a * b.x, a * b.y) return b:scalar_mul_inplace(a)
elseif type(b) == "number" then elseif type(b) == "number" then
return vec2(a.x * b, a.y * b) return a:scalar_mul_inplace(b)
else else
return vec2(a.x * b.x, a.y * b.y) return a:vector_mul_inplace(b)
end end
end end
function vec2.__div(a, b) function vec2.__div(a, b)
return vec2(a.x / b, a.y / b) if type(b) == "number" then
return a:scalar_div_inplace(b)
else
return a:vector_div_inplace(b)
end
end end
-- mask out min component, with preference to keep x -- mask out min component, with preference to keep x