mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-10 02:31:48 +00:00
use existing methods
This commit is contained in:
parent
ce0205b42a
commit
2d0abbd021
16
vec2.lua
16
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)
|
||||
return b:scalar_mul_inplace(a)
|
||||
elseif type(b) == "number" then
|
||||
return vec2(a.x * b, a.y * b)
|
||||
return a:scalar_mul_inplace(b)
|
||||
else
|
||||
return vec2(a.x * b.x, a.y * b.y)
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user