closure.hpp 5.8 KB

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