Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU drawline command switches X1/X2 or Y1/Y2 independently #72

Open
cheapie opened this issue Jan 11, 2025 · 2 comments · May be fixed by #71
Open

GPU drawline command switches X1/X2 or Y1/Y2 independently #72

cheapie opened this issue Jan 11, 2025 · 2 comments · May be fixed by #71
Assignees
Labels
bug Something isn't working

Comments

@cheapie
Copy link

cheapie commented Jan 11, 2025

In the validate_area() function, x1 is switched with x2 and y1 is switched with y2 depending on which is larger, but when drawing a line, this causes the direction of the line to change if x1/x2 are switched but y1/y2 are not, or vice versa.

For example, a line from (16,1) to (1,16) gets turned into (1,1) to (16,16), which is not the same line.

Example Luacontroller program (GPU on channel "gpu", digiscreen or 16x16 rgblightstone on channel "screen"):

if event.type == "program" then
  digiline_send("gpu", {
    { command = "createbuffer", buffer = 0, xsize = 16, ysize = 16 },
    { command = "drawline", buffer = 0, x1 = 16, y1 = 1, x2 = 1, y2 = 16,
      color = "c0ffee" },
    { command = "send", buffer = 0, channel = "screen" },
  })
end

If working properly it will draw a line from the top right to bottom left (/ shape - not perfect but I don't think it ever has been), if not the line will be from top left to bottom right (\ shape).

@SwissalpS SwissalpS added the bug Something isn't working label Jan 11, 2025
@SwissalpS SwissalpS self-assigned this Jan 11, 2025
SwissalpS added a commit that referenced this issue Jan 13, 2025
@SwissalpS SwissalpS linked a pull request Jan 13, 2025 that will close this issue
@SwissalpS
Copy link
Contributor

SwissalpS commented Jan 13, 2025

added a potential fix for this to #71
@cheapie please continue testing and attempting to break something, thanks.

Edit: oh dear, I just found a situation that results in a crash...

@SwissalpS
Copy link
Contributor

OK, I hope this does it now. Have added an underflow check, figured it is more expressive and cleaner than a simple if buff[y] and buff[y][x] then which would require yet another indent for an edge case that can be solved without indents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants