gtl_polygon_usage.htm 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  4. <title>Polygon Usage</title>
  5. </head>
  6. <body>
  7. <p><font face="Courier New">/*<br>
  8. Copyright 2008 Intel Corporation<br>
  9. <br>
  10. Use, modification and distribution are subject to the Boost Software License,<br>
  11. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at<br>
  12. http://www.boost.org/LICENSE_1_0.txt).<br>
  13. */<br>
  14. #include &lt;boost/polygon/polygon.hpp&gt;<br>
  15. #include &lt;cassert&gt;<br>
  16. namespace gtl = boost::polygon;<br>
  17. using namespace boost::polygon::operators;<br><br>
  18. int main() {<br>
  19. &nbsp;&nbsp;&nbsp; //lets construct a 10x10 rectangle shaped polygon<br>
  20. &nbsp;&nbsp;&nbsp; typedef gtl::polygon_data&lt;int&gt; Polygon;<br>
  21. &nbsp;&nbsp;&nbsp; typedef gtl::polygon_traits&lt;Polygon&gt;::point_type Point;<br>
  22. &nbsp;&nbsp;&nbsp; Point pts[] = {gtl::construct&lt;Point&gt;(0, 0),<br>
  23. &nbsp;&nbsp;&nbsp; gtl::construct&lt;Point&gt;(10, 0),<br>
  24. &nbsp;&nbsp;&nbsp; gtl::construct&lt;Point&gt;(10, 10),<br>
  25. &nbsp;&nbsp;&nbsp; gtl::construct&lt;Point&gt;(0, 10) };<br>
  26. &nbsp;&nbsp;&nbsp; Polygon poly;<br>
  27. &nbsp;&nbsp;&nbsp; gtl::set_points(poly, pts, pts+4);<br>
  28. <br>
  29. &nbsp;&nbsp;&nbsp; //now lets see what we can do with this polygon<br>
  30. &nbsp;&nbsp;&nbsp; assert(gtl::area(poly) == 100.0f);<br>
  31. &nbsp;&nbsp;&nbsp; assert(gtl::contains(poly, gtl::construct&lt;Point&gt;(5, 5)));<br>
  32. &nbsp;&nbsp;&nbsp; assert(!gtl::contains(poly, gtl::construct&lt;Point&gt;(15, 5)));<br>
  33. &nbsp;&nbsp;&nbsp; gtl::rectangle_data&lt;int&gt; rect;<br>
  34. &nbsp;&nbsp;&nbsp; assert(gtl::extents(rect, poly)); //get bounding box of poly<br>
  35. &nbsp;&nbsp;&nbsp; assert(gtl::equivalence(rect, poly)); //hey, that's slick<br>
  36. &nbsp;&nbsp;&nbsp; assert(gtl::winding(poly) == gtl::COUNTERCLOCKWISE);<br>
  37. &nbsp;&nbsp;&nbsp; assert(gtl::perimeter(poly) == 40.0f);<br>
  38. <br>
  39. &nbsp;&nbsp;&nbsp; //add 5 to all coords of poly<br>
  40. &nbsp;&nbsp;&nbsp; gtl::convolve(poly, gtl::construct&lt;Point&gt;(5, 5));<br>
  41. &nbsp;&nbsp;&nbsp; //multiply all coords of poly by 2<br>
  42. &nbsp;&nbsp;&nbsp; gtl::scale_up(poly, 2);<br>
  43. &nbsp;&nbsp;&nbsp; gtl::set_points(rect, gtl::point_data&lt;int&gt;(10, 10),<br>
  44. &nbsp;&nbsp;&nbsp; gtl::point_data&lt;int&gt;(30, 30));<br>
  45. &nbsp;&nbsp;&nbsp; assert(gtl::equivalence(poly, rect));<br>
  46. &nbsp;&nbsp;&nbsp; return 0;<br>
  47. }<br>
  48. //Now you know how to use the built in polygon data type<br>
  49. &nbsp;</font></p>
  50. <table class="docinfo" rules="none" frame="void" id="table1">
  51. <colgroup>
  52. <col class="docinfo-name"><col class="docinfo-content">
  53. </colgroup>
  54. <tbody vAlign="top">
  55. <tr>
  56. <th class="docinfo-name">Copyright:</th>
  57. <td>Copyright © Intel Corporation 2008-2010.</td>
  58. </tr>
  59. <tr class="field">
  60. <th class="docinfo-name">License:</th>
  61. <td class="field-body">Distributed under the Boost Software License,
  62. Version 1.0. (See accompanying file <tt class="literal">
  63. <span class="pre">LICENSE_1_0.txt</span></tt> or copy at
  64. <a class="reference" target="_top" href="http://www.boost.org/LICENSE_1_0.txt">
  65. http://www.boost.org/LICENSE_1_0.txt</a>)</td>
  66. </tr>
  67. </table>
  68. </body>
  69. </html>