Almost done drawing lines
This commit is contained in:
parent
74fdcd51f7
commit
abce928481
4 changed files with 159 additions and 7 deletions
40
grid.lua
40
grid.lua
|
@ -34,3 +34,43 @@ function Grid:draw()
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Check all lines and return one, which contains point (if any)
|
||||
function Grid:matchesLine( point, ignoreEnd )
|
||||
local line = self.lines[tableFind( self.lines, point,
|
||||
function( value, innervalue )
|
||||
return innervalue:has( value )
|
||||
end
|
||||
)]
|
||||
|
||||
if line ~= nil and not ignoreEnd then
|
||||
if line.startpoint:equals( point ) then
|
||||
line:clear()
|
||||
line:push( line.startpoint )
|
||||
end
|
||||
if line.endpoint:equals( point ) then
|
||||
line:clear()
|
||||
line:reverse()
|
||||
return line
|
||||
end
|
||||
end
|
||||
|
||||
-- Try to check endpoint
|
||||
if line == nil and not ignoreEnd then
|
||||
line = self.lines[tableFind( self.lines, point,
|
||||
function( value, innervalue )
|
||||
if innervalue.endpoint:equals( value ) then
|
||||
innervalue:clear()
|
||||
innervalue:reverse()
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
)]
|
||||
end
|
||||
return line
|
||||
end
|
||||
|
||||
function Grid:inBounds( point )
|
||||
return point.x <= self.size.x and point.y <= self.size.y
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue