Almost done drawing lines

This commit is contained in:
Alexey 2025-05-20 17:03:47 +03:00
commit abce928481
4 changed files with 159 additions and 7 deletions

View file

@ -38,7 +38,7 @@ function Line:draw()
love.graphics.circle( "fill", sx, sy, Config.linePointRadius )
local ex, ey = self.endpoint:globalCoords()
love.graphics.circle( "fill", ex, ey, Config.linePointRadius )
if #self.points == 1 then
if #self.points <= 1 then
love.graphics.setColor( Color.white )
return
end
@ -52,3 +52,27 @@ function Line:draw()
love.graphics.line( points )
love.graphics.setColor( Color.white )
end
-- Clear points
function Line:clear()
for k, _ in pairs( self.points ) do
self.points[k] = nil
end
end
-- Swap startpoint and endpoint
function Line:reverse()
local swap = self.startpoint
self.startpoint = self.endpoint
self.endpoint = swap
self:push( self.startpoint )
end
-- Check if line has the exact point
function Line:has( point )
return tableHas( self.points, point,
function( value, innervalue )
return innervalue:equals( value )
end
)
end