After we draw the first pixel (which happens outside our main loop) the correct fraction is: fraction = 1/2 + dy/dx If we scale the fraction by 2*dx the following expression results: scaledFraction = dx + 2*dy and the incremental update becomes: scaledFraction += 2*dy // 2*dx*(dy/dx) and our test must be modified to reflect the new scaling if (scaledFraction >= 2*dx) { ... }
fraction = 1/2 + dy/dx
If we scale the fraction by 2*dx the following expression results: scaledFraction = dx + 2*dy and the incremental update becomes: scaledFraction += 2*dy // 2*dx*(dy/dx) and our test must be modified to reflect the new scaling if (scaledFraction >= 2*dx) { ... }
scaledFraction = dx + 2*dy
scaledFraction += 2*dy // 2*dx*(dy/dx)
if (scaledFraction >= 2*dx) { ... }