Line draw algorithmΒΆ

Given two pixel points on the screen, the problem is to determine which pixels need to be colored in between them to rasterize a straight line.

The essence of the algorithm is that if a line passes between two pixels, the pixel that is closer is chosen. This is decided by the relative position of the line with respect to the midpoint between the two pixels.

Line draw algorithm

The bresenham::figure::add_line() method implements the same.