mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-25 23:24:35 +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
|
-- 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
|
||||||
|
Loading…
Reference in New Issue
Block a user