3 ms·
Using fixed point for drawing lines rather than Bresenham's is nothing new. The thing is that Bresenham is resolution-independent. If the registers used have e
by kazinator 11y ago
Using fixed point for drawing lines rather than Bresenham's is nothing new.
The thing is that Bresenham is resolution-independent. If the registers used have enough width to represent the coordinates of the entire display, then the line will be drawn correctly. The error term that is propagated through the loop is always precisely correct. There is no cumulative error from using approximations.
You can think of Bresenham's as being like fixed point, but with a variable denominator for the error term which depends on the specific delta. For instance if we are drawing 600 across (x) and 450 up (y), then the error term is basically an accumulator to which we add 450. Whenever it goes over 600, we subtract 600, and increment y. (Okay, so it is not like fixed point but in fact exact rational math. The error term accumulates numerators, which are compared to the denominator.)
We could represent the same approximately with a fixed point number, but that pins us to a denominator. If we have, say, 8 bits of fractional precision, then we work in multiples of 1/256. Now 450/600 is precisely 3/4, and so we are lucky in this case: 3/4 is a multiple of 1/256: the denominator is a power of two, and so we can step the x coordinate by 1, and the y coordinate by 3/4. The "staircase" will be the same as under Bresenham's.
Suppose delta is <453,599>. Bresenham's still deals with this precisely. 453 is added to the error term, and 599 subtracted when it blows past 599. Yet, 599 is a prime, and 453/599 has no exact representation in fixed point. The best we can do is add more bits of precision to minimize the cumulative error. If the display is on the order of 1000x1000 and we go down to 1/65535 sub-pixel precision in our fixed-point coordinates, maybe there is no noticeable artifact.