tupled.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Use, modification and distribution is subject to the Boost Software License,
  4. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_TUPLED_HPP
  7. #define BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_TUPLED_HPP
  8. #include <string>
  9. #include <boost/tuple/tuple.hpp>
  10. #include <boost/geometry/strategies/side_info.hpp>
  11. namespace boost { namespace geometry
  12. {
  13. namespace policies { namespace relate
  14. {
  15. // "tupled" to return intersection results together.
  16. // Now with two, with some meta-programming and derivations it can also be three (or more)
  17. template <typename Policy1, typename Policy2>
  18. struct segments_tupled
  19. {
  20. typedef boost::tuple
  21. <
  22. typename Policy1::return_type,
  23. typename Policy2::return_type
  24. > return_type;
  25. template <typename Segment1, typename Segment2, typename SegmentIntersectionInfo>
  26. static inline return_type segments_crosses(side_info const& sides,
  27. SegmentIntersectionInfo const& sinfo,
  28. Segment1 const& s1, Segment2 const& s2)
  29. {
  30. return boost::make_tuple
  31. (
  32. Policy1::segments_crosses(sides, sinfo, s1, s2),
  33. Policy2::segments_crosses(sides, sinfo, s1, s2)
  34. );
  35. }
  36. template <typename Segment1, typename Segment2, typename Ratio>
  37. static inline return_type segments_collinear(
  38. Segment1 const& segment1, Segment2 const& segment2,
  39. bool opposite,
  40. int pa1, int pa2, int pb1, int pb2,
  41. Ratio const& ra1, Ratio const& ra2,
  42. Ratio const& rb1, Ratio const& rb2)
  43. {
  44. return boost::make_tuple
  45. (
  46. Policy1::segments_collinear(segment1, segment2,
  47. opposite,
  48. pa1, pa2, pb1, pb2,
  49. ra1, ra2, rb1, rb2),
  50. Policy2::segments_collinear(segment1, segment2,
  51. opposite,
  52. pa1, pa2, pb1, pb2,
  53. ra1, ra2, rb1, rb2)
  54. );
  55. }
  56. template <typename Segment>
  57. static inline return_type degenerate(Segment const& segment,
  58. bool a_degenerate)
  59. {
  60. return boost::make_tuple
  61. (
  62. Policy1::degenerate(segment, a_degenerate),
  63. Policy2::degenerate(segment, a_degenerate)
  64. );
  65. }
  66. template <typename Segment, typename Ratio>
  67. static inline return_type one_degenerate(Segment const& segment,
  68. Ratio const& ratio,
  69. bool a_degenerate)
  70. {
  71. return boost::make_tuple
  72. (
  73. Policy1::one_degenerate(segment, ratio, a_degenerate),
  74. Policy2::one_degenerate(segment, ratio, a_degenerate)
  75. );
  76. }
  77. static inline return_type disjoint()
  78. {
  79. return boost::make_tuple
  80. (
  81. Policy1::disjoint(),
  82. Policy2::disjoint()
  83. );
  84. }
  85. static inline return_type error(std::string const& msg)
  86. {
  87. return boost::make_tuple
  88. (
  89. Policy1::error(msg),
  90. Policy2::error(msg)
  91. );
  92. }
  93. };
  94. }} // namespace policies::relate
  95. }} // namespace boost::geometry
  96. #endif // BOOST_GEOMETRY_GEOMETRY_POLICIES_RELATE_TUPLED_HPP