Fixed sortCoords for draw functions (#749)

This commit is contained in:
lily 2021-04-02 10:30:28 -04:00 committed by GitHub
parent e48427dbbc
commit 9708dd6786
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -132,7 +132,17 @@ function drawLine(startX, startY, endX, endY, colour)
return
end
local minX, maxX, minY, maxY = sortCoords(startX, startY, endX, endY)
local minX = math.min(startX, endX)
local maxX, minY, maxY
if minX == startX then
minY = startY
maxX = endX
maxY = endY
else
minY = endY
maxX = startX
maxY = startY
end
-- TODO: clip to screen rectangle?

View File

@ -67,6 +67,19 @@ describe("The paintutils library", function()
{ " ", "000", "ffe" },
})
end)
it("draws a line going diagonally from bottom left", function()
local w = with_window(3, 3, function()
term.setBackgroundColour(colours.red)
paintutils.drawLine(1, 3, 3, 1)
end)
window_eq(w, {
{ " ", "000", "ffe" },
{ " ", "000", "fef" },
{ " ", "000", "eff" },
})
end)
end)
describe("paintutils.drawBox", function()