fix: remove some problems in point and rects

This commit is contained in:
Kazhnuz 2020-11-27 16:02:21 +01:00
parent fb55c9e706
commit cf1928444f
2 changed files with 11 additions and 2 deletions

View file

@ -31,7 +31,7 @@ function Point:setPosition(x, y)
self.x, self.y = x, y self.x, self.y = x, y
end end
function Point:move(x, y) function Point:goToward(x, y)
local x = x or 0 local x = x or 0
local y = y or 0 local y = y or 0
self:setPosition(self.x + x, self.y + y) self:setPosition(self.x + x, self.y + y)
@ -63,7 +63,7 @@ function Point:getMiddlePoint(x, y)
return utils.math.getMiddlePoint(self.x, self.y, x, y) return utils.math.getMiddlePoint(self.x, self.y, x, y)
end end
function Point:getDirectionFromPoint(other) function Point:getMiddlePointFromPoint(other)
local x, y = other:getPosition() local x, y = other:getPosition()
self:getMiddlePoint(x, y) self:getMiddlePoint(x, y)
end end

View file

@ -29,6 +29,11 @@ function Rect:new(x, y, w, h)
self:setSize(w, h) self:setSize(w, h)
end end
function Rect:set(x, y, w, h)
self:setPosition(x, y)
self:setSize(w, h)
end
function Rect:setSize(w, h) function Rect:setSize(w, h)
self.w = w or self.w self.w = w or self.w
self.h = h or self.h self.h = h or self.h
@ -39,6 +44,10 @@ function Rect:getArea()
return x, y, self.w, self.h return x, y, self.w, self.h
end end
function Rect:getShape()
return self:getArea()
end
function Rect:getCorners() function Rect:getCorners()
local x, y, w, h = self:getArea() local x, y, w, h = self:getArea()
return x, y, x + w, y + h return x, y, x + w, y + h