/Src/Dependencies/Boost/libs/geometry/doc/src/examples/algorithms/transform_with_strategy.cpp

http://hadesmem.googlecode.com/ · C++ · 63 lines · 24 code · 16 blank · 23 comment · 0 complexity · bdf4919697cfbda3dc52d731f157cd5a MD5 · raw file

  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // QuickBook Example
  3. // Copyright (c) 2011 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //[transform_with_strategy
  8. //` Shows how points can be scaled, translated or rotated
  9. #include <iostream>
  10. #include <boost/geometry.hpp>
  11. int main()
  12. {
  13. namespace trans = boost::geometry::strategy::transform;
  14. using boost::geometry::dsv;
  15. typedef boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> point_type;
  16. point_type p1(1.0, 1.0);
  17. // Translate over (1.5, 1.5)
  18. point_type p2;
  19. trans::translate_transformer<point_type, point_type> translate(1.5, 1.5);
  20. boost::geometry::transform(p1, p2, translate);
  21. // Scale with factor 3.0
  22. point_type p3;
  23. trans::scale_transformer<point_type, point_type> scale(3.0);
  24. boost::geometry::transform(p1, p3, scale);
  25. // Rotate with respect to the origin (0,0) over 90 degrees (clockwise)
  26. point_type p4;
  27. trans::rotate_transformer<point_type, point_type, boost::geometry::degree> rotate(90.0);
  28. boost::geometry::transform(p1, p4, rotate);
  29. std::cout
  30. << "p1: " << dsv(p1) << std::endl
  31. << "p2: " << dsv(p2) << std::endl
  32. << "p3: " << dsv(p3) << std::endl
  33. << "p4: " << dsv(p4) << std::endl;
  34. return 0;
  35. }
  36. //]
  37. //[transform_with_strategy_output
  38. /*`
  39. Output:
  40. [pre
  41. p1: (1, 1)
  42. p2: (2.5, 2.5)
  43. p3: (3, 3)
  44. p4: (1, -1)
  45. ]
  46. */
  47. //]