point_order.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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_POINT_ORDER_HPP
  14. #define BOOST_GEOMETRY_CORE_POINT_ORDER_HPP
  15. #include <boost/mpl/assert.hpp>
  16. #include <boost/range/value_type.hpp>
  17. #include <boost/geometry/core/ring_type.hpp>
  18. #include <boost/geometry/core/tag.hpp>
  19. #include <boost/geometry/core/tags.hpp>
  20. #include <boost/geometry/util/bare_type.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_MPL_ASSERT_MSG
  76. (
  77. false, NOT_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
  78. , (types<Geometry>)
  79. );
  80. };
  81. template <typename Point>
  82. struct point_order<point_tag, Point>
  83. : public detail::point_order::clockwise {};
  84. template <typename Segment>
  85. struct point_order<segment_tag, Segment>
  86. : public detail::point_order::clockwise {};
  87. template <typename Box>
  88. struct point_order<box_tag, Box>
  89. : public detail::point_order::clockwise {};
  90. template <typename LineString>
  91. struct point_order<linestring_tag, LineString>
  92. : public detail::point_order::clockwise {};
  93. template <typename Ring>
  94. struct point_order<ring_tag, Ring>
  95. {
  96. static const order_selector value
  97. = geometry::traits::point_order<Ring>::value;
  98. };
  99. // Specialization for polygon: the order is the order of its rings
  100. template <typename Polygon>
  101. struct point_order<polygon_tag, Polygon>
  102. {
  103. static const order_selector value = core_dispatch::point_order
  104. <
  105. ring_tag,
  106. typename ring_type<polygon_tag, Polygon>::type
  107. >::value ;
  108. };
  109. template <typename MultiPoint>
  110. struct point_order<multi_point_tag, MultiPoint>
  111. : public detail::point_order::clockwise {};
  112. template <typename MultiLinestring>
  113. struct point_order<multi_linestring_tag, MultiLinestring>
  114. : public detail::point_order::clockwise {};
  115. // Specialization for multi_polygon: the order is the order of its polygons
  116. template <typename MultiPolygon>
  117. struct point_order<multi_polygon_tag, MultiPolygon>
  118. {
  119. static const order_selector value = core_dispatch::point_order
  120. <
  121. polygon_tag,
  122. typename boost::range_value<MultiPolygon>::type
  123. >::value ;
  124. };
  125. } // namespace core_dispatch
  126. #endif // DOXYGEN_NO_DISPATCH
  127. /*!
  128. \brief \brief_meta{value, point order (clockwise\, counterclockwise),
  129. \meta_geometry_type}
  130. \tparam Geometry \tparam_geometry
  131. \ingroup core
  132. \qbk{[include reference/core/point_order.qbk]}
  133. */
  134. template <typename Geometry>
  135. struct point_order
  136. {
  137. static const order_selector value = core_dispatch::point_order
  138. <
  139. typename tag<Geometry>::type,
  140. typename util::bare_type<Geometry>::type
  141. >::value;
  142. };
  143. }} // namespace boost::geometry
  144. #endif // BOOST_GEOMETRY_CORE_POINT_ORDER_HPP