Graphics /Discover / Bresenham

Bresenham

scenario

Can the Line Stay Integer?

Your incremental line drawer already avoids recomputing m*x + c in every column. But its inner loop still carries a floating-point slope, a floating-point line height, repeated floating-point additions and a rounding operation.

Now impose a stricter constraint: the endpoints are integer pixel centres, and you want the repeated per-column decision to use integer state and simple arithmetic instead of carrying the full floating-point height. The final raster line must still choose the same kind of staircase through the grid.

The problem is to decide what information about the ideal line must be preserved and what information can be discarded once all you care about is the next pixel.

A short DDA loop has callouts on the floating-point slope, stored ideal height, repeated floating-point addition and rounding operation used to choose each row.
DDA avoids repeated multiplication by x, but it still maintains floating-point slope and height state and rounds that height to choose rows.

What smaller piece of state could preserve enough information to choose the next pixel without carrying the complete floating-point line height yi?