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