difference.hpp 4.8 KB

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