67.1.1 Lines

A line is a set of pixels on a raster display (or a set of dots on a page of printer paper) that is identified by two points: a starting point and an ending point. In Windows, the pixel located at the starting point is always included in the line while the pixel located at the ending point is always excluded (these lines are sometimes called inclusive/exclusive).

When an application calls one of the Windows line-drawing functions, the graphics engine or, in some cases, a device driver determines which pixels should be highlighted. The graphics engine is a dynamic-link library which processes graphics function-calls from a Windows application and passes those calls to a device driver. A device driver is a dynamic-link library which receives input from the graphics engine, converts the input to device commands, and passes these commands to the appropriate device. The graphics engine uses a digital differential algorithm (DDA) to determine the set of pixels that define a line. A DDA determines the set of pixels by examining each point on the line and identifying which pixels on the display surface (or dots on the page of paper) correspond to these points. The following illustration shows a line, its starting point, its ending point, and the pixels which were highlighted using a simple DDA:

Applying a DDA to Pixels on a Video Display

The simplest and most common DDA is the Bresenham, or incremental, DDA (a modified version of this algorithm is used to draw lines in Windows version 3.x). The incremental DDA is noted for its simplicity; however, it is also noted for its inaccuracy—because it rounds off to the nearest integer value, it sometimes fails to represent the original line which was requested by the application. The DDA used by the Win32 graphics engine does not round off to the nearest integer. And, as a result, it produces output that is sometimes much closer in appearance to the original line that was requested by the application.

If an application requires line output that cannot be obtained with the new DDA, it can draw its own lines by calling the LineDDA function and supplying a private DDA. However, it's important to note that the LineDDA function will draw lines much slower than the Windows line-drawing functions—if speed is a primary concern, this function should not be used.

An application can use the new Windows DDA to draw single lines and multiple, connected line segments. An application can draw a single line by calling the LineTo function. This function draws a line from a device context's current position to a specified point. An application can draw a series of connected line segments by calling the Polyline function and supplying an array of points that specify the endpoint of each line segment. An application can draw multiple, disjoint series of connected line segments by calling the PolyPolyline function and supplying the required endpoints.

The following illustration shows line output created by calling the LineTo, Polyline, and PolyPolyline functions:

Line Output