From 2d0abbd021a6190d4cb5571ba067e5e8bd1f076e Mon Sep 17 00:00:00 2001 From: Bill Hilbert Date: Wed, 13 Dec 2023 11:10:20 -0500 Subject: [PATCH] use existing methods --- vec2.lua | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/vec2.lua b/vec2.lua index 191cf6a..6ad17d3 100644 --- a/vec2.lua +++ b/vec2.lua @@ -455,25 +455,29 @@ end -- meta functions for mathmatical operations function vec2.__add(a, b) - return vec2(a.x + b.x, a.y + b.y) + return a:vector_add_inplace(b) end function vec2.__sub(a, b) - return vec2(a.x - b.x, a.y - b.y) + return a:vector_sub_inplace(b) end function vec2.__mul(a, b) - if type(a) == "number" then - return vec2(a * b.x, a * b.y) - elseif type(b) == "number" then - return vec2(a.x * b, a.y * b) - else - return vec2(a.x * b.x, a.y * b.y) - end + if type(a) == "number" then + return b:scalar_mul_inplace(a) + elseif type(b) == "number" then + return a:scalar_mul_inplace(b) + else + return a:vector_mul_inplace(b) + end end 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 -- mask out min component, with preference to keep x