needs_self_turns.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2017-2017 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2020.
  4. // Modifications copyright (c) 2020 Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_NEEDS_SELF_TURNS_HPP
  10. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_NEEDS_SELF_TURNS_HPP
  11. #include <boost/range/begin.hpp>
  12. #include <boost/range/size.hpp>
  13. #include <boost/geometry/core/tags.hpp>
  14. #include <boost/geometry/algorithms/num_interior_rings.hpp>
  15. namespace boost { namespace geometry
  16. {
  17. #ifndef DOXYGEN_NO_DETAIL
  18. namespace detail { namespace overlay
  19. {
  20. template
  21. <
  22. typename Geometry,
  23. typename Tag = typename tag<Geometry>::type
  24. >
  25. struct needs_self_turns
  26. {
  27. };
  28. template <typename Geometry>
  29. struct needs_self_turns<Geometry, box_tag>
  30. {
  31. static inline bool apply(Geometry const&)
  32. {
  33. return false;
  34. }
  35. };
  36. template <typename Geometry>
  37. struct needs_self_turns<Geometry, ring_tag>
  38. {
  39. static inline bool apply(Geometry const&)
  40. {
  41. return false;
  42. }
  43. };
  44. template <typename Geometry>
  45. struct needs_self_turns<Geometry, polygon_tag>
  46. {
  47. static inline bool apply(Geometry const& polygon)
  48. {
  49. return geometry::num_interior_rings(polygon) > 0;
  50. }
  51. };
  52. template <typename Geometry>
  53. struct needs_self_turns<Geometry, multi_polygon_tag>
  54. {
  55. static inline bool apply(Geometry const& multi)
  56. {
  57. typedef typename boost::range_value<Geometry>::type polygon_type;
  58. std::size_t const n = boost::size(multi);
  59. return n > 1 || (n == 1
  60. && needs_self_turns<polygon_type>
  61. ::apply(*boost::begin(multi)));
  62. }
  63. };
  64. }} // namespace detail::overlay
  65. #endif // DOXYGEN_NO_DETAIL
  66. }} // namespace boost::geometry
  67. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_NEEDS_SELF_TURNS_HPP