mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-14 04:01:48 +00:00
Merge pull request #68 from billmakes/master
vec2: add meta functions for mathematical operators
This commit is contained in:
commit
90f46c2c6a
27
vec2.lua
27
vec2.lua
@ -453,6 +453,33 @@ function vec2:maxcomp()
|
|||||||
return math.max(self.x, self.y)
|
return math.max(self.x, self.y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- meta functions for mathmatical operations
|
||||||
|
function vec2.__add(a, b)
|
||||||
|
return a:vector_add_inplace(b)
|
||||||
|
end
|
||||||
|
|
||||||
|
function vec2.__sub(a, b)
|
||||||
|
return a:vector_sub_inplace(b)
|
||||||
|
end
|
||||||
|
|
||||||
|
function vec2.__mul(a, b)
|
||||||
|
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)
|
||||||
|
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
|
-- mask out min component, with preference to keep x
|
||||||
function vec2:major_inplace()
|
function vec2:major_inplace()
|
||||||
if self.x > self.y then
|
if self.x > self.y then
|
||||||
|
Loading…
Reference in New Issue
Block a user