test_convert.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 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. #ifndef BOOST_GEOMETRY_TEST_CONVERT_HPP
  8. #define BOOST_GEOMETRY_TEST_CONVERT_HPP
  9. #include <boost/geometry/algorithms/assign.hpp>
  10. #include <boost/geometry/algorithms/convert.hpp>
  11. #include <boost/geometry/algorithms/make.hpp>
  12. #include <boost/geometry/algorithms/num_points.hpp>
  13. #include <boost/geometry/io/wkt/wkt.hpp>
  14. #include <boost/geometry/geometries/geometries.hpp>
  15. #include <boost/geometry/geometries/adapted/c_array.hpp>
  16. #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
  17. #include <boost/variant/variant.hpp>
  18. #include <geometry_test_common.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 Geometry2, typename Geometry1>
  23. void check_mixed(Geometry1 const& geometry1, std::string const& expected, int expected_point_count)
  24. {
  25. Geometry2 geometry2;
  26. bg::convert(geometry1, geometry2);
  27. std::ostringstream out;
  28. out << bg::wkt(geometry2);
  29. BOOST_CHECK_EQUAL(out.str(), expected);
  30. std::size_t n = bg::num_points(geometry2);
  31. BOOST_CHECK_MESSAGE(expected_point_count < 0 || int(n) == expected_point_count,
  32. "convert: "
  33. << " #points expected: " << expected_point_count
  34. << " detected: " << n
  35. << " expected wkt: " << expected
  36. );
  37. }
  38. template <typename Geometry1, typename Geometry2>
  39. void test_mixed(std::string const& wkt, std::string const& expected, int expected_point_count)
  40. {
  41. Geometry1 geometry1;
  42. bg::read_wkt(wkt, geometry1);
  43. check_mixed<Geometry2>(geometry1, expected, expected_point_count);
  44. check_mixed<Geometry2>(boost::variant<Geometry1>(geometry1), expected, expected_point_count);
  45. }
  46. template <typename Geometry1, typename Geometry2>
  47. void test_mixed_identical_result(std::string const& wkt)
  48. {
  49. test_mixed<Geometry1, Geometry2>(wkt, wkt, -1);
  50. test_mixed<Geometry2, Geometry1>(wkt, wkt, -1);
  51. }
  52. template <typename Geometry1, typename Geometry2>
  53. void test_mixed_reversible_result(std::string const& wkt1, std::string const& wkt2)
  54. {
  55. test_mixed<Geometry1, Geometry2>(wkt1, wkt2, -1);
  56. test_mixed<Geometry2, Geometry1>(wkt2, wkt1, -1);
  57. }
  58. #endif