closure.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. // This file was modified by Oracle on 2014.
  6. // Modifications copyright (c) 2014 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_CORE_CLOSURE_HPP
  14. #define BOOST_GEOMETRY_CORE_CLOSURE_HPP
  15. #include <boost/mpl/assert.hpp>
  16. #include <boost/mpl/size_t.hpp>
  17. #include <boost/range/value_type.hpp>
  18. #include <boost/geometry/core/ring_type.hpp>
  19. #include <boost/geometry/core/tag.hpp>
  20. #include <boost/geometry/core/tags.hpp>
  21. #include <boost/geometry/util/bare_type.hpp>
  22. namespace boost { namespace geometry
  23. {
  24. /*!
  25. \brief Enumerates options for defining if polygons are open or closed
  26. \ingroup enum
  27. \details The enumeration closure_selector describes options for if a polygon is
  28. open or closed. In a closed polygon the very first point (per ring) should
  29. be equal to the very last point.
  30. The specific closing property of a polygon type is defined by the closure
  31. metafunction. The closure metafunction defines a value, which is one of the
  32. values enumerated in the closure_selector
  33. \qbk{
  34. [heading See also]
  35. [link geometry.reference.core.closure The closure metafunction]
  36. }
  37. */
  38. enum closure_selector
  39. {
  40. /// Rings are open: first point and last point are different, algorithms
  41. /// close them explicitly on the fly
  42. open = 0,
  43. /// Rings are closed: first point and last point must be the same
  44. closed = 1,
  45. /// (Not yet implemented): algorithms first figure out if ring must be
  46. /// closed on the fly
  47. closure_undertermined = -1
  48. };
  49. namespace traits
  50. {
  51. /*!
  52. \brief Traits class indicating if points within a
  53. ring or (multi)polygon are closed (last point == first point),
  54. open or not known.
  55. \ingroup traits
  56. \par Geometries:
  57. - ring
  58. \tparam G geometry
  59. */
  60. template <typename G>
  61. struct closure
  62. {
  63. static const closure_selector value = closed;
  64. };
  65. } // namespace traits
  66. #ifndef DOXYGEN_NO_DETAIL
  67. namespace core_detail { namespace closure
  68. {
  69. struct closed
  70. {
  71. static const closure_selector value = geometry::closed;
  72. };
  73. /// Metafunction to define the minimum size of a ring:
  74. /// 3 for open rings, 4 for closed rings
  75. template <closure_selector Closure>
  76. struct minimum_ring_size {};
  77. template <>
  78. struct minimum_ring_size<geometry::closed> : boost::mpl::size_t<4> {};
  79. template <>
  80. struct minimum_ring_size<geometry::open> : boost::mpl::size_t<3> {};
  81. }} // namespace detail::point_order
  82. #endif // DOXYGEN_NO_DETAIL
  83. #ifndef DOXYGEN_NO_DISPATCH
  84. namespace core_dispatch
  85. {
  86. template <typename Tag, typename Geometry>
  87. struct closure
  88. {
  89. BOOST_MPL_ASSERT_MSG
  90. (
  91. false, NOT_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
  92. , (types<Geometry>)
  93. );
  94. };
  95. template <typename Box>
  96. struct closure<point_tag, Box> : public core_detail::closure::closed {};
  97. template <typename Box>
  98. struct closure<box_tag, Box> : public core_detail::closure::closed {};
  99. template <typename Box>
  100. struct closure<segment_tag, Box> : public core_detail::closure::closed {};
  101. template <typename LineString>
  102. struct closure<linestring_tag, LineString>
  103. : public core_detail::closure::closed {};
  104. template <typename Ring>
  105. struct closure<ring_tag, Ring>
  106. {
  107. static const closure_selector value
  108. = geometry::traits::closure<Ring>::value;
  109. };
  110. // Specialization for Polygon: the closure is the closure of its rings
  111. template <typename Polygon>
  112. struct closure<polygon_tag, Polygon>
  113. {
  114. static const closure_selector value = core_dispatch::closure
  115. <
  116. ring_tag,
  117. typename ring_type<polygon_tag, Polygon>::type
  118. >::value ;
  119. };
  120. template <typename MultiPoint>
  121. struct closure<multi_point_tag, MultiPoint>
  122. : public core_detail::closure::closed {};
  123. template <typename MultiLinestring>
  124. struct closure<multi_linestring_tag, MultiLinestring>
  125. : public core_detail::closure::closed {};
  126. // Specialization for MultiPolygon: the closure is the closure of Polygon's rings
  127. template <typename MultiPolygon>
  128. struct closure<multi_polygon_tag, MultiPolygon>
  129. {
  130. static const closure_selector value = core_dispatch::closure
  131. <
  132. polygon_tag,
  133. typename boost::range_value<MultiPolygon>::type
  134. >::value ;
  135. };
  136. } // namespace core_dispatch
  137. #endif // DOXYGEN_NO_DISPATCH
  138. /*!
  139. \brief \brief_meta{value, closure (clockwise\, counterclockwise),
  140. \meta_geometry_type}
  141. \tparam Geometry \tparam_geometry
  142. \ingroup core
  143. \qbk{[include reference/core/closure.qbk]}
  144. */
  145. template <typename Geometry>
  146. struct closure
  147. {
  148. static const closure_selector value = core_dispatch::closure
  149. <
  150. typename tag<Geometry>::type,
  151. typename util::bare_type<Geometry>::type
  152. >::value;
  153. };
  154. }} // namespace boost::geometry
  155. #endif // BOOST_GEOMETRY_CORE_CLOSURE_HPP