CC: Tweaked

CC: Tweaked

42M Downloads

drawLine sortCoords not working

lilyzeiset opened this issue ยท 5 comments

commented

The following code should draw a line from the bottom-left to top-right
code
result

drawLine(1,1,w,h) [correctly] and drawLine(1,h,w,1) [incorrectly] draw the same line.

commented
commented

This is rather embarassing ๐Ÿ˜“ I looked over the code a few times even now and I can't see what could've caused this, so guess I should try and wake up a little more first

commented

Lem, it's 7am. Stop looking at GitHub.

commented

I remember when I originally wrote #570, I stared at this code for a VERY long time trying to figure out what it does:

I think that the confusion comes from the fact that the old code only actually attempts to swap the X coordinates, swapping the Y simultaneously. My code swaps both independently (which is the way I think it should work). The line drawing function probably relies on this behaviour implicitly, causing the line to draw upside down?

commented

Yeah that makes sense. The new logic is fine for boxes, where there isn't a direction, but doesn't work for lines.

Woops, should have property tested the pre and post refactoring code.