boost-react-native-bundle
Version:
Boost library as in https://sourceforge.net/projects/boost/files/boost/1.57.0/
86 lines (78 loc) • 3.41 kB
HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Polygon Set Usage</title>
</head>
<body>
<p><font face="Courier New">/*<br>
Copyright 2008 Intel Corporation<br>
<br>
Use, modification and distribution are subject to the Boost Software License,<br>
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at<br>
http://www.boost.org/LICENSE_1_0.txt).<br>
*/<br>
#include <boost/polygon/polygon.hpp><br>
#include <cassert><br>
namespace gtl = boost::polygon;<br>
using namespace boost::polygon::operators;<br><br>
int main() {<br>
//lets declare ourselves a polygon set<br>
using namespace gtl; //because of operators<br>
typedef std::vector<polygon_data<int> > PolygonSet;<br>
PolygonSet ps;<br>
<br>
//lets put some data in<br>
ps += rectangle_data<int>(0, 0, 10, 10);<br>
<br>
//now lets do something interesting<br>
PolygonSet ps2;<br>
ps2 += rectangle_data<int>(5, 5, 15, 15);<br>
PolygonSet ps3;<br>
assign(ps3, ps * ps2); //woah, I just felt the room flex around me<br>
PolygonSet ps4;<br>
ps4 += ps + ps2;<br>
<br>
//assert that area of result is equal to sum of areas<br>
//of input geometry minus the area of overlap between inputs<br>
assert(area(ps4) == area(ps) + area(ps2) - area(ps3));<br>
<br>
//I don't even see the code anymore, all<br>
//I see is bounding box...interval...triangle<br>
<br>
//lets try that again in slow motion shall we?<br>
assert(equivalence((ps + ps2) - (ps * ps2), ps ^ ps2));<br>
<br>
//hmm, subtracting the intersection from the union<br>
//is equivalent to the xor, all this in one line of code,<br>
//now we're programming in bullet time<br>
//(by the way, xor is implemented as one pass, not
composition) <br>
<br>
//just for fun<br>
rectangle_data<int> rect;<br>
assert(extents(rect, ps ^ ps2));<br>
assert(area(rect) == 225);<br>
assert(area(rect ^ (ps ^ ps2)) == area(rect) - area(ps ^ ps2)); <br>
return 0;<br>}<br>
<br>//Now you know how to use the polygon set concept with library polygons<br>
</font></p>
<table class="docinfo" rules="none" frame="void" id="table1">
<colgroup>
<col class="docinfo-name"><col class="docinfo-content">
</colgroup>
<tbody vAlign="top">
<tr>
<th class="docinfo-name">Copyright:</th>
<td>Copyright � Intel Corporation 2008-2010.</td>
</tr>
<tr class="field">
<th class="docinfo-name">License:</th>
<td class="field-body">Distributed under the Boost Software License,
Version 1.0. (See accompanying file <tt class="literal">
<span class="pre">LICENSE_1_0.txt</span></tt> or copy at
<a class="reference" target="_top" href="http://www.boost.org/LICENSE_1_0.txt">
http://www.boost.org/LICENSE_1_0.txt</a>)</td>
</tr>
</table>
</body>
</html>