Windows GDI has these functions:
MoveTo();
LineTo();
They accept coordinates where to start drawing and where to stop drawing.
But how are these functions implemented?? (especially LineTo)
Do they need to calculate all points between point A and point B??
How is this line drawn exactly??
Yes, they calculate each individual point between A and B.
The most common way to do this efficiently is known as Bresenham's Line Algorithm.
Note that Windows LineTo does not draw the last point. When line segments are drawn one after another, this prevents the endpoints from being double drawn.
nobody who never saw the Windows source code can answer this in-depth... BUT Windows is just as any other software: it needs some algorithm to draw a line... one such algorithm you can see here http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
The Moveto is "easier" in that it just updates the current coordinates the system know of...
It doesn't need to calculate all points between A and B (which are infinite) but only the discrete pixels between A and B. That's usually a standard line rasterization algorithm. See Wikipedia for Bresenham's line rasterization algorithm, which is the standard school book example and usually the base for more flexible rasterization algorithms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With