polygon_90_with_holes_data.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. Copyright 2008 Intel Corporation
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. */
  7. #ifndef BOOST_POLYGON_POLYGON_90_WITH_HOLES_DATA_HPP
  8. #define BOOST_POLYGON_POLYGON_90_WITH_HOLES_DATA_HPP
  9. namespace boost { namespace polygon{
  10. #include "isotropy.hpp"
  11. #include "polygon_90_data.hpp"
  12. struct polygon_90_with_holes_concept;
  13. template <typename T>
  14. class polygon_90_with_holes_data {
  15. public:
  16. typedef polygon_90_with_holes_concept geometry_type;
  17. typedef T coordinate_type;
  18. typedef typename polygon_90_data<T>::iterator_type iterator_type;
  19. typedef typename polygon_90_data<T>::compact_iterator_type compact_iterator_type;
  20. typedef typename std::list<polygon_90_data<coordinate_type> >::const_iterator iterator_holes_type;
  21. typedef polygon_90_data<coordinate_type> hole_type;
  22. typedef typename coordinate_traits<T>::area_type area_type;
  23. typedef point_data<T> point_type;
  24. // default constructor of point does not initialize x and y
  25. inline polygon_90_with_holes_data() : self_(), holes_() {} //do nothing default constructor
  26. // initialize a polygon from x,y values, it is assumed that the first is an x
  27. // and that the input is a well behaved polygon
  28. template<class iT>
  29. inline polygon_90_with_holes_data& set(iT input_begin, iT input_end) {
  30. self_.set(input_begin, input_end);
  31. return *this;
  32. }
  33. // initialize a polygon from x,y values, it is assumed that the first is an x
  34. // and that the input is a well behaved polygon
  35. template<class iT>
  36. inline polygon_90_with_holes_data& set_compact(iT input_begin, iT input_end) {
  37. self_.set_compact(input_begin, input_end);
  38. return *this;
  39. }
  40. // initialize a polygon from x,y values, it is assumed that the first is an x
  41. // and that the input is a well behaved polygon
  42. template<class iT>
  43. inline polygon_90_with_holes_data& set_holes(iT input_begin, iT input_end) {
  44. holes_.clear(); //just in case there was some old data there
  45. for( ; input_begin != input_end; ++ input_begin) {
  46. holes_.push_back(hole_type());
  47. holes_.back().set_compact((*input_begin).begin_compact(), (*input_begin).end_compact());
  48. }
  49. return *this;
  50. }
  51. // copy constructor (since we have dynamic memory)
  52. inline polygon_90_with_holes_data(const polygon_90_with_holes_data& that) : self_(that.self_),
  53. holes_(that.holes_) {}
  54. // assignment operator (since we have dynamic memory do a deep copy)
  55. inline polygon_90_with_holes_data& operator=(const polygon_90_with_holes_data& that) {
  56. self_ = that.self_;
  57. holes_ = that.holes_;
  58. return *this;
  59. }
  60. template <typename T2>
  61. inline polygon_90_with_holes_data& operator=(const T2& rvalue);
  62. // get begin iterator, returns a pointer to a const coordinate_type
  63. inline const iterator_type begin() const {
  64. return self_.begin();
  65. }
  66. // get end iterator, returns a pointer to a const coordinate_type
  67. inline const iterator_type end() const {
  68. return self_.end();
  69. }
  70. // get begin iterator, returns a pointer to a const coordinate_type
  71. inline const compact_iterator_type begin_compact() const {
  72. return self_.begin_compact();
  73. }
  74. // get end iterator, returns a pointer to a const coordinate_type
  75. inline const compact_iterator_type end_compact() const {
  76. return self_.end_compact();
  77. }
  78. inline std::size_t size() const {
  79. return self_.size();
  80. }
  81. // get begin iterator, returns a pointer to a const polygon
  82. inline const iterator_holes_type begin_holes() const {
  83. return holes_.begin();
  84. }
  85. // get end iterator, returns a pointer to a const polygon
  86. inline const iterator_holes_type end_holes() const {
  87. return holes_.end();
  88. }
  89. inline std::size_t size_holes() const {
  90. return holes_.size();
  91. }
  92. private:
  93. polygon_90_data<coordinate_type> self_;
  94. std::list<hole_type> holes_;
  95. };
  96. }
  97. }
  98. #endif