Navigation: Up, Table of Contents, Index,

Line Segments (Line)

Line l ( int x1, int y1, int x2, int y2);
Creates a line from (x1, y1) to (x2, y2).

int l.x1 () Returns x-coordinate of the first endpoint.
int l.y1 () Returns y-coordinate of the first endpoint.
int l.x2 () Returns x-coordinate of the second endpoint.
int l.y2 () Returns y-coordinate of the second endpoint.

Example

The following code draws a line segment from (100, 100) to (200, 200) and waits for a mouseclick to finish.

#include <ifmwindow>

int main()
{
    wio << Line(100, 100, 200, 200) << flush;
    wio.wait_for_mouse_click();
}

Notes

Line Segments are somewhat special in X, since they do not include their endpoints, but only the grid points in between. So if you write
    wio << Line(100, 100, 200, 100) 
        << Line(201, 100, 300, 100) 
        << flush;
there does not appear a continuous line segment (100, 100)   (300, 100), it will have a one-pixel gap in the middle.
Next: Class declaration of Rectangle
Navigation: Up, Table of Contents, Index,
Michael Hoffmann. Mon, October 7, 2002.