needs_self_turns.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2017-2017 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_DETAIL_OVERLAY_NEEDS_SELF_TURNS_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_NEEDS_SELF_TURNS_HPP
  8. #include <boost/range.hpp>
  9. #include <boost/geometry/core/tags.hpp>
  10. #include <boost/geometry/algorithms/num_interior_rings.hpp>
  11. namespace boost { namespace geometry
  12. {
  13. #ifndef DOXYGEN_NO_DETAIL
  14. namespace detail { namespace overlay
  15. {
  16. template
  17. <
  18. typename Geometry,
  19. typename Tag = typename tag<Geometry>::type
  20. >
  21. struct needs_self_turns
  22. {
  23. };
  24. template <typename Geometry>
  25. struct needs_self_turns<Geometry, box_tag>
  26. {
  27. static inline bool apply(Geometry const&)
  28. {
  29. return false;
  30. }
  31. };
  32. template <typename Geometry>
  33. struct needs_self_turns<Geometry, ring_tag>
  34. {
  35. static inline bool apply(Geometry const&)
  36. {
  37. return false;
  38. }
  39. };
  40. template <typename Geometry>
  41. struct needs_self_turns<Geometry, polygon_tag>
  42. {
  43. static inline bool apply(Geometry const& polygon)
  44. {
  45. return geometry::num_interior_rings(polygon) > 0;
  46. }
  47. };
  48. template <typename Geometry>
  49. struct needs_self_turns<Geometry, multi_polygon_tag>
  50. {
  51. static inline bool apply(Geometry const& multi)
  52. {
  53. typedef typename boost::range_value<Geometry>::type polygon_type;
  54. std::size_t const n = boost::size(multi);
  55. return n > 1 || (n == 1
  56. && needs_self_turns<polygon_type>
  57. ::apply(*boost::begin(multi)));
  58. }
  59. };
  60. }} // namespace detail::overlay
  61. #endif // DOXYGEN_NO_DETAIL
  62. }} // namespace boost::geometry
  63. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_NEEDS_SELF_TURNS_HPP