Frank Heckenbach wrote:
Kevan Hashemi wrote:
My second use of round() is in drawing lines. But in this case, it is easy to implement an incremental rounding function that adds or subtracts one from an integer as its real-valued cousin rises or falls.
Sounds quite like the standard Bresenham algorithm which works completely with integers.
Yes, but it quite depends on the application whether the Bressenham line drawing algorithm is precise enough. If the "source" coordinates are floating point, you can round the start- and end-coordinates to integer values and then draw a line with the Bressenham algorithm. However, some intermediate pixels will invariably be one pixel off, because the rounding of the start- and end-coordinates also influences the "weight" and rounding of intermediate pixels.
AutoCAD, for example, does this wrong and thus draws ugly lines. It becomes even worse when circles are approximated by polygons.
I have been thinking about an improved Bressenham line drawing algorithm that eliminates this problem, but I never had the time to write one, maybe it already exists, it would be interesting.
Regards,
Adriaan van Os