debug_print_boundary_points.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2015, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_DEBUG_PRINT_BOUNDARY_POINTS_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_DEBUG_PRINT_BOUNDARY_POINTS_HPP
  8. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  9. #include <algorithm>
  10. #include <iostream>
  11. #include <vector>
  12. #include <boost/range.hpp>
  13. #include <boost/geometry/core/point_type.hpp>
  14. #include <boost/geometry/core/tag.hpp>
  15. #include <boost/geometry/core/tags.hpp>
  16. #include <boost/geometry/util/range.hpp>
  17. #include <boost/geometry/io/dsv/write.hpp>
  18. #include <boost/geometry/policies/compare.hpp>
  19. #include <boost/geometry/algorithms/equals.hpp>
  20. #include <boost/geometry/algorithms/not_implemented.hpp>
  21. #endif // BOOST_GEOMETRY_TEST_DEBUG
  22. namespace boost { namespace geometry
  23. {
  24. namespace detail { namespace is_simple
  25. {
  26. #ifdef BOOST_GEOMETRY_TEST_DEBUG
  27. template <typename Linear, typename Tag = typename tag<Linear>::type>
  28. struct debug_boundary_points_printer
  29. : not_implemented<Linear>
  30. {};
  31. template <typename Linestring>
  32. struct debug_boundary_points_printer<Linestring, linestring_tag>
  33. {
  34. static inline void apply(Linestring const& linestring)
  35. {
  36. std::cout << "boundary points: ";
  37. std::cout << " " << geometry::dsv(range::front(linestring));
  38. std::cout << " " << geometry::dsv(range::back(linestring));
  39. std::cout << std::endl << std::endl;
  40. }
  41. };
  42. template <typename MultiLinestring>
  43. struct debug_boundary_points_printer<MultiLinestring, multi_linestring_tag>
  44. {
  45. static inline void apply(MultiLinestring const& multilinestring)
  46. {
  47. typedef typename point_type<MultiLinestring>::type point_type;
  48. typedef std::vector<point_type> point_vector;
  49. point_vector boundary_points;
  50. for (typename boost::range_iterator<MultiLinestring const>::type it
  51. = boost::begin(multilinestring);
  52. it != boost::end(multilinestring); ++it)
  53. {
  54. if ( boost::size(*it) > 1
  55. && !geometry::equals(range::front(*it), range::back(*it)) )
  56. {
  57. boundary_points.push_back( range::front(*it) );
  58. boundary_points.push_back( range::back(*it) );
  59. }
  60. }
  61. std::sort(boundary_points.begin(), boundary_points.end(),
  62. geometry::less<point_type>());
  63. std::cout << "boundary points: ";
  64. for (typename point_vector::const_iterator
  65. pit = boundary_points.begin();
  66. pit != boundary_points.end(); ++pit)
  67. {
  68. std::cout << " " << geometry::dsv(*pit);
  69. }
  70. std::cout << std::endl << std::endl;
  71. }
  72. };
  73. template <typename Linear>
  74. inline void debug_print_boundary_points(Linear const& linear)
  75. {
  76. debug_boundary_points_printer<Linear>::apply(linear);
  77. }
  78. #else
  79. template <typename Linear>
  80. inline void debug_print_boundary_points(Linear const&)
  81. {
  82. }
  83. #endif // BOOST_GEOMETRY_TEST_DEBUG
  84. }} // namespace detail::is_simple
  85. }} // namespace boost::geometry
  86. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_DEBUG_PRINT_BOUNDARY_POINTS_HPP