transform_multi.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2015 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 <iostream>
  12. #include <sstream>
  13. #include <geometry_test_common.hpp>
  14. #include <boost/geometry/algorithms/transform.hpp>
  15. #include <boost/geometry/strategies/strategies.hpp>
  16. #include <boost/geometry/geometries/geometries.hpp>
  17. #include <boost/geometry/geometries/point_xy.hpp>
  18. #include <boost/geometry/io/wkt/wkt.hpp>
  19. // This test is a little different from transform.cpp test.
  20. // This test explicitly tests all geometries, including multi*
  21. // while the transform.cpp tests various strategies.
  22. template <typename Geometry>
  23. void test_transform(std::string const& wkt, std::string const& expected)
  24. {
  25. typedef typename bg::coordinate_type<Geometry>::type coordinate_type;
  26. const std::size_t dim = bg::dimension<Geometry>::value;
  27. Geometry geometry_in, geometry_out;
  28. bg::read_wkt(wkt, geometry_in);
  29. bg::transform(geometry_in, geometry_out,
  30. bg::strategy::transform::scale_transformer<coordinate_type, dim, dim>(2, 2));
  31. std::ostringstream detected;
  32. detected << bg::wkt(geometry_out);
  33. BOOST_CHECK_EQUAL(detected.str(), expected);
  34. }
  35. template <typename T>
  36. void test_all()
  37. {
  38. typedef bg::model::d2::point_xy<T> P;
  39. test_transform<P>(
  40. "POINT(1 1)",
  41. "POINT(2 2)");
  42. test_transform<bg::model::linestring<P> >(
  43. "LINESTRING(1 1,2 2)",
  44. "LINESTRING(2 2,4 4)");
  45. test_transform<bg::model::segment<P> >(
  46. "LINESTRING(1 1,2 2)",
  47. "LINESTRING(2 2,4 4)");
  48. test_transform<bg::model::ring<P> >(
  49. "POLYGON((0 0,0 1,1 0,0 0))",
  50. "POLYGON((0 0,0 2,2 0,0 0))");
  51. test_transform<bg::model::polygon<P> >(
  52. "POLYGON((0 0,0 1,1 0,0 0))",
  53. "POLYGON((0 0,0 2,2 0,0 0))");
  54. test_transform<bg::model::box<P> >(
  55. "POLYGON((0 0,0 1,1 1,1 0,0 0))",
  56. "POLYGON((0 0,0 2,2 2,2 0,0 0))");
  57. test_transform<bg::model::multi_point<P> >(
  58. "MULTIPOINT((1 1),(2 2))",
  59. "MULTIPOINT((2 2),(4 4))");
  60. test_transform<bg::model::multi_linestring<bg::model::linestring<P> > >(
  61. "MULTILINESTRING((1 1,2 2))",
  62. "MULTILINESTRING((2 2,4 4))");
  63. test_transform<bg::model::multi_polygon<bg::model::polygon<P> > >(
  64. "MULTIPOLYGON(((0 0,0 1,1 0,0 0)))",
  65. "MULTIPOLYGON(((0 0,0 2,2 0,0 0)))");
  66. }
  67. int test_main(int, char* [])
  68. {
  69. test_all<double>();
  70. #ifdef HAVE_TTMATH
  71. test_all<ttmath_big>();
  72. #endif
  73. return 0;
  74. }