Martin Krastev wrote:
"Michael Noisternig" <michael.noisternig@xxxxxxxxx> wrote:
[snip]
The slope computed by your slope version is quite likely to have an infinite number of digits, so you already have 1/4 the size of the number consisting of only the least significant bit as error in average. By adding the slope in every iteration that error gets accumulated and there is quite likely to be a case (with not huge line endpoints) were the total error of the line drawn is bigger than in Bresenham's algorithm (that means the line is off from the correct one by at least 1 pixel).
So the correct way would be to re-compute the other coordinate in every iteration, e.g. y = y1 + (y2-y1)*x/(x2-x1). Now by that way you also have very few instructions every iteration but the division hurts badly! (It's slow!)
are you imposing that the division need be performed on _each_ iteration?
y = y1 + (y2-y1)*x/(x2-x1)
is a linear function
y = ax + b
to keep the error within the precisional error margins of the media used (i.e. not to have any additional cumulative error) all you need to do is to use a non-incremental evaluator, and you end up with 1x multiplication and 1x addition per iteration, no unit-errors whatsoever*, and last but not least you end up with no conditions in the inner loop.
I'll do it explicitely for your linear function y = ax + b: a = 1/10 <-- a < 1/10 due to finite number of digits y = a*5 + 0 <-- y < 0.5 --> round(y) = 0
[snip]
just my 0.02 -blu