[ Contact ] [ Links ] [ Previous : 12 / 20 : More Low-level Optimizations (2) ] [ Up ] [ Next : 14 / 20 : Bresenham´s line drawing algorithm ]

More Low-level Optimizations (3)

This test can be made a test against a value of zero if the inital value of scaledFraction has 2*dx subtracted from it. Giving outside the loop:

OffsetScaledFraction = dx + 2*dy - 2*dx = 2*dy - dx,

and the inner loop becomes

OffsetScaledFraction += 2*dy
if (OffsetScaledFraction >= 0) { 
	y = y +1; OffsetScaledFraction -= 2*dx; 
} 

The net result is that we might as well double the values of dy and dx (this can be accomplished with either an add or a shift).


See the "Links" link above to find out the sources of the proposed informations
Pascal Vuylsteker / eScience / Computer Science / ANU
Last modified: 20/4/2004
TOC - Print
Send your comments at :
<Hugh.Fisher@anu.edu.au>