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

http://hadesmem.googlecode.com/ · C++ · 51 lines · 19 code · 14 blank · 18 comment · 0 complexity · add59e807f6e569efb7e864271910527 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. //[make_with_range
  8. //` Using make to construct a linestring with two different range types
  9. #include <iostream>
  10. #include <boost/geometry.hpp>
  11. #include <boost/geometry/geometries/linestring.hpp>
  12. #include <boost/geometry/geometries/point_xy.hpp>
  13. #include <boost/geometry/geometries/adapted/c_array.hpp>
  14. BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) /*< Necessary to register a C array like {1,2} as a point >*/
  15. int main()
  16. {
  17. using boost::geometry::make;
  18. using boost::geometry::detail::make::make_points;
  19. typedef boost::geometry::model::d2::point_xy<double> point;
  20. typedef boost::geometry::model::linestring<point> linestring;
  21. double coordinates[][2] = {{1,2}, {3,4}, {5, 6}}; /*< Initialize with C array points >*/
  22. linestring ls = make_points<linestring>(coordinates);
  23. std::cout << boost::geometry::dsv(ls) << std::endl;
  24. point points[3] = { make<point>(9,8), make<point>(7,6), make<point>(5,4) }; /*< Construct array with points, using make which should work for any point type >*/
  25. std::cout << boost::geometry::dsv(make_points<linestring>(points)) << std::endl; /*< Construct linestring with point-array and output it as Delimiter Separated Values >*/
  26. return 0;
  27. }
  28. //]
  29. //[make_with_range_output
  30. /*`
  31. Output:
  32. [pre
  33. ((1, 2), (3, 4), (5, 6))
  34. ((9, 8), (7, 6), (5, 4))
  35. ]
  36. */
  37. //]