exterior_ring.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_CORE_EXTERIOR_RING_HPP
  11. #define BOOST_GEOMETRY_CORE_EXTERIOR_RING_HPP
  12. #include <boost/mpl/assert.hpp>
  13. #include <boost/type_traits/is_const.hpp>
  14. #include <boost/type_traits/remove_const.hpp>
  15. #include <boost/geometry/core/ring_type.hpp>
  16. #include <boost/geometry/core/tag.hpp>
  17. #include <boost/geometry/core/tags.hpp>
  18. #include <boost/geometry/util/add_const_if_c.hpp>
  19. namespace boost { namespace geometry
  20. {
  21. namespace traits
  22. {
  23. /*!
  24. \brief Traits class defining access to exterior_ring of a polygon
  25. \details Should define const and non const access
  26. \ingroup traits
  27. \tparam Polygon the polygon type
  28. \par Geometries:
  29. - polygon
  30. \par Specializations should provide:
  31. - static inline RING& get(POLY& )
  32. - static inline RING const& get(POLY const& )
  33. */
  34. template <typename Polygon>
  35. struct exterior_ring
  36. {
  37. BOOST_MPL_ASSERT_MSG
  38. (
  39. false, NOT_IMPLEMENTED_FOR_THIS_POLYGON_TYPE
  40. , (types<Polygon>)
  41. );
  42. };
  43. } // namespace traits
  44. #ifndef DOXYGEN_NO_DISPATCH
  45. namespace core_dispatch
  46. {
  47. template <typename Tag, typename Geometry>
  48. struct exterior_ring
  49. {
  50. BOOST_MPL_ASSERT_MSG
  51. (
  52. false, NOT_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
  53. , (types<Geometry>)
  54. );
  55. };
  56. template <typename Polygon>
  57. struct exterior_ring<polygon_tag, Polygon>
  58. {
  59. static
  60. typename geometry::ring_return_type<Polygon>::type
  61. apply(typename add_const_if_c
  62. <
  63. boost::is_const<Polygon>::type::value,
  64. Polygon
  65. >::type& polygon)
  66. {
  67. return traits::exterior_ring
  68. <
  69. typename boost::remove_const<Polygon>::type
  70. >::get(polygon);
  71. }
  72. };
  73. } // namespace core_dispatch
  74. #endif // DOXYGEN_NO_DISPATCH
  75. /*!
  76. \brief Function to get the exterior_ring ring of a polygon
  77. \ingroup exterior_ring
  78. \note OGC compliance: instead of ExteriorRing
  79. \tparam Polygon polygon type
  80. \param polygon the polygon to get the exterior ring from
  81. \return a reference to the exterior ring
  82. */
  83. template <typename Polygon>
  84. inline typename ring_return_type<Polygon>::type exterior_ring(Polygon& polygon)
  85. {
  86. return core_dispatch::exterior_ring
  87. <
  88. typename tag<Polygon>::type,
  89. Polygon
  90. >::apply(polygon);
  91. }
  92. /*!
  93. \brief Function to get the exterior ring of a polygon (const version)
  94. \ingroup exterior_ring
  95. \note OGC compliance: instead of ExteriorRing
  96. \tparam Polygon polygon type
  97. \param polygon the polygon to get the exterior ring from
  98. \return a const reference to the exterior ring
  99. \qbk{distinguish,const version}
  100. */
  101. template <typename Polygon>
  102. inline typename ring_return_type<Polygon const>::type exterior_ring(
  103. Polygon const& polygon)
  104. {
  105. return core_dispatch::exterior_ring
  106. <
  107. typename tag<Polygon>::type,
  108. Polygon const
  109. >::apply(polygon);
  110. }
  111. }} // namespace boost::geometry
  112. #endif // BOOST_GEOMETRY_CORE_EXTERIOR_RING_HPP