difference.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_ALGORITHMS_DIFFERENCE_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DIFFERENCE_HPP
  8. #include <algorithm>
  9. #include <boost/geometry/algorithms/detail/overlay/intersection_insert.hpp>
  10. namespace boost { namespace geometry
  11. {
  12. #ifndef DOXYGEN_NO_DETAIL
  13. namespace detail { namespace difference
  14. {
  15. /*!
  16. \brief_calc2{difference} \brief_strategy
  17. \ingroup difference
  18. \details \details_calc2{difference_insert, spatial set theoretic difference}
  19. \brief_strategy. \details_inserter{difference}
  20. \tparam GeometryOut output geometry type, must be specified
  21. \tparam Geometry1 \tparam_geometry
  22. \tparam Geometry2 \tparam_geometry
  23. \tparam OutputIterator output iterator
  24. \tparam Strategy \tparam_strategy_overlay
  25. \param geometry1 \param_geometry
  26. \param geometry2 \param_geometry
  27. \param out \param_out{difference}
  28. \param strategy \param_strategy{difference}
  29. \return \return_out
  30. \qbk{distinguish,with strategy}
  31. */
  32. template
  33. <
  34. typename GeometryOut,
  35. typename Geometry1,
  36. typename Geometry2,
  37. typename OutputIterator,
  38. typename Strategy
  39. >
  40. inline OutputIterator difference_insert(Geometry1 const& geometry1,
  41. Geometry2 const& geometry2, OutputIterator out,
  42. Strategy const& strategy)
  43. {
  44. concept::check<Geometry1 const>();
  45. concept::check<Geometry2 const>();
  46. concept::check<GeometryOut>();
  47. return geometry::dispatch::intersection_insert
  48. <
  49. Geometry1, Geometry2,
  50. GeometryOut,
  51. overlay_difference,
  52. geometry::detail::overlay::do_reverse<geometry::point_order<Geometry1>::value>::value,
  53. geometry::detail::overlay::do_reverse<geometry::point_order<Geometry2>::value, true>::value
  54. >::apply(geometry1, geometry2, out, strategy);
  55. }
  56. /*!
  57. \brief_calc2{difference}
  58. \ingroup difference
  59. \details \details_calc2{difference_insert, spatial set theoretic difference}.
  60. \details_insert{difference}
  61. \tparam GeometryOut output geometry type, must be specified
  62. \tparam Geometry1 \tparam_geometry
  63. \tparam Geometry2 \tparam_geometry
  64. \tparam OutputIterator output iterator
  65. \param geometry1 \param_geometry
  66. \param geometry2 \param_geometry
  67. \param out \param_out{difference}
  68. \return \return_out
  69. \qbk{[include reference/algorithms/difference_insert.qbk]}
  70. */
  71. template
  72. <
  73. typename GeometryOut,
  74. typename Geometry1,
  75. typename Geometry2,
  76. typename OutputIterator
  77. >
  78. inline OutputIterator difference_insert(Geometry1 const& geometry1,
  79. Geometry2 const& geometry2, OutputIterator out)
  80. {
  81. concept::check<Geometry1 const>();
  82. concept::check<Geometry2 const>();
  83. concept::check<GeometryOut>();
  84. typedef strategy_intersection
  85. <
  86. typename cs_tag<GeometryOut>::type,
  87. Geometry1,
  88. Geometry2,
  89. typename geometry::point_type<GeometryOut>::type
  90. > strategy;
  91. return difference_insert<GeometryOut>(geometry1, geometry2,
  92. out, strategy());
  93. }
  94. }} // namespace detail::difference
  95. #endif // DOXYGEN_NO_DETAIL
  96. /*!
  97. \brief_calc2{difference}
  98. \ingroup difference
  99. \details \details_calc2{difference, spatial set theoretic difference}.
  100. \tparam Geometry1 \tparam_geometry
  101. \tparam Geometry2 \tparam_geometry
  102. \tparam Collection \tparam_output_collection
  103. \param geometry1 \param_geometry
  104. \param geometry2 \param_geometry
  105. \param output_collection the output collection
  106. \qbk{[include reference/algorithms/difference.qbk]}
  107. */
  108. template
  109. <
  110. typename Geometry1,
  111. typename Geometry2,
  112. typename Collection
  113. >
  114. inline void difference(Geometry1 const& geometry1,
  115. Geometry2 const& geometry2, Collection& output_collection)
  116. {
  117. concept::check<Geometry1 const>();
  118. concept::check<Geometry2 const>();
  119. typedef typename boost::range_value<Collection>::type geometry_out;
  120. concept::check<geometry_out>();
  121. detail::difference::difference_insert<geometry_out>(
  122. geometry1, geometry2,
  123. std::back_inserter(output_collection));
  124. }
  125. }} // namespace boost::geometry
  126. #endif // BOOST_GEOMETRY_ALGORITHMS_DIFFERENCE_HPP