point_order.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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-2020.
  6. // Modifications copyright (c) 2014-2020 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_POINT_ORDER_HPP
  14. #define BOOST_GEOMETRY_CORE_POINT_ORDER_HPP
  15. #include <boost/range/value_type.hpp>
  16. #include <boost/geometry/core/ring_type.hpp>
  17. #include <boost/geometry/core/static_assert.hpp>
  18. #include <boost/geometry/core/tag.hpp>
  19. #include <boost/geometry/core/tags.hpp>
  20. #include <boost/geometry/util/type_traits_std.hpp>
  21. namespace boost { namespace geometry
  22. {
  23. /*!
  24. \brief Enumerates options for the order of points within polygons
  25. \ingroup enum
  26. \details The enumeration order_selector describes options for the order of
  27. points within a polygon. Polygons can be ordered either clockwise or
  28. counterclockwise. The specific order of a polygon type is defined by the
  29. point_order metafunction. The point_order metafunction defines a value,
  30. which is one of the values enumerated in the order_selector
  31. \qbk{
  32. [heading See also]
  33. [link geometry.reference.core.point_order The point_order metafunction]
  34. }
  35. */
  36. enum order_selector
  37. {
  38. /// Points are ordered clockwise
  39. clockwise = 1,
  40. /// Points are ordered counter clockwise
  41. counterclockwise = 2,
  42. /// Points might be stored in any order, algorithms will determine it on the
  43. /// fly (not yet supported)
  44. order_undetermined = 0
  45. };
  46. namespace traits
  47. {
  48. /*!
  49. \brief Traits class indicating the order of contained points within a
  50. ring or (multi)polygon, clockwise, counter clockwise or not known.
  51. \ingroup traits
  52. \tparam Ring ring
  53. */
  54. template <typename Ring>
  55. struct point_order
  56. {
  57. static const order_selector value = clockwise;
  58. };
  59. } // namespace traits
  60. #ifndef DOXYGEN_NO_DETAIL
  61. namespace detail { namespace point_order
  62. {
  63. struct clockwise
  64. {
  65. static const order_selector value = geometry::clockwise;
  66. };
  67. }} // namespace detail::point_order
  68. #endif // DOXYGEN_NO_DETAIL
  69. #ifndef DOXYGEN_NO_DISPATCH
  70. namespace core_dispatch
  71. {
  72. template <typename Tag, typename Geometry>
  73. struct point_order
  74. {
  75. BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
  76. "Not implemented for this Geometry type.",
  77. Geometry);
  78. };
  79. template <typename Point>
  80. struct point_order<point_tag, Point>
  81. : public detail::point_order::clockwise {};
  82. template <typename Segment>
  83. struct point_order<segment_tag, Segment>
  84. : public detail::point_order::clockwise {};
  85. template <typename Box>
  86. struct point_order<box_tag, Box>
  87. : public detail::point_order::clockwise {};
  88. template <typename LineString>
  89. struct point_order<linestring_tag, LineString>
  90. : public detail::point_order::clockwise {};
  91. template <typename Ring>
  92. struct point_order<ring_tag, Ring>
  93. {
  94. static const order_selector value
  95. = geometry::traits::point_order<Ring>::value;
  96. };
  97. // Specialization for polygon: the order is the order of its rings
  98. template <typename Polygon>
  99. struct point_order<polygon_tag, Polygon>
  100. {
  101. static const order_selector value = core_dispatch::point_order
  102. <
  103. ring_tag,
  104. typename ring_type<polygon_tag, Polygon>::type
  105. >::value ;
  106. };
  107. template <typename MultiPoint>
  108. struct point_order<multi_point_tag, MultiPoint>
  109. : public detail::point_order::clockwise {};
  110. template <typename MultiLinestring>
  111. struct point_order<multi_linestring_tag, MultiLinestring>
  112. : public detail::point_order::clockwise {};
  113. // Specialization for multi_polygon: the order is the order of its polygons
  114. template <typename MultiPolygon>
  115. struct point_order<multi_polygon_tag, MultiPolygon>
  116. {
  117. static const order_selector value = core_dispatch::point_order
  118. <
  119. polygon_tag,
  120. typename boost::range_value<MultiPolygon>::type
  121. >::value ;
  122. };
  123. } // namespace core_dispatch
  124. #endif // DOXYGEN_NO_DISPATCH
  125. /*!
  126. \brief \brief_meta{value, point order (clockwise\, counterclockwise),
  127. \meta_geometry_type}
  128. \tparam Geometry \tparam_geometry
  129. \ingroup core
  130. \qbk{[include reference/core/point_order.qbk]}
  131. */
  132. template <typename Geometry>
  133. struct point_order
  134. {
  135. static const order_selector value = core_dispatch::point_order
  136. <
  137. typename tag<Geometry>::type,
  138. typename util::remove_cptrref<Geometry>::type
  139. >::value;
  140. };
  141. }} // namespace boost::geometry
  142. #endif // BOOST_GEOMETRY_CORE_POINT_ORDER_HPP