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