append.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. // This file was modified by Oracle on 2014, 2015.
  7. // Modifications copyright (c) 2014-2015, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  9. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  10. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #include <deque>
  15. #include <vector>
  16. #include <boost/concept/requires.hpp>
  17. #include <geometry_test_common.hpp>
  18. #include <boost/geometry/core/access.hpp>
  19. #include <boost/geometry/core/point_type.hpp>
  20. #include <boost/geometry/core/tags.hpp>
  21. #include <boost/geometry/algorithms/make.hpp>
  22. #include <boost/geometry/algorithms/clear.hpp>
  23. #include <boost/geometry/algorithms/append.hpp>
  24. #include <boost/geometry/algorithms/num_points.hpp>
  25. #include <boost/geometry/geometries/geometries.hpp>
  26. #include <boost/geometry/geometries/concepts/check.hpp>
  27. #include <boost/geometry/geometries/register/linestring.hpp>
  28. #include <boost/variant/variant.hpp>
  29. #include <test_common/test_point.hpp>
  30. #include <test_geometries/wrapped_boost_array.hpp>
  31. BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::vector)
  32. BOOST_GEOMETRY_REGISTER_LINESTRING_TEMPLATED(std::deque)
  33. template <bool EnableAll>
  34. struct do_checks
  35. {
  36. template <typename G>
  37. static inline void apply(G const& geometry,
  38. std::size_t size1,
  39. std::size_t = 0,
  40. std::size_t = 0)
  41. {
  42. BOOST_CHECK_EQUAL(bg::num_points(geometry), size1);
  43. }
  44. };
  45. template<>
  46. struct do_checks<true>
  47. {
  48. template <typename G>
  49. static inline void apply(G const& geometry,
  50. std::size_t size1,
  51. std::size_t size2 = 0,
  52. std::size_t size3 = 0)
  53. {
  54. do_checks<false>::apply(geometry, size1);
  55. BOOST_CHECK_EQUAL(bg::num_points(geometry[0]), size2);
  56. BOOST_CHECK_EQUAL(bg::num_points(geometry[1]), size3);
  57. }
  58. };
  59. template <bool HasMultiIndex, bool IsVariant>
  60. struct test_geometry
  61. {
  62. template <typename G>
  63. static inline void apply(G& geometry, bool check)
  64. {
  65. typedef typename bg::point_type<G>::type P;
  66. typedef do_checks<HasMultiIndex && !IsVariant> checks;
  67. bg::append(geometry, bg::make_zero<P>(), -1, 0);
  68. if (check)
  69. {
  70. checks::apply(geometry, 1u, 1u, 0u);
  71. }
  72. // Append a range
  73. std::vector<P> v;
  74. v.push_back(bg::make_zero<P>());
  75. v.push_back(bg::make_zero<P>());
  76. bg::append(geometry, v, -1, 1);
  77. if (check)
  78. {
  79. checks::apply(geometry, 3u, 1u, 2u);
  80. }
  81. bg::clear(geometry);
  82. if (check)
  83. {
  84. do_checks<false>::apply(geometry, 0u);
  85. }
  86. }
  87. };
  88. template <typename G>
  89. void test_geometry_and_variant(bool check = true)
  90. {
  91. G geometry;
  92. boost::variant<G> variant_geometry = G();
  93. test_geometry<false, false>::apply(geometry, check);
  94. test_geometry<false, true>::apply(variant_geometry, check);
  95. }
  96. template <typename MG>
  97. void test_multigeometry_and_variant(bool check = true)
  98. {
  99. typedef typename boost::range_value<MG>::type G;
  100. G geometry;
  101. MG multigeometry;
  102. bg::traits::push_back<MG>::apply(multigeometry, geometry);
  103. bg::traits::push_back<MG>::apply(multigeometry, geometry);
  104. boost::variant<MG> variant_multigeometry = multigeometry;
  105. test_geometry<true, false>::apply(multigeometry, check);
  106. test_geometry<true, true>::apply(variant_multigeometry, check);
  107. }
  108. template <typename P>
  109. void test_all()
  110. {
  111. test_geometry_and_variant<P>(false);
  112. test_geometry_and_variant<bg::model::box<P> >(false);
  113. test_geometry_and_variant<bg::model::segment<P> >(false);
  114. test_geometry_and_variant<bg::model::linestring<P> >();
  115. test_geometry_and_variant<bg::model::ring<P> >();
  116. test_geometry_and_variant<bg::model::polygon<P> >();
  117. test_geometry_and_variant<bg::model::multi_point<P> >();
  118. test_multigeometry_and_variant
  119. <
  120. bg::model::multi_linestring<bg::model::linestring<P> >
  121. >();
  122. test_multigeometry_and_variant
  123. <
  124. bg::model::multi_polygon<bg::model::polygon<P> >
  125. >();
  126. test_geometry_and_variant<std::vector<P> >();
  127. test_geometry_and_variant<std::deque<P> >();
  128. }
  129. int test_main(int, char* [])
  130. {
  131. test_all<test::test_point>();
  132. test_all<bg::model::point<int, 2, bg::cs::cartesian> >();
  133. test_all<bg::model::point<float, 2, bg::cs::cartesian> >();
  134. test_all<bg::model::point<double, 2, bg::cs::cartesian> >();
  135. #ifdef HAVE_TTMATH
  136. test_all<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >();
  137. #endif
  138. return 0;
  139. }