From 99c496df24227a990261ed640bbbe3a21f2fb256 Mon Sep 17 00:00:00 2001 From: Max Cahill <1bardesign@gmail.com> Date: Tue, 8 Jun 2021 11:50:54 +1000 Subject: [PATCH] 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) --- vec2.lua | 47 ++++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/vec2.lua b/vec2.lua index 9f88c5a..a7d32f2 100644 --- a/vec2.lua +++ b/vec2.lua @@ -598,43 +598,36 @@ function vec2:apply_friction_xy(mu_x, mu_y, dt) return self 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() if self.x > self.y then self.y = 0 - elseif self.x < self.y then + else self.x = 0 end return self end --- mask out max component +-- mask out max component, with preference to keep x function vec2:minori() - if self.x > self.y then - self.x = 0 - elseif self.x < self.y then + if self.x < self.y then self.y = 0 - end - 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 + else self.x = 0 end return self 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) return self:copy():majori(axis) end @@ -643,12 +636,4 @@ function vec2:minor(axis) return self:copy():minori(axis) end -function vec2:farthest(axis) - return self:copy():farthesti(axis) -end - -function vec2:closest(axis) - return self:copy():closesti(axis) -end - return vec2