gtl_point_usage.htm 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  4. <title>Point 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; //constructing a gtl point<br>
  20. &nbsp; typedef gtl::point_data&lt;int&gt; Point;<br>
  21. &nbsp; int x = 10;<br>
  22. &nbsp; int y = 20;<br>
  23. &nbsp; Point pt(x, y);<br>
  24. &nbsp; assert(gtl::x(pt) == 10);<br>
  25. &nbsp; assert(gtl::y(pt) == 20);<br>
  26. &nbsp; <br>
  27. &nbsp; //a quick primer in isotropic point access<br>
  28. &nbsp; typedef gtl::orientation_2d O;<br>
  29. &nbsp; using gtl::HORIZONTAL;<br>
  30. &nbsp; using gtl::VERTICAL;<br>
  31. &nbsp; O o = HORIZONTAL;<br>
  32. &nbsp; assert(gtl::x(pt) == gtl::get(pt, o));<br>
  33. &nbsp; <br>
  34. &nbsp; o = o.get_perpendicular();<br>
  35. &nbsp; assert(o == VERTICAL);<br>
  36. &nbsp; assert(gtl::y(pt) == gtl::get(pt, o));<br>
  37. <br>
  38. &nbsp; gtl::set(pt, o, 30);<br>
  39. &nbsp; assert(gtl::y(pt) == 30);<br>
  40. <br>
  41. &nbsp; //using some of the library functions<br>
  42. &nbsp; Point pt2(10, 30);<br>
  43. &nbsp; assert(gtl::equivalence(pt, pt2));<br>
  44. <br>
  45. &nbsp; gtl::transformation&lt;int&gt; tr(gtl::axis_transformation::SWAP_XY);<br>
  46. &nbsp; gtl::transform(pt, tr);<br>
  47. &nbsp; assert(gtl::equivalence(pt, Point(30, 10)));<br>
  48. <br>
  49. &nbsp; gtl::transformation&lt;int&gt; tr2 = tr.inverse();<br>
  50. &nbsp; assert(tr == tr2); //SWAP_XY is its own inverse transform<br>
  51. <br>
  52. &nbsp; gtl::transform(pt, tr2);<br>
  53. &nbsp; assert(gtl::equivalence(pt, pt2)); //the two points are equal again<br>
  54. <br>
  55. &nbsp; gtl::move(pt, o, 10); //move pt 10 units in y<br>
  56. &nbsp; assert(gtl::euclidean_distance(pt, pt2) == 10.0f);<br>
  57. <br>
  58. &nbsp; gtl::move(pt, o.get_perpendicular(), 10); //move pt 10 units in x<br>
  59. &nbsp; assert(gtl::manhattan_distance(pt, pt2) == 20);<br>
  60. <br>
  61. &nbsp; return 0;<br>
  62. }<br>
  63. &nbsp;</font></p>
  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. <td>Copyright © Intel Corporation 2008-2010.</td>
  72. </tr>
  73. <tr class="field">
  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>
  80. </tr>
  81. </table>
  82. </body>
  83. </html>