Drawing a line code

z z at z.com
Sun Nov 6 20:07:47 UTC 2022


On Sunday, 6 November 2022 at 16:48:24 UTC, Joel wrote:
>I want my code fixed up so that works from any two points.

You can add a condition to prevent writing out of the 
image/framebuffer/whatever memory so it won't do any out of 
bounds write.

Another valid algorithm could be testing all pixels for distance 
from the line.(i believe that's what 2D vector rendering software 
does?)

`incrE` and `incrNE`'s use can be replaced with an approach where 
you increment a counter by `dx/dy`(assuming `dy > dx` here) every 
iteration(after you draw the dot i believe) and whenever the 
counter is above `1` you add `sx` or `sy` to the `x` or `y` value 
then substract the counter by `1`.(as the wording implies, you 
will probably need to branch depending on if `dx > dy` or `dy > 
dx`).


More information about the Digitalmars-d-learn mailing list