4 quadrants... I was only thinking 2, when doing the prep_state, I was figuring the CPU sending the line coordinates would know that y would never be decreasing. So line coordinates like (0,10)to(10,0) would be illegal, but I see a case could be made to include the correction feature you mention in the code. Looks easy enough, I will work on this.
If that y1>y0 input requirement exists, then you can calculate dy without the 'if' check that's currently in there.
The error logic is what I am having a difficult time with, still. Hopefully it will click soon.

Bresenham is exactly the same as doing x' = x + dx/dy, but keeping a complex fraction instead of performing a division. I don't know why everybody calls it "error", because it's the numerator in the iteration. I prefer calling it "num" for numerator:
x' = x + num/dy
On each iteration, num = num + dx. Whenever num gets larger than dy, then x=x+1 and num=num-dy. It's nothing more than basic elementary school fraction handling, but for some reason gets obscured with the way Bresenham tends to be described.
As an example, drawing from 0,0 to 3,5. X starts at zero, and every step of Y we add 3/5 to the x coordinate.
Code: Select all
y=0, x = 0 + 0/5
y=1, x = 0 + 3/5
y=2, x = 0 + 6/5 = 1 + 1/5
y=3, x = 1 + 4/5
y=4, x = 1 + 7/5 = 2 + 2/5
y=5, x = 2 + 5/5 = 3 + 0/5
Therefore, the plotted points are (0,0), (1,0), (2,1), (3,1), (4,2), (5,3), taking just the integer portion of X and ignoring the fractional portion.
Note that in the code you have, the numerator is doubled for an "e2" term, rounding up to give a half-pixel offset to the line to balance it nicer. It could also have started off with "x = 0 + 2/5", starting the numerator with a half-pixel offset and leaving out that "e2" calculation. Once you actually start drawing lines, you'll see what a visual difference that offset makes.
The x-coords from above are 0,0,1,1,2,3, which wouldn't look visually straight. With the half-pixel offset, they become 0,1,1,2,2,3, which looks a lot nicer. This is the difference between considering the canonical point location of a pixel to be at the upper-left hand corner of the pixel's area (no offset), vs at its center (coordinate is offset by 1/2).
Should I be using signed notation? I'm avoiding negative numbers...
No, I didn't know if what you were doing was intentional or not. Stick to unsigned.