More color and rectangle lib functionality.
This commit is contained in:
@@ -1,47 +1,45 @@
|
||||
-- For luaJit compatibility.
|
||||
if table.unpack == nil then
|
||||
table.unpack = unpack
|
||||
end
|
||||
|
||||
Rectangle = {}
|
||||
-- Rectangle.TYPE = "Rectangle"
|
||||
|
||||
Rectangle.meta = {
|
||||
__index = Rectangle,
|
||||
__tostring = function( r )
|
||||
return "{"..tostring( r.x )..", "..tostring( r.y )..", "..tostring( r.width )..", "..tostring( r.height ).."}"
|
||||
end,
|
||||
-- __add = function( v1, v2 )
|
||||
-- return Vector2:new( v1.x + v2.x, v1.y + v2.y )
|
||||
-- end,
|
||||
-- __sub = function( v1, v2 )
|
||||
-- return Vector2:new( v1.x - v2.x, v1.y - v2.y )
|
||||
-- end,
|
||||
-- __mul = function( v1, v2 )
|
||||
-- return Vector2:new( v1.x * v2.x, v1.y * v2.y )
|
||||
-- end,
|
||||
-- __div = function( v1, v2 )
|
||||
-- return Vector2:new( v1.x / v2.x, v1.y / v2.y )
|
||||
-- end,
|
||||
-- __mod = function( v, value )
|
||||
-- return Vector2:new( math.fmod( v.x, value ), math.fmod( v.y, value ) )
|
||||
-- end,
|
||||
-- __pow = function( v, value )
|
||||
-- return Vector2:new( v.x ^ value, v.y ^ value )
|
||||
-- end,
|
||||
-- __unm = function( v )
|
||||
-- return Vector2:new( -v.x, -v.y )
|
||||
-- end,
|
||||
-- __idiv = function( v, value )
|
||||
-- return Vector2:new( v.x // value, v.y // value )
|
||||
-- end,
|
||||
-- __len = function( v )
|
||||
-- local len = 0
|
||||
|
||||
-- for _, _ in pairs( v ) do
|
||||
-- len = len + 1
|
||||
-- end
|
||||
|
||||
-- return len
|
||||
-- end,
|
||||
-- __eq = function( v1, v2 )
|
||||
-- return v1.x == v2.x and v1.y == v2.y
|
||||
-- end,
|
||||
__add = function( r1, r2 )
|
||||
return Rectangle:new( r1.x + r2.x, r1.y + r2.y, r1.width + r2.width, r1.height + r2.height )
|
||||
end,
|
||||
__sub = function( r1, r2 )
|
||||
return Rectangle:new( r1.x - r2.x, r1.y - r2.y, r1.width - r2.width, r1.height - r2.height )
|
||||
end,
|
||||
__mul = function( r1, r2 )
|
||||
return Rectangle:new( r1.x * r2.x, r1.y * r2.y, r1.width * r2.width, r1.height * r2.height )
|
||||
end,
|
||||
__div = function( r1, r2 )
|
||||
return Rectangle:new( r1.x / r2.x, r1.y / r2.y, r1.width / r2.width, r1.height / r2.height )
|
||||
end,
|
||||
__mod = function( r, v )
|
||||
return Rectangle:new( math.fmod( r.x, v ), math.fmod( r.y, v ), math.fmod( r.width, v ), math.fmod( r.height, v ) )
|
||||
end,
|
||||
__pow = function( r, v )
|
||||
return Rectangle:new( r.x ^ v, r.y ^ v, r.width ^ v, r.height ^ v )
|
||||
end,
|
||||
__unm = function( r )
|
||||
return Rectangle:new( -r.x, -r.y, -r.width, -r.height )
|
||||
end,
|
||||
__idiv = function( r, v )
|
||||
return Rectangle:new( r.x // v, r.y // v, r.width // v, r.height // v )
|
||||
end,
|
||||
__len = function( _ )
|
||||
return 4
|
||||
end,
|
||||
__eq = function( r1, r2 )
|
||||
return RL.Vector2Equals( { r1.x, r1.y }, { r2.x, r2.y } ) and RL.Vector2Equals( { r1.width, r1.height }, { r2.width, r2.height } )
|
||||
end,
|
||||
}
|
||||
|
||||
function Rectangle:new( x, y, width, height )
|
||||
@@ -86,4 +84,44 @@ function Rectangle:clone()
|
||||
return Rectangle:new( self.x, self.y, self.width, self.height )
|
||||
end
|
||||
|
||||
function Rectangle:scale( scalar )
|
||||
return Rectangle:new( self.x, self.y, self.width * scalar, self.height * scalar )
|
||||
end
|
||||
|
||||
function Rectangle:min( rec )
|
||||
return Rectangle:new( self.x, self.y, math.min( self.width, rec.width ), math.min( self.height, rec.height ) )
|
||||
end
|
||||
|
||||
function Rectangle:max( rec )
|
||||
return Rectangle:new( self.x, self.y, math.max( self.width, rec.width ), math.max( self.height, rec.height ) )
|
||||
end
|
||||
|
||||
function Rectangle:floor()
|
||||
return Rectangle:new( math.floor( self.x ), math.floor( self.y ), math.floor( self.width ), math.floor( self.height ) )
|
||||
end
|
||||
|
||||
function Rectangle:ceil()
|
||||
return Rectangle:new( math.ceil( self.x ), math.ceil( self.y ), math.ceil( self.width ), math.ceil( self.height ) )
|
||||
end
|
||||
|
||||
function Rectangle:area()
|
||||
return self.width * self.height
|
||||
end
|
||||
|
||||
function Rectangle:checkCollisionRec( rec )
|
||||
return RL.CheckCollisionRecs( self, rec )
|
||||
end
|
||||
|
||||
function Rectangle:checkCollisionCircle( center, radius )
|
||||
return RL.CheckCollisionCircleRec( center, radius, self )
|
||||
end
|
||||
|
||||
function Rectangle:checkCollisionPoint( point )
|
||||
return RL.CheckCollisionPointRec( point, self )
|
||||
end
|
||||
|
||||
function Rectangle:getCollisionRec( rec )
|
||||
return Rectangle:new( RL.GetCollisionRec( self, rec ) )
|
||||
end
|
||||
|
||||
return Rectangle
|
||||
|
||||
Reference in New Issue
Block a user