for_each.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #include <algorithms/test_for_each.hpp>
  8. #include <boost/geometry/geometries/geometries.hpp>
  9. template <typename P>
  10. void test_all()
  11. {
  12. test_geometry<P>
  13. (
  14. "POINT(1 1)"
  15. // per point
  16. , 1
  17. , "POINT(101 1)"
  18. , "POINT(101 100)"
  19. // per segment
  20. , ""
  21. , 0
  22. , "POINT(1 1)"
  23. );
  24. test_geometry<bg::model::linestring<P> >
  25. (
  26. "LINESTRING(1 1,2 2)"
  27. , 3
  28. , "LINESTRING(101 1,102 2)"
  29. , "LINESTRING(101 100,102 200)"
  30. , "((1, 1), (2, 2))"
  31. , std::sqrt(2.0)
  32. , "LINESTRING(10 1,2 2)"
  33. );
  34. test_geometry<bg::model::linestring<P> >
  35. (
  36. "LINESTRING EMPTY"
  37. , 0
  38. , "LINESTRING()"
  39. , "LINESTRING()"
  40. , ""
  41. , 0
  42. , "LINESTRING()"
  43. );
  44. test_geometry<bg::model::ring<P> >
  45. (
  46. "POLYGON((1 1,1 4,4 4,4 1,1 1))"
  47. , 11
  48. , "POLYGON((101 1,101 4,104 4,104 1,101 1))"
  49. , "POLYGON((101 100,101 400,104 400,104 100,101 100))"
  50. , "((1, 1), (1, 4)) ((1, 4), (4, 4)) ((4, 4), (4, 1)) ((4, 1), (1, 1))"
  51. , 4 * 3.0
  52. , "POLYGON((10 1,10 4,4 4,4 1,1 1))"
  53. );
  54. test_geometry<bg::model::ring<P> >
  55. (
  56. "POLYGON EMPTY"
  57. , 0
  58. , "POLYGON(())"
  59. , "POLYGON(())"
  60. , ""
  61. , 0
  62. , "POLYGON(())"
  63. );
  64. test_geometry<bg::model::ring<P, true, false> > // open ring
  65. (
  66. "POLYGON((1 1,1 4,4 4,4 1))"
  67. , 10
  68. , "POLYGON((101 1,101 4,104 4,104 1))"
  69. , "POLYGON((101 100,101 400,104 400,104 100))"
  70. , "((1, 1), (1, 4)) ((1, 4), (4, 4)) ((4, 4), (4, 1)) ((4, 1), (1, 1))"
  71. , 4 * 3.0
  72. , "POLYGON((10 1,10 4,4 4,4 1))"
  73. );
  74. test_geometry<bg::model::polygon<P> >
  75. (
  76. "POLYGON((1 1,1 4,4 4,4 1,1 1),(2 2,3 2,3 3,2 3,2 2))"
  77. , 23
  78. , "POLYGON((101 1,101 4,104 4,104 1,101 1),(102 2,103 2,103 3,102 3,102 2))"
  79. , "POLYGON((101 100,101 400,104 400,104 100,101 100),(102 200,103 200,103 300,102 300,102 200))"
  80. , "((1, 1), (1, 4)) ((1, 4), (4, 4)) ((4, 4), (4, 1)) ((4, 1), (1, 1)) "
  81. "((2, 2), (3, 2)) ((3, 2), (3, 3)) ((3, 3), (2, 3)) ((2, 3), (2, 2))"
  82. , 4 * 3.0 + 4 * 1.0
  83. , "POLYGON((10 1,10 4,4 4,4 1,1 1,10 1),(2 2,3 2,3 3,2 3,2 2))"
  84. );
  85. test_geometry<bg::model::polygon<P, true, false> > // open polygon
  86. (
  87. "POLYGON((1 1,1 4,4 4,4 1),(2 2,3 2,3 3,2 3))"
  88. , 20
  89. , "POLYGON((101 1,101 4,104 4,104 1,101 1),(102 2,103 2,103 3,102 3,102 2))"
  90. , "POLYGON((101 100,101 400,104 400,104 100,101 100),(102 200,103 200,103 300,102 300,102 200))"
  91. , "((1, 1), (1, 4)) ((1, 4), (4, 4)) ((4, 4), (4, 1)) ((4, 1), (1, 1)) "
  92. "((2, 2), (3, 2)) ((3, 2), (3, 3)) ((3, 3), (2, 3)) ((2, 3), (2, 2))"
  93. , 4 * 3.0 + 4 * 1.0
  94. , "POLYGON((10 1,10 4,4 4,4 1,10 1),(2 2,3 2,3 3,2 3,2 2))"
  95. );
  96. }
  97. int test_main(int, char* [])
  98. {
  99. test_all<bg::model::point<double, 2, bg::cs::cartesian> >();
  100. #if defined(HAVE_TTMATH)
  101. test_all<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >();
  102. #endif
  103. return 0;
  104. }