mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-25 23:24:35 +00:00
Added maxcomp and mincomp and specified major/minor to always mask an axis - removed farthest and closest because they were under-specified as a result (and questionable utility)
This commit is contained in:
parent
a73a44f424
commit
99c496df24
47
vec2.lua
47
vec2.lua
@ -598,43 +598,36 @@ function vec2:apply_friction_xy(mu_x, mu_y, dt)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
-- mask out min component
|
--minimum/maximum components
|
||||||
|
function vec2:mincomp()
|
||||||
|
return math.min(self.x, self.y)
|
||||||
|
end
|
||||||
|
|
||||||
|
function vec2:maxcomp()
|
||||||
|
return math.max(self.x, self.y)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- mask out min component, with preference to keep x
|
||||||
function vec2:majori()
|
function vec2:majori()
|
||||||
if self.x > self.y then
|
if self.x > self.y then
|
||||||
self.y = 0
|
self.y = 0
|
||||||
elseif self.x < self.y then
|
else
|
||||||
self.x = 0
|
self.x = 0
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
-- mask out max component
|
-- mask out max component, with preference to keep x
|
||||||
function vec2:minori()
|
function vec2:minori()
|
||||||
if self.x > self.y then
|
if self.x < self.y then
|
||||||
self.x = 0
|
|
||||||
elseif self.x < self.y then
|
|
||||||
self.y = 0
|
self.y = 0
|
||||||
end
|
else
|
||||||
return self
|
|
||||||
end
|
|
||||||
-- max out min magnitude component
|
|
||||||
function vec2:farthesti()
|
|
||||||
if math.abs(self.x) > math.abs(self.y) then
|
|
||||||
self.y = 0
|
|
||||||
elseif math.abs(self.x) < math.abs(self.y) then
|
|
||||||
self.x = 0
|
self.x = 0
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
-- max out max magnitude component
|
|
||||||
function vec2:closesti()
|
|
||||||
if math.abs(self.x) > math.abs(self.y) then
|
|
||||||
self.x = 0
|
|
||||||
elseif math.abs(self.x) < math.abs(self.y) then
|
|
||||||
self.y = 0
|
|
||||||
end
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
--garbage generating versions
|
||||||
function vec2:major(axis)
|
function vec2:major(axis)
|
||||||
return self:copy():majori(axis)
|
return self:copy():majori(axis)
|
||||||
end
|
end
|
||||||
@ -643,12 +636,4 @@ function vec2:minor(axis)
|
|||||||
return self:copy():minori(axis)
|
return self:copy():minori(axis)
|
||||||
end
|
end
|
||||||
|
|
||||||
function vec2:farthest(axis)
|
|
||||||
return self:copy():farthesti(axis)
|
|
||||||
end
|
|
||||||
|
|
||||||
function vec2:closest(axis)
|
|
||||||
return self:copy():closesti(axis)
|
|
||||||
end
|
|
||||||
|
|
||||||
return vec2
|
return vec2
|
||||||
|
Loading…
Reference in New Issue
Block a user