print_turns.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2020, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_PRINT_TURNS_HPP
  8. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_PRINT_TURNS_HPP
  9. #include <algorithm>
  10. #include <iostream>
  11. #include <boost/range/begin.hpp>
  12. #include <boost/range/end.hpp>
  13. #include <boost/geometry/algorithms/detail/overlay/traversal_info.hpp>
  14. #include <boost/geometry/algorithms/detail/overlay/turn_info.hpp>
  15. #include <boost/geometry/algorithms/detail/overlay/debug_turn_info.hpp>
  16. #include <boost/geometry/io/wkt/write.hpp>
  17. #include <boost/geometry/io/dsv/write.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. namespace detail { namespace turns
  21. {
  22. struct turn_printer
  23. {
  24. turn_printer(std::ostream & os)
  25. : index(0)
  26. , out(os)
  27. {}
  28. template <typename Turn>
  29. void operator()(Turn const& turn)
  30. {
  31. out << index
  32. << ": " << geometry::method_char(turn.method);
  33. if ( turn.discarded )
  34. out << " (discarded)\n";
  35. else if ( turn.blocked() )
  36. out << " (blocked)\n";
  37. else
  38. out << '\n';
  39. double fraction[2];
  40. fraction[0] = turn.operations[0].fraction.numerator()
  41. / turn.operations[0].fraction.denominator();
  42. out << geometry::operation_char(turn.operations[0].operation)
  43. <<": seg: " << turn.operations[0].seg_id.source_index
  44. << ", m: " << turn.operations[0].seg_id.multi_index
  45. << ", r: " << turn.operations[0].seg_id.ring_index
  46. << ", s: " << turn.operations[0].seg_id.segment_index;
  47. out << ", fr: " << fraction[0];
  48. out << ", col?: " << turn.operations[0].is_collinear;
  49. out << ' ' << geometry::dsv(turn.point) << ' ';
  50. out << '\n';
  51. fraction[1] = turn.operations[1].fraction.numerator()
  52. / turn.operations[1].fraction.denominator();
  53. out << geometry::operation_char(turn.operations[1].operation)
  54. << ": seg: " << turn.operations[1].seg_id.source_index
  55. << ", m: " << turn.operations[1].seg_id.multi_index
  56. << ", r: " << turn.operations[1].seg_id.ring_index
  57. << ", s: " << turn.operations[1].seg_id.segment_index;
  58. out << ", fr: " << fraction[1];
  59. out << ", col?: " << turn.operations[1].is_collinear;
  60. out << ' ' << geometry::dsv(turn.point) << ' ';
  61. ++index;
  62. out << std::endl;
  63. }
  64. int index;
  65. std::ostream & out;
  66. };
  67. template <typename Geometry1, typename Geometry2, typename Turns>
  68. static inline void print_turns(Geometry1 const& g1,
  69. Geometry2 const& g2,
  70. Turns const& turns)
  71. {
  72. std::cout << geometry::wkt(g1) << std::endl;
  73. std::cout << geometry::wkt(g2) << std::endl;
  74. std::for_each(boost::begin(turns), boost::end(turns), turn_printer(std::cout));
  75. }
  76. }} // namespace detail::turns
  77. }} // namespace boost::geometry
  78. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_PRINT_TURNS_HPP