polygon_45_with_holes_data.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_45_WITH_HOLES_DATA_HPP
  8. #define BOOST_POLYGON_POLYGON_45_WITH_HOLES_DATA_HPP
  9. #include "isotropy.hpp"
  10. #include "polygon_45_data.hpp"
  11. namespace boost { namespace polygon{
  12. struct polygon_45_with_holes_concept;
  13. template <typename T>
  14. class polygon_45_with_holes_data {
  15. public:
  16. typedef polygon_45_with_holes_concept geometry_type;
  17. typedef T coordinate_type;
  18. typedef typename polygon_45_data<T>::iterator_type iterator_type;
  19. typedef typename std::list<polygon_45_data<coordinate_type> >::const_iterator iterator_holes_type;
  20. typedef polygon_45_data<coordinate_type> hole_type;
  21. typedef typename coordinate_traits<T>::coordinate_distance area_type;
  22. typedef point_data<T> point_type;
  23. // default constructor of point does not initialize x and y
  24. inline polygon_45_with_holes_data() : self_(), holes_() {} //do nothing default constructor
  25. template<class iT>
  26. inline polygon_45_with_holes_data(iT input_begin, iT input_end) : self_(), holes_() {
  27. set(input_begin, input_end);
  28. }
  29. template<class iT, typename hiT>
  30. inline polygon_45_with_holes_data(iT input_begin, iT input_end, hiT holes_begin, hiT holes_end) : self_(), holes_() {
  31. set(input_begin, input_end);
  32. set_holes(holes_begin, holes_end);
  33. }
  34. template<class iT>
  35. inline polygon_45_with_holes_data& set(iT input_begin, iT input_end) {
  36. self_.set(input_begin, input_end);
  37. return *this;
  38. }
  39. // initialize a polygon from x,y values, it is assumed that the first is an x
  40. // and that the input is a well behaved polygon
  41. template<class iT>
  42. inline polygon_45_with_holes_data& set_holes(iT input_begin, iT input_end) {
  43. holes_.clear(); //just in case there was some old data there
  44. for( ; input_begin != input_end; ++ input_begin) {
  45. holes_.push_back(hole_type());
  46. holes_.back().set((*input_begin).begin(), (*input_begin).end());
  47. }
  48. return *this;
  49. }
  50. // copy constructor (since we have dynamic memory)
  51. inline polygon_45_with_holes_data(const polygon_45_with_holes_data& that) : self_(that.self_),
  52. holes_(that.holes_) {}
  53. // assignment operator (since we have dynamic memory do a deep copy)
  54. inline polygon_45_with_holes_data& operator=(const polygon_45_with_holes_data& that) {
  55. self_ = that.self_;
  56. holes_ = that.holes_;
  57. return *this;
  58. }
  59. template <typename T2>
  60. inline polygon_45_with_holes_data& operator=(const T2& rvalue);
  61. // get begin iterator, returns a pointer to a const coordinate_type
  62. inline const iterator_type begin() const {
  63. return self_.begin();
  64. }
  65. // get end iterator, returns a pointer to a const coordinate_type
  66. inline const iterator_type end() const {
  67. return self_.end();
  68. }
  69. inline std::size_t size() const {
  70. return self_.size();
  71. }
  72. // get begin iterator, returns a pointer to a const polygon
  73. inline const iterator_holes_type begin_holes() const {
  74. return holes_.begin();
  75. }
  76. // get end iterator, returns a pointer to a const polygon
  77. inline const iterator_holes_type end_holes() const {
  78. return holes_.end();
  79. }
  80. inline std::size_t size_holes() const {
  81. return holes_.size();
  82. }
  83. public:
  84. polygon_45_data<coordinate_type> self_;
  85. std::list<hole_type> holes_;
  86. };
  87. }
  88. }
  89. #endif