closure.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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_CLOSURE_HPP
  11. #define BOOST_GEOMETRY_CORE_CLOSURE_HPP
  12. #include <boost/mpl/assert.hpp>
  13. #include <boost/mpl/int.hpp>
  14. #include <boost/range.hpp>
  15. #include <boost/type_traits/remove_const.hpp>
  16. #include <boost/geometry/core/ring_type.hpp>
  17. #include <boost/geometry/core/tag.hpp>
  18. #include <boost/geometry/core/tags.hpp>
  19. namespace boost { namespace geometry
  20. {
  21. /*!
  22. \brief Enumerates options for defining if polygons are open or closed
  23. \ingroup enum
  24. \details The enumeration closure_selector describes options for if a polygon is
  25. open or closed. In a closed polygon the very first point (per ring) should
  26. be equal to the very last point.
  27. The specific closing property of a polygon type is defined by the closure
  28. metafunction. The closure metafunction defines a value, which is one of the
  29. values enumerated in the closure_selector
  30. \qbk{
  31. [heading See also]
  32. [link geometry.reference.core.closure The closure metafunction]
  33. }
  34. */
  35. enum closure_selector
  36. {
  37. /// Rings are open: first point and last point are different, algorithms
  38. /// close them explicitly on the fly
  39. open = 0,
  40. /// Rings are closed: first point and last point must be the same
  41. closed = 1,
  42. /// (Not yet implemented): algorithms first figure out if ring must be
  43. /// closed on the fly
  44. closure_undertermined = -1
  45. };
  46. namespace traits
  47. {
  48. /*!
  49. \brief Traits class indicating if points within a
  50. ring or (multi)polygon are closed (last point == first point),
  51. open or not known.
  52. \ingroup traits
  53. \par Geometries:
  54. - ring
  55. \tparam G geometry
  56. */
  57. template <typename G>
  58. struct closure
  59. {
  60. static const closure_selector value = closed;
  61. };
  62. } // namespace traits
  63. #ifndef DOXYGEN_NO_DETAIL
  64. namespace core_detail { namespace closure
  65. {
  66. struct closed
  67. {
  68. static const closure_selector value = geometry::closed;
  69. };
  70. /// Metafunction to define the minimum size of a ring:
  71. /// 3 for open rings, 4 for closed rings
  72. template <closure_selector Closure>
  73. struct minimum_ring_size {};
  74. template <>
  75. struct minimum_ring_size<geometry::closed> : boost::mpl::int_<4> {};
  76. template <>
  77. struct minimum_ring_size<geometry::open> : boost::mpl::int_<3> {};
  78. }} // namespace detail::point_order
  79. #endif // DOXYGEN_NO_DETAIL
  80. #ifndef DOXYGEN_NO_DISPATCH
  81. namespace core_dispatch
  82. {
  83. template <typename Tag, typename Geometry>
  84. struct closure
  85. {
  86. BOOST_MPL_ASSERT_MSG
  87. (
  88. false, NOT_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
  89. , (types<Geometry>)
  90. );
  91. };
  92. template <typename Box>
  93. struct closure<point_tag, Box> : public core_detail::closure::closed {};
  94. template <typename Box>
  95. struct closure<box_tag, Box> : public core_detail::closure::closed {};
  96. template <typename Box>
  97. struct closure<segment_tag, Box> : public core_detail::closure::closed {};
  98. template <typename LineString>
  99. struct closure<linestring_tag, LineString>
  100. : public core_detail::closure::closed {};
  101. template <typename Ring>
  102. struct closure<ring_tag, Ring>
  103. {
  104. static const closure_selector value
  105. = geometry::traits::closure<Ring>::value;
  106. };
  107. // Specialization for polygon: the closure is the closure of its rings
  108. template <typename Polygon>
  109. struct closure<polygon_tag, Polygon>
  110. {
  111. static const closure_selector value = core_dispatch::closure
  112. <
  113. ring_tag,
  114. typename ring_type<polygon_tag, Polygon>::type
  115. >::value ;
  116. };
  117. } // namespace core_dispatch
  118. #endif // DOXYGEN_NO_DISPATCH
  119. /*!
  120. \brief \brief_meta{value, closure (clockwise\, counterclockwise),
  121. \meta_geometry_type}
  122. \tparam Geometry \tparam_geometry
  123. \ingroup core
  124. \qbk{[include reference/core/closure.qbk]}
  125. */
  126. template <typename Geometry>
  127. struct closure
  128. {
  129. static const closure_selector value = core_dispatch::closure
  130. <
  131. typename tag<Geometry>::type,
  132. typename boost::remove_const<Geometry>::type
  133. >::value;
  134. };
  135. }} // namespace boost::geometry
  136. #endif // BOOST_GEOMETRY_CORE_CLOSURE_HPP