4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=windows-1252">
5 <title>Polygon Set Usage
</title>
10 <p><font face=
"Courier New">/*
<br>
11 Copyright
2008 Intel Corporation
<br>
13 Use, modification and distribution are subject to the Boost Software License,
<br>
14 Version
1.0. (See accompanying file LICENSE_1_0.txt or copy at
<br>
15 http://www.boost.org/LICENSE_1_0.txt).
<br>
17 #include
<boost/polygon/polygon.hpp
><br>
18 #include
<cassert
><br>
19 namespace gtl = boost::polygon;
<br>
20 using namespace boost::polygon::operators;
<br><br>
21 int main() {
<br>
22 //lets declare ourselves a polygon set
<br>
23 using namespace gtl; //because of operators
<br>
24 typedef std::vector
<polygon_data
<int
> > PolygonSet;
<br>
25 PolygonSet ps;
<br>
27 //lets put some data in
<br>
28 ps += rectangle_data
<int
>(
0,
0,
10,
10);
<br>
30 //now lets do something interesting
<br>
31 PolygonSet ps2;
<br>
32 ps2 += rectangle_data
<int
>(
5,
5,
15,
15);
<br>
33 PolygonSet ps3;
<br>
34 assign(ps3, ps * ps2); //woah, I just felt the room flex around me
<br>
35 PolygonSet ps4;
<br>
36 ps4 += ps + ps2;
<br>
38 //assert that area of result is equal to sum of areas
<br>
39 //of input geometry minus the area of overlap between inputs
<br>
40 assert(area(ps4) == area(ps) + area(ps2) - area(ps3));
<br>
42 //I don't even see the code anymore, all
<br>
43 //I see is bounding box...interval...triangle
<br>
45 //lets try that again in slow motion shall we?
<br>
46 assert(equivalence((ps + ps2) - (ps * ps2), ps ^ ps2));
<br>
48 //hmm, subtracting the intersection from the union
<br>
49 //is equivalent to the xor, all this in one line of code,
<br>
50 //now we're programming in bullet time
<br>
51 //(by the way, xor is implemented as one pass, not
52 composition)
<br>
54 //just for fun
<br>
55 rectangle_data
<int
> rect;
<br>
56 assert(extents(rect, ps ^ ps2));
<br>
57 assert(area(rect) ==
225);
<br>
58 assert(area(rect ^ (ps ^ ps2)) == area(rect) - area(ps ^ ps2));
<br>
59 return
0;
<br>}
<br>
60 <br>//Now you know how to use the polygon set concept with library polygons
<br>
64 <table class=
"docinfo" rules=
"none" frame=
"void" id=
"table1">
66 <col class=
"docinfo-name"><col class=
"docinfo-content">
70 <th class=
"docinfo-name">Copyright:
</th>
71 <td>Copyright © Intel Corporation
2008-
2010.
</td>
74 <th class=
"docinfo-name">License:
</th>
75 <td class=
"field-body">Distributed under the Boost Software License,
76 Version
1.0. (See accompanying file
<tt class=
"literal">
77 <span class=
"pre">LICENSE_1_0.txt
</span></tt> or copy at
78 <a class=
"reference" target=
"_top" href=
"http://www.boost.org/LICENSE_1_0.txt">
79 http://www.boost.org/LICENSE_1_0.txt
</a>)
</td>