ring.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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) 2014 Adam Wulkiewicz, Lodz, Poland.
  6. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #ifndef BOOST_GEOMETRY_GEOMETRIES_RING_HPP
  12. #define BOOST_GEOMETRY_GEOMETRIES_RING_HPP
  13. #include <memory>
  14. #include <vector>
  15. #include <boost/concept/assert.hpp>
  16. #include <boost/geometry/core/closure.hpp>
  17. #include <boost/geometry/core/point_order.hpp>
  18. #include <boost/geometry/core/tag.hpp>
  19. #include <boost/geometry/core/tags.hpp>
  20. #include <boost/geometry/geometries/concepts/point_concept.hpp>
  21. #include <boost/config.hpp>
  22. #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
  23. #include <initializer_list>
  24. #endif
  25. namespace boost { namespace geometry
  26. {
  27. namespace model
  28. {
  29. /*!
  30. \brief A ring (aka linear ring) is a closed line which should not be selfintersecting
  31. \ingroup geometries
  32. \tparam Point point type
  33. \tparam ClockWise true for clockwise direction,
  34. false for CounterClockWise direction
  35. \tparam Closed true for closed polygons (last point == first point),
  36. false open points
  37. \tparam Container container type, for example std::vector, std::deque
  38. \tparam Allocator container-allocator-type
  39. \qbk{[include reference/geometries/ring.qbk]}
  40. \qbk{before.synopsis,
  41. [heading Model of]
  42. [link geometry.reference.concepts.concept_ring Ring Concept]
  43. }
  44. */
  45. template
  46. <
  47. typename Point,
  48. bool ClockWise = true, bool Closed = true,
  49. template<typename, typename> class Container = std::vector,
  50. template<typename> class Allocator = std::allocator
  51. >
  52. class ring : public Container<Point, Allocator<Point> >
  53. {
  54. BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
  55. typedef Container<Point, Allocator<Point> > base_type;
  56. public :
  57. /// \constructor_default{ring}
  58. inline ring()
  59. : base_type()
  60. {}
  61. /// \constructor_begin_end{ring}
  62. template <typename Iterator>
  63. inline ring(Iterator begin, Iterator end)
  64. : base_type(begin, end)
  65. {}
  66. #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
  67. /// \constructor_initializer_list{ring}
  68. inline ring(std::initializer_list<Point> l)
  69. : base_type(l.begin(), l.end())
  70. {}
  71. // Commented out for now in order to support Boost.Assign
  72. // Without this assignment operator first the object should be created
  73. // from initializer list, then it shoudl be moved.
  74. //// Without this workaround in MSVC the assignment operator is ambiguous
  75. //#ifndef BOOST_MSVC
  76. // /// \assignment_initializer_list{ring}
  77. // inline ring & operator=(std::initializer_list<Point> l)
  78. // {
  79. // base_type::assign(l.begin(), l.end());
  80. // return *this;
  81. // }
  82. //#endif
  83. #endif
  84. };
  85. } // namespace model
  86. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  87. namespace traits
  88. {
  89. template
  90. <
  91. typename Point,
  92. bool ClockWise, bool Closed,
  93. template<typename, typename> class Container,
  94. template<typename> class Allocator
  95. >
  96. struct tag<model::ring<Point, ClockWise, Closed, Container, Allocator> >
  97. {
  98. typedef ring_tag type;
  99. };
  100. template
  101. <
  102. typename Point,
  103. bool Closed,
  104. template<typename, typename> class Container,
  105. template<typename> class Allocator
  106. >
  107. struct point_order<model::ring<Point, false, Closed, Container, Allocator> >
  108. {
  109. static const order_selector value = counterclockwise;
  110. };
  111. template
  112. <
  113. typename Point,
  114. bool Closed,
  115. template<typename, typename> class Container,
  116. template<typename> class Allocator
  117. >
  118. struct point_order<model::ring<Point, true, Closed, Container, Allocator> >
  119. {
  120. static const order_selector value = clockwise;
  121. };
  122. template
  123. <
  124. typename Point,
  125. bool PointOrder,
  126. template<typename, typename> class Container,
  127. template<typename> class Allocator
  128. >
  129. struct closure<model::ring<Point, PointOrder, true, Container, Allocator> >
  130. {
  131. static const closure_selector value = closed;
  132. };
  133. template
  134. <
  135. typename Point,
  136. bool PointOrder,
  137. template<typename, typename> class Container,
  138. template<typename> class Allocator
  139. >
  140. struct closure<model::ring<Point, PointOrder, false, Container, Allocator> >
  141. {
  142. static const closure_selector value = open;
  143. };
  144. } // namespace traits
  145. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  146. }} // namespace boost::geometry
  147. #endif // BOOST_GEOMETRY_GEOMETRIES_RING_HPP