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_DATA_HPP
9 #define BOOST_POLYGON_POLYGON_90_DATA_HPP
10 namespace boost { namespace polygon{
11 struct polygon_90_concept;
12 template <typename T>
13 class polygon_90_data {
14 public:
15   typedef polygon_90_concept geometry_type;
16   typedef T coordinate_type;
17   typedef typename std::vector<coordinate_type>::const_iterator compact_iterator_type;
18   typedef iterator_compact_to_points<compact_iterator_type, point_data<coordinate_type> > iterator_type;
19   typedef typename coordinate_traits<T>::area_type area_type;
20 
polygon_90_data()21   inline polygon_90_data() : coords_() {} //do nothing default constructor
22 
23   // initialize a polygon from x,y values, it is assumed that the first is an x
24   // and that the input is a well behaved polygon
25   template<class iT>
set(iT begin_point,iT end_point)26   inline polygon_90_data& set(iT begin_point, iT end_point) {
27     return set_compact(iterator_points_to_compact<iT, typename std::iterator_traits<iT>::value_type>(begin_point, end_point),
28                        iterator_points_to_compact<iT, typename std::iterator_traits<iT>::value_type>(end_point, end_point));
29   }
30 
31   template<class iT>
set_compact(iT input_begin,iT input_end)32   inline polygon_90_data& set_compact(iT input_begin, iT input_end) {
33     coords_.clear();  //just in case there was some old data there
34     while(input_begin != input_end) {
35        coords_.insert(coords_.end(), *input_begin);
36        ++input_begin;
37     }
38     return *this;
39   }
40 
41   // copy constructor (since we have dynamic memory)
polygon_90_data(const polygon_90_data & that)42   inline polygon_90_data(const polygon_90_data& that) : coords_(that.coords_) {}
43 
44   // assignment operator (since we have dynamic memory do a deep copy)
operator =(const polygon_90_data & that)45   inline polygon_90_data& operator=(const polygon_90_data& that) {
46     coords_ = that.coords_;
47     return *this;
48   }
49 
50   template <typename T2>
51   inline polygon_90_data& operator=(const T2& rvalue);
52 
53   // assignment operator (since we have dynamic memory do a deep copy)
operator ==(const polygon_90_data & that) const54   inline bool operator==(const polygon_90_data& that) const {
55     return coords_ == that.coords_;
56   }
57 
58   // get begin iterator, returns a pointer to a const Unit
begin() const59   inline iterator_type begin() const { return iterator_type(coords_.begin(), coords_.end()); }
60 
61   // get end iterator, returns a pointer to a const Unit
end() const62   inline iterator_type end() const { return iterator_type(coords_.end(), coords_.end()); }
63 
64   // get begin iterator, returns a pointer to a const Unit
begin_compact() const65   inline compact_iterator_type begin_compact() const { return coords_.begin(); }
66 
67   // get end iterator, returns a pointer to a const Unit
end_compact() const68   inline compact_iterator_type end_compact() const { return coords_.end(); }
69 
size() const70   inline std::size_t size() const { return coords_.size(); }
71 
72 private:
73   std::vector<coordinate_type> coords_;
74 };
75 
76 
77 }
78 }
79 #endif
80