mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 14:14:36 +00:00
add meta functions for mathmatical operators
This commit is contained in:
parent
e4953b6d47
commit
f29882c2ee
23
vec2.lua
23
vec2.lua
@ -453,6 +453,29 @@ 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 vec2(a.x + b.x, a.y + b.y)
|
||||||
|
end
|
||||||
|
|
||||||
|
function vec2.__sub(a, b)
|
||||||
|
return vec2(a.x - b.x, a.y - b.y)
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
function vec2.__div(a, b)
|
||||||
|
return vec2(a.x / b, a.y / b)
|
||||||
|
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