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_90_WITH_HOLES_DATA_HPP |
9 | #define BOOST_POLYGON_POLYGON_90_WITH_HOLES_DATA_HPP |
10 | namespace boost { namespace polygon{ |
11 | #include "isotropy.hpp" |
12 | #include "polygon_90_data.hpp" |
13 | struct polygon_90_with_holes_concept; |
14 | template <typename T> |
15 | class polygon_90_with_holes_data { |
16 | public: |
17 | typedef polygon_90_with_holes_concept geometry_type; |
18 | typedef T coordinate_type; |
19 | typedef typename polygon_90_data<T>::iterator_type iterator_type; |
20 | typedef typename polygon_90_data<T>::compact_iterator_type compact_iterator_type; |
21 | typedef typename std::list<polygon_90_data<coordinate_type> >::const_iterator iterator_holes_type; |
22 | typedef polygon_90_data<coordinate_type> hole_type; |
23 | typedef typename coordinate_traits<T>::area_type area_type; |
24 | typedef point_data<T> point_type; |
25 | |
26 | // default constructor of point does not initialize x and y |
27 | inline polygon_90_with_holes_data() : self_(), holes_() {} //do nothing default constructor |
28 | |
29 | // initialize a polygon from x,y values, it is assumed that the first is an x |
30 | // and that the input is a well behaved polygon |
31 | template<class iT> |
32 | inline polygon_90_with_holes_data& set(iT input_begin, iT input_end) { |
33 | self_.set(input_begin, input_end); |
34 | return *this; |
35 | } |
36 | |
37 | // initialize a polygon from x,y values, it is assumed that the first is an x |
38 | // and that the input is a well behaved polygon |
39 | template<class iT> |
40 | inline polygon_90_with_holes_data& set_compact(iT input_begin, iT input_end) { |
41 | self_.set_compact(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> |
48 | inline polygon_90_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_compact((*input_begin).begin_compact(), (*input_begin).end_compact()); |
53 | } |
54 | return *this; |
55 | } |
56 | |
57 | // copy constructor (since we have dynamic memory) |
58 | inline polygon_90_with_holes_data(const polygon_90_with_holes_data& that) : self_(that.self_), |
59 | holes_(that.holes_) {} |
60 | |
61 | // assignment operator (since we have dynamic memory do a deep copy) |
62 | inline polygon_90_with_holes_data& operator=(const polygon_90_with_holes_data& that) { |
63 | self_ = that.self_; |
64 | holes_ = that.holes_; |
65 | return *this; |
66 | } |
67 | |
68 | template <typename T2> |
69 | inline polygon_90_with_holes_data& operator=(const T2& rvalue); |
70 | |
71 | // get begin iterator, returns a pointer to a const coordinate_type |
72 | inline const iterator_type begin() const { |
73 | return self_.begin(); |
74 | } |
75 | |
76 | // get end iterator, returns a pointer to a const coordinate_type |
77 | inline const iterator_type end() const { |
78 | return self_.end(); |
79 | } |
80 | |
81 | // get begin iterator, returns a pointer to a const coordinate_type |
82 | inline const compact_iterator_type begin_compact() const { |
83 | return self_.begin_compact(); |
84 | } |
85 | |
86 | // get end iterator, returns a pointer to a const coordinate_type |
87 | inline const compact_iterator_type end_compact() const { |
88 | return self_.end_compact(); |
89 | } |
90 | |
91 | inline std::size_t size() const { |
92 | return self_.size(); |
93 | } |
94 | |
95 | // get begin iterator, returns a pointer to a const polygon |
96 | inline const iterator_holes_type begin_holes() const { |
97 | return holes_.begin(); |
98 | } |
99 | |
100 | // get end iterator, returns a pointer to a const polygon |
101 | inline const iterator_holes_type end_holes() const { |
102 | return holes_.end(); |
103 | } |
104 | |
105 | inline std::size_t size_holes() const { |
106 | return holes_.size(); |
107 | } |
108 | |
109 | private: |
110 | polygon_90_data<coordinate_type> self_; |
111 | std::list<hole_type> holes_; |
112 | }; |
113 | } |
114 | } |
115 | #endif |
116 | |