Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

Reference Manual: ifm::Line Navigation: Up, Table of Contents, Index,

Line Segments (ifm::Line)

ifm::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 <IFM/window>

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

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
    ifm::wio << ifm::Line(100, 100, 200, 100) 
             << ifm::Line(201, 100, 300, 100) 
             << ifm::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 ifm::Rectangle
Navigation: Up, Table of Contents, Index,
Michael Hoffmann. Wed, November 17, 2004.