ring.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. #include <initializer_list>
  23. namespace boost { namespace geometry
  24. {
  25. namespace model
  26. {
  27. /*!
  28. \brief A ring (aka linear ring) is a closed line which should not be selfintersecting
  29. \ingroup geometries
  30. \tparam Point point type
  31. \tparam ClockWise true for clockwise direction,
  32. false for CounterClockWise direction
  33. \tparam Closed true for closed polygons (last point == first point),
  34. false open points
  35. \tparam Container container type, for example std::vector, std::deque
  36. \tparam Allocator container-allocator-type
  37. \qbk{[include reference/geometries/ring.qbk]}
  38. \qbk{before.synopsis,
  39. [heading Model of]
  40. [link geometry.reference.concepts.concept_ring Ring Concept]
  41. }
  42. */
  43. template
  44. <
  45. typename Point,
  46. bool ClockWise = true, bool Closed = true,
  47. template<typename, typename> class Container = std::vector,
  48. template<typename> class Allocator = std::allocator
  49. >
  50. class ring : public Container<Point, Allocator<Point> >
  51. {
  52. BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
  53. typedef Container<Point, Allocator<Point> > base_type;
  54. public :
  55. /// \constructor_default{ring}
  56. inline ring()
  57. : base_type()
  58. {}
  59. /// \constructor_begin_end{ring}
  60. template <typename Iterator>
  61. inline ring(Iterator begin, Iterator end)
  62. : base_type(begin, end)
  63. {}
  64. /// \constructor_initializer_list{ring}
  65. inline ring(std::initializer_list<Point> l)
  66. : base_type(l.begin(), l.end())
  67. {}
  68. // Commented out for now in order to support Boost.Assign
  69. // Without this assignment operator first the object should be created
  70. // from initializer list, then it shoudl be moved.
  71. //// Without this workaround in MSVC the assignment operator is ambiguous
  72. //#ifndef BOOST_MSVC
  73. // /// \assignment_initializer_list{ring}
  74. // inline ring & operator=(std::initializer_list<Point> l)
  75. // {
  76. // base_type::assign(l.begin(), l.end());
  77. // return *this;
  78. // }
  79. //#endif
  80. };
  81. } // namespace model
  82. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  83. namespace traits
  84. {
  85. template
  86. <
  87. typename Point,
  88. bool ClockWise, bool Closed,
  89. template<typename, typename> class Container,
  90. template<typename> class Allocator
  91. >
  92. struct tag<model::ring<Point, ClockWise, Closed, Container, Allocator> >
  93. {
  94. typedef ring_tag type;
  95. };
  96. template
  97. <
  98. typename Point,
  99. bool Closed,
  100. template<typename, typename> class Container,
  101. template<typename> class Allocator
  102. >
  103. struct point_order<model::ring<Point, false, Closed, Container, Allocator> >
  104. {
  105. static const order_selector value = counterclockwise;
  106. };
  107. template
  108. <
  109. typename Point,
  110. bool Closed,
  111. template<typename, typename> class Container,
  112. template<typename> class Allocator
  113. >
  114. struct point_order<model::ring<Point, true, Closed, Container, Allocator> >
  115. {
  116. static const order_selector value = clockwise;
  117. };
  118. template
  119. <
  120. typename Point,
  121. bool PointOrder,
  122. template<typename, typename> class Container,
  123. template<typename> class Allocator
  124. >
  125. struct closure<model::ring<Point, PointOrder, true, Container, Allocator> >
  126. {
  127. static const closure_selector value = closed;
  128. };
  129. template
  130. <
  131. typename Point,
  132. bool PointOrder,
  133. template<typename, typename> class Container,
  134. template<typename> class Allocator
  135. >
  136. struct closure<model::ring<Point, PointOrder, false, Container, Allocator> >
  137. {
  138. static const closure_selector value = open;
  139. };
  140. } // namespace traits
  141. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  142. }} // namespace boost::geometry
  143. #endif // BOOST_GEOMETRY_GEOMETRIES_RING_HPP