convert_multi.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. //
  3. // Copyright (c) 2007-2015 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. #include <algorithms/test_convert.hpp>
  8. template <typename Point1, typename Point2>
  9. void test_mixed_point_types()
  10. {
  11. test_mixed_identical_result
  12. <
  13. bg::model::multi_point<Point1>,
  14. bg::model::multi_point<Point2>
  15. >
  16. ("MULTIPOINT((1 1),(2 2),(3 3))");
  17. test_mixed_identical_result
  18. <
  19. bg::model::multi_linestring<bg::model::linestring<Point1> >,
  20. bg::model::multi_linestring<bg::model::linestring<Point2> >
  21. >
  22. ("MULTILINESTRING((1 1,2 2),(3 3,4 4))");
  23. // Single -> multi (always possible)
  24. test_mixed
  25. <
  26. Point1, bg::model::multi_point<Point2>
  27. >
  28. (
  29. "POINT(1 1)",
  30. "MULTIPOINT((1 1))",
  31. 1
  32. );
  33. test_mixed
  34. <
  35. bg::model::linestring<Point1>,
  36. bg::model::multi_linestring<bg::model::linestring<Point2> >
  37. >
  38. (
  39. "LINESTRING(1 1,2 2)",
  40. "MULTILINESTRING((1 1,2 2))",
  41. 2
  42. );
  43. test_mixed
  44. <
  45. bg::model::segment<Point1>,
  46. bg::model::multi_linestring<bg::model::linestring<Point2> >
  47. >
  48. (
  49. "LINESTRING(1 1,2 2)",
  50. "MULTILINESTRING((1 1,2 2))",
  51. 2
  52. );
  53. test_mixed
  54. <
  55. bg::model::box<Point1>,
  56. bg::model::multi_polygon<bg::model::polygon<Point2> >
  57. >
  58. (
  59. "BOX(0 0,1 1)",
  60. "MULTIPOLYGON(((0 0,0 1,1 1,1 0,0 0)))",
  61. 5
  62. );
  63. test_mixed
  64. <
  65. bg::model::ring<Point1, true>,
  66. bg::model::multi_polygon<bg::model::polygon<Point2, false> >
  67. >
  68. (
  69. "POLYGON((0 0,0 1,1 1,1 0,0 0))",
  70. "MULTIPOLYGON(((0 0,1 0,1 1,0 1,0 0)))",
  71. 5
  72. );
  73. // Multi -> single: should not compile (because multi often have 0 or >1 elements)
  74. }
  75. template <typename Point1, typename Point2>
  76. void test_mixed_types()
  77. {
  78. test_mixed_point_types<Point1, Point2>();
  79. test_mixed_point_types<Point2, Point1>();
  80. }
  81. int test_main( int , char* [] )
  82. {
  83. test_mixed_types
  84. <
  85. bg::model::point<int, 2, bg::cs::cartesian>,
  86. bg::model::point<double, 2, bg::cs::cartesian>
  87. >();
  88. return 0;
  89. }