/Src/Dependencies/Boost/libs/geometry/test/algorithms/convert.cpp

http://hadesmem.googlecode.com/ · C++ · 108 lines · 70 code · 26 blank · 12 comment · 0 complexity · 20190166e65b6555f09cf5a508512818 MD5 · raw file

  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
  6. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #include <geometry_test_common.hpp>
  12. #include <boost/geometry/algorithms/assign.hpp>
  13. #include <boost/geometry/algorithms/convert.hpp>
  14. #include <boost/geometry/algorithms/make.hpp>
  15. #include <boost/geometry/algorithms/num_points.hpp>
  16. #include <boost/geometry/geometries/geometries.hpp>
  17. #include <boost/geometry/geometries/adapted/c_array.hpp>
  18. #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
  19. #include <test_common/test_point.hpp>
  20. BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
  21. BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
  22. template <typename P>
  23. void test_all()
  24. {
  25. typedef bg::model::box<P> box_type;
  26. P p;
  27. bg::assign_values(p, 1, 2);
  28. box_type b;
  29. bg::convert(p, b);
  30. BOOST_CHECK_CLOSE((bg::get<0, 0>(b)), 1.0, 0.001);
  31. BOOST_CHECK_CLOSE((bg::get<0, 1>(b)), 2.0, 0.001);
  32. BOOST_CHECK_CLOSE((bg::get<1, 0>(b)), 1.0, 0.001);
  33. BOOST_CHECK_CLOSE((bg::get<1, 1>(b)), 2.0, 0.001);
  34. }
  35. template <typename P>
  36. void test_std()
  37. {
  38. test_all<P>();
  39. typedef bg::model::box<P> box_type;
  40. typedef bg::model::ring<P> ring_type;
  41. typedef bg::model::polygon<P> polygon_type;
  42. box_type b;
  43. bg::set<bg::min_corner, 0>(b, 1);
  44. bg::set<bg::min_corner, 1>(b, 2);
  45. bg::set<bg::max_corner, 0>(b, 3);
  46. bg::set<bg::max_corner, 1>(b, 4);
  47. ring_type ring;
  48. bg::convert(b, ring);
  49. //std::cout << bg::wkt(b) << std::endl;
  50. //std::cout << bg::wkt(ring) << std::endl;
  51. typename boost::range_const_iterator<ring_type>::type it = ring.begin();
  52. BOOST_CHECK_CLOSE(bg::get<0>(*it), 1.0, 0.001);
  53. BOOST_CHECK_CLOSE(bg::get<1>(*it), 2.0, 0.001);
  54. it++;
  55. BOOST_CHECK_CLOSE(bg::get<0>(*it), 1.0, 0.001);
  56. BOOST_CHECK_CLOSE(bg::get<1>(*it), 4.0, 0.001);
  57. it++;
  58. BOOST_CHECK_CLOSE(bg::get<0>(*it), 3.0, 0.001);
  59. BOOST_CHECK_CLOSE(bg::get<1>(*it), 4.0, 0.001);
  60. it++;
  61. BOOST_CHECK_CLOSE(bg::get<0>(*it), 3.0, 0.001);
  62. BOOST_CHECK_CLOSE(bg::get<1>(*it), 2.0, 0.001);
  63. it++;
  64. BOOST_CHECK_CLOSE(bg::get<0>(*it), 1.0, 0.001);
  65. BOOST_CHECK_CLOSE(bg::get<1>(*it), 2.0, 0.001);
  66. BOOST_CHECK_EQUAL(ring.size(), 5u);
  67. polygon_type polygon;
  68. bg::convert(ring, polygon);
  69. BOOST_CHECK_EQUAL(bg::num_points(polygon), 5u);
  70. bg::convert(polygon, ring);
  71. BOOST_CHECK_EQUAL(bg::num_points(ring), 5u);
  72. }
  73. int test_main(int, char* [])
  74. {
  75. test_std<bg::model::point<int, 2, bg::cs::cartesian> >();
  76. test_std<bg::model::point<float, 2, bg::cs::cartesian> >();
  77. test_std<bg::model::point<double, 2, bg::cs::cartesian> >();
  78. #ifdef HAVE_TTMATH
  79. test_std<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >();
  80. #endif
  81. return 0;
  82. }