Boost logo

Boost :

From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2008-04-24 18:03:42

My submission to the vault included the library itself, but no example
code or applications that illustrate how to use it.


The following code snippet compiles warning and error free (in linux gcc
3.4.2). You should have good luck with more recent versions of gcc, icc
and VC as well since we build against those regularly.


#include "gtl.h"


int main(int argc, char **argv) {


    using namespace gtl;

    PolygonSet ps;

    ps.insert(Rectangle(0, 0, 10, 10)); //rectangle with lower left
corner 0,0 and upper right corner 10,10

    ps.insert(Rectangle(5, 5, 15, 15));

    std::vector<Polygon> result;


    if(result.size() != 1) return 1;

    std::cout << result[0] << std::endl;


  return 0;




Polygon 5 10 0 0 10 5 15 15


The format of the output polygon is what I call the "compact"
representation of a manhattan polygon.

In this case the polygon returned has the following vertices: 5,10 0,10
0,0 10,0 10,5 15,5 15,15 5,15 and is the OR of the two input rectangles
(note CC winding convention.)

There are API on the Polygon to get an iterator over vertices as Point
objects, of course, but the << >> operators are used to serialize its
compact representation.

There are also quite a few alternatives for constructing rectangles and
adding geometry data to a PolygonSet. PolygonSet.h is a good place to
start looking at the gtl source code.



Boost list run by bdawes at, gregod at, cpdaniel at, john at