]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <html> |
2 | ||
3 | <head> | |
4 | <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> | |
5 | <title>Polygon Set Usage</title> | |
6 | </head> | |
7 | ||
8 | <body> | |
9 | ||
10 | <p><font face="Courier New">/*<br> | |
11 | Copyright 2008 Intel Corporation<br> | |
12 | <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> | |
16 | */<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> | |
26 | <br> | |
27 | //lets put some data in<br> | |
28 | ps += rectangle_data<int>(0, 0, 10, 10);<br> | |
29 | <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> | |
37 | <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> | |
41 | <br> | |
42 | //I don't even see the code anymore, all<br> | |
43 | //I see is bounding box...interval...triangle<br> | |
44 | <br> | |
45 | //lets try that again in slow motion shall we?<br> | |
46 | assert(equivalence((ps + ps2) - (ps * ps2), ps ^ ps2));<br> | |
47 | <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> | |
53 | <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> | |
61 | </font></p> | |
62 | ||
63 | ||
64 | <table class="docinfo" rules="none" frame="void" id="table1"> | |
65 | <colgroup> | |
66 | <col class="docinfo-name"><col class="docinfo-content"> | |
67 | </colgroup> | |
68 | <tbody vAlign="top"> | |
69 | <tr> | |
70 | <th class="docinfo-name">Copyright:</th> | |
71 |